[FIX] point_of_sale: closing session with zero-valued invoice

The problem is described in https://github.com/odoo/odoo/issues/48550.
This is caused by reconciled receivable line in the invoice being
reconciled with another reconciled receivable line in pos_session's
move_id. The lines are already reconciled because their balance is zero.
So to avoid trying to reconcile those reconciled lines, we do not
include them in the list of lines to be reconciled.

closes odoo/odoo#48587

X-original-commit: f24677098bec9b96108a901dde08bf75dc7d4c5f
Signed-off-by: pimodoo <pimodoo@users.noreply.github.com>
This commit is contained in:
Joseph Caburnay
2020-03-30 10:03:31 +00:00
parent e711dc08d4
commit 0de552c7c5
2 changed files with 20 additions and 2 deletions
+4 -2
View File
@@ -415,7 +415,7 @@ class PosSession(models.Model):
else:
invoice_receivables[key] = self._update_amounts(invoice_receivables[key], {'amount': order.amount_total}, order.date_order)
# side loop to gather receivable lines by account for reconciliation
for move_line in order.account_move.line_ids.filtered(lambda aml: aml.account_id.internal_type == 'receivable'):
for move_line in order.account_move.line_ids.filtered(lambda aml: aml.account_id.internal_type == 'receivable' and not aml.reconciled):
order_account_move_receivable_lines[move_line.account_id.id] |= move_line
else:
order_taxes = defaultdict(tax_amounts)
@@ -597,7 +597,9 @@ class PosSession(models.Model):
for receivable_account_id, amounts in invoice_receivables.items():
invoice_receivable_vals[receivable_account_id].append(self._get_invoice_receivable_vals(receivable_account_id, amounts['amount'], amounts['amount_converted']))
for receivable_account_id, vals in invoice_receivable_vals.items():
invoice_receivable_lines[receivable_account_id] = MoveLine.create(vals)
receivable_line = MoveLine.create(vals)
if (not receivable_line.reconciled):
invoice_receivable_lines[receivable_account_id] = receivable_line
data.update({'invoice_receivable_lines': invoice_receivable_lines})
return data
@@ -18,6 +18,7 @@ class TestPoSBasicConfig(TestPoSCommon):
def setUp(self):
super(TestPoSBasicConfig, self).setUp()
self.config = self.basic_config
self.product0 = self.create_product('Product 0', self.categ_basic, 0.0, 0.0)
self.product1 = self.create_product('Product 1', self.categ_basic, 10.0, 5)
self.product2 = self.create_product('Product 2', self.categ_basic, 20.0, 10)
self.product3 = self.create_product('Product 3', self.categ_basic, 30.0, 15)
@@ -278,6 +279,21 @@ class TestPoSBasicConfig(TestPoSCommon):
# matching number of the receivable lines should be the same
self.assertEqual(receivable_line.full_reconcile_id, invoice_receivable_line.full_reconcile_id)
def test_orders_with_zero_valued_invoiced(self):
"""One invoiced order but with zero receivable line balance."""
self.open_new_session()
orders = [self.create_ui_order_data([(self.product0, 1)], payments=[(self.bank_pm, 0)], customer=self.customer, is_invoiced=True)]
self.env['pos.order'].create_from_ui(orders)
self.pos_session.action_pos_session_validate()
invoice = self.pos_session.order_ids.account_move
invoice_receivable_line = invoice.line_ids.filtered(lambda line: line.account_id == self.receivable_account)
receivable_line = self.pos_session.move_id.line_ids.filtered(lambda line: line.account_id == self.receivable_account)
self.assertTrue(invoice_receivable_line.reconciled)
self.assertTrue(receivable_line.reconciled)
def test_return_order(self):
""" Test return order