Skip to content

Commit c6d71f0

Browse files
committedFeb 27, 2025·
[ADD] account_multicompany_ux: Added unitary test
closes #185 Signed-off-by: rov-adhoc <[email protected]>
1 parent 12a5616 commit c6d71f0

File tree

1 file changed

+79
-0
lines changed

1 file changed

+79
-0
lines changed
 

‎account_multicompany_ux/tests/test_account_multicompany_ux_unit_test.py

+79
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ def setUp(self):
1919
self.second_company_journal = self.env["account.journal"].search(
2020
[("company_id", "=", self.second_company.id), ("type", "=", "sale")], limit=1
2121
)
22+
self.first_company_purchase_journal = self.env["account.journal"].search(
23+
[("company_id", "=", self.first_company.id), ("type", "=", "purchase")], limit=1
24+
)
2225
if not self.second_company_journal:
2326
a_sale = self.env["account.account"].create(
2427
{
@@ -53,6 +56,14 @@ def setUp(self):
5356
self.bank_1.company_id = self.first_company.id
5457
self.env.company = self.first_company
5558

59+
self.account_receivable = self.env["account.account"].create(
60+
{"code": "X2022", "name": "Account Receivable Test", "account_type": "asset_receivable", "reconcile": True}
61+
)
62+
63+
self.account_payable = self.env["account.account"].create(
64+
{"code": "X2023", "name": "Account Payable Test", "account_type": "liability_payable", "reconcile": True}
65+
)
66+
5667
def test_multicompany_sale_order(self):
5768
"""Cambio de compañía de una factura que cuenta con res partner bank seteado para la compañia original"""
5869
invoice = self.env["account.move"].create(
@@ -107,3 +118,71 @@ def test_multicompany_sale_order(self):
107118
"No se realizo de forma correcta el cambio partner_bank_id al cambiar la compañia",
108119
)
109120
invoice.action_post()
121+
122+
def test_account_receivable(self):
123+
"""Cambiamos las cuentas por cobrar/pagar y verificamos que impacten correctamente en la factura."""
124+
125+
# Las cuentas por cobrar y pagar por contacto se encuentran en property_account_receivable_ids y property_account_payable_ids
126+
# ambas contienen el mismo arreglo con las mismas res.company.property pero solo se puede acceder a ellas mediante el contexto property_field
127+
# por eso recorremos el arreglo buscando con el contexto respectivo de las account_payable y account_receivable
128+
129+
for payable in self.partner_ri.property_account_payable_ids:
130+
payable_ctx = payable.with_context(
131+
active_model="res.partner", property_field="property_account_payable_id", active_id=self.partner_ri.id
132+
)
133+
if payable_ctx.property_account_id: # Ahora sí evalúa con el contexto correcto
134+
payable_ctx.property_account_id = self.account_payable
135+
136+
for receivable in self.partner_ri.property_account_receivable_ids:
137+
receivable_ctx = receivable.with_context(
138+
active_model="res.partner",
139+
property_field="property_account_receivable_id",
140+
active_id=self.partner_ri.id,
141+
)
142+
if receivable_ctx.property_account_id: # Ahora sí evalúa con el contexto correcto
143+
receivable_ctx.property_account_id = self.account_receivable
144+
145+
customer_invoice = self.env["account.move"].create(
146+
{
147+
"partner_id": self.partner_ri.id,
148+
"invoice_date": self.today,
149+
"move_type": "out_invoice",
150+
"journal_id": self.first_company_journal.id,
151+
"company_id": self.first_company.id,
152+
"partner_bank_id": self.bank_1.id,
153+
"invoice_line_ids": [
154+
Command.create(
155+
{
156+
"product_id": self.env.ref("product.product_product_16").id,
157+
"quantity": 1,
158+
"price_unit": 100,
159+
}
160+
),
161+
],
162+
}
163+
)
164+
165+
vendor_bill = self.env["account.move"].create(
166+
{
167+
"partner_id": self.partner_ri.id,
168+
"invoice_date": self.today,
169+
"move_type": "in_invoice",
170+
"journal_id": self.first_company_purchase_journal.id,
171+
"company_id": self.first_company.id,
172+
"partner_bank_id": self.bank_1.id,
173+
"invoice_line_ids": [
174+
Command.create(
175+
{
176+
"product_id": self.env.ref("product.product_product_16").id,
177+
"quantity": 1,
178+
"price_unit": 100,
179+
}
180+
),
181+
],
182+
}
183+
)
184+
self.assertTrue(self.account_receivable.id in customer_invoice.line_ids.mapped("account_id.id"))
185+
self.assertTrue(self.account_payable.id in vendor_bill.line_ids.mapped("account_id.id"))
186+
187+
customer_invoice.action_post()
188+
vendor_bill.action_post()

0 commit comments

Comments
 (0)
Please sign in to comment.