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
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ class MrpProduction(models.Model):
copy=False,
)

has_finished_move_lines = fields.Boolean(
compute="_compute_has_finished_move_lines", store=False
)

@api.onchange("lot_producing_id")
def _onchange_lot_producing(self):
res = super()._onchange_lot_producing()
Expand Down Expand Up @@ -77,6 +81,7 @@ def _get_lot_name(self, number=1):
self.product_tracking == "serial"
and self.state not in ("done", "cancel")
and not self.serial_lot_name
and not self.has_finished_move_lines
):
if "from_product_lot_sequence" not in self.env.context or (
"from_product_lot_sequence" in self.env.context
Expand All @@ -95,6 +100,12 @@ def _get_lot_name(self, number=1):
return new_lot_name

def action_generate_serial(self):
if self.has_finished_move_lines:
self.serial_lot_name = False
return super(
MrpProduction,
self.with_context(qty_twith_serial=self.qty_producing),
).action_generate_serial()
if (
"from_product_lot_sequence" in self.env.context
and "from_button_mark_done" in self.env.context
Expand Down Expand Up @@ -137,6 +148,9 @@ def _set_qty_producing(self):

def button_mark_done(self):
if self.product_tracking == "serial":
if self.has_finished_move_lines:
self.serial_lot_name = False
return super().button_mark_done()
if not self.lot_producing_id:
if (
"from_product_lot_sequence" not in self.env.context
Expand Down Expand Up @@ -171,6 +185,8 @@ def _post_inventory(self, cancel_backorder=False):

def create_lot_for_tracking_serial(self):
self.ensure_one()
if self.has_finished_move_lines:
return
moves = self.move_finished_ids.filtered(
lambda x: x.product_id == self.product_id
)
Expand Down Expand Up @@ -254,3 +270,10 @@ def _prepare_stock_lot_values(self):
"company_id": self.company_id.id,
}
return super()._prepare_stock_lot_values()

@api.depends("move_finished_ids.move_line_ids")
def _compute_has_finished_move_lines(self):
for production in self:
production.has_finished_move_lines = any(
production.move_finished_ids.mapped("move_line_ids")
)
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@
</div>
<field name="initial_product_qty" class="oe_inline text-left" />
</div>
<field name="has_finished_move_lines" invisible="1" />
<field
name="serial_lot_name"
attrs="{'invisible': [ ('product_tracking', '!=', 'serial')], 'readonly': [('state', 'in', ('done', 'cancel'))]}"
attrs="{ 'invisible': [ '|', ('product_tracking', '!=', 'serial'), '&amp;', ('product_tracking', '=', 'serial'), '&amp;', ('state', 'not in', ('done','cancel')), ('has_finished_move_lines', '=', True) ], 'readonly': [('state', 'in', ('done', 'cancel'))] }"
/>
</label>

Expand Down