From 91a3cf6fa51d11d3235431dd0b14a62a803609b1 Mon Sep 17 00:00:00 2001 From: Lois Rilo Date: Tue, 28 Mar 2023 17:08:49 +0200 Subject: [PATCH] [ADD] mrp_production_picking_type_from_route --- .../README.rst | 84 ++++ .../__init__.py | 1 + .../__manifest__.py | 14 + .../models/__init__.py | 1 + .../models/mrp_production.py | 29 ++ .../readme/CONTRIBUTORS.rst | 1 + .../readme/DESCRIPTION.rst | 2 + .../readme/USAGE.rst | 6 + .../static/description/index.html | 431 ++++++++++++++++++ .../tests/__init__.py | 1 + ..._mrp_production_picking_type_from_route.py | 81 ++++ 11 files changed, 651 insertions(+) create mode 100644 mrp_production_picking_type_from_route/README.rst create mode 100644 mrp_production_picking_type_from_route/__init__.py create mode 100644 mrp_production_picking_type_from_route/__manifest__.py create mode 100644 mrp_production_picking_type_from_route/models/__init__.py create mode 100644 mrp_production_picking_type_from_route/models/mrp_production.py create mode 100644 mrp_production_picking_type_from_route/readme/CONTRIBUTORS.rst create mode 100644 mrp_production_picking_type_from_route/readme/DESCRIPTION.rst create mode 100644 mrp_production_picking_type_from_route/readme/USAGE.rst create mode 100644 mrp_production_picking_type_from_route/static/description/index.html create mode 100644 mrp_production_picking_type_from_route/tests/__init__.py create mode 100644 mrp_production_picking_type_from_route/tests/test_mrp_production_picking_type_from_route.py diff --git a/mrp_production_picking_type_from_route/README.rst b/mrp_production_picking_type_from_route/README.rst new file mode 100644 index 000000000..1c2bebc30 --- /dev/null +++ b/mrp_production_picking_type_from_route/README.rst @@ -0,0 +1,84 @@ +====================================== +MRP Production Picking Type From Route +====================================== + +.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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/14.0/mrp_production_picking_type_from_route + :alt: OCA/manufacture +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/manufacture-14-0/manufacture-14-0-mrp_production_picking_type_from_route + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png + :target: https://runbot.odoo-community.org/runbot/129/14.0 + :alt: Try me on Runbot + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module add an onchange that updates the operation type based on the +product while creating a new MO manually. + +**Table of contents** + +.. contents:: + :local: + +Usage +===== + +To use this module, you need to: + +#. Go to *Manufacturing > Manufacturing Orders*. +#. Create a new MO. +#. Select a product, the operation type has been updated based on the routes + configured for that product. + +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 smashing it by providing a detailed and welcomed +`feedback `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +~~~~~~~ + +* ForgeFlow + +Contributors +~~~~~~~~~~~~ + +* 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_picking_type_from_route/__init__.py b/mrp_production_picking_type_from_route/__init__.py new file mode 100644 index 000000000..0650744f6 --- /dev/null +++ b/mrp_production_picking_type_from_route/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/mrp_production_picking_type_from_route/__manifest__.py b/mrp_production_picking_type_from_route/__manifest__.py new file mode 100644 index 000000000..4648c005f --- /dev/null +++ b/mrp_production_picking_type_from_route/__manifest__.py @@ -0,0 +1,14 @@ +# Copyright 2023 ForgeFlow S.L. (https://www.forgeflow.com) +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +{ + "name": "MRP Production Picking Type From Route", + "summary": "Updates the operation type creating MO based on the product", + "version": "14.0.1.0.0", + "category": "Manufacture", + "website": "https://github.com/OCA/manufacture", + "author": "ForgeFlow, Odoo Community Association (OCA)", + "license": "AGPL-3", + "application": False, + "depends": ["mrp"], + "installable": True, +} diff --git a/mrp_production_picking_type_from_route/models/__init__.py b/mrp_production_picking_type_from_route/models/__init__.py new file mode 100644 index 000000000..a9e5f13e4 --- /dev/null +++ b/mrp_production_picking_type_from_route/models/__init__.py @@ -0,0 +1 @@ +from . import mrp_production diff --git a/mrp_production_picking_type_from_route/models/mrp_production.py b/mrp_production_picking_type_from_route/models/mrp_production.py new file mode 100644 index 000000000..2e0642ffd --- /dev/null +++ b/mrp_production_picking_type_from_route/models/mrp_production.py @@ -0,0 +1,29 @@ +# Copyright 2023 ForgeFlow S.L. (https://www.forgeflow.com) +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import api, models + + +class MrpProduction(models.Model): + _inherit = "mrp.production" + + # Skip picking_type_id as a onchange trigger, even though the + # extended method is an onchange for picking_type_id too. + # If triggered also from picking_type_id changes, it would be impossible + # to adjust picking_type_id manually. + @api.onchange("product_id", "company_id") + def onchange_product_id(self): + res = super().onchange_product_id() + if self.product_id: + base_domain = [ + ("action", "=", "manufacture"), + "|", + ("company_id", "=", False), + ("company_id", "child_of", self.company_id.id), + ] + res_rule = self.env["procurement.group"]._search_rule( + False, self.product_id, False, base_domain + ) + if res_rule: + self.picking_type_id = res_rule.picking_type_id + return res diff --git a/mrp_production_picking_type_from_route/readme/CONTRIBUTORS.rst b/mrp_production_picking_type_from_route/readme/CONTRIBUTORS.rst new file mode 100644 index 000000000..77dfbe89e --- /dev/null +++ b/mrp_production_picking_type_from_route/readme/CONTRIBUTORS.rst @@ -0,0 +1 @@ +* Lois Rilo diff --git a/mrp_production_picking_type_from_route/readme/DESCRIPTION.rst b/mrp_production_picking_type_from_route/readme/DESCRIPTION.rst new file mode 100644 index 000000000..3615701e5 --- /dev/null +++ b/mrp_production_picking_type_from_route/readme/DESCRIPTION.rst @@ -0,0 +1,2 @@ +This module add an onchange that updates the operation type based on the +product while creating a new MO manually. diff --git a/mrp_production_picking_type_from_route/readme/USAGE.rst b/mrp_production_picking_type_from_route/readme/USAGE.rst new file mode 100644 index 000000000..c3273ca06 --- /dev/null +++ b/mrp_production_picking_type_from_route/readme/USAGE.rst @@ -0,0 +1,6 @@ +To use this module, you need to: + +#. Go to *Manufacturing > Manufacturing Orders*. +#. Create a new MO. +#. Select a product, the operation type has been updated based on the routes + configured for that product. diff --git a/mrp_production_picking_type_from_route/static/description/index.html b/mrp_production_picking_type_from_route/static/description/index.html new file mode 100644 index 000000000..fcd141f06 --- /dev/null +++ b/mrp_production_picking_type_from_route/static/description/index.html @@ -0,0 +1,431 @@ + + + + + + +MRP Production Picking Type From Route + + + +
+

MRP Production Picking Type From Route

+ + +

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

+

This module add an onchange that updates the operation type based on the +product while creating a new MO manually.

+

Table of contents

+ +
+

Usage

+

To use this module, you need to:

+
    +
  1. Go to Manufacturing > Manufacturing Orders.
  2. +
  3. Create a new MO.
  4. +
  5. Select a product, the operation type has been updated based on the routes +configured for that product.
  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 smashing it by providing a detailed and welcomed +feedback.

+

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

+
+
+

Credits

+
+

Authors

+
    +
  • ForgeFlow
  • +
+
+ +
+

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_picking_type_from_route/tests/__init__.py b/mrp_production_picking_type_from_route/tests/__init__.py new file mode 100644 index 000000000..aa36a5d32 --- /dev/null +++ b/mrp_production_picking_type_from_route/tests/__init__.py @@ -0,0 +1 @@ +from . import test_mrp_production_picking_type_from_route diff --git a/mrp_production_picking_type_from_route/tests/test_mrp_production_picking_type_from_route.py b/mrp_production_picking_type_from_route/tests/test_mrp_production_picking_type_from_route.py new file mode 100644 index 000000000..bd359faa6 --- /dev/null +++ b/mrp_production_picking_type_from_route/tests/test_mrp_production_picking_type_from_route.py @@ -0,0 +1,81 @@ +# Copyright 2023 ForgeFlow S.L. (https://www.forgeflow.com) +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo.tests import Form +from odoo.tests.common import TransactionCase + + +class MrpProductionCase(TransactionCase): + def setUp(self): + super(MrpProductionCase, self).setUp() + self.product_model = self.env["product.product"] + self.bom_model = self.env["mrp.bom"] + self.route_model = self.env["stock.location.route"] + self.loc_model = self.env["stock.location"] + self.op_type_model = self.env["stock.picking.type"] + + self.wh = self.env.ref("stock.warehouse0") + self.standard_manuf_route = self.env.ref("mrp.route_warehouse0_manufacture") + self.standard_manuf_op_type = self.wh.manu_type_id + + self.product_1 = self.product_model.create( + {"name": "Product 1", "route_ids": [(6, 0, self.standard_manuf_route.ids)]} + ) + + self.source_loc_2 = self.loc_model.create( + { + "name": "Pre Production 2", + "location_id": self.wh.view_location_id.id, + "usage": "internal", + } + ) + self.op_type_2 = self.op_type_model.create( + { + "name": "Secondary Manufacturing", + "code": "mrp_operation", + "sequence_code": "MO/SEC", + "default_location_src_id": self.source_loc_2.id, + "default_location_dest_id": self.wh.lot_stock_id.id, + } + ) + self.secondary_manuf_route = self.route_model.create( + { + "name": "Secondary Manufacture", + "rule_ids": [ + ( + 0, + 0, + { + "name": "Manufacture with secondary op", + "action": "manufacture", + "picking_type_id": self.op_type_2.id, + "location_src_id": self.source_loc_2.id, + "location_id": self.wh.lot_stock_id.id, + }, + ) + ], + } + ) + self.product_2 = self.product_model.create( + {"name": "Product 2", "route_ids": [(6, 0, self.secondary_manuf_route.ids)]} + ) + + def test_01_create_mo_and_change_product(self): + new_mo = Form(self.env["mrp.production"]) + new_mo.product_id = self.product_1 + self.assertEqual(new_mo.picking_type_id, self.standard_manuf_op_type) + new_mo.product_id = self.product_2 + self.assertEqual(new_mo.picking_type_id, self.op_type_2) + new_mo.save() + # Kept after save: + self.assertEqual(new_mo.picking_type_id, self.op_type_2) + + def test_02_create_mo_change_op_type_manually(self): + new_mo = Form(self.env["mrp.production"]) + new_mo.product_id = self.product_2 + self.assertEqual(new_mo.picking_type_id, self.op_type_2) + new_mo.picking_type_id = self.standard_manuf_op_type + self.assertEqual(new_mo.picking_type_id, self.standard_manuf_op_type) + new_mo.save() + # Kept after save: + self.assertEqual(new_mo.picking_type_id, self.standard_manuf_op_type)