Skip to content

Commit

Permalink
[16.0][FIX] stock_picking_auto_create_lot: fix creating lot for 0 qty…
Browse files Browse the repository at this point in the history
… move lines for serial product
  • Loading branch information
AungKoKoLin1997 committed Feb 23, 2024
1 parent f15eb0d commit 3d0264e
Showing 1 changed file with 31 additions and 7 deletions.
38 changes: 31 additions & 7 deletions stock_picking_auto_create_lot/models/stock_move_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,20 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from odoo import models
from odoo.fields import first
from odoo.tools import OrderedSet
from odoo.tools.float_utils import float_compare


class StockMoveLine(models.Model):

_inherit = "stock.move.line"

def _get_value_production_lot(self):
res = super()._get_value_production_lot()
if "name" in res and not res["name"]:
del res["name"]
return res
def _prepare_auto_lot_values(self):
"""
Prepare multi valued lots per line to use multi creation.
"""
self.ensure_one()
return {"product_id": self.product_id.id, "company_id": self.company_id.id}

def set_lot_auto(self):
"""
Expand All @@ -24,8 +27,7 @@ def set_lot_auto(self):
stock_lot_obj = self.env["stock.lot"]
lots_by_product = dict()
for line in self:
# Prepare multi valued lots per line to use multi creation.
values.append(line._get_value_production_lot())
values.append(line._prepare_auto_lot_values())
lots = stock_lot_obj.create(values)
for lot in lots:
if lot.product_id.id not in lots_by_product:
Expand All @@ -37,3 +39,25 @@ def set_lot_auto(self):
line.lot_id = lot
if lot.product_id.tracking == "serial":
lots_by_product[line.product_id.id] -= lot

def _action_done(self):
ml_ids_to_delete = OrderedSet()
for ml in self:
qty_done_float_compared = float_compare(
ml.qty_done, 0, precision_rounding=ml.product_uom_id.rounding
)
if qty_done_float_compared != 0.00 or ml.is_inventory:
continue
if (
ml.product_id.tracking == "serial"
and ml.product_id.auto_create_lot
and ml.move_id.picking_type_id.auto_create_lot
):
ml_ids_to_delete.add(ml.id)
mls_to_delete = self.env["stock.move.line"].browse(ml_ids_to_delete)
if mls_to_delete:
for ml in mls_to_delete:
lot = self.env["stock.lot"].search([("id", "=", ml.lot_id.id)])
if lot.product_qty == 0.00:
lot.sudo().unlink()
return super(StockMoveLine, self)._action_done()

0 comments on commit 3d0264e

Please sign in to comment.