[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:
Lois Rilo
2021-07-27 12:30:30 +02:00
parent 102d473458
commit 326a046574
10 changed files with 125 additions and 5 deletions

View File

@@ -29,7 +29,7 @@ This module allows you to manually select quants for components of the
manufacturing order. manufacturing order.
The module depends on `stock_quant_manual_assign <https://github.com/OCA/stock-logistics-warehouse/tree/14.0/stock_quant_manual_assign>` 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** **Table of contents**
@@ -63,6 +63,7 @@ Authors
~~~~~~~ ~~~~~~~
* Quartile Limited * Quartile Limited
* ForgeFlow
Contributors Contributors
~~~~~~~~~~~~ ~~~~~~~~~~~~

View File

@@ -0,0 +1,2 @@
from . import wizards
from . import models

View File

@@ -7,9 +7,9 @@
"version": "14.0.1.0.0", "version": "14.0.1.0.0",
"category": "Manufacturing", "category": "Manufacturing",
"license": "AGPL-3", "license": "AGPL-3",
"author": "Quartile Limited, Odoo Community Association (OCA)", "author": "Quartile Limited, ForgeFlow, Odoo Community Association (OCA)",
"website": "https://github.com/OCA/manufacture", "website": "https://github.com/OCA/manufacture",
"depends": ["mrp", "stock_quant_manual_assign"], "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, "installable": True,
} }

View File

@@ -0,0 +1 @@
from . import stock_move

View 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

View File

@@ -2,4 +2,4 @@ This module allows you to manually select quants for components of the
manufacturing order. manufacturing order.
The module depends on `stock_quant_manual_assign <https://github.com/OCA/stock-logistics-warehouse/tree/14.0/stock_quant_manual_assign>` 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.

View File

@@ -371,7 +371,7 @@ ul.auto-toc {
<p>This module allows you to manually select quants for components of the <p>This module allows you to manually select quants for components of the
manufacturing order.</p> manufacturing order.</p>
<p>The module depends on <cite>stock_quant_manual_assign &lt;https://github.com/OCA/stock-logistics-warehouse/tree/14.0/stock_quant_manual_assign&gt;</cite> <p>The module depends on <cite>stock_quant_manual_assign &lt;https://github.com/OCA/stock-logistics-warehouse/tree/14.0/stock_quant_manual_assign&gt;</cite>
module and does not contain any logic per se.</p> module.</p>
<p><strong>Table of contents</strong></p> <p><strong>Table of contents</strong></p>
<div class="contents local topic" id="contents"> <div class="contents local topic" id="contents">
<ul class="simple"> <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> <h2><a class="toc-backref" href="#id4">Authors</a></h2>
<ul class="simple"> <ul class="simple">
<li>Quartile Limited</li> <li>Quartile Limited</li>
<li>ForgeFlow</li>
</ul> </ul>
</div> </div>
<div class="section" id="contributors"> <div class="section" id="contributors">

View File

@@ -0,0 +1 @@
from . import assign_manual_quants

View File

@@ -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,
)

View File

@@ -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>