From 410095fd1e90fe9f6a97d03e097e26f2fc51c4ca Mon Sep 17 00:00:00 2001 From: lreficent Date: Wed, 3 May 2017 19:00:33 +0200 Subject: [PATCH] [9.0][REW] mrp_mto_with_stock: Rework to remove dependency and enhance flexibility --- mrp_mto_with_stock/README.rst | 5 +++-- mrp_mto_with_stock/__openerp__.py | 3 ++- mrp_mto_with_stock/models/__init__.py | 1 + mrp_mto_with_stock/models/mrp.py | 5 ++--- mrp_mto_with_stock/models/product_template.py | 15 ++++++++++++++ .../views/product_template_view.xml | 20 +++++++++++++++++++ 6 files changed, 43 insertions(+), 6 deletions(-) create mode 100644 mrp_mto_with_stock/models/product_template.py create mode 100644 mrp_mto_with_stock/views/product_template_view.xml diff --git a/mrp_mto_with_stock/README.rst b/mrp_mto_with_stock/README.rst index 197e0816f..5e9c0f9fb 100644 --- a/mrp_mto_with_stock/README.rst +++ b/mrp_mto_with_stock/README.rst @@ -18,8 +18,9 @@ To configure this module, you need to: #. Activate the developer mode. #. Go to the products you want to follow this behaviour. -#. In the view form got to the tab *Inventory* and check the box for the - route *Make To Order + Make To Stock*. +#. In the view form go to the tab *Inventory* and set the *Manufacturing + MTO/MTS Locations*. Any other location not specified here will have the + standard behavior. Usage ===== diff --git a/mrp_mto_with_stock/__openerp__.py b/mrp_mto_with_stock/__openerp__.py index 3235afb03..928dbc421 100644 --- a/mrp_mto_with_stock/__openerp__.py +++ b/mrp_mto_with_stock/__openerp__.py @@ -14,5 +14,6 @@ "license": "AGPL-3", "application": False, "installable": True, - "depends": ["mrp", "stock_mts_mto_rule"], + "depends": ["mrp"], + "data": ['views/product_template_view.xml'], } diff --git a/mrp_mto_with_stock/models/__init__.py b/mrp_mto_with_stock/models/__init__.py index f5102a7f2..709cb97b3 100644 --- a/mrp_mto_with_stock/models/__init__.py +++ b/mrp_mto_with_stock/models/__init__.py @@ -4,3 +4,4 @@ # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from . import mrp +from . import product_template diff --git a/mrp_mto_with_stock/models/mrp.py b/mrp_mto_with_stock/models/mrp.py index a2d5565b7..87d1c082f 100644 --- a/mrp_mto_with_stock/models/mrp.py +++ b/mrp_mto_with_stock/models/mrp.py @@ -30,10 +30,9 @@ class MrpProduction(models.Model): # reserve all that is available (standard behaviour): res = super(MrpProduction, self).action_assign() # try to create procurements: - mtos_route = self.env.ref('stock_mts_mto_rule.route_mto_mts') for move in self.move_lines: - if (move.state == 'confirmed' and mtos_route.id in - move.product_id.route_ids.ids): + if (move.state == 'confirmed' and move.location_id in + move.product_id.mrp_mts_mto_location_ids): domain = [('product_id', '=', move.product_id.id), ('state', '=', 'running'), ('move_dest_id', '=', move.id)] diff --git a/mrp_mto_with_stock/models/product_template.py b/mrp_mto_with_stock/models/product_template.py new file mode 100644 index 000000000..11099600d --- /dev/null +++ b/mrp_mto_with_stock/models/product_template.py @@ -0,0 +1,15 @@ +# -*- coding: utf-8 -*- +# Copyright 2017 Eficent Business and IT Consulting Services S.L. +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from openerp import fields, models + + +class ProductTemplate(models.Model): + _inherit = 'product.template' + + mrp_mts_mto_location_ids = fields.Many2many( + comodel_name='stock.location', + string='Manufacturing MTO/MTS Locations', + help='These manufacturing locations will create procurements when ' + 'there is no stock availale in the source location.') diff --git a/mrp_mto_with_stock/views/product_template_view.xml b/mrp_mto_with_stock/views/product_template_view.xml new file mode 100644 index 000000000..cbe221f8f --- /dev/null +++ b/mrp_mto_with_stock/views/product_template_view.xml @@ -0,0 +1,20 @@ + + + + + + + product.template.form - mrp_mto_with_stock + extension + product.template + + + + + + + + +