Skip to content

Commit

Permalink
[IMP] scrap_reason_code: Moved common code to own method
Browse files Browse the repository at this point in the history
  • Loading branch information
patrickrwilson authored and glitchov committed Oct 10, 2022
1 parent 591d432 commit 2ea2d3a
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions scrap_reason_code/models/stock_scrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,25 +23,21 @@ def _onchange_reason_code_id(self):
if self.reason_code_id.location_id:
self.scrap_location_id = self.reason_code_id.location_id

def write(self, vals):
def _update_scrap_reason_code_location(self, vals):
if "reason_code_id" in vals:
location_id = (
self.env["scrap.reason.code"]
.browse(vals.get("reason_code_id"))
.location_id
.location_id.id
)
if location_id:
vals.update({"scrap_location_id": location_id})

def write(self, vals):
self._update_scrap_reason_code_location(vals)
return super(StockScrap, self).write(vals)

@api.model
def create(self, vals):
if "reason_code_id" in vals:
location_id = (
self.env["scrap.reason.code"]
.browse(vals.get("reason_code_id"))
.location_id
)
if location_id:
vals["scrap_location_id"] = location_id.id
self._update_scrap_reason_code_location(vals)
return super(StockScrap, self).create(vals)

0 comments on commit 2ea2d3a

Please sign in to comment.