From f3bd4134960c9a6cda3129ab9c11fa87d5f5f1b8 Mon Sep 17 00:00:00 2001 From: Martin Quinteros Date: Mon, 4 Sep 2023 11:34:27 -0300 Subject: [PATCH] [IMP] Backport from https://github.com/ingadhoc/account-payment/commit/7005cc10ca96baf62fb2ddf8ad3fe3e2b1279a5b --- .../__manifest__.py | 2 +- .../models/account_payment.py | 1 + .../models/account_payment_group.py | 33 +++++++++++-------- 3 files changed, 22 insertions(+), 14 deletions(-) diff --git a/account_payment_group_financial_surcharge/__manifest__.py b/account_payment_group_financial_surcharge/__manifest__.py index 4ef9e1222..80464312d 100644 --- a/account_payment_group_financial_surcharge/__manifest__.py +++ b/account_payment_group_financial_surcharge/__manifest__.py @@ -1,6 +1,6 @@ { "name": "Payment Groups with Financial Surchange", - "version": "15.0.1.0.1", + "version": "15.0.2.0.1", "author": "ADHOC SA", "license": "AGPL-3", "category": "Payment", diff --git a/account_payment_group_financial_surcharge/models/account_payment.py b/account_payment_group_financial_surcharge/models/account_payment.py index 1aca1e656..b2d1ea284 100644 --- a/account_payment_group_financial_surcharge/models/account_payment.py +++ b/account_payment_group_financial_surcharge/models/account_payment.py @@ -62,6 +62,7 @@ def _onchange_instalment(self): for rec in self: rec._inverse_net_amount() + @api.onchange('net_amount') def _inverse_net_amount(self): for rec in self: rec.with_context(skip_account_move_synchronization=True).amount = rec.net_amount * (rec.installment_id.surcharge_coefficient or 1) diff --git a/account_payment_group_financial_surcharge/models/account_payment_group.py b/account_payment_group_financial_surcharge/models/account_payment_group.py index 65afc6246..7c0c19ef2 100644 --- a/account_payment_group_financial_surcharge/models/account_payment_group.py +++ b/account_payment_group_financial_surcharge/models/account_payment_group.py @@ -26,20 +26,27 @@ def post(self): raise UserError( "To validate payment with finacing plan is necessary to have a product surcharge in the " "company of the payment. Please check this in the Account Config") + ## Obtengo las notas de debito relacionadas con el grupo de pago. + ## y computo la suma del precio toal del producto de surchage y si es menor al residual de las notas de debito + ## lo seteo como monto a facturar restandolo de el recargo caculado (esperado) + related_debit_note = self.to_pay_move_line_ids.mapped('move_id').filtered(lambda x: x.l10n_latam_document_type_id.internal_type == 'debit_note') + surchage_products_total = sum(related_debit_note.mapped('line_ids').filtered(lambda x: x.product_id == product).mapped('price_total')) + financing_surcharge_to_invoice = self.financing_surcharge - (min(surchage_products_total, sum(related_debit_note.mapped('amount_residual')))) + if financing_surcharge_to_invoice > 0: + taxes = product.taxes_id.filtered(lambda t: t.company_id.id == self.company_id.id) + journal = self.env['account.journal'].search([('type', '=', 'sale'), ('company_id', '=', self.company_id.id)], limit=1) + wiz = self.env['account.payment.group.invoice.wizard'].with_context( + is_automatic_subcharge=True, active_id=self.id, internal_type='debit_note').create({ + 'journal_id': journal.id, + 'product_id': product.id, + 'tax_ids': [(6, 0, taxes.ids)], + 'amount_total': financing_surcharge_to_invoice, + }) + wiz.with_context(internal_type='debit_note')._onchange_journal_id() + wiz.change_payment_group() + wiz.amount_total = financing_surcharge_to_invoice + wiz.confirm() - taxes = product.taxes_id.filtered(lambda t: t.company_id.id == self.company_id.id) - journal = self.env['account.journal'].search([('type', '=', 'sale'), ('company_id', '=', self.company_id.id)], limit=1) - wiz = self.env['account.payment.group.invoice.wizard'].with_context( - is_automatic_subcharge=True, active_id=self.id, internal_type='debit_note').create({ - 'journal_id': journal.id, - 'product_id': product.id, - 'tax_ids': [(6, 0, taxes.ids)], - 'amount_total': self.financing_surcharge, - }) - wiz._onchange_journal_id() - wiz.change_payment_group() - wiz.amount_total = self.financing_surcharge - wiz.confirm() # If we are registering a payment of a draft invoice then we need to remove the invoice from the debts of the payment group # in order to be able to post/reconcile the payment group (this is needed because in odoo 15 we are not able to renconcile