diff --git a/mrp_stock_orderpoint_manual_procurement/README.rst b/mrp_stock_orderpoint_manual_procurement/README.rst new file mode 100644 index 00000000000..385ab99e965 --- /dev/null +++ b/mrp_stock_orderpoint_manual_procurement/README.rst @@ -0,0 +1,82 @@ +======================================= +MRP Stock Orderpoint Manual Procurement +======================================= + +.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! 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/11.0/mrp_stock_orderpoint_manual_procurement + :alt: OCA/manufacture +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/manufacture-11-0/manufacture-11-0-mrp_stock_orderpoint_manual_procurement + :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/11.0 + :alt: Try me on Runbot + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module updates a new field *Requested by* in Manufacturing Orders +in the case the MO has been created as a result of a manual procurement from +an orderpoint. + +**Table of contents** + +.. contents:: + :local: + +Usage +===== + +Go to an orderpoint an do a manual procurement for a manufactured product. +Your user will be set as *Requeste by* in the newly created MO. + +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 +~~~~~~~ + +* Eficent + +Contributors +~~~~~~~~~~~~ + +* Adria Gil Sorribes +* Lois Rilo Antelo + +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_stock_orderpoint_manual_procurement/__init__.py b/mrp_stock_orderpoint_manual_procurement/__init__.py new file mode 100644 index 00000000000..4b76c7b2d5c --- /dev/null +++ b/mrp_stock_orderpoint_manual_procurement/__init__.py @@ -0,0 +1,3 @@ +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +from . import models diff --git a/mrp_stock_orderpoint_manual_procurement/__manifest__.py b/mrp_stock_orderpoint_manual_procurement/__manifest__.py new file mode 100644 index 00000000000..cd961da0ab5 --- /dev/null +++ b/mrp_stock_orderpoint_manual_procurement/__manifest__.py @@ -0,0 +1,24 @@ +# Copyright 2018 Eficent Business and IT Consulting Services S.L. +# (http://www.eficent.com) +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). +{ + "name": "MRP Stock Orderpoint Manual Procurement", + "summary": "Updates the value of MO Responsible and keeps track" + "of changes regarding this field", + "version": "11.0.1.0.0", + "author": "Eficent, " + "Odoo Community Association (OCA)", + "website": "https://github.com/OCA/manufacture", + "category": "Manufacturing", + "depends": [ + "mrp", + "stock_orderpoint_manual_procurement", + ], + "data": [ + "views/mrp_production_view.xml", + ], + "license": "AGPL-3", + 'installable': True, + 'application': False, + 'auto_install': True +} diff --git a/mrp_stock_orderpoint_manual_procurement/models/__init__.py b/mrp_stock_orderpoint_manual_procurement/models/__init__.py new file mode 100644 index 00000000000..2cafca2ee2e --- /dev/null +++ b/mrp_stock_orderpoint_manual_procurement/models/__init__.py @@ -0,0 +1,4 @@ +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +from . import procurement +from . import mrp_production diff --git a/mrp_stock_orderpoint_manual_procurement/models/mrp_production.py b/mrp_stock_orderpoint_manual_procurement/models/mrp_production.py new file mode 100644 index 00000000000..e4932a66de9 --- /dev/null +++ b/mrp_stock_orderpoint_manual_procurement/models/mrp_production.py @@ -0,0 +1,13 @@ +# Copyright 2019 Eficent Business and IT Consulting Services S.L. +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +from odoo import fields, models + + +class MrpProduction(models.Model): + _inherit = 'mrp.production' + + requested_by = fields.Many2one( + comodel_name='res.users', + track_visibility='always', + ) diff --git a/mrp_stock_orderpoint_manual_procurement/models/procurement.py b/mrp_stock_orderpoint_manual_procurement/models/procurement.py new file mode 100644 index 00000000000..0379a4b42c3 --- /dev/null +++ b/mrp_stock_orderpoint_manual_procurement/models/procurement.py @@ -0,0 +1,18 @@ +# Copyright 2019 Eficent Business and IT Consulting Services S.L. +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +from odoo import models + + +class ProcurementRule(models.Model): + _inherit = 'procurement.rule' + + def _prepare_mo_vals(self, product_id, product_qty, product_uom, + location_id, name, origin, values, bom): + res = super(ProcurementRule, self)._prepare_mo_vals( + product_id, product_qty, product_uom, location_id, name, + origin, values, bom) + requested_uid = self.env.context.get('requested_uid') + if requested_uid: + res.update({'requested_by': requested_uid.id}) + return res diff --git a/mrp_stock_orderpoint_manual_procurement/readme/CONTRIBUTORS.rst b/mrp_stock_orderpoint_manual_procurement/readme/CONTRIBUTORS.rst new file mode 100644 index 00000000000..76e4c541c74 --- /dev/null +++ b/mrp_stock_orderpoint_manual_procurement/readme/CONTRIBUTORS.rst @@ -0,0 +1,2 @@ +* Adria Gil Sorribes +* Lois Rilo Antelo diff --git a/mrp_stock_orderpoint_manual_procurement/readme/DESCRIPTION.rst b/mrp_stock_orderpoint_manual_procurement/readme/DESCRIPTION.rst new file mode 100644 index 00000000000..a6b7f9bfec5 --- /dev/null +++ b/mrp_stock_orderpoint_manual_procurement/readme/DESCRIPTION.rst @@ -0,0 +1,3 @@ +This module updates a new field *Requested by* in Manufacturing Orders +in the case the MO has been created as a result of a manual procurement from +an orderpoint. \ No newline at end of file diff --git a/mrp_stock_orderpoint_manual_procurement/readme/USAGE.rst b/mrp_stock_orderpoint_manual_procurement/readme/USAGE.rst new file mode 100644 index 00000000000..7967b7304c3 --- /dev/null +++ b/mrp_stock_orderpoint_manual_procurement/readme/USAGE.rst @@ -0,0 +1,2 @@ +Go to an orderpoint an do a manual procurement for a manufactured product. +Your user will be set as *Requeste by* in the newly created MO. diff --git a/mrp_stock_orderpoint_manual_procurement/static/description/icon.png b/mrp_stock_orderpoint_manual_procurement/static/description/icon.png new file mode 100644 index 00000000000..3a0328b516c Binary files /dev/null and b/mrp_stock_orderpoint_manual_procurement/static/description/icon.png differ diff --git a/mrp_stock_orderpoint_manual_procurement/static/description/index.html b/mrp_stock_orderpoint_manual_procurement/static/description/index.html new file mode 100644 index 00000000000..213e1435bc9 --- /dev/null +++ b/mrp_stock_orderpoint_manual_procurement/static/description/index.html @@ -0,0 +1,428 @@ + + + + + + +MRP Stock Orderpoint Manual Procurement + + + +
+

MRP Stock Orderpoint Manual Procurement

+ + +

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

+

This module updates a new field Requested by in Manufacturing Orders +in the case the MO has been created as a result of a manual procurement from +an orderpoint.

+

Table of contents

+ +
+

Usage

+

Go to an orderpoint an do a manual procurement for a manufactured product. +Your user will be set as Requeste by in the newly created MO.

+
+
+

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

+
    +
  • Eficent
  • +
+
+
+

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_stock_orderpoint_manual_procurement/tests/__init__.py b/mrp_stock_orderpoint_manual_procurement/tests/__init__.py new file mode 100644 index 00000000000..7f20332cc09 --- /dev/null +++ b/mrp_stock_orderpoint_manual_procurement/tests/__init__.py @@ -0,0 +1 @@ +from . import test_mrp_manual_procurement diff --git a/mrp_stock_orderpoint_manual_procurement/tests/test_mrp_manual_procurement.py b/mrp_stock_orderpoint_manual_procurement/tests/test_mrp_manual_procurement.py new file mode 100644 index 00000000000..fec62474d1c --- /dev/null +++ b/mrp_stock_orderpoint_manual_procurement/tests/test_mrp_manual_procurement.py @@ -0,0 +1,123 @@ +# Copyright 2019 Eficent Business and IT Consulting Services S.L. +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo.tests.common import TransactionCase + + +class TestMrpManualProcurement(TransactionCase): + + def setUp(self, *args, **kwargs): + super(TestMrpManualProcurement, self).setUp(*args, **kwargs) + + self.production_model = self.env['mrp.production'] + self.product_model = self.env['product.product'] + self.orderpoint_model = self.env['stock.warehouse.orderpoint'] + self.loc_model = self.env['stock.location'] + self.route_model = self.env['stock.location.route'] + self.manual_procurement_wiz = self.env['make.procurement.orderpoint'] + self.bom_model = self.env['mrp.bom'] + self.boml_model = self.env['mrp.bom.line'] + + self.warehouse = self.env.ref('stock.warehouse0') + self.stock_loc = self.env.ref('stock.stock_location_stock') + route_manuf = self.env.ref('mrp.route_warehouse0_manufacture') + + # Create a new location and route: + self.secondary_loc = self.loc_model.create({ + 'name': 'Test location', + 'usage': 'internal', + 'location_id': self.warehouse.view_location_id.id, + }) + test_route = self.route_model.create({ + 'name': 'Stock -> Test', + 'product_selectable': True, + 'pull_ids': [(0, 0, { + 'name': 'stock to test', + 'action': 'move', + 'location_id': self.secondary_loc.id, + 'location_src_id': self.stock_loc.id, + 'procure_method': 'make_to_order', + 'picking_type_id': self.env.ref( + 'stock.picking_type_internal').id, + 'propagate': True + })] + }) + + # Prepare Products: + routes = route_manuf + test_route + self.product = self.product_model.create({ + 'name': 'Test Product', + 'route_ids': [(6, 0, routes.ids)], + }) + component = self.product_model.create({ + 'name': 'Test component', + }) + + # Create Bill of Materials: + self.bom_1 = self.bom_model.create({ + 'product_id': self.product.id, + 'product_tmpl_id': self.product.product_tmpl_id.id, + 'product_uom_id': self.product.uom_id.id, + 'product_qty': 1.0, + }) + self.boml_model.create({ + 'bom_id': self.bom_1.id, + 'product_id': component.id, + 'product_qty': 1.0, + }) + + # Create Orderpoint: + self.orderpoint_stock = self.orderpoint_model.create({ + 'warehouse_id': self.warehouse.id, + 'location_id': self.warehouse.lot_stock_id.id, + 'product_id': self.product.id, + 'product_min_qty': 10.0, + 'product_max_qty': 50.0, + 'product_uom': self.product.uom_id.id, + }) + self.orderpoint_secondary_loc = self.orderpoint_model.create({ + 'warehouse_id': self.warehouse.id, + 'location_id': self.secondary_loc.id, + 'product_id': self.product.id, + 'product_min_qty': 10.0, + 'product_max_qty': 20.0, + 'product_uom': self.product.uom_id.id, + }) + + # Create User: + self.test_user = self.env['res.users'].create({ + 'name': 'John', + 'login': 'test', + }) + + def manual_procurement(self, orderpoint, user): + """Make Procurement from Reordering Rule""" + context = { + 'active_model': 'stock.warehouse.orderpoint', + 'active_ids': orderpoint.ids, + 'active_id': orderpoint.id + } + wizard = self.manual_procurement_wiz.sudo(user).\ + with_context(context).create({}) + wizard.make_procurement() + return wizard + + def test_01_manual_procurement_requested_by(self): + """Tests manual procurement fills requested_by field. + Direct MO creation.""" + self.manual_procurement(self.orderpoint_stock, self.test_user) + mo = self.production_model.search([ + ('requested_by', '=', self.test_user.id)]) + self.assertTrue(mo) + self.assertEqual(mo.product_id, self.product) + self.assertEqual(mo.product_qty, 50.0) + + def test_02_manual_procurement_requested_by_indirect(self): + """Tests manual procurement fills requested_by field. + Indirect MO creation (transfer -> MO).""" + self.manual_procurement(self.orderpoint_secondary_loc, self.test_user) + mo = self.production_model.search([ + ('requested_by', '=', self.test_user.id)]) + self.assertTrue(mo) + self.assertEqual(mo.product_id, self.product) + self.assertEqual(mo.product_qty, 20.0) diff --git a/mrp_stock_orderpoint_manual_procurement/views/mrp_production_view.xml b/mrp_stock_orderpoint_manual_procurement/views/mrp_production_view.xml new file mode 100644 index 00000000000..2371d229720 --- /dev/null +++ b/mrp_stock_orderpoint_manual_procurement/views/mrp_production_view.xml @@ -0,0 +1,17 @@ + + + + + + mrp.production.form - mrp_stock_orderpoint_manual_procurement + mrp.production + + + + + + + + + diff --git a/oca_dependencies.txt b/oca_dependencies.txt index ab4a3dafda4..aec8f1367bc 100644 --- a/oca_dependencies.txt +++ b/oca_dependencies.txt @@ -2,4 +2,4 @@ # Add a repository url and branch if you need a forked version product-attribute purchase-workflow -stock-logistics-warehouse +stock-logistics-warehouse \ No newline at end of file