[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/odoo#162019
X-original-commit: 18119d446bdca9c04b7085bd1a1bd2f0e0b94ff3
Related: odoo/enterprise#60816
Signed-off-by: William André (wan) <wan@odoo.com>
Signed-off-by: Julien Van Roy (juvr) <juvr@odoo.com>
This commit is contained in:
@@ -880,12 +880,10 @@ class ResPartner(models.Model):
|
||||
return None
|
||||
return self.env['res.partner'].search(domain + extra_domain, limit=1)
|
||||
|
||||
company = company or self.env.company
|
||||
for search_method in (search_with_vat, search_with_domain, search_with_phone_mail, search_with_name):
|
||||
for extra_domain in ([*self.env['res.partner']._check_company_domain(company), ('company_id', '!=', False)], []):
|
||||
partner = search_method(extra_domain)
|
||||
if partner and len(partner) == 1:
|
||||
return partner
|
||||
partner = search_method(self.env['res.partner']._check_company_domain(company or self.env.company))
|
||||
if partner and len(partner) == 1:
|
||||
return partner
|
||||
return self.env['res.partner']
|
||||
|
||||
def _merge_method(self, destination, source):
|
||||
|
||||
@@ -352,7 +352,9 @@ class AccountEdiCommon(models.AbstractModel):
|
||||
def _import_retrieve_and_fill_partner(self, invoice, name, phone, mail, vat, country_code=False):
|
||||
""" Retrieve the partner, if no matching partner is found, create it (only if he has a vat and a name)
|
||||
"""
|
||||
invoice.partner_id = self.env['res.partner']._retrieve_partner(name=name, phone=phone, mail=mail, vat=vat)
|
||||
invoice.partner_id = self.env['res.partner'] \
|
||||
.with_company(invoice.company_id) \
|
||||
._retrieve_partner(name=name, phone=phone, mail=mail, vat=vat)
|
||||
if not invoice.partner_id and name and vat:
|
||||
partner_vals = {'name': name, 'email': mail, 'phone': phone}
|
||||
country = self.env.ref(f'base.{country_code.lower()}', raise_if_not_found=False) if country_code else False
|
||||
|
||||
Reference in New Issue
Block a user