summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--addons/point_of_sale/models/pos_order.py47
1 files changed, 25 insertions, 22 deletions
diff --git a/addons/point_of_sale/models/pos_order.py b/addons/point_of_sale/models/pos_order.py
index 13f99cf187a..20d499c1c5a 100644
--- a/addons/point_of_sale/models/pos_order.py
+++ b/addons/point_of_sale/models/pos_order.py
@@ -376,16 +376,18 @@ class PosOrder(models.Model):
rounding_applied = float_round(self.amount_paid - self.amount_total,
precision_rounding=new_move.currency_id.rounding)
rounding_line = new_move.line_ids.filtered(lambda line: line.is_rounding_line)
+ if rounding_line and rounding_line.debit > 0:
+ rounding_line_difference = rounding_line.debit + rounding_applied
+ elif rounding_line and rounding_line.credit > 0:
+ rounding_line_difference = -rounding_line.credit + rounding_applied
+ else:
+ rounding_line_difference = rounding_applied
if rounding_applied:
if rounding_applied > 0.0:
account_id = new_move.invoice_cash_rounding_id.loss_account_id.id
else:
account_id = new_move.invoice_cash_rounding_id.profit_account_id.id
if rounding_line:
- if rounding_line.debit > 0:
- rounding_line_difference = rounding_line.debit + rounding_applied
- else:
- rounding_line_difference = -rounding_line.credit + rounding_applied
if rounding_line_difference:
rounding_line.with_context(check_move_validity=False).write({
'debit': rounding_applied < 0.0 and -rounding_applied or 0.0,
@@ -393,25 +395,9 @@ class PosOrder(models.Model):
'account_id': account_id,
'price_unit': rounding_applied,
})
- existing_terms_line = new_move.line_ids.filtered(
- lambda line: line.account_id.user_type_id.type in ('receivable', 'payable'))
- if existing_terms_line.debit > 0:
- existing_terms_line_new_val = float_round(
- existing_terms_line.debit + rounding_line_difference,
- precision_rounding=new_move.currency_id.rounding)
- else:
- existing_terms_line_new_val = float_round(
- -existing_terms_line.credit + rounding_line_difference,
- precision_rounding=new_move.currency_id.rounding)
- existing_terms_line.write({
- 'debit': existing_terms_line_new_val > 0.0 and existing_terms_line_new_val or 0.0,
- 'credit': existing_terms_line_new_val < 0.0 and -existing_terms_line_new_val or 0.0,
- })
-
- new_move._recompute_payment_terms_lines()
else:
- self.env['account.move.line'].create({
+ self.env['account.move.line'].with_context(check_move_validity=False).create({
'debit': rounding_applied < 0.0 and -rounding_applied or 0.0,
'credit': rounding_applied > 0.0 and rounding_applied or 0.0,
'quantity': 1.0,
@@ -428,7 +414,24 @@ class PosOrder(models.Model):
})
else:
if rounding_line:
- rounding_line.unlink()
+ rounding_line.with_context(check_move_validity=False).unlink()
+ if rounding_line_difference:
+ existing_terms_line = new_move.line_ids.filtered(
+ lambda line: line.account_id.user_type_id.type in ('receivable', 'payable'))
+ if existing_terms_line.debit > 0:
+ existing_terms_line_new_val = float_round(
+ existing_terms_line.debit + rounding_line_difference,
+ precision_rounding=new_move.currency_id.rounding)
+ else:
+ existing_terms_line_new_val = float_round(
+ -existing_terms_line.credit + rounding_line_difference,
+ precision_rounding=new_move.currency_id.rounding)
+ existing_terms_line.write({
+ 'debit': existing_terms_line_new_val > 0.0 and existing_terms_line_new_val or 0.0,
+ 'credit': existing_terms_line_new_val < 0.0 and -existing_terms_line_new_val or 0.0,
+ })
+
+ new_move._recompute_payment_terms_lines()
return new_move
def action_pos_order_paid(self):