From 9415b749af3bbb2183e2b3cba483e7f4db770bf3 Mon Sep 17 00:00:00 2001 From: sergio-teruel Date: Wed, 26 Jun 2024 13:49:52 +0200 Subject: [PATCH] [ADD] stock-weighing: Add module --- mrp_weighing/README.rst | 79 ++++ mrp_weighing/__init__.py | 3 + mrp_weighing/__manifest__.py | 16 + mrp_weighing/models/__init__.py | 3 + mrp_weighing/models/mrp_production.py | 34 ++ mrp_weighing/models/stock_move.py | 59 +++ mrp_weighing/readme/CONTRIBUTORS.md | 3 + mrp_weighing/readme/DESCRIPTION.md | 1 + mrp_weighing/static/description/index.html | 424 ++++++++++++++++++ mrp_weighing/views/mrp_production_view.xml | 21 + mrp_weighing/wizards/__init__.py | 2 + .../wizards/weigh_operation_selection.py | 20 + 12 files changed, 665 insertions(+) create mode 100644 mrp_weighing/README.rst create mode 100644 mrp_weighing/__init__.py create mode 100644 mrp_weighing/__manifest__.py create mode 100644 mrp_weighing/models/__init__.py create mode 100644 mrp_weighing/models/mrp_production.py create mode 100644 mrp_weighing/models/stock_move.py create mode 100644 mrp_weighing/readme/CONTRIBUTORS.md create mode 100644 mrp_weighing/readme/DESCRIPTION.md create mode 100644 mrp_weighing/static/description/index.html create mode 100644 mrp_weighing/views/mrp_production_view.xml create mode 100644 mrp_weighing/wizards/__init__.py create mode 100644 mrp_weighing/wizards/weigh_operation_selection.py diff --git a/mrp_weighing/README.rst b/mrp_weighing/README.rst new file mode 100644 index 00000000..379c13b6 --- /dev/null +++ b/mrp_weighing/README.rst @@ -0,0 +1,79 @@ +==================================== +Weighing assistant in batch pickings +==================================== + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:4c66742998294dc1a2cda1baab1b6a2921b00c423fe8325408af433c2543a566 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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%2Fstock--weighing-lightgray.png?logo=github + :target: https://github.com/OCA/stock-weighing/tree/15.0/mrp_weighing + :alt: OCA/stock-weighing +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/stock-weighing-15-0/stock-weighing-15-0-mrp_weighing + :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/stock-weighing&target_branch=15.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +Weighing production finished moves + +**Table of contents** + +.. contents:: + :local: + +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 +------- + +* Tecnativa + +Contributors +------------ + +- `Tecnativa `__ + + - Sergio Teruel + - Carlos Dauden + +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/stock-weighing `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/mrp_weighing/__init__.py b/mrp_weighing/__init__.py new file mode 100644 index 00000000..d6a490a3 --- /dev/null +++ b/mrp_weighing/__init__.py @@ -0,0 +1,3 @@ +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl) +from . import models +from . import wizards diff --git a/mrp_weighing/__manifest__.py b/mrp_weighing/__manifest__.py new file mode 100644 index 00000000..bffa5350 --- /dev/null +++ b/mrp_weighing/__manifest__.py @@ -0,0 +1,16 @@ +# Copyright 2024 Tecnativa - Sergio Teruel +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl) +{ + "name": "Weighing assistant in batch pickings", + "summary": "Launch the weighing assistant from batch pickings", + "version": "15.0.1.0.0", + "author": "Tecnativa, Odoo Community Association (OCA)", + "website": "https://github.com/OCA/stock-weighing", + "license": "AGPL-3", + "category": "MRP", + "depends": [ + "stock_weighing", + "mrp", + ], + "data": ["views/mrp_production_view.xml"], +} diff --git a/mrp_weighing/models/__init__.py b/mrp_weighing/models/__init__.py new file mode 100644 index 00000000..d4440f24 --- /dev/null +++ b/mrp_weighing/models/__init__.py @@ -0,0 +1,3 @@ +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl) +from . import mrp_production +from . import stock_move diff --git a/mrp_weighing/models/mrp_production.py b/mrp_weighing/models/mrp_production.py new file mode 100644 index 00000000..82b53e1a --- /dev/null +++ b/mrp_weighing/models/mrp_production.py @@ -0,0 +1,34 @@ +# Copyright 2024 Tecnativa - Sergio Teruel +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl) +import ast + +from odoo import _, api, fields, models + + +class MrpProduction(models.Model): + _inherit = "mrp.production" + + weighing_operations = fields.Boolean(related="picking_type_id.weighing_operations") + has_weighing_operations = fields.Boolean(compute="_compute_has_weighing_operations") + + @api.depends("move_finished_ids") + def _compute_has_weighing_operations(self): + for mrp_production in self: + mrp_production.has_weighing_operations = ( + mrp_production.move_finished_ids.filtered("has_weight") + ) + + def action_weighing_operations(self): + """Weighing operations for this production order""" + action = self.env["ir.actions.actions"]._for_xml_id( + "stock_weighing.weighing_operation_action" + ) + weight_moves = self.move_finished_ids.filtered("has_weight") + action["name"] = _("Weighing operations for %(name)s", name=self.name) + action["domain"] = [("id", "in", weight_moves.ids)] + action["context"] = dict( + self.env.context, + **ast.literal_eval(action["context"]), + group_by=["production_id"] + ) + return action diff --git a/mrp_weighing/models/stock_move.py b/mrp_weighing/models/stock_move.py new file mode 100644 index 00000000..a833685d --- /dev/null +++ b/mrp_weighing/models/stock_move.py @@ -0,0 +1,59 @@ +# Copyright 2024 Tecnativa - Sergio Teruel +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl) +from odoo import api, models + + +class StockMove(models.Model): + _inherit = "stock.move" + + @api.model + def action_mrp_production_weighing(self): + """Used in the start screen""" + action = self.env["ir.actions.actions"]._for_xml_id("mrp.mrp_production_action") + ctx = {"search_default_todo": True} + action["context"] = ctx + return action + + @api.model + def _has_weigh_domain(self): + # All finished moves can be processed" + # TODO: Check with David + return [] + + def action_add_move_line(self): + action = super().action_add_move_line() + if not self.production_id.lot_producing_id: + return action + default_lot_id = False + if self.product_id == self.production_id.product_id: + default_lot_id = self.production_id.lot_producing_id.id + else: + last_lot = self.move_line_ids.lot_id[-1:] + if last_lot: + default_lot_id = last_lot.id + elif self.has_tracking: + lot = self.env["stock.production.lot"].search( + [ + ("company_id", "=", self.company_id.id), + ("product_id", "=", self.product_id.id), + ("name", "=", self.production_id.lot_producing_id.name), + ], + limit=1, + ) + if lot: + default_lot_id = lot.id + else: + sml = self.move_line_ids[:1] + if not sml: + sml = self.env["stock.move.line"].new( + { + "lot_name": self.production_id.lot_producing_id.name, + "product_id": self.product_id.id, + "company_id": self.company_id.id, + } + ) + sml._create_and_assign_production_lot() + default_lot_id = sml.lot_id.id + if default_lot_id: + action["context"].update({"default_lot_id": default_lot_id}) + return action diff --git a/mrp_weighing/readme/CONTRIBUTORS.md b/mrp_weighing/readme/CONTRIBUTORS.md new file mode 100644 index 00000000..ae3658e5 --- /dev/null +++ b/mrp_weighing/readme/CONTRIBUTORS.md @@ -0,0 +1,3 @@ +- [Tecnativa](https://www.tecnativa.com) + - Sergio Teruel + - Carlos Dauden diff --git a/mrp_weighing/readme/DESCRIPTION.md b/mrp_weighing/readme/DESCRIPTION.md new file mode 100644 index 00000000..740229a8 --- /dev/null +++ b/mrp_weighing/readme/DESCRIPTION.md @@ -0,0 +1 @@ +Weighing production finished moves diff --git a/mrp_weighing/static/description/index.html b/mrp_weighing/static/description/index.html new file mode 100644 index 00000000..555de601 --- /dev/null +++ b/mrp_weighing/static/description/index.html @@ -0,0 +1,424 @@ + + + + + +Weighing assistant in batch pickings + + + +
+

Weighing assistant in batch pickings

+ + +

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

+

Weighing production finished moves

+

Table of contents

+ +
+

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

+
    +
  • Tecnativa
  • +
+
+
+

Contributors

+
    +
  • Tecnativa
      +
    • Sergio Teruel
    • +
    • Carlos Dauden
    • +
    +
  • +
+
+
+

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/stock-weighing project on GitHub.

+

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

+
+
+
+ + diff --git a/mrp_weighing/views/mrp_production_view.xml b/mrp_weighing/views/mrp_production_view.xml new file mode 100644 index 00000000..5244c523 --- /dev/null +++ b/mrp_weighing/views/mrp_production_view.xml @@ -0,0 +1,21 @@ + + + + mrp.production + + +
+ + +
+
+
+
diff --git a/mrp_weighing/wizards/__init__.py b/mrp_weighing/wizards/__init__.py new file mode 100644 index 00000000..ea8f7724 --- /dev/null +++ b/mrp_weighing/wizards/__init__.py @@ -0,0 +1,2 @@ +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl) +from . import weigh_operation_selection diff --git a/mrp_weighing/wizards/weigh_operation_selection.py b/mrp_weighing/wizards/weigh_operation_selection.py new file mode 100644 index 00000000..1e016470 --- /dev/null +++ b/mrp_weighing/wizards/weigh_operation_selection.py @@ -0,0 +1,20 @@ +# Copyright 2024 Tecnativa - Sergio Teruel +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl) +from odoo import _, api, models + + +class WeightOperationSelection(models.TransientModel): + _inherit = "weigh.operation.selection" + + @api.model + def _get_weighing_start_screen_actions(self): + actions = super()._get_weighing_start_screen_actions() + actions.append( + { + "title": _("Production Orders"), + "description": _("Weighing Production Orders"), + "icon": "fa-wrench", + "method": "action_mrp_production_weighing", + } + ) + return actions