From c58ef14a01f600d75391f2a9c38bb2b30e0e2528 Mon Sep 17 00:00:00 2001 From: qdp-odoo <qdp@odoo.com> Date: Fri, 13 Apr 2018 11:41:29 +0200 Subject: [PATCH] [FIX] account: tax adjustment wizard fixed. The former version of the tax adjustment wizard was copying the selected tax on both the credit and debit line of the created journal entry. Although it was fine for the belgian use case (since the report was taking only the sum.debit or sum.credit to gather data for grid 61/62), this was a stupid limitation as it was preventing to use that wizard to touch any grid using sum.balance (as both lines would be taken into account and cancelling each other). To enhance/fix this, we introduce a fields.selection in the wizard to depict if the tax needs to be copied on the debit OR the credit line. Inspired by ticket 1826242. --- addons/account/i18n/account.pot | 5 +++++ addons/account/wizard/wizard_tax_adjustments.py | 17 +++++++++++++---- .../wizard/wizard_tax_adjustments_view.xml | 12 ++++++++++-- 3 files changed, 28 insertions(+), 6 deletions(-) diff --git a/addons/account/i18n/account.pot b/addons/account/i18n/account.pot index e899b46b5afb..8b3c1c4f6cc5 100644 --- a/addons/account/i18n/account.pot +++ b/addons/account/i18n/account.pot @@ -1330,6 +1330,11 @@ msgstr "" msgid "Adjustment Tax" msgstr "" +#. module: account +#: model:ir.model.fields,field_description:account.field_tax_adjustments_wizard_adjustment_type +msgid "Adjustment Type" +msgstr "" + #. module: account #: model:ir.ui.view,arch_db:account.view_account_tax_template_form #: model:ir.ui.view,arch_db:account.view_tax_form diff --git a/addons/account/wizard/wizard_tax_adjustments.py b/addons/account/wizard/wizard_tax_adjustments.py index 8c5002347c01..22d2235ef04f 100644 --- a/addons/account/wizard/wizard_tax_adjustments.py +++ b/addons/account/wizard/wizard_tax_adjustments.py @@ -18,24 +18,26 @@ 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', 'Adjustment in favor of the Estate'), ('credit', 'Adjustment in your favor')], string="Adjustment Type", store=False, required=True) company_currency_id = fields.Many2one('res.currency', readonly=True, default=lambda self: self.env.user.company_id.currency_id) tax_id = fields.Many2one('account.tax', string='Adjustment Tax', ondelete='restrict', domain=[('type_tax_use', '=', 'none'), ('tax_adjustment', '=', True)], required=True) @api.multi def _create_move(self): + adjustment_type = self.env.context.get('adjustment_type', (self.amount > 0.0 and 'debit' or 'credit')) debit_vals = { 'name': self.reason, - 'debit': self.amount, + 'debit': abs(self.amount), 'credit': 0.0, 'account_id': self.debit_account_id.id, - 'tax_line_id': self.tax_id.id, + 'tax_line_id': adjustment_type == 'debit' and self.tax_id.id or False, } credit_vals = { 'name': self.reason, 'debit': 0.0, - 'credit': self.amount, + 'credit': abs(self.amount), 'account_id': self.credit_account_id.id, - 'tax_line_id': self.tax_id.id, + 'tax_line_id': adjustment_type == 'credit' and self.tax_id.id or False, } vals = { 'journal_id': self.journal_id.id, @@ -48,6 +50,13 @@ class TaxAdjustments(models.TransientModel): 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() diff --git a/addons/account/wizard/wizard_tax_adjustments_view.xml b/addons/account/wizard/wizard_tax_adjustments_view.xml index 8a2b22e65445..ef75999ba4dd 100644 --- a/addons/account/wizard/wizard_tax_adjustments_view.xml +++ b/addons/account/wizard/wizard_tax_adjustments_view.xml @@ -12,6 +12,7 @@ <group> <group> <field name="amount"/> + <field name="adjustment_type"/> </group> <group> <field name="tax_id" widget="selection"/> @@ -26,9 +27,16 @@ </group> </group> <footer> - <button name="create_move" string="Create and post move" type="object" default_focus="1" class="oe_highlight"/> - or + <div attrs="{'invisible': [('adjustment_type', '=', 'credit')]}"> + <button name="create_move_debit" string="Create and post move" type="object" default_focus="1" class="oe_highlight"/> + or <button string="Cancel" class="oe_link" special="cancel" /> + </div> + <div attrs="{'invisible': [('adjustment_type', '!=', 'credit')]}"> + <button name="create_move_credit" string="Create and post move" type="object" default_focus="1" class="oe_highlight"/> + or + <button string="Cancel" class="oe_link" special="cancel" /> + </div> </footer> </form> </field> -- GitLab