Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[IMP] Backport from https://github.com/ingadhoc/account-payment/commi… #394

Open
wants to merge 1 commit into
base: 15.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion account_payment_group_financial_surcharge/__manifest__.py
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down