You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

35 lines
1.3 KiB

  1. from odoo import models, api
  2. class ResPartner(models.Model):
  3. _inherit = "res.partner"
  4. _order = "is_company desc, country_id, department_id, display_name, id"
  5. @api.onchange("state_id")
  6. def _onchange_state_id(self):
  7. state = self.state_id
  8. if state:
  9. if self.partner_scale in ["dept", "loc"]:
  10. crck = self.search(
  11. [("partner_scale", "=", "reg"), ("state_id", "=", state)], limit=1
  12. )
  13. if crck and crck != self.crck_partner_id:
  14. main = self.env.ref("base.main_partner")
  15. if self.crck_partner_id != main:
  16. self.crck_partner_id = main
  17. elif self.partner_scale == "reg":
  18. self.crck_partner_id = self
  19. @api.onchange("department_id")
  20. def _onchange_department_id(self):
  21. dept = self.department_id
  22. if dept and self.partner_scale == "loc":
  23. cdck = self.search(
  24. [("partner_scale", "=", "dep"), ("department_id", "=", dept)], limit=1
  25. )
  26. if cdck and cdck != self.cdck_partner_id:
  27. main = self.env.ref("base.main_partner")
  28. if self.cdck_partner_id != main:
  29. self.cdck_partner_id = main
  30. elif self.partner_scale == "dep":
  31. self.cdck_partner_id = self