From 2ea2d3a6c4f4e5395cc7448529ad854a58026662 Mon Sep 17 00:00:00 2001 From: Patrick Wilson <36892066+patrickrwilson@users.noreply.github.com> Date: Mon, 16 May 2022 14:22:21 -0400 Subject: [PATCH] [IMP] scrap_reason_code: Moved common code to own method --- scrap_reason_code/models/stock_scrap.py | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/scrap_reason_code/models/stock_scrap.py b/scrap_reason_code/models/stock_scrap.py index 9b3f9027702a..0764ae597b0b 100644 --- a/scrap_reason_code/models/stock_scrap.py +++ b/scrap_reason_code/models/stock_scrap.py @@ -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)