|
|
@ -259,26 +259,13 @@ class ResPartner(models.Model): |
|
|
|
partner.cdck_partner_id = partner.local_partner_id.cdck_partner_id |
|
|
|
todo = self - local_ok |
|
|
|
if todo: |
|
|
|
structures = todo.filtered( |
|
|
|
lambda rp: rp.is_company |
|
|
|
and rp.ffck_network |
|
|
|
and rp.partner_code |
|
|
|
and len(rp.partner_code) >= 2 |
|
|
|
and int(rp.partner_scale) == 4 |
|
|
|
) |
|
|
|
licensees = todo.filtered( |
|
|
|
lambda rp: not rp.is_company |
|
|
|
and rp.ffck_network |
|
|
|
and int(rp.partner_scale) == 5 |
|
|
|
and rp.country_department_id |
|
|
|
) |
|
|
|
dept_codes = todo.mapped( |
|
|
|
lambda rp: rp.ffck_network |
|
|
|
and ( |
|
|
|
rp.is_company |
|
|
|
and rp.partner_code |
|
|
|
and len(rp.partner_code) >= 2 |
|
|
|
and int(rp.partner_scale) in (3, 4) |
|
|
|
and int(rp.partner_scale) >= 4 |
|
|
|
and rp.partner_code[:2] |
|
|
|
or not rp.is_company |
|
|
|
and rp.country_department_id |
|
|
@ -298,17 +285,29 @@ class ResPartner(models.Model): |
|
|
|
] |
|
|
|
) |
|
|
|
cdck_by_code = {cdck.partner_code[:2]: cdck for cdck in cdck_ok} |
|
|
|
cdck_codes = cdck_by_code.keys() |
|
|
|
structures = todo.filtered( |
|
|
|
lambda rp: rp.is_company |
|
|
|
and rp.ffck_network |
|
|
|
and rp.partner_code |
|
|
|
and len(rp.partner_code) >= 2 |
|
|
|
and int(rp.partner_scale) == 4 |
|
|
|
and rp.partner_code[:2] in cdck_codes |
|
|
|
) |
|
|
|
licensees = todo.filtered( |
|
|
|
lambda rp: not rp.is_company |
|
|
|
and rp.ffck_network |
|
|
|
and int(rp.partner_scale) == 5 |
|
|
|
and rp.country_department_id.code in cdck_codes |
|
|
|
) |
|
|
|
# Treat structures |
|
|
|
for partner in structures: |
|
|
|
partner.cdck_partner_id = cdck_by_code[partner.partner_code[:2]] |
|
|
|
# Treat licensees |
|
|
|
for partner in licensees: |
|
|
|
dept = partner.country_department_id |
|
|
|
local = partner.local_partner_id |
|
|
|
local_cd = local.cdck_partner_id |
|
|
|
partner.cdck_partner_id = ( |
|
|
|
local_cd if local and local_cd else cdck_by_code[dept.code] |
|
|
|
) |
|
|
|
dept = partner.country_department_id.code |
|
|
|
if dept in cdck_codes: |
|
|
|
partner.cdck_partner_id = cdck_by_code[dept] |
|
|
|
# treat others |
|
|
|
for partner in todo - (structures | licensees): |
|
|
|
partner.cdck_partner_id = False |
|
|
|