-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e6f3c42
commit 1040f60
Showing
3 changed files
with
43 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,13 @@ | ||
# Copyright 2020 ACSONE SA/NV | ||
# Copyright 2024 Quartile Limited | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
|
||
from odoo import models | ||
from odoo.fields import first | ||
|
||
|
||
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 set_lot_auto(self): | ||
""" | ||
Create lots using create_multi to avoid too much queries | ||
As move lines were created by product or by tracked 'serial' | ||
products, we apply the lot with both different approaches. | ||
""" | ||
values = [] | ||
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()) | ||
lots = stock_lot_obj.create(values) | ||
for lot in lots: | ||
if lot.product_id.id not in lots_by_product: | ||
lots_by_product[lot.product_id.id] = lot | ||
else: | ||
lots_by_product[lot.product_id.id] += lot | ||
for line in self: | ||
lot = first(lots_by_product[line.product_id.id]) | ||
line.lot_id = lot | ||
if lot.product_id.tracking == "serial": | ||
lots_by_product[line.product_id.id] -= lot | ||
def _get_lot_sequence(self): | ||
self.ensure_one() | ||
return self.env["ir.sequence"].next_by_code("stock.lot.serial") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters