From a9587d0bdbb50df90128c33a76bdf017116c507a Mon Sep 17 00:00:00 2001 From: Olivier Colson Date: Fri, 24 May 2019 11:42:41 +0000 Subject: [PATCH] [IMP] account: use tags on aml for tax adjustment Make use of the new tax model to suppress 'adjustment' type for taxes, and refactor the generic adjustment wizard so that it direcly sets tags on the account move lines generated instead of needing an tax. [IMP] l10n_be: remove taxes of type 'adjustment' closes odoo/odoo#33669 Signed-off-by: Quentin De Paoli (qdp) --- addons/account/models/chart_template.py | 4 +- .../account/wizard/wizard_tax_adjustments.py | 54 ++++++-------- .../wizard/wizard_tax_adjustments_view.xml | 15 ++-- .../data/account_tax_template_data.xml | 70 ------------------- doc/webservices/localization.rst | 1 - 5 files changed, 28 insertions(+), 116 deletions(-) diff --git a/addons/account/models/chart_template.py b/addons/account/models/chart_template.py index 09d85002816..bcd8d8c8d7b 100644 --- a/addons/account/models/chart_template.py +++ b/addons/account/models/chart_template.py @@ -798,8 +798,8 @@ class AccountTaxTemplate(models.Model): chart_template_id = fields.Many2one('account.chart.template', string='Chart Template', required=True) name = fields.Char(string='Tax Name', required=True) - type_tax_use = fields.Selection([('sale', 'Sales'), ('purchase', 'Purchases'), ('none', 'None'), ('adjustment', 'Adjustment')], string='Tax Scope', required=True, default="sale", - help="Determines where the tax is selectable. Note : 'None' means a tax can't be used by itself, however it can still be used in a group. 'adjustment' is used to perform tax adjustment.") + type_tax_use = fields.Selection([('sale', 'Sales'), ('purchase', 'Purchases'), ('none', 'None')], string='Tax Scope', required=True, default="sale", + help="Determines where the tax is selectable. Note : 'None' means a tax can't be used by itself, however it can still be used in a group.") amount_type = fields.Selection(default='percent', string="Tax Computation", required=True, selection=[('group', 'Group of Taxes'), ('fixed', 'Fixed'), ('percent', 'Percentage of Price'), ('division', 'Percentage of Price Tax Included')]) active = fields.Boolean(default=True, help="Set active to false to hide the tax without removing it.") diff --git a/addons/account/wizard/wizard_tax_adjustments.py b/addons/account/wizard/wizard_tax_adjustments.py index 4dd21030802..736396531fb 100644 --- a/addons/account/wizard/wizard_tax_adjustments.py +++ b/addons/account/wizard/wizard_tax_adjustments.py @@ -18,28 +18,27 @@ class TaxAdjustments(models.TransientModel): debit_account_id = fields.Many2one('account.account', string='Debit account', required=True, domain=[('deprecated', '=', False)]) credit_account_id = fields.Many2one('account.account', string='Credit account', required=True, domain=[('deprecated', '=', False)]) amount = fields.Monetary(currency_field='company_currency_id', required=True) - adjustment_type = fields.Selection([('debit', 'Applied on debit journal item'), ('credit', 'Applied on credit journal item')], string="Adjustment Type", store=False, required=True) - company_currency_id = fields.Many2one('res.currency', readonly=True, default=lambda self: self.env.company.currency_id) - tax_id = fields.Many2one('account.tax', string='Adjustment Tax', ondelete='restrict', domain=[('type_tax_use', '=', 'adjustment')], required=True) + adjustment_type = fields.Selection([('debit', 'Applied on debit journal item'), ('credit', 'Applied on credit journal item')], string="Adjustment Type", required=True) + tax_report_line_id = fields.Many2one(string="Report Line", comodel_name='account.tax.report.line', required=True, help="The report line to make an adjustment for.") + company_currency_id = fields.Many2one('res.currency', readonly=True, default=lambda x: x.env.company_id.currency_id) + country_id = fields.Many2one(string="Country", comodel_name='res.country', readonly=True, default=lambda x: x.env.company_id.country_id) - @api.multi - def _create_move(self): - adjustment_type = self.env.context.get('adjustment_type', (self.amount > 0.0 and 'debit' or 'credit')) + def create_move(self): move_line_vals = [] - is_debit = adjustment_type == 'debit' - for tax_vals in self.tax_id.compute_all(abs(self.amount))['taxes']: - repartition_line = self.env['account.tax.repartition.line'].browse(tax_vals['tax_repartition_line_id']) - # Vals for the amls corresponding to the tax - move_line_vals.append((0, 0, { - 'name': self.reason, - 'debit': is_debit and abs(self.amount) or 0, - 'credit': not is_debit and abs(self.amount) or 0, - 'account_id': is_debit and self.debit_account_id.id or self.credit_account_id.id, - 'tax_repartition_line_id': repartition_line.id, - 'tax_base_amount': tax_vals['base'], - 'tag_ids': [(6, False, repartition_line.tag_ids.ids)], - })) + is_debit = self.adjustment_type == 'debit' + sign_multiplier = (self.amount<0 and -1 or 1) * (self.adjustment_type == 'credit' and -1 or 1) + filter_lambda = (sign_multiplier < 0) and (lambda x: x.tax_negate) or (lambda x: not x.tax_negate) + adjustment_tag = self.tax_report_line_id.tag_ids.filtered(filter_lambda) + + # Vals for the amls corresponding to the ajustment tag + move_line_vals.append((0, 0, { + 'name': self.reason, + 'debit': is_debit and abs(self.amount) or 0, + 'credit': not is_debit and abs(self.amount) or 0, + 'account_id': is_debit and self.debit_account_id.id or self.credit_account_id.id, + 'tag_ids': [(6, False, [adjustment_tag.id])], + })) # Vals for the counterpart line move_line_vals.append((0, 0, { @@ -47,7 +46,6 @@ class TaxAdjustments(models.TransientModel): 'debit': not is_debit and abs(self.amount) or 0, 'credit': is_debit and abs(self.amount) or 0, 'account_id': is_debit and self.credit_account_id.id or self.debit_account_id.id, - 'tax_repartition_line_id': False, })) # Create the move @@ -59,22 +57,10 @@ class TaxAdjustments(models.TransientModel): } move = self.env['account.move'].create(vals) move.post() - return move.id - @api.multi - def create_move_debit(self): - return self.with_context(adjustment_type='debit').create_move() - - @api.multi - def create_move_credit(self): - return self.with_context(adjustment_type='credit').create_move() - - def create_move(self): - #create the adjustment move - move_id = self._create_move() - #return an action showing the created move + # Return an action opening the created move action = self.env.ref(self.env.context.get('action', 'account.action_move_line_form')) result = action.read()[0] result['views'] = [(False, 'form')] - result['res_id'] = move_id + result['res_id'] = move.id return result diff --git a/addons/account/wizard/wizard_tax_adjustments_view.xml b/addons/account/wizard/wizard_tax_adjustments_view.xml index 3295a28f373..8c0bf8f826e 100644 --- a/addons/account/wizard/wizard_tax_adjustments_view.xml +++ b/addons/account/wizard/wizard_tax_adjustments_view.xml @@ -9,13 +9,16 @@

+ + + + - - + @@ -27,14 +30,8 @@
-
-
-
-
diff --git a/addons/l10n_be/data/account_tax_template_data.xml b/addons/l10n_be/data/account_tax_template_data.xml index 70c71a446b2..45268c90b81 100644 --- a/addons/l10n_be/data/account_tax_template_data.xml +++ b/addons/l10n_be/data/account_tax_template_data.xml @@ -3260,74 +3260,4 @@ ]"/> - - 9000 - Régularisation en faveur de l'état - Régularisation en faveur de l'état - - 0.0 - fixed - adjustment - - - - - - - 9010 - Régularisation en faveur du déclarant - Régularisation en faveur du déclarant - - 0.0 - fixed - adjustment - - - - - diff --git a/doc/webservices/localization.rst b/doc/webservices/localization.rst index 238e49788e6..38cb6c0947c 100644 --- a/doc/webservices/localization.rst +++ b/doc/webservices/localization.rst @@ -213,7 +213,6 @@ The only difference being that you must use the ``account.tax.template`` model. ...