Skip to content

Commit c6bb8e7

Browse files
committed
[FIX] account_edi[_ubl_cii]: company_id when searching retrieve_partner
Bug: 1. Have at least 2 companies ("A" and "B") 2. Export an xml (Bis 3 for instance) for an invoice with customer "Azure Interior" 3. Set a company on "Azure Interior" (say: A) 4. Import the xml in multicompany mode, with current company = B The partner "Azure Interior" should be retrieved, but when writing it on the invoice, it will throw a UserError "odoo.exceptions.UserError: Incompatible companies on records: 'Draft Invoice (* 63) (INV/2024/00006)' belongs to company 'B' and 'Partner' (partner_id: 'Azure Interior') belongs to another company." Cause: We try to write a partner on an invoice belonging to another company. It only occors when we have several companies selected because there is the global rule `base.res_partner_rule` that will add `('company_id', 'in', company_ids + [False])` to any search domain on the partner (`company_ids` is replaced by `env.companies.ids`, see `_eval_context`). Fix: Ensure any search domain contains `env.company.id`: the `company_id` of the move being created. opw-3829223 closes odoo#162208 X-original-commit: 992532e Related: odoo/enterprise#60928 Signed-off-by: William André (wan) <[email protected]> Signed-off-by: Julien Van Roy (juvr) <[email protected]>
1 parent 138dacf commit c6bb8e7

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

addons/account/models/partner.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -886,12 +886,10 @@ def search_with_domain(extra_domain):
886886
return None
887887
return self.env['res.partner'].search(domain + extra_domain, limit=1)
888888

889-
company = company or self.env.company
890889
for search_method in (search_with_vat, search_with_domain, search_with_phone_mail, search_with_name):
891-
for extra_domain in ([*self.env['res.partner']._check_company_domain(company), ('company_id', '!=', False)], []):
892-
partner = search_method(extra_domain)
893-
if partner and len(partner) == 1:
894-
return partner
890+
partner = search_method(self.env['res.partner']._check_company_domain(company or self.env.company))
891+
if partner and len(partner) == 1:
892+
return partner
895893
return self.env['res.partner']
896894

897895
def _merge_method(self, destination, source):

addons/account_edi_ubl_cii/models/account_edi_common.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,9 @@ def _import_invoice_ubl_cii(self, invoice, file_data, new=False):
352352
def _import_retrieve_and_fill_partner(self, invoice, name, phone, mail, vat, country_code=False):
353353
""" Retrieve the partner, if no matching partner is found, create it (only if he has a vat and a name)
354354
"""
355-
invoice.partner_id = self.env['res.partner']._retrieve_partner(name=name, phone=phone, mail=mail, vat=vat)
355+
invoice.partner_id = self.env['res.partner'] \
356+
.with_company(invoice.company_id) \
357+
._retrieve_partner(name=name, phone=phone, mail=mail, vat=vat)
356358
if not invoice.partner_id and name and vat:
357359
partner_vals = {'name': name, 'email': mail, 'phone': phone}
358360
country = self.env.ref(f'base.{country_code.lower()}', raise_if_not_found=False) if country_code else False

0 commit comments

Comments
 (0)