diff --git a/ssi_stock/models/stock_production_lot.py b/ssi_stock/models/stock_production_lot.py index deb3079..d0b0138 100644 --- a/ssi_stock/models/stock_production_lot.py +++ b/ssi_stock/models/stock_production_lot.py @@ -12,21 +12,25 @@ class StockProductionLot(models.Model): @api.depends( "stock_move_line_ids", - "stock_move_line_ids.date", "stock_move_line_ids.move_id.state", "tracking", ) - def _compute_serial_number_in_date(self): - for rec in self: - serial_number_in_date = False - if rec.tracking == "serial": - criteria = [("lot_id", "=", rec.id), ("state", "=", "done")] - - first_move_line_id = self.env["stock.move.line"].search( - criteria, order="date, id", limit=1 + def _compute_stock_move_line(self): + for record in self: + first_sml = last_sml = False + if record.tracking == "serial": + criteria = [ + ("lot_id", "=", record.id), + ("move_id.state", "=", "done"), + ] + smls = self.env["stock.move.line"].search( + criteria, order="date asc, id asc" ) - serial_number_in_date = first_move_line_id.date - rec.serial_number_in_date = serial_number_in_date + if len(smls) == 1: + first_sml = smls[0] + last_sml = smls[-1] + record.first_stock_move_line_id = first_sml + record.last_stock_move_line_id = last_sml tracking = fields.Selection(related="product_id.tracking", store=True) stock_move_line_ids = fields.One2many( @@ -35,9 +39,25 @@ def _compute_serial_number_in_date(self): string="Stock Move Lines", copy=False, ) + first_stock_move_line_id = fields.Many2one( + string="First Stock Move Line", + comodel_name="stock.move.line", + compute="_compute_stock_move_line", + store=True, + ) + last_stock_move_line_id = fields.Many2one( + string="Last Stock Move Line", + comodel_name="stock.move.line", + compute="_compute_stock_move_line", + store=True, + ) serial_number_in_date = fields.Datetime( string="Incoming Date", - compute="_compute_serial_number_in_date", - compute_sudo=False, - store=False, + related="first_stock_move_line_id.date", + store=True, + ) + serial_number_current_location_id = fields.Many2one( + string="Current Location", + related="last_stock_move_line_id.location_dest_id", + store=True, ) diff --git a/ssi_stock/views/stock_production_lot_views.xml b/ssi_stock/views/stock_production_lot_views.xml index dc52800..453c605 100644 --- a/ssi_stock/views/stock_production_lot_views.xml +++ b/ssi_stock/views/stock_production_lot_views.xml @@ -15,11 +15,52 @@ name="serial_number_in_date" invisible="context.get('tracking') != 'serial'" /> + + + + + + + + + stock.production.lot - search + stock.production.lot + + + + + + + + + + + + stock.production.lot - form stock.production.lot @@ -28,10 +69,23 @@ + + + +