Skip to content

Commit

Permalink
[ADD] l10n_br Account Invoice Merge Test
Browse files Browse the repository at this point in the history
  • Loading branch information
MateusONunes committed Dec 6, 2023
1 parent d66eaf2 commit 0e55d3f
Show file tree
Hide file tree
Showing 2 changed files with 127 additions and 0 deletions.
3 changes: 3 additions & 0 deletions l10n_br_account_invoice_merge/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Copyright 2023 - Mateus ONunes <[email protected]>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from . import test_account_invoice_merge
124 changes: 124 additions & 0 deletions l10n_br_account_invoice_merge/tests/test_account_invoice_merge.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
# Copyright 2023 - Mateus ONunes <[email protected]>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).

from odoo.exceptions import UserError
from odoo.addons.account.tests.common import tagged, AccountTestInvoicingCommon

@tagged('post_install', '-at_install')
class TestAccountInvoiceMerge(AccountTestInvoicingCommon):
"""
Tests for l10n_br Account Invoice Merge.
"""

@classmethod
def setUpClass(self, chart_template_ref=None):
super().setUpClass(chart_template_ref)
self.env.user.groups_id |= self.env.ref("l10n_br_fiscal.group_manager")
self.env.user.groups_id |= self.env.ref("account.group_account_invoice")
self.par_model = self.env["res.partner"]
self.context = self.env["res.users"].context_get()
self.acc_model = self.env["account.account"]
self.inv_model = self.env["account.move"]
self.inv_line_model = self.env["account.move.line"]
self.wiz = self.env["invoice.merge"]
self.product = self.env.ref("product.product_product_8")
self.account_receive = self.env.ref("account.data_account_type_receivable")
self.partner1 = self._create_partner(self)
self.invoice_account = self.acc_model.search(
[("user_type_id", "=", self.account_receive.id)],
limit=1,
)
self.journal = self.env["account.journal"].search(
[("type", "=", "sale")], limit=1
)

self.document_type01 = self.env["l10n_br_fiscal.document.type"].search(
[("code", "=", "01")], limit=1
)

self.fiscal_operation_venda = self.env["l10n_br_fiscal.operation"].search(
[("code", "=", "Venda")], limit=1
)

self.invoice1 = self._create_invoice(self, self.partner1, "A")
self.invoice_line1 = self._create_inv_line(self, self.invoice1)

def _create_partner(self):
partner = self.par_model.create(
{"name": "Test Partner", "supplier_rank": 1, "company_type": "company"}
)
return partner

def _create_inv_line(self, invoice):
lines = invoice.invoice_line_ids
invoice.write(
{
"invoice_line_ids": [
(
0,
False,
{
"name": "test invoice line",
"quantity": 1.0,
"price_unit": 3.0,
"move_id": invoice.id,
"product_id": self.product.id,
"exclude_from_invoice_tab": False,
},
)
]
}
)
return invoice.invoice_line_ids - lines

def _create_invoice(self, partner, name, journal=False, move_type=False):
if not journal:
journal = self.journal
if not move_type:
move_type = "out_invoice"

invoice = self.inv_model.create(
{
"partner_id": partner.id,
"name": name,
"move_type": move_type,
"journal_id": journal.id,
'document_type_id': self.document_type01.id,
'fiscal_operation_id': self.fiscal_operation_venda.id
}
)
return invoice

def test_dirty_check(self):
"""Check l10n_br fields"""
wiz_id = self.wiz.with_context(active_model="account.move")

# Check with two different document type
# Create the invoice 2 with a different document type
invoice2 = self._create_invoice(self.partner1, "D")
document_type02 = self.env["l10n_br_fiscal.document.type"].search(
[("code", "=", "02")], limit=1
)
invoice2.write({"document_type_id": document_type02.id})
self._create_inv_line(invoice2)
invoices = self.invoice1 | invoice2
with self.assertRaises(UserError):
wiz_id.with_context(
active_ids=invoices.ids,
active_model=invoices._name,
).fields_view_get()

# Check with two different fiscal_operation_id
# Create the invoice 3 with a different document type
fiscal_operation_compras = self.env["l10n_br_fiscal.operation"].search(
[("code", "=", "Compras")], limit=1
)
invoice3 = self._create_invoice(self.partner1, "D")
invoice3.write({"fiscal_operation_id": fiscal_operation_compras.id})
self._create_inv_line(invoice3)
invoices = self.invoice1 | invoice3
with self.assertRaises(UserError):
wiz_id.with_context(
active_ids=invoices.ids,
active_model=invoices._name,
).fields_view_get()

0 comments on commit 0e55d3f

Please sign in to comment.