diff --git a/mrp_production_auto_post_inventory/README.rst b/mrp_production_auto_post_inventory/README.rst new file mode 100644 index 000000000..67f365e6b --- /dev/null +++ b/mrp_production_auto_post_inventory/README.rst @@ -0,0 +1,84 @@ +============================== +Production Auto Post-Inventory +============================== + +.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! 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_production_auto_post_inventory + :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_production_auto_post_inventory + :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 allows the user to set to automatic the post inventory step +in a manufacturing order. Having this option activated, the inventory will +be automatically posted after some quantity has been produced without the +need of completing the whole manufacturing order. + +**Table of contents** + +.. contents:: + :local: + +Usage +===== + +In Manufacture -> Settings a new checkbox is added: + +.. image:: /mrp_production_auto_post_inventory/static/description/AutoPostInventory_Option.png + :alt: Checkbox added in Manufacture Settings + +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 + +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_auto_post_inventory/__init__.py b/mrp_production_auto_post_inventory/__init__.py new file mode 100644 index 000000000..2c9b3790d --- /dev/null +++ b/mrp_production_auto_post_inventory/__init__.py @@ -0,0 +1,3 @@ +from . import models +from . import wizard +from . import tests diff --git a/mrp_production_auto_post_inventory/__manifest__.py b/mrp_production_auto_post_inventory/__manifest__.py new file mode 100644 index 000000000..ee88fb20f --- /dev/null +++ b/mrp_production_auto_post_inventory/__manifest__.py @@ -0,0 +1,19 @@ +# Copyright 2016-19 Eficent Business and IT Consulting Services S.L. +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +{ + 'name': 'Production Auto Post-Inventory', + 'version': '11.0.1.0.0', + 'category': 'MRP', + 'author': 'Eficent, ' + 'Odoo Community Association (OCA)', + 'website': 'https://github.com/oca/manufacture', + 'license': 'AGPL-3', + 'depends': [ + 'mrp', + ], + 'data': [ + 'views/res_config_settings.xml', + ], + 'installable': True, +} diff --git a/mrp_production_auto_post_inventory/models/__init__.py b/mrp_production_auto_post_inventory/models/__init__.py new file mode 100644 index 000000000..338ff08cc --- /dev/null +++ b/mrp_production_auto_post_inventory/models/__init__.py @@ -0,0 +1,2 @@ +from . import company +from . import res_config_settings diff --git a/mrp_production_auto_post_inventory/models/company.py b/mrp_production_auto_post_inventory/models/company.py new file mode 100644 index 000000000..b0dc3eb7a --- /dev/null +++ b/mrp_production_auto_post_inventory/models/company.py @@ -0,0 +1,14 @@ +# Copyright 2016-19 Eficent Business and IT Consulting Services S.L. +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import models, fields + + +class ResCompany(models.Model): + _inherit = "res.company" + + mrp_production_auto_post_inventory = fields.Boolean( + string="Production Auto Post-Inventory", + help="Sets to automatic the post-inventory step in a manufacturing" + "order. The inventory will be automatically posted after some " + "quantity has been produced") diff --git a/mrp_production_auto_post_inventory/models/res_config_settings.py b/mrp_production_auto_post_inventory/models/res_config_settings.py new file mode 100644 index 000000000..1607145d9 --- /dev/null +++ b/mrp_production_auto_post_inventory/models/res_config_settings.py @@ -0,0 +1,12 @@ +# © 2017 Akretion (http://www.akretion.com) +# @author Alexis de Lattre +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import models, fields + + +class ResConfigSettings(models.TransientModel): + _inherit = 'res.config.settings' + + mrp_production_auto_post_inventory = fields.Boolean( + related='company_id.mrp_production_auto_post_inventory') diff --git a/mrp_production_auto_post_inventory/readme/CONTRIBUTORS.rst b/mrp_production_auto_post_inventory/readme/CONTRIBUTORS.rst new file mode 100644 index 000000000..afabf1ede --- /dev/null +++ b/mrp_production_auto_post_inventory/readme/CONTRIBUTORS.rst @@ -0,0 +1 @@ +* Adria Gil Sorribes diff --git a/mrp_production_auto_post_inventory/readme/DESCRIPTION.rst b/mrp_production_auto_post_inventory/readme/DESCRIPTION.rst new file mode 100644 index 000000000..aa8fa508c --- /dev/null +++ b/mrp_production_auto_post_inventory/readme/DESCRIPTION.rst @@ -0,0 +1,4 @@ +This module allows the user to set to automatic the post inventory step +in a manufacturing order. Having this option activated, the inventory will +be automatically posted after some quantity has been produced without the +need of completing the whole manufacturing order. diff --git a/mrp_production_auto_post_inventory/readme/USAGE.rst b/mrp_production_auto_post_inventory/readme/USAGE.rst new file mode 100644 index 000000000..05aa0c1da --- /dev/null +++ b/mrp_production_auto_post_inventory/readme/USAGE.rst @@ -0,0 +1,4 @@ +In Manufacture -> Settings a new checkbox is added: + +.. image:: /mrp_production_auto_post_inventory/static/description/AutoPostInventory_Option.png + :alt: Checkbox added in Manufacture Settings diff --git a/mrp_production_auto_post_inventory/static/description/AutoPostInventory_Option.png b/mrp_production_auto_post_inventory/static/description/AutoPostInventory_Option.png new file mode 100644 index 000000000..953f4b260 Binary files /dev/null and b/mrp_production_auto_post_inventory/static/description/AutoPostInventory_Option.png differ diff --git a/mrp_production_auto_post_inventory/static/description/index.html b/mrp_production_auto_post_inventory/static/description/index.html new file mode 100644 index 000000000..8f474ccc0 --- /dev/null +++ b/mrp_production_auto_post_inventory/static/description/index.html @@ -0,0 +1,406 @@ + + + + + + +Production Auto Post-Inventory + + + +
+

Production Auto Post-Inventory

+ + +

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

+

This module allows the user to set to automatic the post inventory step +in a manufacturing order. Having this option activated, the inventory will +be automatically posted after some quantity has been produced without the +need of completing the whole manufacturing order.

+

Table of contents

+ +
+

Usage

+

In Manufacture -> Settings a new checkbox is added:

+Checkbox added in Manufacture Settings +
+
+

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_production_auto_post_inventory/tests/__init__.py b/mrp_production_auto_post_inventory/tests/__init__.py new file mode 100644 index 000000000..fae3edd10 --- /dev/null +++ b/mrp_production_auto_post_inventory/tests/__init__.py @@ -0,0 +1 @@ +from . import test_mrp_production diff --git a/mrp_production_auto_post_inventory/tests/test_mrp_production.py b/mrp_production_auto_post_inventory/tests/test_mrp_production.py new file mode 100644 index 000000000..14cfeb145 --- /dev/null +++ b/mrp_production_auto_post_inventory/tests/test_mrp_production.py @@ -0,0 +1,111 @@ +# 2018 Eficent Business and IT Consulting Services S.L. +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +import odoo.tests.common as common + + +class TestMrpProductionAutoPost(common.SavepointCase): + + @classmethod + def setUpClass(cls): + super(TestMrpProductionAutoPost, cls).setUpClass() + + cls.product_obj = cls.env['product.product'] + cls.production_obj = cls.env['mrp.production'] + cls.produce_wiz = cls.env['mrp.product.produce'] + cls.company_obj = cls.env['res.company'] + cls.bom_obj = cls.env['mrp.bom'] + cls.bom_line_obj = cls.env['mrp.bom.line'] + cls.stock_move_obj = cls.env['stock.move'] + + # Get company + cls.company_1 = cls.company_obj._company_default_get('mrp.production') + + # Create products: + cls.product_top = cls.product_obj.create({ + 'name': 'Final Product', + 'type': 'product', + }) + cls.component_1 = cls.product_obj.create({ + 'name': 'RM 01', + 'type': 'product', + 'standard_price': 10.0, + }) + cls.component_2 = cls.product_obj.create({ + 'name': 'RM 01', + 'type': 'product', + 'standard_price': 15.0, + }) + + # Create Bills of Materials: + cls.bom_top = cls.bom_obj.create({ + 'product_tmpl_id': cls.product_top.product_tmpl_id.id, + }) + cls.line_top_1 = cls.bom_line_obj.create({ + 'product_id': cls.component_1.id, + 'bom_id': cls.bom_top.id, + 'product_qty': 2.0, + }) + cls.line_top_2 = cls.bom_line_obj.create({ + 'product_id': cls.component_2.id, + 'bom_id': cls.bom_top.id, + 'product_qty': 3.0, + }) + + def _produce(self, mo, qty=0.0): + wiz = self.produce_wiz.with_context({ + 'active_id': mo.id, + 'active_ids': [mo.id], + }).create({ + 'product_qty': qty or mo.product_qty, + }) + wiz.do_produce() + return True + + def test_01_manufacture_order_no_auto_post(self): + """Create Manufacture Order with auto post inventory False""" + self.company_1.mrp_production_auto_post_inventory = False + mo = self.production_obj.create({ + 'name': 'MO-01', + 'product_id': self.product_top.id, + 'product_uom_id': self.product_top.uom_id.id, + 'product_qty': 5.0, + 'bom_id': self.bom_top.id, + 'company_id': self.company_1.id, + }) + mo.action_assign() + self._produce(mo, 1.0) + raw_moves = self.stock_move_obj.search([ + ('raw_material_production_id', '=', mo.id), + ('state', '=', 'done')] + ) + finished_moves = self.stock_move_obj.search([ + ('production_id', '=', mo.id), + ('state', '=', 'done')] + ) + self.assertEqual(len(raw_moves), 0) + self.assertEqual(len(finished_moves), 0) + + def test_02_manufacture_order_auto_post(self): + """Create Manufacture Order with auto post inventory True""" + self.company_1.mrp_production_auto_post_inventory = True + mo = self.production_obj.create({ + 'name': 'MO-01', + 'product_id': self.product_top.id, + 'product_uom_id': self.product_top.uom_id.id, + 'product_qty': 5.0, + 'bom_id': self.bom_top.id, + 'company_id': self.company_1.id, + }) + mo.action_assign() + self._produce(mo, 1.0) + raw_moves = self.stock_move_obj.search([ + ('raw_material_production_id', '=', mo.id), + ('state', '=', 'done')] + ) + finished_moves = self.stock_move_obj.search([ + ('production_id', '=', mo.id), + ('state', '=', 'done')] + ) + self.assertEqual(len(raw_moves), 2) + self.assertEqual(len(finished_moves), 1) diff --git a/mrp_production_auto_post_inventory/views/res_config_settings.xml b/mrp_production_auto_post_inventory/views/res_config_settings.xml new file mode 100644 index 000000000..20f6cf3f8 --- /dev/null +++ b/mrp_production_auto_post_inventory/views/res_config_settings.xml @@ -0,0 +1,31 @@ + + + + + + + mrp.production.auto.post.inventory.settings.form + res.config.settings + + +
+
+
+ +
+
+
+
+
+
+
+ +
diff --git a/mrp_production_auto_post_inventory/wizard/__init__.py b/mrp_production_auto_post_inventory/wizard/__init__.py new file mode 100644 index 000000000..216003589 --- /dev/null +++ b/mrp_production_auto_post_inventory/wizard/__init__.py @@ -0,0 +1 @@ +from . import mrp_product_produce diff --git a/mrp_production_auto_post_inventory/wizard/mrp_product_produce.py b/mrp_production_auto_post_inventory/wizard/mrp_product_produce.py new file mode 100644 index 000000000..9ac63e3f1 --- /dev/null +++ b/mrp_production_auto_post_inventory/wizard/mrp_product_produce.py @@ -0,0 +1,15 @@ +# Copyright 2016-19 Eficent Business and IT Consulting Services S.L. +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import api, models + + +class MrpProductProduce(models.TransientModel): + _inherit = "mrp.product.produce" + + @api.multi + def do_produce(self): + res = super(MrpProductProduce, self).do_produce() + if self.production_id.company_id.mrp_production_auto_post_inventory: + self.production_id.post_inventory() + return res