From 29097e10d80b2d77fd78c767d2a9bbd8d00a7cb4 Mon Sep 17 00:00:00 2001 From: althaf shaik Date: Mon, 31 Jul 2023 10:31:40 +0530 Subject: [PATCH] [FIX] account: restrict to create payment without payment date This traceback raises when user tries to create payment without payment date. To reproduce this issue: 1) Install 'account' 2) Open any existing invoice (not a DRAFT one) 3) Click 'REGISTER PAYMENT' button. 4) Now remove 'Payment Date' Error: 'Expected singleton: account.payment.term()' Note:- 'TypeError: unsupported operand type(s) for +=: 'float' and 'NoneType'' is also produced for some invoices. When user removes 'payment_date' '_compute_amount' method will be called, In which '_get_total_amount_in_wizard_currency_to_full_reconcile' method is used. In '_get_total_amount_in_wizard_currency_to_full_reconcile' method, '_get_total_amount_using_same_currency' is used to get total amount. On '_get_total_amount_using_same_currency' method payment_date is passed as an argument for '_is_eligible_for_early_payment_discount' method. See: https://github.com/odoo/odoo/blob/ed2e26633458f1284437286f71eba43c8d1818a7/addons/account/wizard/account_payment_register.py#L490-L498 On '_is_eligible_for_early_payment_discount' method if no reference date, its returning True. which leads to above traceback See: https://github.com/odoo/odoo/blob/ed2e26633458f1284437286f71eba43c8d1818a7/addons/account/models/account_move.py#L1902-L1905 sentry-4337953422 closes odoo/odoo#134721 X-original-commit: a05be50b9cf75fb0226f7b464b3a8f580465d462 Signed-off-by: Laurent Smet (las) --- addons/account/wizard/account_payment_register.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/addons/account/wizard/account_payment_register.py b/addons/account/wizard/account_payment_register.py index c986ff6d198..3ca43914c2b 100644 --- a/addons/account/wizard/account_payment_register.py +++ b/addons/account/wizard/account_payment_register.py @@ -553,7 +553,9 @@ class AccountPaymentRegister(models.TransientModel): @api.depends('can_edit_wizard', 'source_amount', 'source_amount_currency', 'source_currency_id', 'company_id', 'currency_id', 'payment_date') def _compute_amount(self): for wizard in self: - if wizard.source_currency_id and wizard.can_edit_wizard: + if not wizard.journal_id or not wizard.currency_id or not wizard.payment_date: + wizard.amount = wizard.amount + elif wizard.source_currency_id and wizard.can_edit_wizard: batch_result = wizard._get_batches()[0] wizard.amount = wizard._get_total_amount_in_wizard_currency_to_full_reconcile(batch_result)[0] else: @@ -563,7 +565,9 @@ class AccountPaymentRegister(models.TransientModel): @api.depends('can_edit_wizard', 'payment_date', 'currency_id', 'amount') def _compute_early_payment_discount_mode(self): for wizard in self: - if wizard.can_edit_wizard and wizard.currency_id: + if not wizard.journal_id or not wizard.currency_id or not wizard.payment_date: + wizard.early_payment_discount_mode = wizard.early_payment_discount_mode + elif wizard.can_edit_wizard: batch_result = wizard._get_batches()[0] total_amount_residual_in_wizard_currency, mode = wizard._get_total_amount_in_wizard_currency_to_full_reconcile(batch_result) wizard.early_payment_discount_mode = \ @@ -575,7 +579,7 @@ class AccountPaymentRegister(models.TransientModel): @api.depends('can_edit_wizard', 'amount') def _compute_payment_difference(self): for wizard in self: - if wizard.can_edit_wizard: + if wizard.can_edit_wizard and wizard.payment_date: batch_result = wizard._get_batches()[0] total_amount_residual_in_wizard_currency = wizard\ ._get_total_amount_in_wizard_currency_to_full_reconcile(batch_result, early_payment_discount=False)[0]