diff --git a/mrp_production_quant_manual_assign/README.rst b/mrp_production_quant_manual_assign/README.rst index 063f151e2..75ea0be32 100644 --- a/mrp_production_quant_manual_assign/README.rst +++ b/mrp_production_quant_manual_assign/README.rst @@ -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 ` -module and does not contain any logic per se. +module. **Table of contents** @@ -63,6 +63,7 @@ Authors ~~~~~~~ * Quartile Limited +* ForgeFlow Contributors ~~~~~~~~~~~~ diff --git a/mrp_production_quant_manual_assign/__init__.py b/mrp_production_quant_manual_assign/__init__.py index e69de29bb..976591c99 100644 --- a/mrp_production_quant_manual_assign/__init__.py +++ b/mrp_production_quant_manual_assign/__init__.py @@ -0,0 +1,2 @@ +from . import wizards +from . import models diff --git a/mrp_production_quant_manual_assign/__manifest__.py b/mrp_production_quant_manual_assign/__manifest__.py index 98d41a866..52b74f97f 100644 --- a/mrp_production_quant_manual_assign/__manifest__.py +++ b/mrp_production_quant_manual_assign/__manifest__.py @@ -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, } diff --git a/mrp_production_quant_manual_assign/models/__init__.py b/mrp_production_quant_manual_assign/models/__init__.py new file mode 100644 index 000000000..6bda2d242 --- /dev/null +++ b/mrp_production_quant_manual_assign/models/__init__.py @@ -0,0 +1 @@ +from . import stock_move diff --git a/mrp_production_quant_manual_assign/models/stock_move.py b/mrp_production_quant_manual_assign/models/stock_move.py new file mode 100644 index 000000000..dec00e10b --- /dev/null +++ b/mrp_production_quant_manual_assign/models/stock_move.py @@ -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 diff --git a/mrp_production_quant_manual_assign/readme/DESCRIPTION.rst b/mrp_production_quant_manual_assign/readme/DESCRIPTION.rst index f8570c1ad..8a779fc1a 100644 --- a/mrp_production_quant_manual_assign/readme/DESCRIPTION.rst +++ b/mrp_production_quant_manual_assign/readme/DESCRIPTION.rst @@ -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 ` -module and does not contain any logic per se. +module. diff --git a/mrp_production_quant_manual_assign/static/description/index.html b/mrp_production_quant_manual_assign/static/description/index.html index f38ab22b2..32fd43b5c 100644 --- a/mrp_production_quant_manual_assign/static/description/index.html +++ b/mrp_production_quant_manual_assign/static/description/index.html @@ -371,7 +371,7 @@ ul.auto-toc {

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

    @@ -409,6 +409,7 @@ If you spotted it first, help us smashing it by providing a detailed and welcome

    Authors

    • Quartile Limited
    • +
    • ForgeFlow
diff --git a/mrp_production_quant_manual_assign/wizards/__init__.py b/mrp_production_quant_manual_assign/wizards/__init__.py new file mode 100644 index 000000000..781c26d93 --- /dev/null +++ b/mrp_production_quant_manual_assign/wizards/__init__.py @@ -0,0 +1 @@ +from . import assign_manual_quants diff --git a/mrp_production_quant_manual_assign/wizards/assign_manual_quants.py b/mrp_production_quant_manual_assign/wizards/assign_manual_quants.py new file mode 100644 index 000000000..2f126695c --- /dev/null +++ b/mrp_production_quant_manual_assign/wizards/assign_manual_quants.py @@ -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, + ) diff --git a/mrp_production_quant_manual_assign/wizards/assign_manual_quants_view.xml b/mrp_production_quant_manual_assign/wizards/assign_manual_quants_view.xml new file mode 100644 index 000000000..0aa8121d6 --- /dev/null +++ b/mrp_production_quant_manual_assign/wizards/assign_manual_quants_view.xml @@ -0,0 +1,24 @@ + + + + assign.manual.quants.form - mrp_production_quant_manual_assign + assign.manual.quants + + + + + + + + + + +