Skip to content

Commit

Permalink
[ADD] account_payment_financial_surcharge: added unitary tests
Browse files Browse the repository at this point in the history
closes #521

Signed-off-by: rov-adhoc <[email protected]>
  • Loading branch information
feg-adhoc committed Sep 2, 2024
1 parent 5e22011 commit 84e2dc7
Show file tree
Hide file tree
Showing 4 changed files with 117 additions and 1 deletion.
1 change: 1 addition & 0 deletions account_payment_financial_surcharge/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
from . import models
from . import wizards
from . import tests
2 changes: 1 addition & 1 deletion account_payment_financial_surcharge/__manifest__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "Payments with Financial Surchange",
"version": "17.0.1.1.0",
"version": "17.0.1.2.0",
"author": "ADHOC SA",
"license": "AGPL-3",
"category": "Payment",
Expand Down
1 change: 1 addition & 0 deletions account_payment_financial_surcharge/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import test_account_payment_financial_surcharge
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
import odoo.tests.common as common
from odoo import Command, fields


class TestAccountPaymentFinancialSurcharge(common.TransactionCase):

def setUp(self):
super().setUp()
self.today = fields.Date.today()
self.first_company = self.env['res.company'].search([('name', '=', 'Muebleria ARG'),('use_payment_pro','=',True)])
self.partner_ri = self.env['res.partner'].search([('name', '=', 'ADHOC SA')])

self.first_company_journal = self.env['account.journal'].search([('company_id', '=', self.first_company.id), ('type', '=', 'bank')], limit=1)

installment_dic_1 = {
'name': 'Plan 1 cuota 10%',
'installment': 1,
'divisor': 1,
'surcharge_coefficient': 1.01
}
installment_dic_2 = {
'name': 'Plan 3 cuotas 30%',
'installment': 3,
'divisor': 1,
'surcharge_coefficient': 1.03
}
self.account_card = self.env['account.card'].create({'name':'Visa1', 'installment_ids': [(0, 0, installment_dic_1), (0, 0, installment_dic_2)]})

manual_payment_method_id = self.env.ref('account.account_payment_method_manual_in').id
self.card_payment_method = self.env['account.payment.method.line'].create({
'name': 'Tarjetas',
'payment_method_id': manual_payment_method_id,
'journal_id': self.first_company_journal.id,
})
self.card_payment_method.available_card_ids = [self.account_card.id]

self.product_surcharge = self.env.ref('card_installment.product_product_financial')
self.env['res.config.settings'].search([('company_id', '=', self.first_company.id)]).payment_term_surcharge_product_id = self.product_surcharge.id

def test_payment_financial_surcharge_1(self):
invoice = self.env['account.move'].create({
'partner_id': self.partner_ri.id,
'date': self.today,
'move_type': 'out_invoice',
'journal_id': self.first_company_journal.id,
'company_id': self.first_company.id,
'invoice_line_ids': [
Command.create({
'product_id': self.env.ref('product.product_product_16').id,
'quantity': 1,
'price_unit': 1000,
}),
],
})

invoice.action_post()
original_amount = invoice.amount_total

vals = {
'journal_id': self.first_company_journal.id
}

action_context = invoice.action_register_payment()['context']
payment = self.env['account.payment'].with_context(action_context).create(vals)

payment.write({
'payment_method_line_id': self.card_payment_method.id,
'card_id': self.account_card.id,
'installment_id': self.account_card.installment_ids[0].id
})

payment._inverse_net_amount()
payment.action_post()

self.assertEqual(round(payment.amount,2), original_amount + payment.financing_surcharge, "Fallo el monto total")
self.assertEqual(payment.financing_surcharge, payment.matched_move_line_ids[1].balance, "Fallo el monto de la ND por el recargo")

def test_payment_financial_surcharge_2(self):
invoice = self.env['account.move'].create({
'partner_id': self.partner_ri.id,
'date': self.today,
'move_type': 'out_invoice',
'journal_id': self.first_company_journal.id,
'company_id': self.first_company.id,
'invoice_line_ids': [
Command.create({
'product_id': self.env.ref('product.product_product_16').id,
'quantity': 1,
'price_unit': 1000,
}),
],
})

invoice.action_post()
original_amount = invoice.amount_total

vals = {
'journal_id': self.first_company_journal.id
}

action_context = invoice.action_register_payment()['context']
payment = self.env['account.payment'].with_context(action_context).create(vals)

payment.write({
'payment_method_line_id': self.card_payment_method.id,
'card_id': self.account_card.id,
'installment_id': self.account_card.installment_ids[1].id
})

payment._inverse_net_amount()
payment.action_post()

self.assertEqual(round(payment.amount,2), original_amount + payment.financing_surcharge, "Fallo el monto total")
self.assertEqual(payment.financing_surcharge, payment.matched_move_line_ids[1].balance, "Fallo el monto de la ND por el recargo")

0 comments on commit 84e2dc7

Please sign in to comment.