[FIX] point_of_sale: fix rounding logic
Use case specifically for round globally, but the justifications hold anyway Have a session with one tax, multiple partners, and returns of freight (negative amounts) When validating a pos.session, the computation of amls was a bit out of logic, Namely, we grouped tax lines by : 1. their tax id (correct) 2. their partner_id (not wrong but limited) 3. their balance > 0 (wrong) The justification for point 2 and 3 is two fold: - Ultimately, the order is level of granularity that really makes sense It's the order that is paid and therefore that has both legal and business meaning and on which the amounts are retrieved anyway - On the order, we litterally make the sum of tax amounts of each line, aggregating credit and debit under the same variable It is only logic to do the same for grouping the taxes at validation time This commit only corrects the behavior for the rounding method 'globally' OPW 1865700 closes #26203
This commit is contained in:
@@ -179,7 +179,7 @@ class PosOrder(models.Model):
|
||||
}
|
||||
|
||||
@api.model
|
||||
def _get_account_move_line_group_data_type_key(self, data_type, values):
|
||||
def _get_account_move_line_group_data_type_key(self, data_type, values, options={}):
|
||||
"""
|
||||
Return a tuple which will be used as a key for grouping account
|
||||
move lines in _create_account_move_line method.
|
||||
@@ -194,10 +194,16 @@ class PosOrder(models.Model):
|
||||
values['analytic_account_id'],
|
||||
values['debit'] > 0)
|
||||
elif data_type == 'tax':
|
||||
return ('tax',
|
||||
values['partner_id'],
|
||||
values['tax_line_id'],
|
||||
values['debit'] > 0)
|
||||
order_id = values.pop('order_id', False)
|
||||
tax_key = ('tax',
|
||||
values['partner_id'],
|
||||
values['tax_line_id'],
|
||||
values['debit'] > 0)
|
||||
if options.get('rounding_method') == 'round_globally':
|
||||
tax_key = ('tax',
|
||||
values['tax_line_id'],
|
||||
order_id)
|
||||
return tax_key
|
||||
elif data_type == 'counter_part':
|
||||
return ('counter_part',
|
||||
values['partner_id'],
|
||||
@@ -307,7 +313,7 @@ class PosOrder(models.Model):
|
||||
'move_id': move.id,
|
||||
})
|
||||
|
||||
key = self._get_account_move_line_group_data_type_key(data_type, values)
|
||||
key = self._get_account_move_line_group_data_type_key(data_type, values, {'rounding_method': rounding_method})
|
||||
if not key:
|
||||
return
|
||||
|
||||
@@ -321,6 +327,14 @@ class PosOrder(models.Model):
|
||||
current_value['quantity'] = current_value.get('quantity', 0.0) + values.get('quantity', 0.0)
|
||||
current_value['credit'] = current_value.get('credit', 0.0) + values.get('credit', 0.0)
|
||||
current_value['debit'] = current_value.get('debit', 0.0) + values.get('debit', 0.0)
|
||||
if key[0] == 'tax' and rounding_method == 'round_globally':
|
||||
if current_value['debit'] - current_value['credit'] > 0:
|
||||
current_value['debit'] = current_value['debit'] - current_value['credit']
|
||||
current_value['credit'] = 0
|
||||
else:
|
||||
current_value['credit'] = current_value['credit'] - current_value['debit']
|
||||
current_value['debit'] = 0
|
||||
|
||||
else:
|
||||
grouped_data[key].append(values)
|
||||
|
||||
@@ -380,7 +394,8 @@ class PosOrder(models.Model):
|
||||
'credit': ((tax['amount'] > 0) and tax['amount']) or 0.0,
|
||||
'debit': ((tax['amount'] < 0) and -tax['amount']) or 0.0,
|
||||
'tax_line_id': tax['id'],
|
||||
'partner_id': partner_id
|
||||
'partner_id': partner_id,
|
||||
'order_id': order.id
|
||||
})
|
||||
|
||||
# round tax lines per order
|
||||
|
||||
Reference in New Issue
Block a user