|
|
@ -0,0 +1,35 @@ |
|
|
|
from odoo import models, api |
|
|
|
|
|
|
|
|
|
|
|
class ResPartner(models.Model): |
|
|
|
_inherit = "res.partner" |
|
|
|
_order = "is_company desc, country_id, department_id, display_name, id" |
|
|
|
|
|
|
|
@api.onchange("state_id") |
|
|
|
def _onchange_state_id(self): |
|
|
|
state = self.state_id |
|
|
|
if state: |
|
|
|
if self.partner_scale in ["dept", "loc"]: |
|
|
|
crck = self.search( |
|
|
|
[("partner_scale", "=", "reg"), ("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": |
|
|
|
self.crck_partner_id = self |
|
|
|
|
|
|
|
@api.onchange("department_id") |
|
|
|
def _onchange_department_id(self): |
|
|
|
dept = self.department_id |
|
|
|
if dept and self.partner_scale == "loc": |
|
|
|
cdck = self.search( |
|
|
|
[("partner_scale", "=", "dep"), ("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": |
|
|
|
self.cdck_partner_id = self |