Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FW][FIX] account: quick edit analytic distribution posted line #147195

Open
wants to merge 1 commit into
base: 17.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion addons/account/models/account_move_line.py
Expand Up @@ -944,7 +944,7 @@ def _compute_all_tax(self):
'group_tax_id': tax['group'] and tax['group'].id or False,
'account_id': tax['account_id'] or line.account_id.id,
'currency_id': line.currency_id.id,
'analytic_distribution': (tax['analytic'] or not tax['use_in_tax_closing']) and line.analytic_distribution,
'analytic_distribution': ((tax['analytic'] or not tax['use_in_tax_closing']) and line.move_id.state == 'draft') and line.analytic_distribution,
'tax_ids': [(6, 0, tax['tax_ids'])],
'tax_tag_ids': [(6, 0, tax['tag_ids'])],
'partner_id': line.move_id.partner_id.id or line.partner_id.id,
Expand Down
56 changes: 54 additions & 2 deletions addons/account/tests/test_account_analytic.py
Expand Up @@ -29,9 +29,9 @@ def setUpClass(cls, chart_template_ref=None):
'company_id': False,
})

def create_invoice(self, partner, product):
def create_invoice(self, partner, product, move_type='out_invoice'):
return self.env['account.move'].create([{
'move_type': 'out_invoice',
'move_type': move_type,
'partner_id': partner.id,
'date': '2017-01-01',
'invoice_date': '2017-01-01',
Expand Down Expand Up @@ -210,3 +210,55 @@ def test_mandatory_plan_validation(self):
invoice.invoice_line_ids.analytic_distribution = {self.analytic_account_b.id: 0.9}
invoice.action_post()
self.assertEqual(invoice.state, 'posted')

def test_set_anaylytic_distribution_posted_line(self):
"""
Test that we can set the analytic distribution on the product line of a move, when the line has tax with
repartition lines used in tax closing. Although the change can not be applied on the tax line, we should
not raise any error.
"""
tax = self.tax_purchase_a.copy({
'name': 'taXXX',
'invoice_repartition_line_ids': [
Command.create({
'repartition_type': 'base',
'use_in_tax_closing': False,
}),
Command.create({
'repartition_type': 'tax',
'factor_percent': 50,
'use_in_tax_closing': False,
}),
Command.create({
'repartition_type': 'tax',
'factor_percent': 50,
'account_id': self.company_data['default_account_tax_purchase'].id,
'use_in_tax_closing': True,
}),
],
'refund_repartition_line_ids': [
Command.create({
'repartition_type': 'base',
'use_in_tax_closing': False,
}),
Command.create({
'repartition_type': 'tax',
'factor_percent': 50,
'use_in_tax_closing': False,
}),
Command.create({
'repartition_type': 'tax',
'factor_percent': 50,
'account_id': self.company_data['default_account_tax_purchase'].id,
'use_in_tax_closing': True,
}),
],
})

bill = self.create_invoice(self.partner_a, self.product_a, move_type='in_invoice')
bill.invoice_line_ids.tax_ids = [Command.set(tax.ids)]
bill.action_post()

line = bill.line_ids.filtered(lambda l: l.display_type == 'product')
line.write({'analytic_distribution': {self.analytic_account_a.id: 100}})
self.assertEqual(line.analytic_distribution, {str(self.analytic_account_a.id): 100})