Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 49 additions & 28 deletions mrp_show_finished_moves/models/mrp_production.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,24 +44,34 @@ def _increment_serial_number(self, serial):
)
return new_serial

def _update_move_next_serial(self):
def _update_move_next_serial(self, qty):
for production in self:
production._compute_last_manufactured_lot()
if production.last_manufactured_lot:
next_serial = self._increment_serial_number(
next_serial = production._increment_serial_number(
production.last_manufactured_lot
)
if next_serial:
moves_to_update = production.move_finished_ids.filtered(
lambda m: m.product_id == production.product_id
)
moves_to_update.write(
{
"next_serial": next_serial,
"next_serial_count": production.product_qty,
}
lambda m: (
m.product_id == production.product_id
and m.state not in ("done", "cancel")
)
)
moves_to_update.action_clear_lines_show_details()
moves_to_update.action_assign_serial_show_details()
for move in moves_to_update:
if (
qty != move.next_serial_count
or next_serial != move.next_serial
):
move.write(
{
"next_serial": next_serial,
"next_serial_count": qty,
}
)
move.action_clear_lines_show_details()
move.action_assign_serial_show_details()
production.qty_producing = move.quantity_done

def action_show_finished_move_lines(self):
self.ensure_one()
Expand Down Expand Up @@ -179,7 +189,24 @@ def button_mark_done(self):
yes_label=_("Yes, adjust quantities and proceed"),
no_label=_("No, review data first"),
)
return super().button_mark_done()
res = super().button_mark_done()

for production in self:
partials = self.env["mrp.production"].search(
[
("procurement_group_id", "=", production.procurement_group_id.id),
("id", "!=", production.id),
("state", "!=", "done"),
]
)
for partial in partials:
partial._compute_last_manufactured_lot()
if (
partial.last_manufactured_lot
and partial.product_id.tracking == "serial"
):
partial._update_move_next_serial(partial.product_qty)
return res

def _launch_qty_warning(self, production, message, yes_label, no_label):
"""Launches the generic quantity warning wizard with context-specific text."""
Expand Down Expand Up @@ -210,20 +237,17 @@ def update_quantity_done(self):
wo.qty_producing = quantity_done
wo.qty_produced = quantity_done

@api.model
def create(self, vals):
production = super().create(vals)
if (
production.last_manufactured_lot
and production.product_id.tracking == "serial"
):
production._update_move_next_serial()
return production
def action_confirm(self):
res = super().action_confirm()
for production in self:
if production.product_id.tracking == "serial":
production._update_move_next_serial(production.product_qty)
return res

def write(self, vals):
res = super().write(vals)
if "lot_producing_id" in vals:
for production in self:
for production in self:
if "lot_producing_id" in vals:
new_name = (
production.lot_producing_id.name
if production.lot_producing_id
Expand Down Expand Up @@ -252,11 +276,8 @@ def write(self, vals):
)
)
move.move_line_ids = ml_cmds
if (
"last_manufactured_lot" in vals
and production.product_id.tracking == "serial"
):
production._update_move_next_serial()
if "qty_producing" in vals and production.product_id.tracking == "serial":
production._update_move_next_serial(production.qty_producing)
return res


Expand Down
22 changes: 22 additions & 0 deletions mrp_show_finished_moves/models/stock_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,25 @@ def action_show_move_lines_packages(self):
"res_model": "stock.quant.package",
"domain": [("id", "in", all_packages.ids)],
}

def write(self, vals):
res = super().write(vals)
for move in self:
if (
move.product_id.tracking == "serial"
and "next_serial_count" in vals
and move.product_id == move.production_id.product_id
and move.state not in ["done", "cancel"]
):
production = move.production_id
production._compute_last_manufactured_lot()
if production.last_manufactured_lot:
next_serial = production._increment_serial_number(
production.last_manufactured_lot
)
move.next_serial = next_serial
move.action_clear_lines_show_details()
move.action_assign_serial_show_details()
if production.qty_producing != move.quantity_done:
production.qty_producing = move.quantity_done
return res