@@ -8,17 +8,34 @@ class ResPartner(models.Model):
88 _inherit = "res.partner"
99 _check_company_auto = True
1010
11- @api .model
12- def _default_operating_unit (self ):
13- user = self .env ["res.users" ].browse (self .env .user .id )
14- return user .default_operating_unit_id
15-
1611 operating_unit_ids = fields .Many2many (
17- "operating.unit" ,
18- "operating_unit_partner_rel" ,
19- "partner_id" ,
20- "operating_unit_id" ,
21- "Operating Units" ,
22- required = True ,
23- default = lambda self : self ._default_operating_unit (),
12+ comodel_name = "operating.unit" ,
13+ relation = "operating_unit_partner_rel" ,
14+ column1 = "partner_id" ,
15+ column2 = "operating_unit_id" ,
16+ string = "Operating Units" ,
2417 )
18+
19+ @api .model
20+ def _user_ous_domain (self ):
21+ ou_ids = self .env .user .operating_unit_ids .ids
22+ domain = [
23+ "|" ,
24+ ("operating_unit_ids" , "in" , ou_ids ),
25+ ("operating_unit_ids" , "=" , False ),
26+ ]
27+ return domain
28+
29+ # Extending methods to replace a record rule.
30+ # Ref: https://github.com/OCA/operating-unit/issues/258
31+ @api .model
32+ def search (self , args , offset = 0 , limit = None , order = None ):
33+ # Get the OUs of the user
34+ domain = self ._user_ous_domain ()
35+ return super ().search (domain + args , offset = offset , limit = limit , order = order )
36+
37+ @api .model
38+ def search_count (self , args , limit = None ):
39+ # Get the OUs of the user
40+ domain = self ._user_ous_domain ()
41+ return super ().search_count (domain + args , limit = limit )
0 commit comments