diff --git a/mrp_no_partial/README.rst b/mrp_no_partial/README.rst new file mode 100644 index 000000000..16c454ea7 --- /dev/null +++ b/mrp_no_partial/README.rst @@ -0,0 +1,91 @@ +============== +Mrp No Partial +============== + +.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! 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/10.0/mrp_no_partial + :alt: OCA/manufacture +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/manufacture-10-0/manufacture-10-0-mrp_no_partial + :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/10.0 + :alt: Try me on Runbot + +|badge1| |badge2| |badge3| |badge4| |badge5| + +With this module, you can restrict Production Orders validation if all +product quantities don't correspond to the quantities to do. + +**Table of contents** + +.. contents:: + :local: + +Usage +===== + +* Go to Inventory > Configuration > Warehouse Management > Operation Types +* Select the manufacturing type you want to restrict and then check + the 'No Partial Production Orders' checkbox. +* Create a Production Order with some product quantities. +* Don't fill in quantities and try to validate + +Changelog +========= + +10.0.1.0.0 (2019-02-04) +~~~~~~~~~~~~~~~~~~~~~~~ + +* First version + +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 +~~~~~~~ + +* ACSONE SA/NV + +Contributors +~~~~~~~~~~~~ + +* Denis Roussel + +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_no_partial/__init__.py b/mrp_no_partial/__init__.py new file mode 100644 index 000000000..0650744f6 --- /dev/null +++ b/mrp_no_partial/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/mrp_no_partial/__manifest__.py b/mrp_no_partial/__manifest__.py new file mode 100644 index 000000000..ae1550e77 --- /dev/null +++ b/mrp_no_partial/__manifest__.py @@ -0,0 +1,19 @@ +# -*- coding: utf-8 -*- +# Copyright 2019 ACSONE SA/NV +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +{ + 'name': 'Mrp No Partial', + 'summary': """ + Block the production order if all quantities are not done""", + 'version': '10.0.1.0.0', + 'license': 'AGPL-3', + 'author': 'ACSONE SA/NV,Odoo Community Association (OCA)', + 'website': 'https://github.com/OCA/manufacture', + 'depends': [ + 'mrp', + ], + 'data': [ + 'views/stock_picking_type.xml', + ], +} diff --git a/mrp_no_partial/models/__init__.py b/mrp_no_partial/models/__init__.py new file mode 100644 index 000000000..20c015049 --- /dev/null +++ b/mrp_no_partial/models/__init__.py @@ -0,0 +1,2 @@ +from . import stock_picking_type +from . import mrp_production diff --git a/mrp_no_partial/models/mrp_production.py b/mrp_no_partial/models/mrp_production.py new file mode 100644 index 000000000..7b449420c --- /dev/null +++ b/mrp_no_partial/models/mrp_production.py @@ -0,0 +1,36 @@ +# -*- coding: utf-8 -*- +# Copyright 2019 ACSONE SA/NV +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import api, models, _ +from odoo.tools import float_compare +from odoo.exceptions import ValidationError + + +class MrpProduction(models.Model): + + _inherit = 'mrp.production' + + @api.multi + def button_mark_done(self): + """ + Check if picking type option is set. + If all moves are not done or cancel, block validation. + :return: + """ + self.ensure_one() + if self.picking_type_id.mrp_no_partial: + # Check only raw moves + moves = self.move_raw_ids + current_moves = moves.filtered( + lambda x: + float_compare( + x.quantity_done, + x.product_uom_qty, + precision_rounding=x.product_uom.rounding) < 0) + if current_moves: + raise ValidationError( + _('Please fill in every product quantity in this ' + 'Production Order. You cannot validate a ' + 'Production Order with not done quantities!')) + return super(MrpProduction, self).button_mark_done() diff --git a/mrp_no_partial/models/stock_picking_type.py b/mrp_no_partial/models/stock_picking_type.py new file mode 100644 index 000000000..79d52abb5 --- /dev/null +++ b/mrp_no_partial/models/stock_picking_type.py @@ -0,0 +1,16 @@ +# -*- coding: utf-8 -*- +# Copyright 2019 ACSONE SA/NV +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import fields, models + + +class StockPickingType(models.Model): + + _inherit = 'stock.picking.type' + + mrp_no_partial = fields.Boolean( + string="No Partial Production Orders", + help="Check this if you want to block production orders if " + "all the quantities have not been done.", + ) diff --git a/mrp_no_partial/readme/CONTRIBUTORS.rst b/mrp_no_partial/readme/CONTRIBUTORS.rst new file mode 100644 index 000000000..9179ee4b8 --- /dev/null +++ b/mrp_no_partial/readme/CONTRIBUTORS.rst @@ -0,0 +1 @@ +* Denis Roussel diff --git a/mrp_no_partial/readme/DESCRIPTION.rst b/mrp_no_partial/readme/DESCRIPTION.rst new file mode 100644 index 000000000..b7f838ecf --- /dev/null +++ b/mrp_no_partial/readme/DESCRIPTION.rst @@ -0,0 +1,2 @@ +With this module, you can restrict Production Orders validation if all +product quantities don't correspond to the quantities to do. diff --git a/mrp_no_partial/readme/HISTORY.rst b/mrp_no_partial/readme/HISTORY.rst new file mode 100644 index 000000000..428fb55b6 --- /dev/null +++ b/mrp_no_partial/readme/HISTORY.rst @@ -0,0 +1,4 @@ +10.0.1.0.0 (2019-02-04) +~~~~~~~~~~~~~~~~~~~~~~~ + +* First version diff --git a/mrp_no_partial/readme/USAGE.rst b/mrp_no_partial/readme/USAGE.rst new file mode 100644 index 000000000..127dcf92f --- /dev/null +++ b/mrp_no_partial/readme/USAGE.rst @@ -0,0 +1,5 @@ +* Go to Inventory > Configuration > Warehouse Management > Operation Types +* Select the manufacturing type you want to restrict and then check + the 'No Partial Production Orders' checkbox. +* Create a Production Order with some product quantities. +* Don't fill in quantities and try to validate diff --git a/mrp_no_partial/static/description/icon.png b/mrp_no_partial/static/description/icon.png new file mode 100644 index 000000000..3a0328b51 Binary files /dev/null and b/mrp_no_partial/static/description/icon.png differ diff --git a/mrp_no_partial/static/description/index.html b/mrp_no_partial/static/description/index.html new file mode 100644 index 000000000..415ca2810 --- /dev/null +++ b/mrp_no_partial/static/description/index.html @@ -0,0 +1,444 @@ + + + + + + +Mrp No Partial + + + +
+

Mrp No Partial

+ + +

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

+

With this module, you can restrict Production Orders validation if all +product quantities don’t correspond to the quantities to do.

+

Table of contents

+ +
+

Usage

+
    +
  • Go to Inventory > Configuration > Warehouse Management > Operation Types
  • +
  • Select the manufacturing type you want to restrict and then check +the ‘No Partial Production Orders’ checkbox.
  • +
  • Create a Production Order with some product quantities.
  • +
  • Don’t fill in quantities and try to validate
  • +
+
+
+

Changelog

+
+

10.0.1.0.0 (2019-02-04)

+
    +
  • First version
  • +
+
+
+
+

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

+
    +
  • ACSONE SA/NV
  • +
+
+
+

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_no_partial/tests/__init__.py b/mrp_no_partial/tests/__init__.py new file mode 100644 index 000000000..06c763c70 --- /dev/null +++ b/mrp_no_partial/tests/__init__.py @@ -0,0 +1 @@ +from . import test_no_partial diff --git a/mrp_no_partial/tests/test_no_partial.py b/mrp_no_partial/tests/test_no_partial.py new file mode 100644 index 000000000..a4a225e72 --- /dev/null +++ b/mrp_no_partial/tests/test_no_partial.py @@ -0,0 +1,104 @@ +# -*- coding: utf-8 -*- +# Copyright 2019 ACSONE SA/NV +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo.tests import common +from odoo.exceptions import ValidationError + + +class TestNoPartial(common.TransactionCase): + + def setUp(self): + super(TestNoPartial, self).setUp() + self.production_obj = self.env['mrp.production'] + self.bom_obj = self.env['mrp.bom'] + self.location = self.env.ref('stock.stock_location_stock') + self.picking_type = self.env.ref('mrp.picking_type_manufacturing') + + self.picking_type.mrp_no_partial = True + + self.uom = self.env.ref('product.product_uom_unit') + + self.product = self.env['product.product'].create({ + 'name': 'Product MRP', + 'type': 'product', + 'uom_id': self.uom.id, + }) + self.product_raw_material = self.env['product.product'].create({ + 'name': 'Raw Material', + 'type': 'product', + 'uom_id': self.uom.id, + }) + + product_qty = self.env['stock.change.product.qty'].create({ + 'location_id': self.location.id, + 'product_id': self.product_raw_material.id, + 'new_quantity': 100.0, + }) + product_qty.change_product_qty() + + self.product_raw_material2 = self.env['product.product'].create({ + 'name': 'Raw Material 2', + 'type': 'product', + 'uom_id': self.uom.id, + }) + + product_qty = self.env['stock.change.product.qty'].create({ + 'location_id': self.location.id, + 'product_id': self.product_raw_material2.id, + 'new_quantity': 100.0, + }) + product_qty.change_product_qty() + + self.bom = self.env['mrp.bom'].create({ + 'product_id': self.product.id, + 'product_tmpl_id': self.product.product_tmpl_id.id, + 'bom_line_ids': ([ + (0, 0, { + 'product_id': self.product_raw_material.id, + 'product_qty': 5, + 'product_uom_id': self.uom.id + }), + (0, 0, { + 'product_id': self.product_raw_material2.id, + 'product_qty': 4, + 'product_uom_id': self.uom.id + }), + ]) + }) + + # Create Production Order + vals = { + 'picking_type_id': self.picking_type.id, + 'product_id': self.product.id, + 'product_qty': 1, + 'product_uom_id': self.uom.id, + 'bom_id': self.bom.id + + } + self.production = self.production_obj.create(vals) + + def test_no_partial(self): + self.production.action_assign() + self.assertEquals( + 'assigned', + self.production.availability, + ) + # Check with no quantity done + with self.assertRaises(ValidationError): + self.production.button_mark_done() + + # Check with partial quantities + for raw_move in self.production.move_raw_ids: + raw_move.quantity_done += 1 + + # Complete quantities + for raw_move in self.production.move_raw_ids: + raw_move.quantity_done = raw_move.quantity_available + + self.production.button_mark_done() + + def test_partial(self): + self.picking_type.mrp_no_partial = False + self.production.action_assign() + self.production.button_mark_done() diff --git a/mrp_no_partial/views/stock_picking_type.xml b/mrp_no_partial/views/stock_picking_type.xml new file mode 100644 index 000000000..ec8bf1119 --- /dev/null +++ b/mrp_no_partial/views/stock_picking_type.xml @@ -0,0 +1,19 @@ + + + + + + + stock.picking.type.form (in mrp_no_partial) + stock.picking.type + + + + + + + + + diff --git a/setup/mrp_no_partial/odoo/__init__.py b/setup/mrp_no_partial/odoo/__init__.py new file mode 100644 index 000000000..de40ea7ca --- /dev/null +++ b/setup/mrp_no_partial/odoo/__init__.py @@ -0,0 +1 @@ +__import__('pkg_resources').declare_namespace(__name__) diff --git a/setup/mrp_no_partial/odoo/addons/__init__.py b/setup/mrp_no_partial/odoo/addons/__init__.py new file mode 100644 index 000000000..de40ea7ca --- /dev/null +++ b/setup/mrp_no_partial/odoo/addons/__init__.py @@ -0,0 +1 @@ +__import__('pkg_resources').declare_namespace(__name__) diff --git a/setup/mrp_no_partial/odoo/addons/mrp_no_partial b/setup/mrp_no_partial/odoo/addons/mrp_no_partial new file mode 120000 index 000000000..faec1466b --- /dev/null +++ b/setup/mrp_no_partial/odoo/addons/mrp_no_partial @@ -0,0 +1 @@ +../../../../mrp_no_partial/ \ No newline at end of file diff --git a/setup/mrp_no_partial/setup.py b/setup/mrp_no_partial/setup.py new file mode 100644 index 000000000..28c57bb64 --- /dev/null +++ b/setup/mrp_no_partial/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)