mirror of
https://gitlab.com/datalifeit/trytond-aeat_sii
synced 2023-12-13 20:30:37 +01:00
Update the way that tax and total amount are calculated trying to control all the possibles combinations
This commit is contained in:
parent
0c703b4427
commit
99be12ccc4
4 changed files with 3943 additions and 73 deletions
|
@ -25,6 +25,8 @@ class TemplateTax:
|
|||
'Intracommunity Key')
|
||||
sii_subjected_key = fields.Selection(IVA_SUBJECTED, 'Subjected Key')
|
||||
sii_excemption_key = fields.Selection(EXCEMPTION_CAUSE, 'Excemption Key')
|
||||
tax_used = fields.Boolean('Used in Tax')
|
||||
invoice_used = fields.Boolean('Used in invoice Total')
|
||||
|
||||
def _get_tax_value(self, tax=None):
|
||||
res = super(TemplateTax, self)._get_tax_value(tax)
|
||||
|
@ -50,3 +52,5 @@ class Tax:
|
|||
'Intracommunity Key')
|
||||
sii_subjected_key = fields.Selection(IVA_SUBJECTED, 'Subjected Key')
|
||||
sii_excemption_key = fields.Selection(EXCEMPTION_CAUSE, 'Excemption Key')
|
||||
tax_used = fields.Boolean('Used in Tax')
|
||||
invoice_used = fields.Boolean('Used in invoice Total')
|
||||
|
|
|
@ -20,23 +20,7 @@ __all__ = [
|
|||
_logger = getLogger(__name__)
|
||||
|
||||
|
||||
# Only for 3.4 and 3.8 version
|
||||
def _amount_getter(field_name):
|
||||
def amount_getter(self, field):
|
||||
pool = Pool()
|
||||
InvoiceTax = pool.get('account.invoice.tax')
|
||||
if isinstance(field, InvoiceTax):
|
||||
invoice = field.invoice
|
||||
else:
|
||||
invoice = field
|
||||
val = attrgetter(field_name)(field)
|
||||
credit_note = invoice.type in ('in_credit_note', 'out_credit_note')
|
||||
return val if val is None or not credit_note else -val
|
||||
return amount_getter
|
||||
|
||||
|
||||
class BaseTrytonInvoiceMapper(Model):
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(BaseTrytonInvoiceMapper, self).__init__(*args, **kwargs)
|
||||
self.pool = Pool()
|
||||
|
@ -51,29 +35,42 @@ class BaseTrytonInvoiceMapper(Model):
|
|||
exempt_kind = attrgetter('sii_excemption_key')
|
||||
counterpart_nif = attrgetter('party.vat_number')
|
||||
|
||||
def get_untaxed_amount(self, invoice):
|
||||
taxes = self.taxes(invoice)
|
||||
untaxed = 0
|
||||
for tax in taxes:
|
||||
untaxed += _amount_getter('company_base')
|
||||
return untaxed
|
||||
def get_tax_amount(self, tax):
|
||||
invoice = tax.invoice
|
||||
val = attrgetter('company_amount')(tax)
|
||||
credit_note = invoice.type in ('in_credit_note', 'out_credit_note')
|
||||
return val if val is None or not credit_note else -val
|
||||
|
||||
def get_total_amount(self, invoice):
|
||||
def get_tax_base(self, tax):
|
||||
invoice = tax.invoice
|
||||
val = attrgetter('company_base')(tax)
|
||||
credit_note = invoice.type in ('in_credit_note', 'out_credit_note')
|
||||
return val if val is None or not credit_note else -val
|
||||
|
||||
def get_invoice_untaxed(self, invoice):
|
||||
taxes = self.taxes(invoice)
|
||||
total = 0
|
||||
taxes_base = 0
|
||||
for tax in taxes:
|
||||
tax_base = _amount_getter('company_base')
|
||||
tax_amount = _amount_getter('company_amount')
|
||||
total += (tax_base + tax_amount)
|
||||
return total
|
||||
taxes_base += self.get_tax_base(tax)
|
||||
return taxes_base
|
||||
|
||||
def get_invoice_total(self, invoice):
|
||||
taxes = self.total_invoice_taxes(invoice)
|
||||
taxes_base = 0
|
||||
taxes_amount = 0
|
||||
val = attrgetter('company_total_amount')(invoice)
|
||||
for tax in taxes:
|
||||
taxes_base += self.get_tax_base(tax)
|
||||
taxes_amount += self.get_tax_amount(tax)
|
||||
return (taxes_amount + taxes_base)
|
||||
|
||||
counterpart_id_type = attrgetter('party.sii_identifier_type')
|
||||
counterpart_id = counterpart_nif
|
||||
untaxed_amount = get_untaxed_amount
|
||||
total_amount = get_total_amount
|
||||
untaxed_amount = get_invoice_untaxed
|
||||
total_amount = get_invoice_total
|
||||
tax_rate = attrgetter('tax.rate')
|
||||
tax_base = _amount_getter('company_base')
|
||||
tax_amount = _amount_getter('company_amount')
|
||||
tax_base = get_tax_base
|
||||
tax_amount = get_tax_amount
|
||||
|
||||
def counterpart_name(self, invoice):
|
||||
return tools.unaccent(invoice.party.name)
|
||||
|
@ -107,7 +104,16 @@ class BaseTrytonInvoiceMapper(Model):
|
|||
return [
|
||||
invoice_tax for invoice_tax in invoice.taxes
|
||||
if (
|
||||
invoice_tax.tax.sii_subjected_key == 'S1' and
|
||||
invoice_tax.tax.tax_used and
|
||||
not invoice_tax.tax.recargo_equivalencia
|
||||
)
|
||||
]
|
||||
|
||||
def total_invoice_taxes(self, invoice):
|
||||
return [
|
||||
invoice_tax for invoice_tax in invoice.taxes
|
||||
if (
|
||||
invoice_tax.tax.invoice_used and
|
||||
not invoice_tax.tax.recargo_equivalencia
|
||||
)
|
||||
]
|
||||
|
|
|
@ -4,6 +4,10 @@ contains the full copyright notices and license terms. -->
|
|||
<data>
|
||||
<xpath expr="/form/notebook/page[@id="code"]" position="after">
|
||||
<page string="AEAT SII" id="aeatsii">
|
||||
<label name="tax_used"/>
|
||||
<field name="tax_used"/>
|
||||
<label name="invoice_used"/>
|
||||
<field name="invoice_used"/>
|
||||
<label name="sii_book_key"/>
|
||||
<field name="sii_book_key"/>
|
||||
<label name="sii_issued_key"/>
|
||||
|
|
Loading…
Reference in a new issue