-
Notifications
You must be signed in to change notification settings - Fork 1
/
account.py
143 lines (128 loc) · 4.91 KB
/
account.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
# -*- coding: utf-8 -*-
from openerp import models, fields, api
class sii_document_class(models.Model):
_inherit = 'sii.document_class'
amount_untaxed = fields.Float(
string='Untaxed',
compute='_get_amounts',)
amount_tax = fields.Float(
string='Tax',
compute='_get_amounts',)
amount_total = fields.Float(
string='total',
compute='_get_amounts',)
@api.one
def _get_amounts(self):
"""
"""
amount_untaxed = False
amount_tax = False
amount_total = False
vat_ledger_id = self._context.get('vat_ledger_id', False)
if vat_ledger_id:
vat_ledger = self.env['account.vat.ledger'].browse(vat_ledger_id)
(amount_untaxed, amount_tax, amount_total) = self.get_amounts(
vat_ledger)
self.amount_untaxed = amount_untaxed
self.amount_tax = amount_tax
self.amount_total = amount_total
@api.model
def get_amounts(self, vat_ledger):
domain = [
('state', 'not in', ['draft', 'cancel']),
('sii_document_class_id', '=', self.id),
('journal_id', 'in', vat_ledger.journal_ids.ids),
('period_id', '=', vat_ledger.period_id.id)
]
invoices = self.env['account.invoice'].search(domain)
amount_untaxed = sum([x.amount_untaxed for x in invoices])
amount_tax = sum([x.amount_tax for x in invoices])
amount_total = sum([x.amount_total for x in invoices])
if self.document_type == 'credit_note':
amount_untaxed = -amount_untaxed
amount_tax = -amount_tax
amount_total = -amount_total
return (amount_untaxed, amount_tax, amount_total)
class account_tax_code(models.Model):
_inherit = 'account.tax.code'
amount_untaxed = fields.Float(
string='Untaxed',
compute='_get_amounts',)
amount_tax = fields.Float(
string='Tax',
compute='_get_amounts',)
amount_total = fields.Float(
string='total',
compute='_get_amounts',)
@api.one
def _get_amounts(self):
"""
"""
amount_untaxed = False
amount_tax = False
vat_ledger_id = self._context.get('vat_ledger_id', False)
if vat_ledger_id:
vat_ledger = self.env['account.vat.ledger'].browse(vat_ledger_id)
(amount_untaxed, amount_tax, amount_total) = self.get_amounts(
vat_ledger)
self.amount_untaxed = amount_untaxed
self.amount_tax = amount_tax
self.amount_total = amount_total
@api.model
def get_amounts(
self, vat_ledger, responsability=False, journal_type=None):
taxes_domain = [
('invoice_id', 'in', vat_ledger.invoice_ids.ids),
('tax_code_id.id', '=', self.id)]
# ('tax_code_id.parent_id.name', '=', 'IVA')]
if journal_type:
taxes_domain.append(
('invoice_id.journal_id.type', 'in', journal_type))
if responsability:
taxes_domain.append(
('invoice_id.responsability_id', '=', responsability.id))
invoice_taxes = self.env['account.invoice.tax'].search(
taxes_domain)
amount_untaxed = sum([x.base for x in invoice_taxes])
amount_tax = sum([x.tax_amount for x in invoice_taxes])
amount_total = amount_untaxed + amount_tax
return (amount_untaxed, amount_tax, amount_total)
class sii_responsability(models.Model):
_inherit = 'sii.responsability'
amount_untaxed = fields.Float(
string='Untaxed',
compute='_get_amounts',)
amount_tax = fields.Float(
string='Tax',
compute='_get_amounts',)
amount_total = fields.Float(
string='total',
compute='_get_amounts',)
@api.one
def _get_amounts(self):
"""
"""
amount_untaxed = False
amount_tax = False
amount_total = False
vat_ledger_id = self._context.get('vat_ledger_id', False)
if vat_ledger_id:
vat_ledger = self.env['account.vat.ledger'].browse(vat_ledger_id)
(amount_untaxed, amount_tax, amount_total) = self.get_amounts(
vat_ledger)
self.amount_untaxed = amount_untaxed
self.amount_tax = amount_tax
self.amount_total = amount_total
@api.model
def get_amounts(self, vat_ledger, tax_code=False):
domain = [
('state', 'not in', ['draft', 'cancel']),
('responsability_id', '=', self.id),
('journal_id', 'in', vat_ledger.journal_ids.ids),
('period_id', '=', vat_ledger.period_id.id)
]
invoices = self.env['account.invoice'].search(domain)
amount_untaxed = sum([x.amount_untaxed for x in invoices])
amount_tax = sum([x.amount_tax for x in invoices])
amount_total = sum([x.amount_total for x in invoices])
return (amount_untaxed, amount_tax, amount_total)