Skip to content

Commit

Permalink
[9.0][ADD] mrp_production_putaway_strategy (OCA#215)
Browse files Browse the repository at this point in the history
* [9.0][ADD] mrp_production_putaway_strategy

* small fix

* fixes

* [FIX] travis and readme.

* [FIX] adapt tests to new logic
  • Loading branch information
JordiBForgeFlow committed Oct 9, 2018
1 parent d55dc66 commit 7c49f97
Show file tree
Hide file tree
Showing 8 changed files with 234 additions and 0 deletions.
80 changes: 80 additions & 0 deletions mrp_production_putaway_strategy/README.rst
Original file line number Diff line number Diff line change
@@ -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
<https://github.com/OCA/manufacture/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 <https://github.com/OCA/maintainer-tools/blob/master/template/module/static/description/icon.svg>`_.

Contributors
------------

* Jordi Ballester <jordi.ballester@eficent.com>
* Lois Rilo <lois.rilo@eficent.com>


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.
5 changes: 5 additions & 0 deletions mrp_production_putaway_strategy/__init__.py
Original file line number Diff line number Diff line change
@@ -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
17 changes: 17 additions & 0 deletions mrp_production_putaway_strategy/__openerp__.py
Original file line number Diff line number Diff line change
@@ -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,
}
5 changes: 5 additions & 0 deletions mrp_production_putaway_strategy/models/__init__.py
Original file line number Diff line number Diff line change
@@ -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
23 changes: 23 additions & 0 deletions mrp_production_putaway_strategy/models/mrp_production.py
Original file line number Diff line number Diff line change
@@ -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()
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions mrp_production_putaway_strategy/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -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
99 changes: 99 additions & 0 deletions mrp_production_putaway_strategy/tests/test_mrp_production.py
Original file line number Diff line number Diff line change
@@ -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.")

0 comments on commit 7c49f97

Please sign in to comment.