|
| 1 | +from odoo import tools |
| 2 | +from odoo.exceptions import ValidationError |
| 3 | +from odoo.tests import Form, common, tagged |
| 4 | + |
| 5 | + |
| 6 | +@tagged("post_install", "-at_install") |
| 7 | +class TestPatchDummy(common.TransactionCase): |
| 8 | + def test_dummy(self): |
| 9 | + # a trivial test so the test runner reports >0 tests (avoids the 0-tests warning) |
| 10 | + self.assertTrue(True) |
| 11 | + |
| 12 | + |
| 13 | +# Only apply the patch while running tests |
| 14 | +if tools.config.get("test_enable"): |
| 15 | + from odoo.addons.l10n_ar.tests.test_manual import TestArManual |
| 16 | + |
| 17 | + def test_15_liquido_producto_sales_patch(self): |
| 18 | + """Patcheamos para que la validacion se haga al momento de validar la factura y no antes""" |
| 19 | + |
| 20 | + # Verify that the default sales journals ara created as is ARCA POS |
| 21 | + self.assertTrue(self.journal.l10n_ar_is_pos) |
| 22 | + |
| 23 | + # If we create an invoice it will not use manual numbering |
| 24 | + invoice = self._create_invoice_ar() |
| 25 | + self.assertFalse(invoice.l10n_latam_manual_document_number) |
| 26 | + |
| 27 | + # Create a new sale journal that is not ARCA POS |
| 28 | + self.journal = self._create_journal("preprinted", data={"l10n_ar_is_pos": False}) |
| 29 | + self.assertFalse(self.journal.l10n_ar_is_pos) |
| 30 | + |
| 31 | + doc_27_lu_a = self.env.ref("l10n_ar.dc_liq_uci_a") |
| 32 | + payment_term_id = self.env.ref("account.account_payment_term_end_following_month") |
| 33 | + |
| 34 | + # 60, 61, 27, 28, 45, 46 |
| 35 | + # In this case manual numbering should be True and the latam document numer should be required |
| 36 | + with Form(self.env["account.move"].with_context(default_move_type="out_invoice")) as invoice_form: |
| 37 | + invoice_form.ref = "demo_liquido_producto_1: Vendor bill liquido producto (DOC 186)" |
| 38 | + invoice_form.partner_id = self.res_partner_adhoc |
| 39 | + invoice_form.invoice_payment_term_id = payment_term_id |
| 40 | + invoice_form.journal_id = self.journal |
| 41 | + invoice_form.l10n_latam_document_type_id = doc_27_lu_a |
| 42 | + with invoice_form.invoice_line_ids.new() as line_form: |
| 43 | + line_form.product_id = self.env.ref("product.product_product_4") |
| 44 | + line_form.quantity = 1 |
| 45 | + line_form.price_unit = 100 |
| 46 | + invoice = invoice_form.save() |
| 47 | + |
| 48 | + # Should fail when posting without document number |
| 49 | + with self.assertRaisesRegex(ValidationError, "Please set the document number"): |
| 50 | + invoice.action_post() |
| 51 | + |
| 52 | + # Adding the document number will let us to save and validate the number without any problems |
| 53 | + with Form(self.env["account.move"].with_context(default_move_type="out_invoice")) as invoice_form: |
| 54 | + invoice_form.ref = "demo_liquido_producto_1: Vendor bill liquido producto (DOC 186)" |
| 55 | + invoice_form.partner_id = self.res_partner_adhoc |
| 56 | + invoice_form.invoice_payment_term_id = payment_term_id |
| 57 | + invoice_form.journal_id = self.journal |
| 58 | + invoice_form.l10n_latam_document_type_id = doc_27_lu_a |
| 59 | + invoice_form.l10n_latam_document_number = "00077-00000077" |
| 60 | + with invoice_form.invoice_line_ids.new() as line_form: |
| 61 | + line_form.product_id = self.env.ref("product.product_product_4") |
| 62 | + line_form.quantity = 1 |
| 63 | + line_form.price_unit = 100 |
| 64 | + invoice = invoice_form.save() |
| 65 | + invoice.action_post() |
| 66 | + |
| 67 | + def test_16_liquido_producto_purchase_patch(self): |
| 68 | + """Patcheamos para que la validacion se haga al momento de validar la factura y no antes""" |
| 69 | + |
| 70 | + # By default purchase journals ar not ARCA POS journal |
| 71 | + purchase_not_pos_journal = self.env["account.journal"].search( |
| 72 | + [ |
| 73 | + ("type", "=", "purchase"), |
| 74 | + ("company_id", "=", self.env.company.id), |
| 75 | + ("l10n_latam_use_documents", "=", True), |
| 76 | + ] |
| 77 | + ) |
| 78 | + self.assertFalse(purchase_not_pos_journal.l10n_ar_is_pos) |
| 79 | + |
| 80 | + doc_60_lp_a = self.env.ref("l10n_ar.dc_a_cvl") |
| 81 | + payment_term_id = self.env.ref("account.account_payment_term_end_following_month") |
| 82 | + |
| 83 | + with Form(self.env["account.move"].with_context(default_move_type="in_invoice")) as bill_form: |
| 84 | + bill_form.ref = "demo_liquido_producto_1: Vendor bill liquido producto (DOC 186)" |
| 85 | + bill_form.partner_id = self.res_partner_adhoc |
| 86 | + bill_form.invoice_payment_term_id = payment_term_id |
| 87 | + bill_form.invoice_date = "2023-02-09" |
| 88 | + bill_form.l10n_latam_document_type_id = doc_60_lp_a |
| 89 | + with bill_form.invoice_line_ids.new() as line_form: |
| 90 | + line_form.product_id = self.env.ref("product.product_product_4") |
| 91 | + line_form.quantity = 1 |
| 92 | + line_form.price_unit = 100 |
| 93 | + bill = bill_form.save() |
| 94 | + |
| 95 | + self.assertEqual(bill.journal_id, purchase_not_pos_journal) |
| 96 | + |
| 97 | + # Should fail when posting without document number |
| 98 | + with self.assertRaisesRegex(ValidationError, "Please set the document number"): |
| 99 | + bill.action_post() |
| 100 | + |
| 101 | + # Create a new journal that is an ARCA POS |
| 102 | + purchase_pos_journal = self._create_journal("preprinted", data={"type": "purchase", "l10n_ar_is_pos": True}) |
| 103 | + |
| 104 | + with Form(self.env["account.move"].with_context(default_move_type="in_invoice")) as bill_form: |
| 105 | + bill_form.ref = "demo_liquido_producto_1: Vendor bill liquido producto (DOC 186)" |
| 106 | + bill_form.partner_id = self.res_partner_adhoc |
| 107 | + bill_form.invoice_payment_term_id = payment_term_id |
| 108 | + bill_form.invoice_date = "2023-02-09" |
| 109 | + bill_form.journal_id = purchase_pos_journal |
| 110 | + bill_form.l10n_latam_document_type_id = doc_60_lp_a |
| 111 | + bill_form.l10n_latam_document_number = "00077-00000077" |
| 112 | + with bill_form.invoice_line_ids.new() as line_form: |
| 113 | + line_form.product_id = self.env.ref("product.product_product_4") |
| 114 | + line_form.quantity = 1 |
| 115 | + line_form.price_unit = 100 |
| 116 | + bill = bill_form.save() |
| 117 | + bill.action_post() |
| 118 | + |
| 119 | + # If we create an invoice it will not use manual numbering |
| 120 | + self.assertFalse(bill.l10n_latam_manual_document_number) |
| 121 | + |
| 122 | + def propagate(method1, method2): |
| 123 | + if method1: |
| 124 | + for attr in ("_returns",): |
| 125 | + if hasattr(method1, attr) and not hasattr(method2, attr): |
| 126 | + setattr(method2, attr, getattr(method1, attr)) |
| 127 | + return method2 |
| 128 | + |
| 129 | + def _patch_method(cls, name, method): |
| 130 | + origin = getattr(cls, name) |
| 131 | + method.origin = origin |
| 132 | + wrapped = propagate(origin, method) |
| 133 | + wrapped.origin = origin |
| 134 | + setattr(cls, name, wrapped) |
| 135 | + |
| 136 | + _patch_method( |
| 137 | + TestArManual, |
| 138 | + "test_15_liquido_producto_sales", |
| 139 | + test_15_liquido_producto_sales_patch, |
| 140 | + ) |
| 141 | + _patch_method( |
| 142 | + TestArManual, |
| 143 | + "test_16_liquido_producto_purchase", |
| 144 | + test_16_liquido_producto_purchase_patch, |
| 145 | + ) |
0 commit comments