Skip to content

Commit

Permalink
[IMP] l10n_it_reverse_charge: add test
Browse files Browse the repository at this point in the history
  • Loading branch information
odooNextev committed Jul 16, 2024
1 parent 4e20b22 commit acad3b1
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 2 deletions.
57 changes: 55 additions & 2 deletions l10n_it_reverse_charge/tests/rc_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,21 @@ def setUpClass(cls, chart_template_ref=None):
cls._create_rc_types()
cls._create_rc_type_taxes()
cls._create_fiscal_position()
cls._create_currency_rate(cls.env.ref("base.EUR").id, 1.1)

cls.supplier_extraEU = cls.partner_model.create(
{
"name": "Extra EU supplier",
"property_account_position_id": cls.fiscal_position_extra.id,
}
)
cls.supplier_extraEU_EUR = cls.partner_model.create(
{
"name": "Extra EU Euro supplier",
"property_account_position_id": cls.fiscal_position_extra_no_si.id,
"currency_id": cls.env.ref("base.EUR"),
}
)
cls.supplier_intraEU = cls.partner_model.create(
{
"name": "Intra EU supplier",
Expand Down Expand Up @@ -102,9 +110,14 @@ def setUpClass(cls, chart_template_ref=None):
)

@classmethod
def create_invoice(cls, partner, amounts, taxes=None, post=True):
def create_invoice(cls, partner, amounts, taxes=None, post=True, currency=None):
invoice = cls.init_invoice(
"in_invoice", partner=partner, post=post, amounts=amounts, taxes=taxes
"in_invoice",
partner=partner,
post=post,
amounts=amounts,
taxes=taxes,
currency=currency,
)
for line in invoice.invoice_line_ids:
line.account_id = cls.invoice_line_account.id
Expand Down Expand Up @@ -224,6 +237,20 @@ def _create_rc_types(cls):
}
)

cls.rc_type_eeu_no_selfinvoice_extra = rc_type_model.create(
{
"name": "Extra EU (selfinvoice)",
"method": "selfinvoice",
"partner_type": "other",
"with_supplier_self_invoice": False,
"partner_id": cls.env.ref("base.main_partner").id,
"journal_id": cls.journal_selfinvoice_extra.id,
"supplier_journal_id": cls.journal_cee_extra.id,
"payment_journal_id": cls.journal_reconciliation.id,
"transitory_account_id": cls.account_selfinvoice.id,
}
)

cls.rc_type_exempt = rc_type_model.create(
{
"name": "Intra EU (exempt)",
Expand Down Expand Up @@ -255,6 +282,14 @@ def _create_rc_type_taxes(cls):
}
)

cls.rc_type_tax_eeu_no_selfinvoice_extra = rc_type_tax_model.create(
{
"rc_type_id": cls.rc_type_eeu_no_selfinvoice_extra.id,
"purchase_tax_id": cls.tax_22ae.id,
"sale_tax_id": cls.tax_22ve.id,
}
)

cls.rc_type_tax_exempt = rc_type_tax_model.create(
{
"rc_type_id": cls.rc_type_exempt.id,
Expand All @@ -274,6 +309,24 @@ def _create_fiscal_position(cls):
{"name": "Extra EU", "rc_type_id": cls.rc_type_eeu.id}
)

cls.fiscal_position_extra_no_si = model_fiscal_position.create(
{
"name": "Extra EU no extra self invoice",
"rc_type_id": cls.rc_type_eeu_no_selfinvoice_extra.id,
}
)

cls.fiscal_position_exempt = model_fiscal_position.create(
{"name": "Intra EU exempt", "rc_type_id": cls.rc_type_exempt.id}
)

@classmethod
def _create_currency_rate(cls, currency_id, rate, date="2016-01-01"):
cls.env["res.currency.rate"].create(
{
"name": date,
"currency_id": currency_id,
"rate": rate,
"company_id": cls.env.company.id,
}
)
40 changes: 40 additions & 0 deletions l10n_it_reverse_charge/tests/test_rc.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,46 @@ def test_supplier_extraEU_no_outstanding_payment(self):
payments_lines = (self_purchase_payment | self_purchase_rc_payment).line_ids
self.assertTrue(all(payments_lines.mapped("reconciled")))

def test_supplier_extraEU_no_outstanding_payment_different_currencies(self):
"""
Self invoice from Extra EU partner in a different currency
"""
invoice = self.create_invoice(
self.supplier_extraEU_EUR,
amounts=[100],
taxes=self.tax_22ae,
currency=self.env.ref("base.EUR"),
)

self_invoice = invoice.rc_self_invoice_id
self_payment = self_invoice.rc_payment_move_id
self.assertTrue(self_payment)

# check self invoice amount
invoices_amounts_sum = (
invoice.amount_untaxed_signed + self_invoice.amount_untaxed_signed
)
self.assertEqual(invoices_amounts_sum, 0.0)

# check amount conversion
invoice_amount_untaxed_usd = invoice.currency_id._convert(
invoice.amount_untaxed,
invoice.company_id.currency_id,
invoice.company_id,
invoice.invoice_date,
)
self_invoice_test_line = self_invoice.line_ids.filtered(
lambda x: x.name == "test line"
)
self.assertEqual(
invoice_amount_untaxed_usd, abs(self_invoice_test_line.balance)
)

# check amount_currency setting
self.assertEqual(
invoice.amount_untaxed, abs(self_invoice_test_line.amount_currency)
)

def test_extra_EU_draft_and_reconfirm(self):
"""Check that an invoice with RC Self Purchase Invoice
can be reset to draft and confirmed again."""
Expand Down

0 comments on commit acad3b1

Please sign in to comment.