-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'xx/13.0' into 16.0
- Loading branch information
Showing
7 changed files
with
234 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Copyright 2022 Yiğit Budak (https://github.com/yibudak) | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
{ | ||
"name": "Altinkaya Stock Lot Extensions", | ||
"summary": "Adds custom fields to stock.production.lot", | ||
"version": "13.0.1.0.0", | ||
"category": "stock", | ||
"website": "https://github.com/yibudak", | ||
"author": "Yiğit Budak", | ||
"license": "AGPL-3", | ||
"application": False, | ||
"installable": True, | ||
"depends": ["stock", "mrp"], | ||
"data": [ | ||
"wizards/mrp_product_produce_view.xml", | ||
], | ||
} |
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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# Copyright 2022 Yiğit Budak (https://github.com/yibudak) | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl) | ||
from odoo import models, api | ||
|
||
|
||
class StockInventory(models.Model): | ||
_inherit = "stock.inventory" | ||
|
||
|
||
def action_validate(self): | ||
return super(StockInventory, self).action_validate() |
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 |
---|---|---|
@@ -0,0 +1,44 @@ | ||
from odoo import api, models | ||
|
||
|
||
class InventoryLine(models.Model): | ||
_inherit = "stock.inventory.line" | ||
|
||
|
||
def _create_missing_lot(self): | ||
"""EXPERIMENTAL: Create a lot for the move line if it is missing.""" | ||
for rec in self: | ||
if rec.product_id.tracking != "none" and not rec.prod_lot_id: | ||
# yigit: When working with negative quantities, any lot without quant | ||
# is causing issues, try to search quant and link it to lot | ||
related_quant = rec.env["stock.quant"].search( | ||
[ | ||
("product_id", "=", rec.product_id.id), | ||
("location_id", "=", rec.inventory_location_id.id), | ||
("quantity", "=", rec.product_qty), | ||
("lot_id", "=", False), | ||
], | ||
limit=1, | ||
) | ||
prod_lot_id = self.env["stock.production.lot"].create( | ||
{ | ||
"product_id": rec.product_id.id, | ||
"ref": rec.inventory_id.name or "", | ||
"product_qty": rec.product_qty, | ||
"quant_ids": [(6, 0, related_quant.ids)], | ||
} | ||
) | ||
rec.prod_lot_id = prod_lot_id.id | ||
return True | ||
|
||
@api.model | ||
def create(self, vals): | ||
res = super(InventoryLine, self).create(vals) | ||
res._create_missing_lot() | ||
return res | ||
|
||
@api.model | ||
def write(self, vals): | ||
res = super(InventoryLine, self).write(vals) | ||
self._create_missing_lot() | ||
return res |
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 |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# Copyright 2022 Yiğit Budak (https://github.com/yibudak) | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl) | ||
from odoo import models, api | ||
|
||
|
||
class StockMoveLine(models.Model): | ||
_inherit = "stock.move.line" | ||
|
||
|
||
def _create_missing_lot(self): | ||
"""EXPERIMENTAL: Create a lot for the move line if it is missing.""" | ||
for rec in self: | ||
if rec.product_id.tracking != "none" and not rec.lot_id: | ||
lot_id = self.env["stock.production.lot"].create( | ||
{"product_id": rec.product_id.id, "ref": rec.move_id.name or ""} | ||
) | ||
rec.lot_id = lot_id.id | ||
return True | ||
|
||
@api.model | ||
def create(self, vals): | ||
res = super(StockMoveLine, self).create(vals) | ||
res._create_missing_lot() | ||
return res | ||
|
||
@api.model | ||
def write(self, vals): | ||
res = super(StockMoveLine, self).write(vals) | ||
self._create_missing_lot() | ||
return res |
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 |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# Copyright 2022 Yiğit Budak (https://github.com/yibudak) | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl) | ||
from odoo import models, api | ||
from odoo.tools import float_compare, float_is_zero | ||
|
||
|
||
class StockPickin(models.Model): | ||
_inherit = "stock.picking" | ||
|
||
# | ||
# def button_validate(self): | ||
# """Overridden to create lot_id for move_lines automatically""" | ||
# picking_type = self.picking_type_id | ||
# precision_digits = self.env["decimal.precision"].precision_get( | ||
# "Product Unit of Measure" | ||
# ) | ||
# no_quantities_done = all( | ||
# float_is_zero(move_line.qty_done, precision_digits=precision_digits) | ||
# for move_line in self.move_line_ids.filtered( | ||
# lambda m: m.state not in ("done", "cancel") | ||
# ) | ||
# ) | ||
# if picking_type.use_create_lots or picking_type.use_existing_lots: | ||
# lines_to_check = self.move_line_ids | ||
# if not no_quantities_done: | ||
# lines_to_check = lines_to_check.filtered( | ||
# lambda ml: float_compare( | ||
# ml.qty_done, | ||
# 0, | ||
# precision_rounding=ml.product_uom_id.rounding, | ||
# ) | ||
# ) | ||
# for line in lines_to_check: | ||
# product = line.product_id | ||
# if product and product.tracking != "none": | ||
# if not line.lot_name and not line.lot_id: | ||
# vals = { | ||
# "product_id": product.id, | ||
# "ref": self.origin or "", | ||
# } | ||
# created_lot = line.lot_id.create(vals) | ||
# line.write( | ||
# {"lot_id": created_lot.id, "lot_name": created_lot.name} | ||
# ) | ||
# return super(StockPickin, self).button_validate() |
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 |
---|---|---|
@@ -0,0 +1,64 @@ | ||
# Copyright 2022 Yiğit Budak (https://github.com/yibudak) | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl) | ||
from odoo import models, fields, api, _ | ||
from odoo.exceptions import UserError | ||
from odoo.tools import float_is_zero | ||
|
||
|
||
class MrpProductProduce(models.TransientModel): | ||
_inherit = "mrp.product.produce" | ||
|
||
|
||
def do_produce(self): | ||
"""Override do_produce method on MRP to generate lot_id automatically""" | ||
if any( | ||
[ | ||
x.product_id.tracking != "none" | ||
and not x.lot_id | ||
and not float_is_zero( | ||
x.qty_done, precision_rounding=x.product_uom_id.rounding | ||
) | ||
for x in self.produce_line_ids | ||
] | ||
): | ||
raise UserError(_("Some products are tracked by lots but no lot is set.")) | ||
|
||
if self.product_tracking != "none" and not self.lot_id: | ||
# If lot created within label printing wizard, use it | ||
if self.production_id.lot_id_to_create: | ||
self.lot_id = self.production_id.lot_id_to_create | ||
else: | ||
vals = { | ||
"product_id": self.product_id.id, | ||
"ref": self.production_id.origin or "", | ||
} | ||
self.lot_id = self.lot_id.create(vals) | ||
return super(MrpProductProduce, self).do_produce() | ||
|
||
@api.onchange("product_qty") | ||
def _onchange_product_qty(self): | ||
"""Override _onchange_product_qty method on MRP to remove duplicate | ||
rows caused by split procurement rules""" | ||
res = super(MrpProductProduce, self)._onchange_product_qty() | ||
for line in self.produce_line_ids.filtered(lambda p: not p.lot_id): | ||
real_line = self.produce_line_ids.filtered( | ||
lambda x: x.qty_to_consume == line.qty_to_consume | ||
and x.product_id == line.product_id | ||
and x.lot_id | ||
) | ||
if real_line: | ||
self.produce_line_ids -= line | ||
return res | ||
|
||
|
||
class MrpProductProduceLine(models.TransientModel): | ||
_inherit = "mrp.product.produce.line" | ||
|
||
# We've added this field to prevent selection of a lot that is not in the | ||
# raw materials location of the production order. | ||
location_src_id = fields.Many2one( | ||
"stock.location", | ||
"Raw Materials Location", | ||
related="raw_product_produce_id.production_id.location_src_id", | ||
readonly=True, | ||
) |
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 |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<odoo> | ||
<record id="view_mrp_product_produce_lot_inherit_form" model="ir.ui.view"> | ||
<field name="name">mrp.product.produce.form.inherit.lot</field> | ||
<field name="model">mrp.product.produce</field> | ||
<field name="inherit_id" ref="mrp.view_mrp_product_produce_wizard"/> | ||
<field name="arch" type="xml"> | ||
<field name="lot_id" position="attributes"> | ||
<attribute name="attrs">{'invisible': True, 'required': False}</attribute> | ||
</field> | ||
|
||
<xpath expr="//field[@name='raw_workorder_line_ids']/tree/field[@name='product_tracking']" position="after"> | ||
<field name="location_src_id" invisible="1"/> | ||
</xpath> | ||
|
||
<xpath expr="//field[@name='raw_workorder_line_ids']/tree/field[@name='lot_id']" position="attributes"> | ||
<attribute name="options">{'no_create': True, 'no_create_edit':True}</attribute> | ||
<attribute name="domain">[('product_id', '=', product_id), ('quant_ids.location_id', '=', location_src_id)]</attribute> | ||
</xpath> | ||
</field> | ||
</record> | ||
</odoo> |