diff --git a/mrp_production_putaway_strategy/README.rst b/mrp_production_putaway_strategy/README.rst new file mode 100644 index 000000000..392ce3655 --- /dev/null +++ b/mrp_production_putaway_strategy/README.rst @@ -0,0 +1,80 @@ +.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 + +=============================== +MRP Production Putaway Strategy +=============================== + +This module allows to apply putaway strategies to the products resulting from +the manufacturing orders. + +The finished products will be placed in the location designated by the putaway +strategy (if they do not have another destination move), based on the +finished products location that was defined in the manufacturing order. + +Configuration +============= + +To configure a putaway strategy follow the next steps: + +#. Go to 'Inventory / Settings' and activate the option 'Advanced routing of + products using rules'. +#. Define a putaway strategy in the location zone where the finished products + are supposed to be placed, and indicate the specific sub-location/bin + where the products should be placed. + +Usage +===== + +To use this module proceed as follows: + +#. Create a manufacturing order and indicate the product and the finished + products location zone. +#. Confirm the manufacturing order. +#. You will notice that the finished products location has changed to the + putaway location, and the chatter shows a message indicating that the + putaway strategy was applied. + +.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas + :alt: Try me on Runbot + :target: https://runbot.odoo-community.org/runbot/129/9.0 + + +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. + +Credits +======= + +Images +------ + +* Odoo Community Association: `Icon `_. + +Contributors +------------ + +* Jordi Ballester +* Lois Rilo + + +Maintainer +---------- + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +This module is maintained by the OCA. + +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. + +To contribute to this module, please visit https://odoo-community.org. diff --git a/mrp_production_putaway_strategy/__init__.py b/mrp_production_putaway_strategy/__init__.py new file mode 100644 index 000000000..1ef17e386 --- /dev/null +++ b/mrp_production_putaway_strategy/__init__.py @@ -0,0 +1,5 @@ +# -*- coding: utf-8 -*- +# © 2017 Eficent Business and IT Consulting Services S.L. +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +from . import models diff --git a/mrp_production_putaway_strategy/__openerp__.py b/mrp_production_putaway_strategy/__openerp__.py new file mode 100644 index 000000000..2c79827b2 --- /dev/null +++ b/mrp_production_putaway_strategy/__openerp__.py @@ -0,0 +1,17 @@ +# -*- coding: utf-8 -*- +# © 2017 Eficent Business and IT Consulting Services S.L. +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +{ + "name": "MRP Production Putaway Strategy", + "summary": "Applies putaway strategies to manufacturing orders for " + "finished products.", + "version": "9.0.1.0.0", + "author": "Eficent, " + "Odoo Community Association (OCA)", + "website": "http://www.eficent.com", + "category": "Manufacture", + "depends": ["mrp"], + "license": "AGPL-3", + "installable": True, +} diff --git a/mrp_production_putaway_strategy/models/__init__.py b/mrp_production_putaway_strategy/models/__init__.py new file mode 100644 index 000000000..e62eb8998 --- /dev/null +++ b/mrp_production_putaway_strategy/models/__init__.py @@ -0,0 +1,5 @@ +# -*- coding: utf-8 -*- +# © 2017 Eficent Business and IT Consulting Services S.L. +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +from . import mrp_production diff --git a/mrp_production_putaway_strategy/models/mrp_production.py b/mrp_production_putaway_strategy/models/mrp_production.py new file mode 100644 index 000000000..55ea6ecf9 --- /dev/null +++ b/mrp_production_putaway_strategy/models/mrp_production.py @@ -0,0 +1,23 @@ +# -*- coding: utf-8 -*- +# © 2017 Eficent Business and IT Consulting Services S.L. +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +from openerp import api, models, _ + + +class MrpProduction(models.Model): + _inherit = 'mrp.production' + + @api.multi + def action_confirm(self): + for mo in self: + if not mo.move_prod_id: + location = self.env['stock.location'].get_putaway_strategy( + mo.location_dest_id, mo.product_id) + if location: + message = _( + 'Applied Putaway strategy to finished products ' + 'location %s.' % mo.location_dest_id.complete_name) + mo.message_post(message, message_type='comment') + mo.location_dest_id = location + return super(MrpProduction, self).action_confirm() diff --git a/mrp_production_putaway_strategy/static/description/icon.png b/mrp_production_putaway_strategy/static/description/icon.png new file mode 100644 index 000000000..3a0328b51 Binary files /dev/null and b/mrp_production_putaway_strategy/static/description/icon.png differ diff --git a/mrp_production_putaway_strategy/tests/__init__.py b/mrp_production_putaway_strategy/tests/__init__.py new file mode 100644 index 000000000..96c2b358f --- /dev/null +++ b/mrp_production_putaway_strategy/tests/__init__.py @@ -0,0 +1,5 @@ +# -*- coding: utf-8 -*- +# © 2017 Eficent Business and IT Consulting Services S.L. +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +from . import test_mrp_production diff --git a/mrp_production_putaway_strategy/tests/test_mrp_production.py b/mrp_production_putaway_strategy/tests/test_mrp_production.py new file mode 100644 index 000000000..6cb82d865 --- /dev/null +++ b/mrp_production_putaway_strategy/tests/test_mrp_production.py @@ -0,0 +1,99 @@ +# -*- coding: utf-8 -*- +# © 2017 Eficent Business and IT Consulting Services S.L. +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +from openerp.tests.common import TransactionCase + + +class MrpProductionCase(TransactionCase): + + def setUp(self, *args, **kwargs): + super(MrpProductionCase, self).setUp(*args, **kwargs) + + self.warehouse = self.env["stock.warehouse"].create({ + "name": "X Warehouse", + "code": "X WH", + "reception_steps": "one_step", + "delivery_steps": "ship_only", + "resupply_from_wh": False, + "default_resupply_wh_id": False, + }) + + self.category = self.env['product.category'].create({'name': 'Test'}) + + self.loc_stock = self.warehouse.lot_stock_id + self.bin_loc_stock = self.env['stock.location'].create({ + 'name': 'Bin 1', + 'location_id': self.loc_stock.id, + 'usage': 'internal' + }) + + self.putaway_strategy = self.env['product.putaway'].create({ + 'name': 'Fixed Loc', + 'method': 'fixed', + 'fixed_location_ids': [( + 0, 0, {'fixed_location_id': self.bin_loc_stock.id, + 'category_id': self.category.id})] + }) + self.loc_stock.putaway_strategy_id = self.putaway_strategy + + self.loc_production = self.env.ref( + "stock.location_production") + self.product1 = self.env.ref("product.product_product_18") + self.product1.categ_id = self.category + self.bom1 = self.env.ref("mrp.mrp_bom_3") + + def _create_mo(self, product=False, bom=False, src_loc=False, + dest_loc=False, qty=10.0, uom=False, move_prod_id=False): + if not product: + product = self.product1 + uom = product.uom_id + if not bom: + bom = self.bom1 + if not src_loc: + src_loc = self.loc_stock + if not dest_loc: + dest_loc = self.loc_stock + res = { + "product_id": product.id, + "bom_id": bom.id, + "location_src_id": src_loc.id, + "location_dest_id": dest_loc.id, + "product_qty": qty, + "product_uom": uom.id, + "move_prod_id": move_prod_id.id if move_prod_id else False, + } + return self.env['mrp.production'].create(res) + + def test_putaway_strategy_01(self): + """Tests if the putaway strategy applies to a Manufacturing Order + without destination move.""" + # Create MO + mo = self._create_mo() + # Click confirm button + mo.signal_workflow("button_confirm") + for finished in mo.move_created_ids: + self.assertEqual( + finished.location_dest_id, self.bin_loc_stock, + "Putaway strategy hasn't been applied.") + + def test_putaway_strategy_02(self): + """Tests if the destination location is respected whenever a + destination move is set for the Manufactuing Order.""" + # Create a destination transfer. + move = self.env['stock.move'].create({ + "name": "Destination move for the test MO", + "product_id": self.product1.id, + "product_uom_qty": 10.0, + "product_uom": self.product1.uom_id.id, + "location_id": self.loc_stock.id, + "location_dest_id": self.bin_loc_stock.id, + }) + # Create MO + mo = self._create_mo(move_prod_id=move) + # Click confirm button + mo.signal_workflow("button_confirm") + for finished in mo.move_created_ids: + self.assertEqual( + finished.location_dest_id, self.loc_stock, + "Destination move has not been respected.")