diff --git a/ffck_commons/models/res_partner.py b/ffck_commons/models/res_partner.py
index 12bf54a..d1a2125 100644
--- a/ffck_commons/models/res_partner.py
+++ b/ffck_commons/models/res_partner.py
@@ -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
diff --git a/ffck_commons/views/res_partner.xml b/ffck_commons/views/res_partner.xml
index 55e62fa..ee3fde0 100644
--- a/ffck_commons/views/res_partner.xml
+++ b/ffck_commons/views/res_partner.xml
@@ -34,7 +34,7 @@
attrs="{'invisible': [('is_company','=',False)]}" />
+ attrs="{'invisible': ['|',('is_company','=',True),'|',('birthdate_date','=',False), ('nationality_id','=',False)]}" />