diff --git a/l10n_it_reverse_charge/tests/rc_common.py b/l10n_it_reverse_charge/tests/rc_common.py index adee3149a466..0d94e8f5e5ae 100644 --- a/l10n_it_reverse_charge/tests/rc_common.py +++ b/l10n_it_reverse_charge/tests/rc_common.py @@ -43,6 +43,13 @@ def setUpClass(cls, chart_template_ref=None): "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", @@ -230,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)", @@ -261,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, @@ -280,6 +309,13 @@ 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} ) diff --git a/l10n_it_reverse_charge/tests/test_rc.py b/l10n_it_reverse_charge/tests/test_rc.py index 8125a78c7997..ab13cec6f489 100644 --- a/l10n_it_reverse_charge/tests/test_rc.py +++ b/l10n_it_reverse_charge/tests/test_rc.py @@ -176,22 +176,40 @@ 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, + self.supplier_extraEU_EUR, amounts=[100], - taxes=self.tax_0_pur, + taxes=self.tax_22ae, currency=self.env.ref("base.EUR"), ) - self_purchase_invoice = invoice.rc_self_purchase_invoice_id - self_purchase_payment = self_purchase_invoice.rc_payment_move_id - self.assertTrue(self_purchase_payment) + self_invoice = invoice.rc_self_invoice_id + self_payment = self_invoice.rc_payment_move_id + self.assertTrue(self_payment) - self_purchase_rc_invoice = self_purchase_invoice.rc_self_invoice_id - self_purchase_rc_payment = self_purchase_rc_invoice.rc_payment_move_id - self.assertTrue(self_purchase_rc_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) + ) - payments_lines = (self_purchase_payment | self_purchase_rc_payment).line_ids - self.assertTrue(all(payments_lines.mapped("reconciled"))) + # 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