Skip to content

Commit

Permalink
[IMP] product_origin : set automatically country, when state is defined
Browse files Browse the repository at this point in the history
  • Loading branch information
legalsylvain committed Jan 11, 2024
1 parent 1a8fb95 commit 3f8a635
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
5 changes: 5 additions & 0 deletions product_origin/models/product_product.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ def onchange_country_id(self):
if self.state_id and self.state_id.country_id != self.country_id:
self.state_id = False

@api.onchange("state_id")
def onchange_state_id(self):
if self.state_id:
self.country_id = self.state_id.country_id

@api.depends("country_id")
def _compute_state_id_domain(self):
for product in self.filtered(lambda x: x.country_id):
Expand Down
5 changes: 5 additions & 0 deletions product_origin/models/product_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ def onchange_country_id(self):
if self.state_id and self.state_id.country_id != self.country_id:
self.state_id = False

@api.onchange("state_id")
def onchange_state_id(self):
if self.state_id:
self.country_id = self.state_id.country_id

@api.constrains("country_id", "state_id")
def _check_country_id_state_id(self):
for template in self.filtered(lambda x: x.state_id and x.country_id):
Expand Down

0 comments on commit 3f8a635

Please sign in to comment.