From 3e36feb09fb9dc69b4b20950187aeb86528abd9c Mon Sep 17 00:00:00 2001 From: "Benjamin Frantzen (bfr)" Date: Wed, 11 Mar 2020 08:36:44 +0000 Subject: [PATCH] [IMP]account: allow excluding some tax repartition lines from the tax closing entry TASK ID : 2212170 closes odoo/odoo#47979 Related: odoo/enterprise#9356 Related: odoo/upgrade#999 Signed-off-by: oco-odoo --- addons/account/models/account.py | 8 ++++++++ addons/account/models/chart_template.py | 12 +++++++++++- addons/account/views/account_view.xml | 1 + 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/addons/account/models/account.py b/addons/account/models/account.py index e999cae4bc3..c8365d3f535 100644 --- a/addons/account/models/account.py +++ b/addons/account/models/account.py @@ -2004,6 +2004,14 @@ class AccountTaxRepartitionLine(models.Model): country_id = fields.Many2one(string="Country", comodel_name='res.country', related='company_id.country_id', help="Technical field used to restrict tags domain in form view.") company_id = fields.Many2one(string="Company", comodel_name='res.company', compute="_compute_company", store=True, help="The company this repartition line belongs to.") sequence = fields.Integer(string="Sequence", default=1, help="The order in which display and match repartition lines. For refunds to work properly, invoice repartition lines should be arranged in the same order as the credit note repartition lines they correspond to.") + use_in_tax_closing = fields.Boolean(string="Tax Closing Entry") + + @api.onchange('account_id') + def _on_change_account_id(self): + if not self.account_id: + self.use_in_tax_closing = False + else: + self.use_in_tax_closing = not(self.account_id.internal_group == 'income' or self.account_id.internal_group == 'expense') @api.constrains('invoice_tax_id', 'refund_tax_id') def validate_tax_template_link(self): diff --git a/addons/account/models/chart_template.py b/addons/account/models/chart_template.py index c0558d962d7..d004a02235e 100644 --- a/addons/account/models/chart_template.py +++ b/addons/account/models/chart_template.py @@ -983,6 +983,7 @@ class AccountTaxTemplate(models.Model): # Tax Repartition Line Template + class AccountTaxRepartitionLineTemplate(models.Model): _name = "account.tax.repartition.line.template" _description = "Tax Repartition Line Template" @@ -993,6 +994,7 @@ class AccountTaxRepartitionLineTemplate(models.Model): invoice_tax_id = fields.Many2one(comodel_name='account.tax.template', help="The tax set to apply this repartition on invoices. Mutually exclusive with refund_tax_id") refund_tax_id = fields.Many2one(comodel_name='account.tax.template', help="The tax set to apply this repartition on refund invoices. Mutually exclusive with invoice_tax_id") tag_ids = fields.Many2many(string="Financial Tags", relation='account_tax_repartition_financial_tags', comodel_name='account.account.tag', copy=True, help="Additional tags that will be assigned by this repartition line for use in financial reports") + use_in_tax_closing = fields.Boolean(string="Tax Closing Entry") # These last two fields are helpers used to ease the declaration of account.account.tag objects in XML. # They are directly linked to account.tax.report.line objects, which create corresponding + and - tags @@ -1003,7 +1005,7 @@ class AccountTaxRepartitionLineTemplate(models.Model): @api.model def create(self, vals): if vals.get('plus_report_line_ids'): - vals['plus_report_line_ids'] = self._convert_tag_syntax_to_orm(vals['plus_report_line_ids']) + vals['plus_report_line_ids'] = self._convert_tag_syntax_to_orm(vals['plus_report_line_ids']) if vals.get('minus_report_line_ids'): vals['minus_report_line_ids'] = self._convert_tag_syntax_to_orm(vals['minus_report_line_ids']) @@ -1011,6 +1013,13 @@ class AccountTaxRepartitionLineTemplate(models.Model): if vals.get('tag_ids'): vals['tag_ids'] = self._convert_tag_syntax_to_orm(vals['tag_ids']) + if vals.get('use_in_tax_closing') is None: + if not vals.get('account_id'): + vals['use_in_tax_closing'] = False + else: + internal_group = self.env['account.account.template'].browse(vals.get('account_id')).user_type_id.internal_group + vals['use_in_tax_closing'] = not (internal_group == 'income' or internal_group == 'expense') + return super(AccountTaxRepartitionLineTemplate, self).create(vals) @api.model @@ -1051,6 +1060,7 @@ class AccountTaxRepartitionLineTemplate(models.Model): 'repartition_type': record.repartition_type, 'tag_ids': [(6, 0, tags_to_add.ids)], 'company_id': company.id, + 'use_in_tax_closing': record.use_in_tax_closing })) return rslt diff --git a/addons/account/views/account_view.xml b/addons/account/views/account_view.xml index 60e322adff6..9efba01c734 100644 --- a/addons/account/views/account_view.xml +++ b/addons/account/views/account_view.xml @@ -1078,6 +1078,7 @@ action = model.setting_init_bank_account_action() +