Skip to content
Snippets Groups Projects
Commit a0fed3b8 authored by Goffin Simon's avatar Goffin Simon
Browse files

[FIX] sale: _compute_analytic with amount=0

Steps to reproduce:
-Create a product P  with a standard price = 0 and its internal category
is in perpetual valuation
-Create a SO with an analytic account and a line with one product P
-Confirm the SO
-Create and validate the invoice

Bug: The delivered qty on the SO was equal to 2 instead of 1 because two
analytic lines are created by function create_analytic_lines with amount=0.
So in function _compute_analytic, the domain was [('so_line', 'in', self.ids), ('amount', '<=', 0.0)]
and it summed the two analytic lines for these two lines. Now analytic lines with amount=0 and linked
to a move line are summed if the they are linked to entries for an account of type "Expenses"(user_type_id).

opw:727302
parent 1dc36170
No related branches found
No related tags found
No related merge requests found
......@@ -13,7 +13,19 @@ class SaleOrderLine(models.Model):
lines = {}
if not domain:
# To filter on analyic lines linked to an expense
domain = [('so_line', 'in', self.ids), ('amount', '<=', 0.0)]
expense_type_id = self.env.ref('account.data_account_type_expenses', raise_if_not_found=False)
expense_type_id = expense_type_id and expense_type_id.id
domain = [
('so_line', 'in', self.ids),
'|',
('amount', '<', 0),
'&',
('amount', '=', 0),
'|',
('move_id', '=', False),
('move_id.account_id.user_type_id', '=', expense_type_id)
]
data = self.env['account.analytic.line'].read_group(
domain,
['so_line', 'unit_amount', 'product_uom_id'], ['product_uom_id', 'so_line'], lazy=False
......
......@@ -161,7 +161,20 @@ class SaleOrderLine(models.Model):
def _compute_analytic(self, domain=None):
if not domain:
# To filter on analyic lines linked to an expense
domain = [('so_line', 'in', self.ids), '|', ('amount', '<=', 0.0), ('is_timesheet', '=', True)]
expense_type_id = self.env.ref('account.data_account_type_expenses', raise_if_not_found=False)
expense_type_id = expense_type_id and expense_type_id.id
domain = [
('so_line', 'in', self.ids),
'|',
'|',
('amount', '<', 0.0),
('is_timesheet', '=', True),
'&',
('amount', '=', 0),
'|',
('move_id', '=', False),
('move_id.account_id.user_type_id', '=', expense_type_id)
]
return super(SaleOrderLine, self)._compute_analytic(domain=domain)
@api.model
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment