[IMP] mrp_component_operation: enhance extensibility of scrap vals

aditionally some adjustments have been done:
- create_date is a magic field, no need to include it in the vals.
- production_id is the inverse name of mo_id.scrap_ids.
This commit is contained in:
Lois Rilo
2023-05-29 12:16:18 +02:00
parent 81a9a1cbf0
commit be7858d5f5
2 changed files with 15 additions and 14 deletions

View File

@@ -1 +1,2 @@
* David Jiménez <david.jimenez@forgeflow.com>
* Lois Rilo <lois.rilo@forgeflow.com>

View File

@@ -84,9 +84,8 @@ class MrpComponentOperate(models.Model):
res = []
return res
def _create_scrap(self):
scrap = self.env["stock.scrap"].create(
{
def _create_scrap_vals(self):
return {
"origin": self.mo_id.name,
"product_id": self.product_id.id,
"lot_id": self.lot_id.id,
@@ -94,11 +93,12 @@ class MrpComponentOperate(models.Model):
"product_uom_id": self.product_id.product_tmpl_id.uom_id.id,
"location_id": self.operation_id.source_location_id.id,
"scrap_location_id": self.operation_id.scrap_location_id.id,
"create_date": fields.Datetime.now(),
"company_id": self.env.company.id,
"production_id": self.mo_id.id,
}
)
self.mo_id.scrap_ids |= scrap
def _create_scrap(self):
scrap = self.env["stock.scrap"].create(self._create_scrap_vals())
scrap.action_validate()
return scrap