[FIX] account: Fix tax lines generation with analytic
The analytic account/tags must be set on taxes only when the 'analytic' box is ticked. closes odoo/odoo#39088 --task: 2089557 X-original-commit: 0ed224048d2d5f7e6c37af42fb8865237b874b94 Signed-off-by: Quentin De Paoli (qdp) <qdp@openerp.com>
This commit is contained in:
@@ -411,8 +411,8 @@ class AccountMove(models.Model):
|
||||
'tax_repartition_line_id': tax_vals['tax_repartition_line_id'],
|
||||
'account_id': account.id,
|
||||
'currency_id': base_line.currency_id.id,
|
||||
'analytic_tag_ids': [(6, 0, base_line.analytic_tag_ids.ids)],
|
||||
'analytic_account_id': base_line.analytic_account_id.id,
|
||||
'analytic_tag_ids': [(6, 0, tax_vals['analytic'] and base_line.analytic_tag_ids.ids or [])],
|
||||
'analytic_account_id': tax_vals['analytic'] and base_line.analytic_account_id.id,
|
||||
'tax_ids': [(6, 0, tax_vals['tax_ids'])],
|
||||
'tag_ids': [(6, 0, tax_vals['tag_ids'])],
|
||||
}
|
||||
|
||||
@@ -522,6 +522,148 @@ class TestAccountMoveOutInvoiceOnchanges(InvoiceTestCommon):
|
||||
'amount_total': 1730.0,
|
||||
})
|
||||
|
||||
def test_out_invoice_line_onchange_analytic(self):
|
||||
self.env.user.groups_id += self.env.ref('analytic.group_analytic_accounting')
|
||||
self.env.user.groups_id += self.env.ref('analytic.group_analytic_tags')
|
||||
|
||||
analytic_tag = self.env['account.analytic.tag'].create({
|
||||
'name': 'test_analytic_tag',
|
||||
})
|
||||
|
||||
analytic_account = self.env['account.analytic.account'].create({
|
||||
'name': 'test_analytic_account',
|
||||
'partner_id': self.invoice.partner_id.id,
|
||||
'code': 'TEST'
|
||||
})
|
||||
|
||||
move_form = Form(self.invoice)
|
||||
with move_form.invoice_line_ids.edit(0) as line_form:
|
||||
line_form.analytic_account_id = analytic_account
|
||||
line_form.analytic_tag_ids.add(analytic_tag)
|
||||
move_form.save()
|
||||
|
||||
# The tax is not flagged as an analytic one. It should change nothing on the taxes.
|
||||
self.assertInvoiceValues(self.invoice, [
|
||||
{
|
||||
**self.product_line_vals_1,
|
||||
'analytic_account_id': analytic_account.id,
|
||||
'analytic_tag_ids': analytic_tag.ids,
|
||||
},
|
||||
{
|
||||
**self.product_line_vals_2,
|
||||
'analytic_account_id': False,
|
||||
'analytic_tag_ids': [],
|
||||
},
|
||||
{
|
||||
**self.tax_line_vals_1,
|
||||
'analytic_account_id': False,
|
||||
'analytic_tag_ids': [],
|
||||
},
|
||||
{
|
||||
**self.tax_line_vals_2,
|
||||
'analytic_account_id': False,
|
||||
'analytic_tag_ids': [],
|
||||
},
|
||||
{
|
||||
**self.term_line_vals_1,
|
||||
'analytic_account_id': False,
|
||||
'analytic_tag_ids': [],
|
||||
},
|
||||
], self.move_vals)
|
||||
|
||||
move_form = Form(self.invoice)
|
||||
with move_form.invoice_line_ids.edit(0) as line_form:
|
||||
line_form.analytic_account_id = self.env['account.analytic.account']
|
||||
line_form.analytic_tag_ids.clear()
|
||||
move_form.save()
|
||||
|
||||
# Enable the analytic
|
||||
self.tax_sale_a.analytic = True
|
||||
|
||||
move_form = Form(self.invoice)
|
||||
with move_form.invoice_line_ids.edit(0) as line_form:
|
||||
line_form.analytic_account_id = analytic_account
|
||||
line_form.analytic_tag_ids.add(analytic_tag)
|
||||
move_form.save()
|
||||
|
||||
# The tax is flagged as an analytic one.
|
||||
# A new tax line must be generated.
|
||||
self.assertInvoiceValues(self.invoice, [
|
||||
{
|
||||
**self.product_line_vals_1,
|
||||
'analytic_account_id': analytic_account.id,
|
||||
'analytic_tag_ids': analytic_tag.ids,
|
||||
},
|
||||
{
|
||||
**self.product_line_vals_2,
|
||||
'analytic_account_id': False,
|
||||
'analytic_tag_ids': [],
|
||||
},
|
||||
{
|
||||
**self.tax_line_vals_1,
|
||||
'price_unit': 150.0,
|
||||
'price_subtotal': 150.0,
|
||||
'price_total': 150.0,
|
||||
'credit': 150.0,
|
||||
'analytic_account_id': analytic_account.id,
|
||||
'analytic_tag_ids': analytic_tag.ids,
|
||||
},
|
||||
{
|
||||
**self.tax_line_vals_1,
|
||||
'price_unit': 30.0,
|
||||
'price_subtotal': 30.0,
|
||||
'price_total': 30.0,
|
||||
'credit': 30.0,
|
||||
'analytic_account_id': False,
|
||||
'analytic_tag_ids': [],
|
||||
},
|
||||
{
|
||||
**self.tax_line_vals_2,
|
||||
'analytic_account_id': False,
|
||||
'analytic_tag_ids': [],
|
||||
},
|
||||
{
|
||||
**self.term_line_vals_1,
|
||||
'analytic_account_id': False,
|
||||
'analytic_tag_ids': [],
|
||||
},
|
||||
], self.move_vals)
|
||||
|
||||
move_form = Form(self.invoice)
|
||||
with move_form.invoice_line_ids.edit(0) as line_form:
|
||||
line_form.analytic_account_id = self.env['account.analytic.account']
|
||||
line_form.analytic_tag_ids.clear()
|
||||
move_form.save()
|
||||
|
||||
# The tax line has been removed.
|
||||
self.assertInvoiceValues(self.invoice, [
|
||||
{
|
||||
**self.product_line_vals_1,
|
||||
'analytic_account_id': False,
|
||||
'analytic_tag_ids': [],
|
||||
},
|
||||
{
|
||||
**self.product_line_vals_2,
|
||||
'analytic_account_id': False,
|
||||
'analytic_tag_ids': [],
|
||||
},
|
||||
{
|
||||
**self.tax_line_vals_1,
|
||||
'analytic_account_id': False,
|
||||
'analytic_tag_ids': [],
|
||||
},
|
||||
{
|
||||
**self.tax_line_vals_2,
|
||||
'analytic_account_id': False,
|
||||
'analytic_tag_ids': [],
|
||||
},
|
||||
{
|
||||
**self.term_line_vals_1,
|
||||
'analytic_account_id': False,
|
||||
'analytic_tag_ids': [],
|
||||
},
|
||||
], self.move_vals)
|
||||
|
||||
def test_out_invoice_line_onchange_cash_rounding_1(self):
|
||||
move_form = Form(self.invoice)
|
||||
# Add a cash rounding having 'add_invoice_line'.
|
||||
|
||||
Reference in New Issue
Block a user