From a83beb377dbdd3c924bb6475cca337a3a1b9c3fc Mon Sep 17 00:00:00 2001 From: RemiFr82 Date: Mon, 27 May 2024 01:20:34 +0200 Subject: [PATCH] [IMP] crock_base --- crock_base/__init__.py | 1 + crock_base/__manifest__.py | 2 +- crock_base/hooks.py | 29 +++++++++++++++++++++++++++++ crock_base/models/res_partner.py | 12 ++++++------ 4 files changed, 37 insertions(+), 7 deletions(-) create mode 100644 crock_base/hooks.py diff --git a/crock_base/__init__.py b/crock_base/__init__.py index 0650744..cc6b635 100644 --- a/crock_base/__init__.py +++ b/crock_base/__init__.py @@ -1 +1,2 @@ from . import models +from .hooks import post_init_hook diff --git a/crock_base/__manifest__.py b/crock_base/__manifest__.py index 419cc00..64b2b44 100644 --- a/crock_base/__manifest__.py +++ b/crock_base/__manifest__.py @@ -48,6 +48,6 @@ "installable": True, "maintainer": "RemiFr82", "pre_init_hook": "", - "post_init_hook": "", + "post_init_hook": "post_init_hook", "uninstall_hook": "", } diff --git a/crock_base/hooks.py b/crock_base/hooks.py new file mode 100644 index 0000000..c48d1ca --- /dev/null +++ b/crock_base/hooks.py @@ -0,0 +1,29 @@ +import logging + +from odoo.api import Environment, SUPERUSER_ID + +_logger = logging.getLogger(__name__) + + +# def pre_init_hook(cr, registry): +# env = Environment(cr, SUPERUSER_ID, {}) +# _logger.info("Pre init hook") + + +def post_init_hook(cr, registry): + env = Environment(cr, SUPERUSER_ID, {}) + env.sudo().ref("base.main_partner").write( + { + "association": True, + "ffck_network": True, + "partner_code": "CR10", + "ffck_structure_type_id": env.ref("ffck_commond.ffck_structure_type_crck"), + "ref": "CROCK", + } + ) + _logger.info("\n#####\nPost init hook from CROCK addons passed...\n#####\n") + + +# def uninstall_hook(cr, registry): +# env = Environment(cr, SUPERUSER_ID, {}) +# _logger.info("Uninstall hook") diff --git a/crock_base/models/res_partner.py b/crock_base/models/res_partner.py index a775a6e..9dcf0e9 100644 --- a/crock_base/models/res_partner.py +++ b/crock_base/models/res_partner.py @@ -9,28 +9,28 @@ class ResPartner(models.Model): def _onchange_state_id(self): state = self.state_id if state: - if self.partner_scale in ["dept", "loc"]: + if self.partner_scale in ["3", "4"]: crck = self.search( - [("partner_scale", "=", "reg"), ("state_id", "=", state)], limit=1 + [("partner_scale", "=", "2"), ("state_id", "=", state)], limit=1 ) if crck and crck != self.crck_partner_id: main = self.env.ref("base.main_partner") if self.crck_partner_id != main: self.crck_partner_id = main - elif self.partner_scale == "reg": + elif self.partner_scale == "2": self.crck_partner_id = self @api.onchange("country_department_id") def _onchange_country_department_id(self): dept = self.country_department_id - if dept and self.partner_scale == "loc": + if dept and self.partner_scale == "4": cdck = self.search( - [("partner_scale", "=", "dep"), ("country_department_id", "=", dept)], + [("partner_scale", "=", "3"), ("country_department_id", "=", dept)], limit=1, ) if cdck and cdck != self.cdck_partner_id: main = self.env.ref("base.main_partner") if self.cdck_partner_id != main: self.cdck_partner_id = main - elif self.partner_scale == "dep": + elif self.partner_scale == "3": self.cdck_partner_id = self