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

[16.0][FIX] product_analytic: analytic distribution compute #678

Open
wants to merge 1 commit into
base: 16.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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion product_analytic/models/account_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,12 @@ def _inverse_product_id(self):
return res
for line in self:
inv_type = line.move_id.move_type
if line.product_id and inv_type and inv_type != "entry":
if (
line.product_id
and not line.analytic_distribution
and inv_type
and inv_type != "entry"
):
ana_accounts = (
line.product_id.product_tmpl_id._get_product_analytic_accounts()
)
Expand Down
51 changes: 51 additions & 0 deletions product_analytic/tests/test_account_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,3 +240,54 @@ def test_create_out_category(self):
int(analytic_account_id[0]),
self.analytic_account2.id,
)

def test_create_out_copy(self):
# Create invoice with product default analytic distribution
invoice = self.env["account.move"].create(
[
{
"partner_id": self.partner.id,
"journal_id": self.journal_sale.id,
"move_type": "out_invoice",
"invoice_line_ids": [
Command.create(
{
"name": "Test line",
"quantity": 1,
"price_unit": 50,
"account_id": self.account_out.id,
"product_id": self.product.id,
}
)
],
}
]
)
invoice_line = invoice.invoice_line_ids[0]
analytic_account_id = [key for key in invoice_line.analytic_distribution]
self.assertEqual(
int(analytic_account_id[0]),
self.product.income_analytic_account_id.id,
)
# Modify the analytic distribution
invoice_line.analytic_distribution = {
self.analytic_account2.id: 100,
}
analytic_account_id = [key for key in invoice_line.analytic_distribution]
self.assertEqual(
int(analytic_account_id[0]),
self.analytic_account2.id,
)
# Duplicate the invoice to check the analytic distribution is copied
new_invoice = invoice.copy()
new_invoice_line = new_invoice.invoice_line_ids[0]
analytic_account_id = [key for key in new_invoice_line.analytic_distribution]
self.assertNotEqual(
int(analytic_account_id[0]),
self.product.income_analytic_account_id.id,
"The analytic distribution should be copied, not recomputed.",
)
self.assertEqual(
int(analytic_account_id[0]),
self.analytic_account2.id,
)
Loading