@@ -19,6 +19,9 @@ def setUp(self):
19
19
self .second_company_journal = self .env ["account.journal" ].search (
20
20
[("company_id" , "=" , self .second_company .id ), ("type" , "=" , "sale" )], limit = 1
21
21
)
22
+ self .first_company_purchase_journal = self .env ["account.journal" ].search (
23
+ [("company_id" , "=" , self .first_company .id ), ("type" , "=" , "purchase" )], limit = 1
24
+ )
22
25
if not self .second_company_journal :
23
26
a_sale = self .env ["account.account" ].create (
24
27
{
@@ -53,6 +56,14 @@ def setUp(self):
53
56
self .bank_1 .company_id = self .first_company .id
54
57
self .env .company = self .first_company
55
58
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
+
56
67
def test_multicompany_sale_order (self ):
57
68
"""Cambio de compañía de una factura que cuenta con res partner bank seteado para la compañia original"""
58
69
invoice = self .env ["account.move" ].create (
@@ -107,3 +118,71 @@ def test_multicompany_sale_order(self):
107
118
"No se realizo de forma correcta el cambio partner_bank_id al cambiar la compañia" ,
108
119
)
109
120
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