From 343e2180d2bb64a48c86d6d457ea107f032e1470 Mon Sep 17 00:00:00 2001 From: Juan Jose Scarafia Date: Thu, 27 Jul 2023 12:56:43 -0300 Subject: [PATCH] [IMP] l10n_latam_check: checks warnings MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Task Adhoc: 32844 Task Latam: 1053 Description of the issue/feature this PR addresses: 1. If the date is changed in the payment wizard don't update the check amount. 2. Payment currency should be the same as the check currency. 3. Warning in the payment register for example if the currency of the check is different than the currency of the payment. 4. Check on companies without country. Company without country should not use checks. 5. Not possible pay with a check with a date that is prior to the check creation date (vendor bill payment date should be after the Customer Invoice payment date when the check was created). 6. If the payment amount is changed and it does not match the check amount then a warning pops up. Current behavior before PR: 1. If the date is changed in the payment wizard is updated the check amount. 2. Payment currency can be different than the check currency. 3. No warning in the payment register for example if the currency of the check is different than the currency of the payment. 4. Check on companies without country. Company without country can use checks. 5. Possible to pay with a check with a date that is prior to the check creation date (vendor bill payment date should be after the Customer Invoice payment date when the check was created). 6. If the payment amount is changed and it does not match the check amount then a warning not pops up. Desired behavior after PR is merged: 1. If the date is changed in the payment wizard the check amount is not updated. 2. Payment currency should be the same as the check currency. 3. Warning in the payment register for example if the currency of the check is different than the currency of the payment. 4. Check on companies without country. Company with country can`t use checks. 5. Not possible to pay with a check with a date that is prior to the check creation date (vendor bill payment date should be after the Customer Invoice payment date when the check was created). 6. If the payment amount is changed and it does not match the check amount then a warning pops up. closes odoo/odoo#140832 X-original-commit: 0c62f78759ee1a6447c7cacf857a9f45a702c3fb Signed-off-by: William André (wan) --- .../models/account_payment.py | 46 +++++++++++-------- .../wizards/account_payment_register.py | 15 ++++-- 2 files changed, 38 insertions(+), 23 deletions(-) diff --git a/addons/l10n_latam_check/models/account_payment.py b/addons/l10n_latam_check/models/account_payment.py index fe1addfe8c1..4e2a197a471 100644 --- a/addons/l10n_latam_check/models/account_payment.py +++ b/addons/l10n_latam_check/models/account_payment.py @@ -100,7 +100,7 @@ class AccountPayment(models.Model): @api.onchange('l10n_latam_check_issuer_vat') def _clean_l10n_latam_check_issuer_vat(self): - for rec in self.filtered('l10n_latam_check_issuer_vat'): + for rec in self.filtered(lambda x: x.l10n_latam_check_issuer_vat and x.company_id.country_id.code): stdnum_vat = stdnum.util.get_cc_module(rec.company_id.country_id.code, 'vat') if hasattr(stdnum_vat, 'compact'): rec.l10n_latam_check_issuer_vat = stdnum_vat.compact(rec.l10n_latam_check_issuer_vat) @@ -114,37 +114,27 @@ class AccountPayment(models.Model): raise ValidationError(error_message) @api.depends('payment_method_line_id', 'l10n_latam_check_issuer_vat', 'l10n_latam_check_bank_id', 'company_id', - 'check_number', 'l10n_latam_check_id', 'state', 'date', 'is_internal_transfer') + 'l10n_latam_check_number', 'l10n_latam_check_id', 'state', 'date', 'is_internal_transfer', 'amount', 'currency_id') def _compute_l10n_latam_check_warning_msg(self): - """ Compute warning message for latam checks checks """ + """ + Compute warning message for latam checks checks + We use l10n_latam_check_number as de dependency because on the interface this is the field the user is using. + Another approach could be to add an onchange on _inverse_l10n_latam_check_number method + """ self.l10n_latam_check_warning_msg = False latam_draft_checks = self.filtered( lambda x: x.state == 'draft' and (x.l10n_latam_manual_checks or x.payment_method_line_id.code in [ 'in_third_party_checks', 'out_third_party_checks', 'new_third_party_checks'])) for rec in latam_draft_checks: msgs = rec._get_blocking_l10n_latam_warning_msg() - # moved third party check - if rec.l10n_latam_check_id: - date = rec.date or fields.Datetime.now() - last_operation = rec.env['account.payment'].search([ - ('state', '=', 'posted'), - '|', ('l10n_latam_check_id', '=', rec.l10n_latam_check_id.id), - ('id', '=', rec.l10n_latam_check_id.id), - ], order="date desc, id desc", limit=1) - if last_operation and last_operation[0].date > date: - msgs.append(_( - "It seems you're trying to move a check with a date (%s) prior to last operation done with " - "the check (%s). This may be wrong, please double check it. By continue, the last operation on " - "the check will remain being %s", - format_date(self.env, date), last_operation.display_name, last_operation.display_name)) # new third party check - elif rec.check_number and rec.payment_method_line_id.code == 'new_third_party_checks' and \ + if rec.l10n_latam_check_number and rec.payment_method_line_id.code == 'new_third_party_checks' and \ rec.l10n_latam_check_bank_id and rec.l10n_latam_check_issuer_vat: same_checks = self.search([ ('company_id', '=', rec.company_id.id), ('l10n_latam_check_bank_id', '=', rec.l10n_latam_check_bank_id.id), ('l10n_latam_check_issuer_vat', '=', rec.l10n_latam_check_issuer_vat), - ('check_number', '=', rec.check_number), + ('check_number', '=', rec.l10n_latam_check_number), ('id', '!=', rec._origin.id)]) if same_checks: msgs.append(_( @@ -156,6 +146,10 @@ class AccountPayment(models.Model): def _get_blocking_l10n_latam_warning_msg(self): msgs = [] for rec in self.filtered('l10n_latam_check_id'): + if rec.currency_id != rec.l10n_latam_check_id.currency_id: + msgs.append(_( + 'The currency of the payment (%s) and the currency of the check (%s) must be the same.') % ( + rec.currency_id.name, rec.l10n_latam_check_id.currency_id.name)) if not rec.currency_id.is_zero(rec.l10n_latam_check_id.amount - rec.amount): msgs.append(_( 'The amount of the payment (%s) does not match the amount of the selected check (%s). ' @@ -176,6 +170,20 @@ class AccountPayment(models.Model): rec.l10n_latam_check_id.l10n_latam_check_current_journal_id: msgs.append(_("Check '%s' is on journal '%s', it can't be received it again", rec.l10n_latam_check_id.display_name, rec.journal_id.name)) + # moved third party check + if rec.l10n_latam_check_id: + date = rec.date or fields.Datetime.now() + last_operation = rec.env['account.payment'].search([ + ('state', '=', 'posted'), + '|', ('l10n_latam_check_id', '=', rec.l10n_latam_check_id.id), + ('id', '=', rec.l10n_latam_check_id.id), + ], order="date desc, id desc", limit=1) + if last_operation and last_operation[0].date > date: + msgs.append(_( + "It seems you're trying to move a check with a date (%s) prior to last operation done with " + "the check (%s). This may be wrong, please double check it. By continue, the last operation on " + "the check will remain being %s", + format_date(self.env, date), last_operation.display_name, last_operation.display_name)) return msgs @api.depends('is_internal_transfer') diff --git a/addons/l10n_latam_check/wizards/account_payment_register.py b/addons/l10n_latam_check/wizards/account_payment_register.py index 6075a6c4423..0290e9d4ca6 100644 --- a/addons/l10n_latam_check/wizards/account_payment_register.py +++ b/addons/l10n_latam_check/wizards/account_payment_register.py @@ -41,10 +41,17 @@ class AccountPaymentRegister(models.TransientModel): rec.l10n_latam_check_issuer_vat = rec.partner_id.vat (self - new_third_party_checks).l10n_latam_check_issuer_vat = False - @api.onchange('l10n_latam_check_id') - def _onchange_amount(self): - for rec in self.filtered('l10n_latam_check_id'): - rec.amount = rec.l10n_latam_check_id.amount + @api.depends('l10n_latam_check_id') + def _compute_amount(self): + super()._compute_amount() + for wizard in self.filtered('l10n_latam_check_id'): + wizard.amount = wizard.l10n_latam_check_id.amount + + @api.depends('l10n_latam_check_id') + def _compute_currency_id(self): + super()._compute_currency_id() + for wizard in self.filtered('l10n_latam_check_id'): + wizard.currency_id = wizard.l10n_latam_check_id.currency_id @api.onchange('l10n_latam_check_number') def _onchange_l10n_latam_check_number(self):