Skip to content

Commit

Permalink
[IMP] reason code location set as a scrap location if set
Browse files Browse the repository at this point in the history
  • Loading branch information
Bhavesh Odedra authored and glitchov committed Oct 10, 2022
1 parent e075a54 commit e86baf5
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions scrap_reason_code/models/stock_scrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,23 @@ def _onchange_reason_code_id(self):

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

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

0 comments on commit e86baf5

Please sign in to comment.