From e0fb0fbc265cfa90e7f5c617c2ee426b0b28398f Mon Sep 17 00:00:00 2001 From: Brice bib Bartoletti Date: Wed, 6 Dec 2023 17:30:46 +0000 Subject: [PATCH] [FIX] PoS: payment date should be order date MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The aim of this commit is to correct the date of the payment. Context: When creating a PoS session and a PoS order on date X The customer gets its invoice on date Y the payment date is printed on the invoice Before this commit: The payment date will always be the date of the invoice After this commit: The payment date will always be the date of the order, the date at which is was really paid. Corner case not taken care of in this commit: Claiming the invoice after the `fiscalyear_lock_date`. In such a case, the payment date will be set to today (the invoice_date) again. This should be really rare as setting that lock date in short time frame is quite unusual. closes odoo/odoo#146259 Task-id: 3629054 X-original-commit: 732e43d8a6d4012eafb434952ccb6609f9be8066 Signed-off-by: Nicolas Viseur (vin) Signed-off-by: Brice Bartoletti (bib) --- addons/point_of_sale/models/pos_payment.py | 2 +- addons/point_of_sale/tests/test_pos_basic_config.py | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/addons/point_of_sale/models/pos_payment.py b/addons/point_of_sale/models/pos_payment.py index bd0ff002a10..08a4e7a685a 100644 --- a/addons/point_of_sale/models/pos_payment.py +++ b/addons/point_of_sale/models/pos_payment.py @@ -75,7 +75,7 @@ class PosPayment(models.Model): journal = pos_session.config_id.journal_id payment_move = self.env['account.move'].with_context(default_journal_id=journal.id).create({ 'journal_id': journal.id, - 'date': fields.Date.context_today(payment), + 'date': fields.Date.context_today(order, order.date_order), 'ref': _('Invoice payment for %s (%s) using %s', order.name, order.account_move.name, payment_method.name), 'pos_payment_ids': payment.ids, }) diff --git a/addons/point_of_sale/tests/test_pos_basic_config.py b/addons/point_of_sale/tests/test_pos_basic_config.py index 75d72e7d45e..6759cdafcf6 100644 --- a/addons/point_of_sale/tests/test_pos_basic_config.py +++ b/addons/point_of_sale/tests/test_pos_basic_config.py @@ -934,5 +934,11 @@ class TestPoSBasicConfig(TestPoSCommon): order_to_invoice.write({'partner_id': test_customer.id}) order_to_invoice.action_pos_order_invoice() # check invoice - self.assertTrue(order_to_invoice.account_move, 'Invoice should be created.') - self.assertTrue(order_to_invoice.account_move.invoice_date != order_to_invoice.date_order.date(), 'Invoice date should not be the same as order date since the session was closed.') + invoice = order_to_invoice.account_move + self.assertTrue(invoice, 'Invoice should be created.') + self.assertNotEqual(invoice.invoice_date, order_to_invoice.date_order.date(), 'Invoice date should not be the same as order date since the session was closed.') + + # check that the payment date is set to the order date which + # is the real payment date and not to the invoice_date + payment = invoice.line_ids.full_reconcile_id.reconciled_line_ids.move_id - invoice + self.assertEqual(payment.date, order_to_invoice.date_order.date())