diff --git a/mrp_production_quant_manual_assign/README.rst b/mrp_production_quant_manual_assign/README.rst new file mode 100644 index 00000000..533faf95 --- /dev/null +++ b/mrp_production_quant_manual_assign/README.rst @@ -0,0 +1,97 @@ +==================================== +Production - Manual Quant Assignment +==================================== + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:958dcd462d86360bad9fc7c79701a3e028c9593fc8ca08b3b310369b1d4751d3 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png + :target: https://odoo-community.org/page/development-status + :alt: Beta +.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 +.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fmanufacture-lightgray.png?logo=github + :target: https://github.com/OCA/manufacture/tree/16.0/mrp_production_quant_manual_assign + :alt: OCA/manufacture +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/manufacture-16-0/manufacture-16-0-mrp_production_quant_manual_assign + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png + :target: https://runboat.odoo-community.org/builds?repo=OCA/manufacture&target_branch=16.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module allows you to manually select quants for components of the +manufacturing order. + +The module depends on `stock_quant_manual_assign ` +module. + +**Table of contents** + +.. contents:: + :local: + +Usage +===== + +To use this module, you need to: + +#. Open a manufacturing order. +#. Click on the tag icon next to Reserved Quantity of a move line, which opens + a wizard for manually selecting quants. +#. Select quants and update quantities to assign (reserve), then Confirm. + +Bug Tracker +=========== + +Bugs are tracked on `GitHub Issues `_. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us to smash it by providing a detailed and welcomed +`feedback `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +~~~~~~~ + +* Quartile Limited +* ForgeFlow + +Contributors +~~~~~~~~~~~~ + +* `Quartile Limited `_: + + * Yoshi Tashiro + +* `ForgeFlow `_: + + * Lois Rilo + +Maintainers +~~~~~~~~~~~ + +This module is maintained by the OCA. + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use. + +This module is part of the `OCA/manufacture `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/mrp_production_quant_manual_assign/__init__.py b/mrp_production_quant_manual_assign/__init__.py new file mode 100644 index 00000000..976591c9 --- /dev/null +++ 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 new file mode 100644 index 00000000..ef1e3272 --- /dev/null +++ b/mrp_production_quant_manual_assign/__manifest__.py @@ -0,0 +1,15 @@ +# Copyright 2021 Quartile Limited +# Copyright 2021 ForgeFlow S.L. (http://www.forgeflow.com) +# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html + +{ + "name": "Production - Manual Quant Assignment", + "version": "16.0.1.0.0", + "category": "Manufacturing", + "license": "AGPL-3", + "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", "wizards/assign_manual_quants_view.xml"], + "installable": True, +} diff --git a/mrp_production_quant_manual_assign/i18n/es.po b/mrp_production_quant_manual_assign/i18n/es.po new file mode 100644 index 00000000..835d4b3d --- /dev/null +++ b/mrp_production_quant_manual_assign/i18n/es.po @@ -0,0 +1,52 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * mrp_production_quant_manual_assign +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2023-07-10 10:08+0000\n" +"Last-Translator: Ivorra78 \n" +"Language-Team: none\n" +"Language: es\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=2; plural=n != 1;\n" +"X-Generator: Weblate 4.17\n" + +#. module: mrp_production_quant_manual_assign +#: model:ir.model,name:mrp_production_quant_manual_assign.model_assign_manual_quants +msgid "Assign Manual Quants" +msgstr "Asignación manual de cantidades" + +#. module: mrp_production_quant_manual_assign +#: model:ir.model,name:mrp_production_quant_manual_assign.model_assign_manual_quants_lines +msgid "Assign Manual Quants Lines" +msgstr "Asignación manual de líneas de cantidades" + +#. module: mrp_production_quant_manual_assign +#: model:ir.model.fields,field_description:mrp_production_quant_manual_assign.field_assign_manual_quants__is_production_single_lot +msgid "Is Production Single Lot" +msgstr "es un lote de producción única" + +#. module: mrp_production_quant_manual_assign +#: model_terms:ir.ui.view,arch_db:mrp_production_quant_manual_assign.mrp_production_form_view +msgid "Manual Quants" +msgstr "cantidades manuales" + +#. module: mrp_production_quant_manual_assign +#: model:ir.model.fields,field_description:mrp_production_quant_manual_assign.field_assign_manual_quants_lines__qty_done +msgid "Qty Done" +msgstr "Cantidad finalizada" + +#. module: mrp_production_quant_manual_assign +#: model:ir.model,name:mrp_production_quant_manual_assign.model_stock_move +msgid "Stock Move" +msgstr "Movimiento de existencias" + +#. module: mrp_production_quant_manual_assign +#: model:ir.model.fields,field_description:mrp_production_quant_manual_assign.field_assign_manual_quants_lines__to_consume_now +msgid "To Consume Now" +msgstr "Para consumir ahora" diff --git a/mrp_production_quant_manual_assign/i18n/it.po b/mrp_production_quant_manual_assign/i18n/it.po new file mode 100644 index 00000000..83e3b354 --- /dev/null +++ b/mrp_production_quant_manual_assign/i18n/it.po @@ -0,0 +1,52 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * mrp_production_quant_manual_assign +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2023-06-12 09:09+0000\n" +"Last-Translator: mymage \n" +"Language-Team: none\n" +"Language: it\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=2; plural=n != 1;\n" +"X-Generator: Weblate 4.17\n" + +#. module: mrp_production_quant_manual_assign +#: model:ir.model,name:mrp_production_quant_manual_assign.model_assign_manual_quants +msgid "Assign Manual Quants" +msgstr "Assegna quanto manuale" + +#. module: mrp_production_quant_manual_assign +#: model:ir.model,name:mrp_production_quant_manual_assign.model_assign_manual_quants_lines +msgid "Assign Manual Quants Lines" +msgstr "Assegna righe quanti manuali" + +#. module: mrp_production_quant_manual_assign +#: model:ir.model.fields,field_description:mrp_production_quant_manual_assign.field_assign_manual_quants__is_production_single_lot +msgid "Is Production Single Lot" +msgstr "È un lotto di produzione singolo" + +#. module: mrp_production_quant_manual_assign +#: model_terms:ir.ui.view,arch_db:mrp_production_quant_manual_assign.mrp_production_form_view +msgid "Manual Quants" +msgstr "Quanti manuali" + +#. module: mrp_production_quant_manual_assign +#: model:ir.model.fields,field_description:mrp_production_quant_manual_assign.field_assign_manual_quants_lines__qty_done +msgid "Qty Done" +msgstr "Qta. prodotta" + +#. module: mrp_production_quant_manual_assign +#: model:ir.model,name:mrp_production_quant_manual_assign.model_stock_move +msgid "Stock Move" +msgstr "Movimento di magazzino" + +#. module: mrp_production_quant_manual_assign +#: model:ir.model.fields,field_description:mrp_production_quant_manual_assign.field_assign_manual_quants_lines__to_consume_now +msgid "To Consume Now" +msgstr "Da consumare adesso" diff --git a/mrp_production_quant_manual_assign/i18n/ja.po b/mrp_production_quant_manual_assign/i18n/ja.po new file mode 100644 index 00000000..b87e352f --- /dev/null +++ b/mrp_production_quant_manual_assign/i18n/ja.po @@ -0,0 +1,51 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * mrp_production_quant_manual_assign +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2023-11-01 01:30+0000\n" +"PO-Revision-Date: 2023-11-01 01:30+0000\n" +"Last-Translator: \n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: mrp_production_quant_manual_assign +#: model:ir.model,name:mrp_production_quant_manual_assign.model_assign_manual_quants +msgid "Assign Manual Quants" +msgstr "手動在庫割当" + +#. module: mrp_production_quant_manual_assign +#: model:ir.model,name:mrp_production_quant_manual_assign.model_assign_manual_quants_lines +msgid "Assign Manual Quants Lines" +msgstr "手動在庫明細割当" + +#. module: mrp_production_quant_manual_assign +#: model:ir.model.fields,field_description:mrp_production_quant_manual_assign.field_assign_manual_quants__is_production_single_lot +msgid "Is Production Single Lot" +msgstr "単一ロットの製造" + +#. module: mrp_production_quant_manual_assign +#: model_terms:ir.ui.view,arch_db:mrp_production_quant_manual_assign.mrp_production_form_view +msgid "Manual Quants" +msgstr "手動割当" + +#. module: mrp_production_quant_manual_assign +#: model:ir.model.fields,field_description:mrp_production_quant_manual_assign.field_assign_manual_quants_lines__qty_done +msgid "Qty Done" +msgstr "完了数量" + +#. module: mrp_production_quant_manual_assign +#: model:ir.model,name:mrp_production_quant_manual_assign.model_stock_move +msgid "Stock Move" +msgstr "在庫移動" + +#. module: mrp_production_quant_manual_assign +#: model:ir.model.fields,field_description:mrp_production_quant_manual_assign.field_assign_manual_quants_lines__to_consume_now +msgid "To Consume Now" +msgstr "今すぐ消費" diff --git a/mrp_production_quant_manual_assign/i18n/mrp_production_quant_manual_assign.pot b/mrp_production_quant_manual_assign/i18n/mrp_production_quant_manual_assign.pot new file mode 100644 index 00000000..14aab9f4 --- /dev/null +++ b/mrp_production_quant_manual_assign/i18n/mrp_production_quant_manual_assign.pot @@ -0,0 +1,49 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * mrp_production_quant_manual_assign +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.0\n" +"Report-Msgid-Bugs-To: \n" +"Last-Translator: \n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: mrp_production_quant_manual_assign +#: model:ir.model,name:mrp_production_quant_manual_assign.model_assign_manual_quants +msgid "Assign Manual Quants" +msgstr "" + +#. module: mrp_production_quant_manual_assign +#: model:ir.model,name:mrp_production_quant_manual_assign.model_assign_manual_quants_lines +msgid "Assign Manual Quants Lines" +msgstr "" + +#. module: mrp_production_quant_manual_assign +#: model:ir.model.fields,field_description:mrp_production_quant_manual_assign.field_assign_manual_quants__is_production_single_lot +msgid "Is Production Single Lot" +msgstr "" + +#. module: mrp_production_quant_manual_assign +#: model_terms:ir.ui.view,arch_db:mrp_production_quant_manual_assign.mrp_production_form_view +msgid "Manual Quants" +msgstr "" + +#. module: mrp_production_quant_manual_assign +#: model:ir.model.fields,field_description:mrp_production_quant_manual_assign.field_assign_manual_quants_lines__qty_done +msgid "Qty Done" +msgstr "" + +#. module: mrp_production_quant_manual_assign +#: model:ir.model,name:mrp_production_quant_manual_assign.model_stock_move +msgid "Stock Move" +msgstr "" + +#. module: mrp_production_quant_manual_assign +#: model:ir.model.fields,field_description:mrp_production_quant_manual_assign.field_assign_manual_quants_lines__to_consume_now +msgid "To Consume Now" +msgstr "" diff --git a/mrp_production_quant_manual_assign/i18n/pt_BR.po b/mrp_production_quant_manual_assign/i18n/pt_BR.po new file mode 100644 index 00000000..79744f44 --- /dev/null +++ b/mrp_production_quant_manual_assign/i18n/pt_BR.po @@ -0,0 +1,52 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * mrp_production_quant_manual_assign +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 12.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2021-03-15 07:45+0000\n" +"Last-Translator: Marcel Savegnago \n" +"Language-Team: none\n" +"Language: pt_BR\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=2; plural=n > 1;\n" +"X-Generator: Weblate 4.3.2\n" + +#. module: mrp_production_quant_manual_assign +#: model:ir.model,name:mrp_production_quant_manual_assign.model_assign_manual_quants +msgid "Assign Manual Quants" +msgstr "" + +#. module: mrp_production_quant_manual_assign +#: model:ir.model,name:mrp_production_quant_manual_assign.model_assign_manual_quants_lines +msgid "Assign Manual Quants Lines" +msgstr "" + +#. module: mrp_production_quant_manual_assign +#: model:ir.model.fields,field_description:mrp_production_quant_manual_assign.field_assign_manual_quants__is_production_single_lot +msgid "Is Production Single Lot" +msgstr "" + +#. module: mrp_production_quant_manual_assign +#: model_terms:ir.ui.view,arch_db:mrp_production_quant_manual_assign.mrp_production_form_view +msgid "Manual Quants" +msgstr "Quantidades Manuais" + +#. module: mrp_production_quant_manual_assign +#: model:ir.model.fields,field_description:mrp_production_quant_manual_assign.field_assign_manual_quants_lines__qty_done +msgid "Qty Done" +msgstr "" + +#. module: mrp_production_quant_manual_assign +#: model:ir.model,name:mrp_production_quant_manual_assign.model_stock_move +msgid "Stock Move" +msgstr "" + +#. module: mrp_production_quant_manual_assign +#: model:ir.model.fields,field_description:mrp_production_quant_manual_assign.field_assign_manual_quants_lines__to_consume_now +msgid "To Consume Now" +msgstr "" 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 00000000..6bda2d24 --- /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 00000000..dec00e10 --- /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/CONTRIBUTORS.rst b/mrp_production_quant_manual_assign/readme/CONTRIBUTORS.rst new file mode 100644 index 00000000..cc55b779 --- /dev/null +++ b/mrp_production_quant_manual_assign/readme/CONTRIBUTORS.rst @@ -0,0 +1,7 @@ +* `Quartile Limited `_: + + * Yoshi Tashiro + +* `ForgeFlow `_: + + * Lois Rilo diff --git a/mrp_production_quant_manual_assign/readme/DESCRIPTION.rst b/mrp_production_quant_manual_assign/readme/DESCRIPTION.rst new file mode 100644 index 00000000..8a779fc1 --- /dev/null +++ b/mrp_production_quant_manual_assign/readme/DESCRIPTION.rst @@ -0,0 +1,5 @@ +This module allows you to manually select quants for components of the +manufacturing order. + +The module depends on `stock_quant_manual_assign ` +module. diff --git a/mrp_production_quant_manual_assign/readme/USAGE.rst b/mrp_production_quant_manual_assign/readme/USAGE.rst new file mode 100644 index 00000000..12ad59d9 --- /dev/null +++ b/mrp_production_quant_manual_assign/readme/USAGE.rst @@ -0,0 +1,6 @@ +To use this module, you need to: + +#. Open a manufacturing order. +#. Click on the tag icon next to Reserved Quantity of a move line, which opens + a wizard for manually selecting quants. +#. Select quants and update quantities to assign (reserve), then Confirm. diff --git a/mrp_production_quant_manual_assign/static/description/icon.png b/mrp_production_quant_manual_assign/static/description/icon.png new file mode 100644 index 00000000..3a0328b5 Binary files /dev/null and b/mrp_production_quant_manual_assign/static/description/icon.png differ diff --git a/mrp_production_quant_manual_assign/static/description/index.html b/mrp_production_quant_manual_assign/static/description/index.html new file mode 100644 index 00000000..08ff4618 --- /dev/null +++ b/mrp_production_quant_manual_assign/static/description/index.html @@ -0,0 +1,443 @@ + + + + + + +Production - Manual Quant Assignment + + + +
+

Production - Manual Quant Assignment

+ + +

Beta License: AGPL-3 OCA/manufacture Translate me on Weblate Try me on Runboat

+

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.

+

Table of contents

+ +
+

Usage

+

To use this module, you need to:

+
    +
  1. Open a manufacturing order.
  2. +
  3. Click on the tag icon next to Reserved Quantity of a move line, which opens +a wizard for manually selecting quants.
  4. +
  5. Select quants and update quantities to assign (reserve), then Confirm.
  6. +
+
+
+

Bug Tracker

+

Bugs are tracked on GitHub Issues. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us to smash it by providing a detailed and welcomed +feedback.

+

Do not contact contributors directly about support or help with technical issues.

+
+
+

Credits

+
+

Authors

+
    +
  • Quartile Limited
  • +
  • ForgeFlow
  • +
+
+
+

Contributors

+ +
+
+

Maintainers

+

This module is maintained by the OCA.

+Odoo Community Association +

OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use.

+

This module is part of the OCA/manufacture project on GitHub.

+

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

+
+
+
+ + diff --git a/mrp_production_quant_manual_assign/views/mrp_production_views.xml b/mrp_production_quant_manual_assign/views/mrp_production_views.xml new file mode 100644 index 00000000..a3574ff0 --- /dev/null +++ b/mrp_production_quant_manual_assign/views/mrp_production_views.xml @@ -0,0 +1,23 @@ + + + + mrp.production.form + mrp.production + + + + + + + diff --git a/stock_quant_manual_assign/views/stock_picking_type_views.xml b/stock_quant_manual_assign/views/stock_picking_type_views.xml new file mode 100644 index 00000000..8c1d4051 --- /dev/null +++ b/stock_quant_manual_assign/views/stock_picking_type_views.xml @@ -0,0 +1,16 @@ + + + + Operation Types + stock.picking.type + + + + + + + + diff --git a/stock_quant_manual_assign/wizard/__init__.py b/stock_quant_manual_assign/wizard/__init__.py new file mode 100644 index 00000000..781c26d9 --- /dev/null +++ b/stock_quant_manual_assign/wizard/__init__.py @@ -0,0 +1 @@ +from . import assign_manual_quants diff --git a/stock_quant_manual_assign/wizard/assign_manual_quants.py b/stock_quant_manual_assign/wizard/assign_manual_quants.py new file mode 100644 index 00000000..79e8c44e --- /dev/null +++ b/stock_quant_manual_assign/wizard/assign_manual_quants.py @@ -0,0 +1,256 @@ +# Copyright 2015 Mikel Arregi - AvanzOSC +# Copyright 2015 Oihane Crucelaegui - AvanzOSC +# Copyright 2018 Fanha Giang +# Copyright 2018 Tecnativa - Vicent Cubells +# Copyright 2018 Tecnativa - Pedro M. Baeza +# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html + +from odoo import Command, _, api, fields, models +from odoo.exceptions import ValidationError +from odoo.tools.float_utils import float_compare, float_is_zero + + +class AssignManualQuants(models.TransientModel): + _name = "assign.manual.quants" + _description = "Assign Manual Quants" + + @api.constrains("quants_lines") + def _check_qty(self): + precision_digits = self.env["decimal.precision"].precision_get( + "Product Unit of Measure" + ) + for record in self.filtered("quants_lines"): + if ( + float_compare( + record.lines_qty, + record.move_id.product_qty, + precision_digits=precision_digits, + ) + > 0 + ): + raise ValidationError(_("Quantity is higher than the needed one")) + + @api.depends("move_id", "quants_lines", "quants_lines.qty") + def _compute_qties(self): + for record in self: + record.lines_qty = sum( + record.quants_lines.filtered("selected").mapped("qty") + ) + record.move_qty = record.move_id.product_qty - record.lines_qty + + lines_qty = fields.Float( + string="Reserved qty", + compute="_compute_qties", + digits="Product Unit of Measure", + ) + move_qty = fields.Float( + string="Remaining qty", + compute="_compute_qties", + digits="Product Unit of Measure", + ) + quants_lines = fields.One2many( + comodel_name="assign.manual.quants.lines", + inverse_name="assign_wizard", + string="Quants", + ) + move_id = fields.Many2one( + comodel_name="stock.move", + string="Move", + ) + + def assign_quants(self): + move = self.move_id + move._do_unreserve() + for line in self.quants_lines: + line._assign_quant_line() + if move.picking_type_id.auto_fill_qty_done: + # Auto-fill all lines as done + for ml in move.move_line_ids: + ml.qty_done = ml.reserved_uom_qty + move._recompute_state() + move.mapped("picking_id")._compute_state() + return {} + + @api.model + def _domain_for_available_quants(self, move): + return [ + ("location_id", "child_of", move.location_id.id), + ("product_id", "=", move.product_id.id), + ("quantity", ">", 0), + ] + + @api.model + def _get_available_quants(self, move): + domain = self._domain_for_available_quants(move) + return self.env["stock.quant"].search(domain) + + @api.model + def default_get(self, fields_list): + res = super().default_get(fields_list) + move = self.env["stock.move"].browse(self.env.context["active_id"]) + available_quants = self._get_available_quants(move) + quants_lines_commands = [Command.clear()] + for quant in available_quants: + line = self._prepare_wizard_line(move, quant) + quants_lines_commands.append(Command.create(line)) + res.update({"quants_lines": quants_lines_commands, "move_id": move.id}) + return res + + @api.model + def _prepare_wizard_line(self, move, quant): + line = { + "quant_id": quant.id, + "on_hand": quant.quantity, + "location_id": quant.location_id.id, + "lot_id": quant.lot_id.id, + "package_id": quant.package_id.id, + "owner_id": quant.owner_id.id, + "selected": False, + } + 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"] = sum(move_lines.mapped("reserved_uom_qty")) + line["selected"] = bool(line["qty"]) + line["reserved"] = quant.reserved_quantity - line["qty"] + return line + + +class AssignManualQuantsLines(models.TransientModel): + _name = "assign.manual.quants.lines" + _description = "Assign Manual Quants Lines" + _rec_name = "quant_id" + _order = "location_id, lot_id, package_id" + + assign_wizard = fields.Many2one( + comodel_name="assign.manual.quants", + string="Move", + required=True, + ondelete="cascade", + ) + quant_id = fields.Many2one( + comodel_name="stock.quant", + string="Quant", + required=True, + ondelete="cascade", + ) + location_id = fields.Many2one( + comodel_name="stock.location", + string="Location", + related="quant_id.location_id", + store=True, + ) + lot_id = fields.Many2one( + comodel_name="stock.lot", + string="Lot", + related="quant_id.lot_id", + store=True, + ) + package_id = fields.Many2one( + comodel_name="stock.quant.package", + string="Package", + related="quant_id.package_id", + store=True, + ) + owner_id = fields.Many2one( + comodel_name="res.partner", + string="Owner", + related="quant_id.owner_id", + store=True, + ) + # This is not correctly shown as related or computed, so we make it regular + on_hand = fields.Float( + readonly=True, + digits="Product Unit of Measure", + ) + reserved = fields.Float( + string="Others Reserved", digits="Product Unit of Measure", readonly=True + ) + selected = fields.Boolean(string="Select") + qty = fields.Float(string="QTY", digits="Product Unit of Measure") + + @api.onchange("selected") + def _onchange_selected(self): + precision = self.env["decimal.precision"].precision_get( + "Product Unit of Measure" + ) + if not self.selected: + self.qty = 0 + elif float_is_zero(self.qty, precision): + # This takes current "snapshot" situation, so that we don't + # have to compute each time if current reserved quantity is + # for this current move. If other operations change available + # quantity on quant, a constraint would be raised later on + # validation. + quant_qty = self.on_hand - self.reserved + remaining_qty = self.assign_wizard.move_qty + self.qty = min(quant_qty, remaining_qty) + + @api.constrains("qty") + def _check_qty(self): + precision_digits = self.env["decimal.precision"].precision_get( + "Product Unit of Measure" + ) + for record in self.filtered("qty"): + quant = record.quant_id + move_lines = record.assign_wizard.move_id.move_line_ids.filtered( + lambda ml: ( + ml.location_id == quant.location_id and ml.lot_id == quant.lot_id + ) + ) + reserved = quant.reserved_quantity - sum( + move_lines.mapped("reserved_uom_qty") + ) + if ( + float_compare( + record.qty, + record.quant_id.quantity - reserved, + precision_digits=precision_digits, + ) + > 0 + ): + raise ValidationError( + _( + "Selected line quantity is higher than the available " + "one. Maybe an operation with this product has been " + "done meanwhile or you have manually increased the " + "suggested value." + ) + ) + + def _assign_quant_line(self): + self.ensure_one() + quant = self.env["stock.quant"] + precision_digits = self.env["decimal.precision"].precision_get( + "Product Unit of Measure" + ) + move = self.assign_wizard.move_id + if float_compare(self.qty, 0.0, precision_digits=precision_digits) > 0: + available_quantity = quant._get_available_quantity( + move.product_id, + self.quant_id.location_id, + lot_id=self.quant_id.lot_id, + package_id=self.quant_id.package_id, + owner_id=self.quant_id.owner_id, + ) + if ( + float_compare( + available_quantity, 0.0, precision_digits=precision_digits + ) + <= 0 + ): + return + move._update_reserved_quantity( + self.qty, + available_quantity, + self.quant_id.location_id, + lot_id=self.quant_id.lot_id, + package_id=self.quant_id.package_id, + owner_id=self.quant_id.owner_id, + strict=True, + ) diff --git a/stock_quant_manual_assign/wizard/assign_manual_quants_view.xml b/stock_quant_manual_assign/wizard/assign_manual_quants_view.xml new file mode 100644 index 00000000..18e8e5ae --- /dev/null +++ b/stock_quant_manual_assign/wizard/assign_manual_quants_view.xml @@ -0,0 +1,55 @@ + + + + assign.manual.quants.form + assign.manual.quants + +
+ + + + + + + + + + + + + + + + + + +
+
+
+
+
+ + + Manual assignment + assign.manual.quants + form + new + {} + +