Browse Source

[IMP] crock_base

16.0
RemiFr82 6 months ago
parent
commit
a83beb377d
  1. 1
      crock_base/__init__.py
  2. 2
      crock_base/__manifest__.py
  3. 29
      crock_base/hooks.py
  4. 12
      crock_base/models/res_partner.py

1
crock_base/__init__.py

@ -1 +1,2 @@
from . import models from . import models
from .hooks import post_init_hook

2
crock_base/__manifest__.py

@ -48,6 +48,6 @@
"installable": True, "installable": True,
"maintainer": "RemiFr82", "maintainer": "RemiFr82",
"pre_init_hook": "", "pre_init_hook": "",
"post_init_hook": "",
"post_init_hook": "post_init_hook",
"uninstall_hook": "", "uninstall_hook": "",
} }

29
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")

12
crock_base/models/res_partner.py

@ -9,28 +9,28 @@ class ResPartner(models.Model):
def _onchange_state_id(self): def _onchange_state_id(self):
state = self.state_id state = self.state_id
if state: if state:
if self.partner_scale in ["dept", "loc"]:
if self.partner_scale in ["3", "4"]:
crck = self.search( 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: if crck and crck != self.crck_partner_id:
main = self.env.ref("base.main_partner") main = self.env.ref("base.main_partner")
if self.crck_partner_id != main: if self.crck_partner_id != main:
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 self.crck_partner_id = self
@api.onchange("country_department_id") @api.onchange("country_department_id")
def _onchange_country_department_id(self): def _onchange_country_department_id(self):
dept = self.country_department_id dept = self.country_department_id
if dept and self.partner_scale == "loc":
if dept and self.partner_scale == "4":
cdck = self.search( cdck = self.search(
[("partner_scale", "=", "dep"), ("country_department_id", "=", dept)],
[("partner_scale", "=", "3"), ("country_department_id", "=", dept)],
limit=1, limit=1,
) )
if cdck and cdck != self.cdck_partner_id: if cdck and cdck != self.cdck_partner_id:
main = self.env.ref("base.main_partner") main = self.env.ref("base.main_partner")
if self.cdck_partner_id != main: if self.cdck_partner_id != main:
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 self.cdck_partner_id = self
Loading…
Cancel
Save