mirror of
https://github.com/OCA/manufacture.git
synced 2025-01-28 16:37:15 +02:00
[IMP] mrp_production_quant_manual_assign: select lots to be consumed
this feature is only useful for MOs of final product that are tracked by serial numbers.
This commit is contained in:
@@ -29,7 +29,7 @@ This module allows you to manually select quants for components of the
|
||||
manufacturing order.
|
||||
|
||||
The module depends on `stock_quant_manual_assign <https://github.com/OCA/stock-logistics-warehouse/tree/14.0/stock_quant_manual_assign>`
|
||||
module and does not contain any logic per se.
|
||||
module.
|
||||
|
||||
**Table of contents**
|
||||
|
||||
@@ -63,6 +63,7 @@ Authors
|
||||
~~~~~~~
|
||||
|
||||
* Quartile Limited
|
||||
* ForgeFlow
|
||||
|
||||
Contributors
|
||||
~~~~~~~~~~~~
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
from . import wizards
|
||||
from . import models
|
||||
|
||||
@@ -7,9 +7,9 @@
|
||||
"version": "14.0.1.0.0",
|
||||
"category": "Manufacturing",
|
||||
"license": "AGPL-3",
|
||||
"author": "Quartile Limited, Odoo Community Association (OCA)",
|
||||
"author": "Quartile Limited, ForgeFlow, Odoo Community Association (OCA)",
|
||||
"website": "https://github.com/OCA/manufacture",
|
||||
"depends": ["mrp", "stock_quant_manual_assign"],
|
||||
"data": ["views/mrp_production_views.xml"],
|
||||
"data": ["views/mrp_production_views.xml", "wizards/assign_manual_quants_view.xml"],
|
||||
"installable": True,
|
||||
}
|
||||
|
||||
1
mrp_production_quant_manual_assign/models/__init__.py
Normal file
1
mrp_production_quant_manual_assign/models/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
from . import stock_move
|
||||
19
mrp_production_quant_manual_assign/models/stock_move.py
Normal file
19
mrp_production_quant_manual_assign/models/stock_move.py
Normal file
@@ -0,0 +1,19 @@
|
||||
# Copyright 2021 ForgeFlow S.L. (http://www.forgeflow.com)
|
||||
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html
|
||||
|
||||
from odoo import models
|
||||
from odoo.tools.float_utils import float_is_zero
|
||||
|
||||
|
||||
class StockMove(models.Model):
|
||||
_inherit = "stock.move"
|
||||
|
||||
# While https://github.com/odoo/odoo/pull/74268 is not closed.
|
||||
def _should_bypass_set_qty_producing(self):
|
||||
res = super()._should_bypass_set_qty_producing()
|
||||
if self.has_tracking != "none" and float_is_zero(
|
||||
self.quantity_done, precision_rounding=self.product_uom.rounding
|
||||
):
|
||||
# If some serial/lot has been selected to be consumed we don't change the selection.
|
||||
return False
|
||||
return res
|
||||
@@ -2,4 +2,4 @@ This module allows you to manually select quants for components of the
|
||||
manufacturing order.
|
||||
|
||||
The module depends on `stock_quant_manual_assign <https://github.com/OCA/stock-logistics-warehouse/tree/14.0/stock_quant_manual_assign>`
|
||||
module and does not contain any logic per se.
|
||||
module.
|
||||
|
||||
@@ -371,7 +371,7 @@ ul.auto-toc {
|
||||
<p>This module allows you to manually select quants for components of the
|
||||
manufacturing order.</p>
|
||||
<p>The module depends on <cite>stock_quant_manual_assign <https://github.com/OCA/stock-logistics-warehouse/tree/14.0/stock_quant_manual_assign></cite>
|
||||
module and does not contain any logic per se.</p>
|
||||
module.</p>
|
||||
<p><strong>Table of contents</strong></p>
|
||||
<div class="contents local topic" id="contents">
|
||||
<ul class="simple">
|
||||
@@ -409,6 +409,7 @@ If you spotted it first, help us smashing it by providing a detailed and welcome
|
||||
<h2><a class="toc-backref" href="#id4">Authors</a></h2>
|
||||
<ul class="simple">
|
||||
<li>Quartile Limited</li>
|
||||
<li>ForgeFlow</li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="section" id="contributors">
|
||||
|
||||
1
mrp_production_quant_manual_assign/wizards/__init__.py
Normal file
1
mrp_production_quant_manual_assign/wizards/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
from . import assign_manual_quants
|
||||
@@ -0,0 +1,71 @@
|
||||
# Copyright 2021 ForgeFlow S.L. (http://www.forgeflow.com)
|
||||
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html
|
||||
|
||||
from odoo import api, fields, models
|
||||
from odoo.tools.float_utils import float_is_zero
|
||||
|
||||
|
||||
class AssignManualQuants(models.TransientModel):
|
||||
_inherit = "assign.manual.quants"
|
||||
|
||||
is_production_single_lot = fields.Boolean()
|
||||
|
||||
def _is_production_single_lot(self, move):
|
||||
mo = move.raw_material_production_id
|
||||
if not mo:
|
||||
return False
|
||||
if mo.product_id.tracking == "serial":
|
||||
return True
|
||||
return False
|
||||
|
||||
@api.model
|
||||
def default_get(self, fields):
|
||||
res = super(AssignManualQuants, self).default_get(fields)
|
||||
move = self.env["stock.move"].browse(self.env.context["active_id"])
|
||||
res.update({"is_production_single_lot": self._is_production_single_lot(move)})
|
||||
return res
|
||||
|
||||
@api.model
|
||||
def _prepare_wizard_line(self, move, quant):
|
||||
line = super()._prepare_wizard_line(move, quant)
|
||||
if self._is_production_single_lot(move):
|
||||
move_lines = move.move_line_ids.filtered(
|
||||
lambda ml: (
|
||||
ml.location_id == quant.location_id
|
||||
and ml.lot_id == quant.lot_id
|
||||
and ml.owner_id == quant.owner_id
|
||||
and ml.package_id == quant.package_id
|
||||
)
|
||||
)
|
||||
line["qty_done"] = sum(move_lines.mapped("qty_done"))
|
||||
line["to_consume_now"] = bool(line["qty_done"])
|
||||
return line
|
||||
|
||||
def assign_quants(self):
|
||||
res = super(AssignManualQuants, self).assign_quants()
|
||||
move = self.move_id
|
||||
if self._is_production_single_lot(move):
|
||||
precision_digits = self.env["decimal.precision"].precision_get(
|
||||
"Product Unit of Measure"
|
||||
)
|
||||
lots_to_consume = self.quants_lines.filtered(
|
||||
lambda l: l.to_consume_now
|
||||
).mapped("lot_id")
|
||||
for ml in move.move_line_ids:
|
||||
if ml.lot_id in lots_to_consume:
|
||||
ml.qty_done = ml.product_qty
|
||||
elif float_is_zero(ml.product_qty, precision_digits=precision_digits):
|
||||
ml.unlink()
|
||||
else:
|
||||
ml.qty_done = 0.0
|
||||
return res
|
||||
|
||||
|
||||
class AssignManualQuantsLines(models.TransientModel):
|
||||
_inherit = "assign.manual.quants.lines"
|
||||
|
||||
to_consume_now = fields.Boolean()
|
||||
qty_done = fields.Float(
|
||||
digits="Product Unit of Measure",
|
||||
readonly=True,
|
||||
)
|
||||
@@ -0,0 +1,24 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<odoo>
|
||||
<record model="ir.ui.view" id="assign_manual_quants_form_view">
|
||||
<field
|
||||
name="name"
|
||||
>assign.manual.quants.form - mrp_production_quant_manual_assign</field>
|
||||
<field name="model">assign.manual.quants</field>
|
||||
<field
|
||||
name="inherit_id"
|
||||
ref="stock_quant_manual_assign.assign_manual_quants_form_view"
|
||||
/>
|
||||
<field name="arch" type="xml">
|
||||
<field name="selected" position="after">
|
||||
<field
|
||||
name="to_consume_now"
|
||||
attrs="{'column_invisible': [('parent.is_production_single_lot', '=', False)]}"
|
||||
/>
|
||||
</field>
|
||||
<field name="move_id" position="after">
|
||||
<field name="is_production_single_lot" invisible="1" />
|
||||
</field>
|
||||
</field>
|
||||
</record>
|
||||
</odoo>
|
||||
Reference in New Issue
Block a user