Skip to content

Commit

Permalink
[16.0][IMP] mrp_stock_move_cost: Improve the "update_production_cost"…
Browse files Browse the repository at this point in the history
… function.
  • Loading branch information
alfredoavanzosc authored and anajuaristi committed Oct 18, 2024
1 parent 252f626 commit 4bebe45
Showing 1 changed file with 6 additions and 19 deletions.
25 changes: 6 additions & 19 deletions mrp_stock_move_cost/models/mrp_production.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,28 +26,15 @@ def _put_cost_in_mrp_production(self):
def update_prodution_cost(self):
price_unit_cost = 0
cost = 0
cond = [
"|",
("move_id.raw_material_production_id", "=", self.id),
("move_id.production_id", "=", self.id),
]
lines = self.env["stock.move.line"].search(cond)
if lines:
consumed_lines = lines.filtered(
lambda x: x.move_id.raw_material_production_id == self
)
cost = sum(consumed_lines.mapped("cost"))
produce_lines = lines.filtered(lambda x: x.move_id.production_id == self)
for produce_line in produce_lines:
price_unit_cost = 0
if produce_line.qty_done > 0:
price_unit_cost = cost / produce_line.qty_done
produce_line.price_unit_cost = price_unit_cost
if self.move_raw_ids:
cost = sum(self.move_raw_ids.mapped("cost"))
if cost and self.move_finished_ids:
for move in self.move_finished_ids:
if move.quantity_done > 0:
move.price_unit_cost = cost / move.quantity_done
self.cost = cost
if cost and self.qty_producing:
price_unit_cost = cost / self.qty_producing
else:
price_unit_cost = 0
self.price_unit_cost = price_unit_cost
if self.lot_producing_id:
self.lot_producing_id.with_context(from_production=True).purchase_price = (
Expand Down

0 comments on commit 4bebe45

Please sign in to comment.