[10.0][MIG] mrp_production_putaway_strategy

This commit is contained in:
lreficent
2018-01-11 15:59:11 +01:00
committed by Joan Mateu Jordi
parent e98d83e659
commit 410f72a811
6 changed files with 28 additions and 52 deletions

View File

@@ -38,7 +38,7 @@ To use this module proceed as follows:
.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas .. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas
:alt: Try me on Runbot :alt: Try me on Runbot
:target: https://runbot.odoo-community.org/runbot/129/9.0 :target: https://runbot.odoo-community.org/runbot/129/10.0
Bug Tracker Bug Tracker

View File

@@ -1,5 +1,4 @@
# -*- coding: utf-8 -*- # -*- 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). # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from . import models from . import models

View File

@@ -6,7 +6,7 @@
"name": "MRP Production Putaway Strategy", "name": "MRP Production Putaway Strategy",
"summary": "Applies putaway strategies to manufacturing orders for " "summary": "Applies putaway strategies to manufacturing orders for "
"finished products.", "finished products.",
"version": "9.0.1.0.0", "version": "10.0.1.0.0",
"author": "Eficent, " "author": "Eficent, "
"Odoo Community Association (OCA)", "Odoo Community Association (OCA)",
"website": "http://www.eficent.com", "website": "http://www.eficent.com",

View File

@@ -1,5 +1,4 @@
# -*- coding: utf-8 -*- # -*- 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). # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from . import mrp_production from . import mrp_production

View File

@@ -1,23 +1,26 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# © 2017 Eficent Business and IT Consulting Services S.L. # © 2017-18 Eficent Business and IT Consulting Services S.L.
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from openerp import api, models, _ from odoo import api, models, _
class MrpProduction(models.Model): class MrpProduction(models.Model):
_inherit = 'mrp.production' _inherit = 'mrp.production'
@api.multi @api.model
def action_confirm(self): def create(self, vals):
for mo in self: location_dest = self.env['stock.location'].browse(vals.get(
if not mo.move_prod_id: 'location_dest_id'))
location = self.env['stock.location'].get_putaway_strategy( product = self.env['product.product'].browse(vals.get('product_id'))
mo.location_dest_id, mo.product_id) location_id = location_dest.get_putaway_strategy(product)
if location: if location_id:
message = _( vals['location_dest_id'] = location_id
'Applied Putaway strategy to finished products ' mo = super(MrpProduction, self).create(vals)
'location %s.' % mo.location_dest_id.complete_name) if location_id:
mo.message_post(message, message_type='comment') message = _(
mo.location_dest_id = location "Applied Putaway strategy to finished products.\n"
return super(MrpProduction, self).action_confirm() "Finished Products Location: %s." %
mo.location_dest_id.complete_name)
mo.message_post(message, message_type='comment')
return mo

View File

@@ -1,8 +1,8 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# © 2017 Eficent Business and IT Consulting Services S.L. # © 2017-18 Eficent Business and IT Consulting Services S.L.
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from openerp.tests.common import TransactionCase from odoo.tests.common import TransactionCase
class MrpProductionCase(TransactionCase): class MrpProductionCase(TransactionCase):
@@ -39,15 +39,15 @@ class MrpProductionCase(TransactionCase):
self.loc_production = self.env.ref( self.loc_production = self.env.ref(
"stock.location_production") "stock.location_production")
self.product1 = self.env.ref("product.product_product_18") self.product1 = self.env.ref("mrp.product_product_19")
self.product1.categ_id = self.category self.product1.categ_id = self.category
self.bom1 = self.env.ref("mrp.mrp_bom_3") self.bom1 = self.env.ref("mrp.mrp_bom_3")
def _create_mo(self, product=False, bom=False, src_loc=False, def _create_mo(self, product=False, bom=False, src_loc=False,
dest_loc=False, qty=10.0, uom=False, move_prod_id=False): dest_loc=False, qty=10.0, uom=False):
if not product: if not product:
product = self.product1 product = self.product1
uom = product.uom_id uom = product.uom_id or uom
if not bom: if not bom:
bom = self.bom1 bom = self.bom1
if not src_loc: if not src_loc:
@@ -60,40 +60,15 @@ class MrpProductionCase(TransactionCase):
"location_src_id": src_loc.id, "location_src_id": src_loc.id,
"location_dest_id": dest_loc.id, "location_dest_id": dest_loc.id,
"product_qty": qty, "product_qty": qty,
"product_uom": uom.id, "product_uom_id": uom.id,
"move_prod_id": move_prod_id.id if move_prod_id else False,
} }
return self.env['mrp.production'].create(res) return self.env['mrp.production'].create(res)
def test_putaway_strategy_01(self): def test_putaway_strategy_01(self):
"""Tests if the putaway strategy applies to a Manufacturing Order """Tests if the putaway strategy applies to a Manufacturing Order."""
without destination move."""
# Create MO # Create MO
mo = self._create_mo() mo = self._create_mo()
# Click confirm button for finished in mo.move_finished_ids:
mo.signal_workflow("button_confirm")
for finished in mo.move_created_ids:
self.assertEqual( self.assertEqual(
finished.location_dest_id, self.bin_loc_stock, finished.location_dest_id, self.bin_loc_stock,
"Putaway strategy hasn't been applied.") "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.")