From cffe9df2107f6b2aad70a70af9ddc2f4fc68d20a Mon Sep 17 00:00:00 2001 From: Sergi Almacellas Abellana Date: Sun, 11 Oct 2020 23:38:37 +0200 Subject: [PATCH] Add link between IVA and recargo taxes issue9182 review301261002 --- CHANGELOG | 1 + account.py | 59 +++++++++++++++++++++++++++++++++++++- tax.xml | 13 +++------ tax_normal.xml | 13 +++------ tax_pyme.xml | 13 +++------ view/tax_form.xml | 4 ++- view/tax_template_form.xml | 4 ++- 7 files changed, 77 insertions(+), 30 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 0f263e2209..fa7192bca8 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,4 @@ +* Link recargo tax with its related VAT taxes * Add purchase service tax group Version 5.6.0 - 2020-05-04 diff --git a/account.py b/account.py index c2034bd631..dfc38b7711 100644 --- a/account.py +++ b/account.py @@ -1,7 +1,7 @@ # This file is part of Tryton. The COPYRIGHT file at the top level of # this repository contains the full copyright notices and license terms. from trytond.model import fields -from trytond.pool import PoolMeta +from trytond.pool import PoolMeta, Pool from trytond.pyson import Bool, Eval @@ -42,6 +42,7 @@ class TaxTemplate(metaclass=PoolMeta): es_vat_list_code = fields.Char("Spanish VAT List Code") es_ec_purchases_list_code = fields.Char("Spanish EC Purchase List Code") + es_reported_with = fields.Many2One('account.tax.template', "Reported With") def _get_tax_value(self, tax=None): value = super()._get_tax_value(tax=tax) @@ -50,6 +51,29 @@ class TaxTemplate(metaclass=PoolMeta): value[name] = getattr(self, name) return value + @classmethod + def create_tax( + cls, account_id, company_id, template2account, template2tax=None): + pool = Pool() + Tax = pool.get('account.tax') + super().create_tax( + account_id, company_id, template2account, template2tax) + + to_write = [] + + for template_id, tax_id in template2tax.items(): + template = cls(template_id) + if not template.es_reported_with: + continue + reported_with = template2tax[template.es_reported_with.id] + to_write.append([Tax(tax_id)]) + to_write.append({ + 'es_reported_with': reported_with, + }) + + if to_write: + Tax.write(*to_write) + class Tax(metaclass=PoolMeta): __name__ = 'account.tax' @@ -66,3 +90,36 @@ class Tax(metaclass=PoolMeta): & ~Eval('template_override', False)), }, depends=['template', 'template_override']) + es_reported_with = fields.Many2One('account.tax', "Reported with", + states={ + 'readonly': (Bool(Eval('template', -1)) + & ~Eval('template_override', False)), + }, + depends=['template', 'template_override']) + + @classmethod + def update_tax(cls, company_id, template2account, template2tax=None): + super().update_tax(company_id, template2account, template2tax) + + to_write = [] + + for template_id, tax_id in template2tax.items(): + tax = cls(tax_id) + if not tax.template_override: + values = {} + reported_with = (tax.es_reported_with.id + if tax.es_reported_with else None) + if (tax.template.es_reported_with + and reported_with != template2tax.get( + tax.template.es_reported_with.id)): + values['es_reported_with'] = template2tax.get( + tax.template.es_reported_with.id) + elif (not tax.template.es_reported_with + and tax.es_reported_with): + values['es_reported_with'] = None + if values: + to_write.append([tax]) + to_write.append(values) + + if to_write: + cls.write(*to_write) diff --git a/tax.xml b/tax.xml index 8a71db0c35..8747376b5d 100644 --- a/tax.xml +++ b/tax.xml @@ -2,7 +2,7 @@ - + IVA 21% (bienes) IVA 21% @@ -87,6 +87,7 @@ this repository contains the full copyright notices and license terms. --> + Recargo Equivalencia 1.4% @@ -97,6 +98,7 @@ this repository contains the full copyright notices and license terms. --> + Recargo Equivalencia 0.5% @@ -107,6 +109,7 @@ this repository contains the full copyright notices and license terms. --> + IVA Exportaciones (bienes) @@ -433,8 +436,6 @@ this repository contains the full copyright notices and license terms. --> - - IVA Intracomunitario. Bienes (1) IVA Intracomunitario (1) @@ -504,8 +505,6 @@ this repository contains the full copyright notices and license terms. --> - - Impuesto sobre el Valor Añadido - Autoliquidación AEAT303 @@ -1864,8 +1863,6 @@ this repository contains the full copyright notices and license terms. --> tax credit - - Recargo de Equivalencia @@ -1931,8 +1928,6 @@ this repository contains the full copyright notices and license terms. --> purchase - - diff --git a/tax_normal.xml b/tax_normal.xml index a21758c0a6..4fdf276c5c 100644 --- a/tax_normal.xml +++ b/tax_normal.xml @@ -2,7 +2,7 @@ - + IVA 21% (bienes) IVA 21% @@ -87,6 +87,7 @@ this repository contains the full copyright notices and license terms. --> + Recargo Equivalencia 1.4% @@ -97,6 +98,7 @@ this repository contains the full copyright notices and license terms. --> + Recargo Equivalencia 0.5% @@ -107,6 +109,7 @@ this repository contains the full copyright notices and license terms. --> + IVA Exportaciones (bienes) @@ -433,8 +436,6 @@ this repository contains the full copyright notices and license terms. --> - - IVA Intracomunitario. Bienes (1) IVA Intracomunitario (1) @@ -504,8 +505,6 @@ this repository contains the full copyright notices and license terms. --> - - Impuesto sobre el Valor Añadido - Autoliquidación AEAT303 @@ -1864,8 +1863,6 @@ this repository contains the full copyright notices and license terms. --> tax credit - - Recargo de Equivalencia @@ -1931,8 +1928,6 @@ this repository contains the full copyright notices and license terms. --> purchase - - diff --git a/tax_pyme.xml b/tax_pyme.xml index 07852a8c92..4e678478dc 100644 --- a/tax_pyme.xml +++ b/tax_pyme.xml @@ -2,7 +2,7 @@ - + IVA 21% (bienes) IVA 21% @@ -87,6 +87,7 @@ this repository contains the full copyright notices and license terms. --> + Recargo Equivalencia 1.4% @@ -97,6 +98,7 @@ this repository contains the full copyright notices and license terms. --> + Recargo Equivalencia 0.5% @@ -107,6 +109,7 @@ this repository contains the full copyright notices and license terms. --> + IVA Exportaciones (bienes) @@ -433,8 +436,6 @@ this repository contains the full copyright notices and license terms. --> - - IVA Intracomunitario. Bienes (1) IVA Intracomunitario (1) @@ -504,8 +505,6 @@ this repository contains the full copyright notices and license terms. --> - - Impuesto sobre el Valor Añadido - Autoliquidación AEAT303 @@ -1864,8 +1863,6 @@ this repository contains the full copyright notices and license terms. --> tax credit - - Recargo de Equivalencia @@ -1931,8 +1928,6 @@ this repository contains the full copyright notices and license terms. --> purchase - - diff --git a/view/tax_form.xml b/view/tax_form.xml index 668caf504d..0ea48f5556 100644 --- a/view/tax_form.xml +++ b/view/tax_form.xml @@ -3,9 +3,11 @@ this repository contains the full copyright notices and license terms. --> - + diff --git a/view/tax_template_form.xml b/view/tax_template_form.xml index 668caf504d..0ea48f5556 100644 --- a/view/tax_template_form.xml +++ b/view/tax_template_form.xml @@ -3,9 +3,11 @@ this repository contains the full copyright notices and license terms. --> - +