[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.
This commit is contained in:
qdp-odoo
2018-04-13 11:41:34 +02:00
parent 7a1db7e620
commit c58ef14a01
3 changed files with 28 additions and 6 deletions
+5
View File
@@ -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
@@ -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()
@@ -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>