From 85e9e323a64238b55704292a2ec3466dbd477fd9 Mon Sep 17 00:00:00 2001 From: Florian da Costa Date: Wed, 12 Aug 2015 19:22:57 +0200 Subject: [PATCH 01/11] fix stock_mts_mto procurement check method --- stock_mts_mto_rule/model/procurement.py | 33 +++++++++++++++++++------ 1 file changed, 25 insertions(+), 8 deletions(-) diff --git a/stock_mts_mto_rule/model/procurement.py b/stock_mts_mto_rule/model/procurement.py index cb563241f..fdafa30e5 100644 --- a/stock_mts_mto_rule/model/procurement.py +++ b/stock_mts_mto_rule/model/procurement.py @@ -19,12 +19,21 @@ # along with this program. If not, see . # ############################################################################### -from openerp import models, api +from openerp import models, api, fields class ProcurementOrder(models.Model): _inherit = 'procurement.order' + mts_mto_procurement_id = fields.Many2one( + 'procurement.order', + string="Mto+Mts Procurement", + copy=False) + mts_mto_procurement_ids = fields.One2many( + 'procurement.order', + 'mts_mto_procurement_id', + string="Procurements") + @api.multi def get_mto_qty_to_order(self): self.ensure_one() @@ -52,23 +61,31 @@ class ProcurementOrder(models.Model): 'product_qty': qty, 'product_uos_qty': uos_qty, 'rule_id': rule.id, + 'mts_mto_procurement_id': proc.id, } @api.model def _check(self, procurement): if procurement.rule_id and \ procurement.rule_id.action == 'split_procurement': - if procurement.state == 'running': + cancel_proc_list = [x.state == 'cancel' + for x in procurement.mts_mto_procurement_ids] + done_cancel_test_list = [ + x.state in ('done', 'cancel') + for x in procurement.mts_mto_procurement_ids] + if all(cancel_proc_list): + procurement.write({'state': 'cancel'}) + elif all(done_cancel_test_list): return True return super(ProcurementOrder, self)._check(procurement) @api.multi - def run(self, autocommit=False): - res = super(ProcurementOrder, self).run(autocommit=autocommit) - for proc in self: - if proc.rule_id and \ - proc.rule_id.action == 'split_procurement': - proc.check() + def check(self, autocommit=False): + res = super(ProcurementOrder, self).check(autocommit=autocommit) + for procurement in self: + if procurement.mts_mto_procurement_id: + procurement.mts_mto_procurement_id.check( + autocommit=autocommit) return res @api.model From c975c65440260d1a3a80235c01d8fd3b8a6d4881 Mon Sep 17 00:00:00 2001 From: OCA Transbot Date: Mon, 26 Oct 2015 07:57:56 -0400 Subject: [PATCH 02/11] OCA Transbot updated translations from Transifex --- stock_mts_mto_rule/i18n/sl.po | 107 ++++++++++++++++++++++++++++++++++ 1 file changed, 107 insertions(+) create mode 100644 stock_mts_mto_rule/i18n/sl.po diff --git a/stock_mts_mto_rule/i18n/sl.po b/stock_mts_mto_rule/i18n/sl.po new file mode 100644 index 000000000..bd7b21544 --- /dev/null +++ b/stock_mts_mto_rule/i18n/sl.po @@ -0,0 +1,107 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * stock_mts_mto_rule +# +# Translators: +# Matjaž Mozetič , 2015 +msgid "" +msgstr "" +"Project-Id-Version: stock-logistics-warehouse (8.0)\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2015-10-24 09:07+0000\n" +"PO-Revision-Date: 2015-10-23 12:22+0000\n" +"Last-Translator: Matjaž Mozetič \n" +"Language-Team: Slovenian (http://www.transifex.com/oca/OCA-stock-logistics-warehouse-8-0/language/sl/)\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Language: sl\n" +"Plural-Forms: nplurals=4; plural=(n%100==1 ? 0 : n%100==2 ? 1 : n%100==3 || n%100==4 ? 2 : 3);\n" + +#. module: stock_mts_mto_rule +#: code:addons/stock_mts_mto_rule/model/warehouse.py:53 +#, python-format +msgid "Can't find MTO Rule on the warehouse" +msgstr "Za skladišče ni pravila 'po naročilu'" + +#. module: stock_mts_mto_rule +#: code:addons/stock_mts_mto_rule/model/warehouse.py:60 +#, python-format +msgid "Can't find MTS Rule on the warehouse" +msgstr "Za skladišče ni pravila 'na zalogo'" + +#. module: stock_mts_mto_rule +#: code:addons/stock_mts_mto_rule/model/warehouse.py:49 +#, python-format +msgid "Can't find any generic MTS+MTO route." +msgstr "Ni generične proge 'na zalogo' + 'po naročilu'" + +#. module: stock_mts_mto_rule +#: code:addons/stock_mts_mto_rule/model/rule.py:36 +#, python-format +msgid "Choose between MTS and MTO" +msgstr "Izbira med 'Na zalogo' in 'Po naročilu'" + +#. module: stock_mts_mto_rule +#: help:stock.warehouse,mto_mts_management:0 +msgid "" +"If this new route is selected on product form view, a purchase order will be" +" created only if the virtual stock is less than 0 else, the product will be " +"taken from stocks" +msgstr "Če je na prikazu obrazca proizvoda izbrana ta proga, se nabavni nalog ustvari le, če je navidezna zaloga manj od 0. V nasprotnem primeru se proizvod vzame iz zaloge." + +#. module: stock_mts_mto_rule +#: field:procurement.rule,mto_rule_id:0 +msgid "MTO Rule" +msgstr "Pravilo 'Po naročilu'" + +#. module: stock_mts_mto_rule +#: field:stock.warehouse,mts_mto_rule_id:0 +msgid "MTO+MTS rule" +msgstr "Pravilo 'Po naročilu' + 'Na zalogo'" + +#. module: stock_mts_mto_rule +#: field:procurement.rule,mts_rule_id:0 +msgid "MTS Rule" +msgstr "Pravilo 'Na zalogo'" + +#. module: stock_mts_mto_rule +#: code:addons/stock_mts_mto_rule/model/warehouse.py:63 +#, python-format +msgid "MTS+MTO" +msgstr "Na zalogo + Po naročilu" + +#. module: stock_mts_mto_rule +#: model:stock.location.route,name:stock_mts_mto_rule.route_mto_mts +msgid "Make To Order + Make To Stock" +msgstr "Naredi po naročilu + Naredi na zalogo" + +#. module: stock_mts_mto_rule +#: field:procurement.order,mts_mto_procurement_id:0 +msgid "Mto+Mts Procurement" +msgstr "Oskrbovanja 'po naročilu'+'na zalogo'" + +#. module: stock_mts_mto_rule +#: model:ir.model,name:stock_mts_mto_rule.model_procurement_order +msgid "Procurement" +msgstr "Oskrbovanje" + +#. module: stock_mts_mto_rule +#: model:ir.model,name:stock_mts_mto_rule.model_procurement_rule +msgid "Procurement Rule" +msgstr "Oskrbovalno pravilo" + +#. module: stock_mts_mto_rule +#: field:procurement.order,mts_mto_procurement_ids:0 +msgid "Procurements" +msgstr "Oskrbovanja" + +#. module: stock_mts_mto_rule +#: field:stock.warehouse,mto_mts_management:0 +msgid "Use MTO+MTS rules" +msgstr "Uporabi pravila Po naročilu + Na zalogo" + +#. module: stock_mts_mto_rule +#: model:ir.model,name:stock_mts_mto_rule.model_stock_warehouse +msgid "Warehouse" +msgstr "Skladišče" From ef2e611bc8713223622338bbf0339171503e4fd8 Mon Sep 17 00:00:00 2001 From: Lionel Sausin Date: Wed, 25 Nov 2015 15:56:51 +0100 Subject: [PATCH 03/11] Update READMEs Conforms to the latest README template: bugtracker, runbot etc. Fixes bugtracker URL on some modules. States OCA as maintainer, removes other contributors from the 'Maintainer' section. --- stock_mts_mto_rule/README.rst | 32 +++++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/stock_mts_mto_rule/README.rst b/stock_mts_mto_rule/README.rst index 130c57887..00f85b320 100644 --- a/stock_mts_mto_rule/README.rst +++ b/stock_mts_mto_rule/README.rst @@ -1,6 +1,8 @@ .. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg - :alt: License: AGPL-3 + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 +================== Stock MTS+MTO Rule ================== @@ -35,13 +37,29 @@ After validation, a purchase order with 2 products will be created. Usage ===== -You have to choose the mts+mto route on the product form. -You should not choose both mts+mto route and mto route. +You have to select the mts+mto route on the product form. +You should not select both the mts+mto route and the mto route. + +.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas + :alt: Try me on Runbot + :target: https://runbot.odoo-community.org/runbot/153/8.0 Configuration ============= -You have to choose 'Use MTO+MTS rules' on the company's warehouse form. +You have to select 'Use MTO+MTS rules' on the company's warehouse form. + +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 +`_. Note: In order to see this option, you must enable "Manage advanced routes for your warehouse" under Settings -> Configuration -> Warehouse. @@ -56,9 +74,9 @@ Contributors Maintainer ---------- -.. image:: http://odoo-community.org/logo.png +.. image:: https://odoo-community.org/logo.png :alt: Odoo Community Association - :target: http://odoo-community.org + :target: https://odoo-community.org This module is maintained by the OCA. @@ -66,4 +84,4 @@ 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 http://odoo-community.org. +To contribute to this module, please visit https://odoo-community.org. From 4de0cbb1e2a87a54f6c39e6f6c076b8118d37e46 Mon Sep 17 00:00:00 2001 From: JulioSerna Date: Tue, 5 Jan 2016 20:49:12 +0000 Subject: [PATCH 04/11] set pull rule of customer location like split_procurement to allow when warehouse is two/three steps delivery propagate move by mts-mto in pick/pack/out --- stock_mts_mto_rule/model/warehouse.py | 26 ++++++++++++++++++- .../tests/test_mto_mts_route.py | 10 ++++--- 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/stock_mts_mto_rule/model/warehouse.py b/stock_mts_mto_rule/model/warehouse.py index 6f06ada0f..0c10b17aa 100644 --- a/stock_mts_mto_rule/model/warehouse.py +++ b/stock_mts_mto_rule/model/warehouse.py @@ -70,6 +70,26 @@ class Warehouse(models.Model): 'picking_type_id': warehouse.mto_pull_id.picking_type_id.id, } + @api.model + def _get_push_pull_rules(self, warehouse, active, values, new_route_id): + pull_obj = self.env['procurement.rule'] + res = super(Warehouse, self)._get_push_pull_rules( + warehouse, active, values, new_route_id) + customer_location = warehouse._get_partner_locations() + location_id = customer_location[0].id + if warehouse.mto_mts_management: + for pull in res[1]: + if pull['location_id'] == location_id: + pull_mto_mts = pull.copy() + pull_mto_mts_id = pull_obj.create(pull_mto_mts) + pull.update({ + 'action': 'split_procurement', + 'mto_rule_id': pull_mto_mts_id.id, + 'mts_rule_id': pull_mto_mts_id.id, + 'sequence': 10 + }) + return res + @api.multi def create_routes(self, warehouse): pull_model = self.env['procurement.rule'] @@ -94,7 +114,11 @@ class Warehouse(models.Model): for warehouse in self: if warehouse.mts_mto_rule_id: warehouse.mts_mto_rule_id.unlink() - return super(Warehouse, self).write(vals) + res = super(Warehouse, self).write(vals) + if 'mto_mts_management' in vals: + self.with_context({'active_test': False}).change_route( + warehouse, new_delivery_step=warehouse.delivery_steps) + return res @api.model def get_all_routes_for_wh(self, warehouse): diff --git a/stock_mts_mto_rule/tests/test_mto_mts_route.py b/stock_mts_mto_rule/tests/test_mto_mts_route.py index bc38de754..eacf3c3e4 100644 --- a/stock_mts_mto_rule/tests/test_mto_mts_route.py +++ b/stock_mts_mto_rule/tests/test_mto_mts_route.py @@ -34,12 +34,15 @@ class TestMtoMtsRoute(TransactionCase): def test_standard_mts_route(self): self.procurement.run() + procurement_id = self.procurement_obj.search([ + ('group_id', '=', self.procurement.group_id.id), + ('move_ids', '!=', False)], limit=1) self.assertEqual('make_to_stock', - self.procurement.move_ids[0].procure_method) + procurement_id.move_ids[0].procure_method) self.assertEqual(self.procurement.product_qty, - self.procurement.move_ids[0].product_uom_qty) + procurement_id.move_ids[0].product_uom_qty) self.assertEqual('confirmed', - self.procurement.move_ids[0].state) + procurement_id.move_ids[0].state) def test_mts_mto_route_split(self): mto_mts_route = self.env.ref('stock_mts_mto_rule.route_mto_mts') @@ -81,6 +84,7 @@ class TestMtoMtsRoute(TransactionCase): self.warehouse.mto_mts_management = True self.product = self.env.ref('product.product_product_4') self.company_partner = self.env.ref('base.main_partner') + self.procurement_obj = self.env['procurement.order'] self.group = self.env['procurement.group'].create({ 'name': 'test', }) From d44541d2d29a031eb49b342f87b8320f79db29ff Mon Sep 17 00:00:00 2001 From: OCA Transbot Date: Sun, 31 Jan 2016 00:24:23 -0500 Subject: [PATCH 05/11] OCA Transbot updated translations from Transifex --- stock_mts_mto_rule/i18n/de.po | 107 ++++++++++++++++++++++++++++++++++ 1 file changed, 107 insertions(+) create mode 100644 stock_mts_mto_rule/i18n/de.po diff --git a/stock_mts_mto_rule/i18n/de.po b/stock_mts_mto_rule/i18n/de.po new file mode 100644 index 000000000..40d9d8d0a --- /dev/null +++ b/stock_mts_mto_rule/i18n/de.po @@ -0,0 +1,107 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * stock_mts_mto_rule +# +# Translators: +# Rudolf Schnapka , 2016 +msgid "" +msgstr "" +"Project-Id-Version: stock-logistics-warehouse (8.0)\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2016-01-14 01:38+0000\n" +"PO-Revision-Date: 2016-01-14 09:50+0000\n" +"Last-Translator: Rudolf Schnapka \n" +"Language-Team: German (http://www.transifex.com/oca/OCA-stock-logistics-warehouse-8-0/language/de/)\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Language: de\n" +"Plural-Forms: nplurals=2; plural=(n != 1);\n" + +#. module: stock_mts_mto_rule +#: code:addons/stock_mts_mto_rule/model/warehouse.py:53 +#, python-format +msgid "Can't find MTO Rule on the warehouse" +msgstr "Kann MTO-Regel zum Lager nicht finden" + +#. module: stock_mts_mto_rule +#: code:addons/stock_mts_mto_rule/model/warehouse.py:60 +#, python-format +msgid "Can't find MTS Rule on the warehouse" +msgstr "Kann MTS-Regel zum Lager nicht finden" + +#. module: stock_mts_mto_rule +#: code:addons/stock_mts_mto_rule/model/warehouse.py:49 +#, python-format +msgid "Can't find any generic MTS+MTO route." +msgstr "Kann keine allg. MTO- oder MTS-Route finden" + +#. module: stock_mts_mto_rule +#: code:addons/stock_mts_mto_rule/model/rule.py:36 +#, python-format +msgid "Choose between MTS and MTO" +msgstr "Wähle aus MTO und MTS" + +#. module: stock_mts_mto_rule +#: help:stock.warehouse,mto_mts_management:0 +msgid "" +"If this new route is selected on product form view, a purchase order will be" +" created only if the virtual stock is less than 0 else, the product will be " +"taken from stocks" +msgstr "Wird diese neue Route in der Produktdetailsicht gewählt, wird eine Beschaffung nur dann bewirkt, wenn der Planbestand unter 0 fällt, anderenfalls wird das Produkt aus dem Bestand genommen." + +#. module: stock_mts_mto_rule +#: field:procurement.rule,mto_rule_id:0 +msgid "MTO Rule" +msgstr "MTO-Regel" + +#. module: stock_mts_mto_rule +#: field:stock.warehouse,mts_mto_rule_id:0 +msgid "MTO+MTS rule" +msgstr "MTO+MTS-Regel" + +#. module: stock_mts_mto_rule +#: field:procurement.rule,mts_rule_id:0 +msgid "MTS Rule" +msgstr "MTS-Regel" + +#. module: stock_mts_mto_rule +#: code:addons/stock_mts_mto_rule/model/warehouse.py:63 +#, python-format +msgid "MTS+MTO" +msgstr "MTS+MTO" + +#. module: stock_mts_mto_rule +#: model:stock.location.route,name:stock_mts_mto_rule.route_mto_mts +msgid "Make To Order + Make To Stock" +msgstr "MTO Auftragsfertigung + MTS Lagerfertigung" + +#. module: stock_mts_mto_rule +#: field:procurement.order,mts_mto_procurement_id:0 +msgid "Mto+Mts Procurement" +msgstr "MTO+MTS-Beschaffung" + +#. module: stock_mts_mto_rule +#: model:ir.model,name:stock_mts_mto_rule.model_procurement_order +msgid "Procurement" +msgstr "Beschaffung" + +#. module: stock_mts_mto_rule +#: model:ir.model,name:stock_mts_mto_rule.model_procurement_rule +msgid "Procurement Rule" +msgstr "Beschaffungsregel" + +#. module: stock_mts_mto_rule +#: field:procurement.order,mts_mto_procurement_ids:0 +msgid "Procurements" +msgstr "Beschaffungen" + +#. module: stock_mts_mto_rule +#: field:stock.warehouse,mto_mts_management:0 +msgid "Use MTO+MTS rules" +msgstr "Verwende MTO+MTS-Regeln" + +#. module: stock_mts_mto_rule +#: model:ir.model,name:stock_mts_mto_rule.model_stock_warehouse +msgid "Warehouse" +msgstr "Warenlager" From 924ec05f9446f33821b1d8a8866c212bca833cac Mon Sep 17 00:00:00 2001 From: OCA Transbot Date: Sun, 14 Feb 2016 00:54:47 -0500 Subject: [PATCH 06/11] OCA Transbot updated translations from Transifex --- stock_mts_mto_rule/i18n/es.po | 107 ++++++++++++++++++++++++++++++++++ 1 file changed, 107 insertions(+) create mode 100644 stock_mts_mto_rule/i18n/es.po diff --git a/stock_mts_mto_rule/i18n/es.po b/stock_mts_mto_rule/i18n/es.po new file mode 100644 index 000000000..2427c3ec1 --- /dev/null +++ b/stock_mts_mto_rule/i18n/es.po @@ -0,0 +1,107 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * stock_mts_mto_rule +# +# Translators: +# Antonio Trueba, 2016 +msgid "" +msgstr "" +"Project-Id-Version: stock-logistics-warehouse (8.0)\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2016-01-14 01:38+0000\n" +"PO-Revision-Date: 2016-02-10 16:39+0000\n" +"Last-Translator: Antonio Trueba\n" +"Language-Team: Spanish (http://www.transifex.com/oca/OCA-stock-logistics-warehouse-8-0/language/es/)\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Language: es\n" +"Plural-Forms: nplurals=2; plural=(n != 1);\n" + +#. module: stock_mts_mto_rule +#: code:addons/stock_mts_mto_rule/model/warehouse.py:53 +#, python-format +msgid "Can't find MTO Rule on the warehouse" +msgstr "" + +#. module: stock_mts_mto_rule +#: code:addons/stock_mts_mto_rule/model/warehouse.py:60 +#, python-format +msgid "Can't find MTS Rule on the warehouse" +msgstr "" + +#. module: stock_mts_mto_rule +#: code:addons/stock_mts_mto_rule/model/warehouse.py:49 +#, python-format +msgid "Can't find any generic MTS+MTO route." +msgstr "" + +#. module: stock_mts_mto_rule +#: code:addons/stock_mts_mto_rule/model/rule.py:36 +#, python-format +msgid "Choose between MTS and MTO" +msgstr "" + +#. module: stock_mts_mto_rule +#: help:stock.warehouse,mto_mts_management:0 +msgid "" +"If this new route is selected on product form view, a purchase order will be" +" created only if the virtual stock is less than 0 else, the product will be " +"taken from stocks" +msgstr "" + +#. module: stock_mts_mto_rule +#: field:procurement.rule,mto_rule_id:0 +msgid "MTO Rule" +msgstr "" + +#. module: stock_mts_mto_rule +#: field:stock.warehouse,mts_mto_rule_id:0 +msgid "MTO+MTS rule" +msgstr "" + +#. module: stock_mts_mto_rule +#: field:procurement.rule,mts_rule_id:0 +msgid "MTS Rule" +msgstr "" + +#. module: stock_mts_mto_rule +#: code:addons/stock_mts_mto_rule/model/warehouse.py:63 +#, python-format +msgid "MTS+MTO" +msgstr "" + +#. module: stock_mts_mto_rule +#: model:stock.location.route,name:stock_mts_mto_rule.route_mto_mts +msgid "Make To Order + Make To Stock" +msgstr "" + +#. module: stock_mts_mto_rule +#: field:procurement.order,mts_mto_procurement_id:0 +msgid "Mto+Mts Procurement" +msgstr "" + +#. module: stock_mts_mto_rule +#: model:ir.model,name:stock_mts_mto_rule.model_procurement_order +msgid "Procurement" +msgstr "Abastecimiento" + +#. module: stock_mts_mto_rule +#: model:ir.model,name:stock_mts_mto_rule.model_procurement_rule +msgid "Procurement Rule" +msgstr "Regla de abastecimiento" + +#. module: stock_mts_mto_rule +#: field:procurement.order,mts_mto_procurement_ids:0 +msgid "Procurements" +msgstr "Abastecimientos" + +#. module: stock_mts_mto_rule +#: field:stock.warehouse,mto_mts_management:0 +msgid "Use MTO+MTS rules" +msgstr "" + +#. module: stock_mts_mto_rule +#: model:ir.model,name:stock_mts_mto_rule.model_stock_warehouse +msgid "Warehouse" +msgstr "Almacén" From cc39a4bee0a37fb094c0766e85af1527ab9347e0 Mon Sep 17 00:00:00 2001 From: Levent Karakas Date: Tue, 1 Mar 2016 16:09:41 +0200 Subject: [PATCH 07/11] stock move name fix --- stock_mts_mto_rule/model/procurement.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stock_mts_mto_rule/model/procurement.py b/stock_mts_mto_rule/model/procurement.py index fdafa30e5..a92fb5bab 100644 --- a/stock_mts_mto_rule/model/procurement.py +++ b/stock_mts_mto_rule/model/procurement.py @@ -56,7 +56,7 @@ class ProcurementOrder(models.Model): origin = (proc.group_id and (proc.group_id.name + ":") or "") + \ (proc.rule_id and proc.rule_id.name or proc.origin or "/") return { - 'name': rule.name, + 'name': proc.name, 'origin': origin, 'product_qty': qty, 'product_uos_qty': uos_qty, From 63e1e26e29b5ff4f0b3843007477174aa4683b0a Mon Sep 17 00:00:00 2001 From: Florian da Costa Date: Thu, 10 Mar 2016 15:22:13 +0100 Subject: [PATCH 08/11] Do no run mts mto procurement if it already has been splited into at least another procurement --- stock_mts_mto_rule/README.rst | 9 +++++++++ stock_mts_mto_rule/model/procurement.py | 2 ++ 2 files changed, 11 insertions(+) diff --git a/stock_mts_mto_rule/README.rst b/stock_mts_mto_rule/README.rst index 00f85b320..91c13ea9c 100644 --- a/stock_mts_mto_rule/README.rst +++ b/stock_mts_mto_rule/README.rst @@ -49,6 +49,15 @@ Configuration You have to select 'Use MTO+MTS rules' on the company's warehouse form. +Known issues +============ + +If you cancel a delivery order and then recreate it from Recreate +Delivery Order button in sale order form, then the stock level at the time of +the Re-Creation won't be taken into account. So if a purchase order was created +when the sale order was first validated, a similar purchase order will be created +during the Re-creation of the delivery order, even if not needed regarding the actual stock. + Bug Tracker =========== diff --git a/stock_mts_mto_rule/model/procurement.py b/stock_mts_mto_rule/model/procurement.py index a92fb5bab..2a8586c57 100644 --- a/stock_mts_mto_rule/model/procurement.py +++ b/stock_mts_mto_rule/model/procurement.py @@ -92,6 +92,8 @@ class ProcurementOrder(models.Model): def _run(self, procurement): if procurement.rule_id and \ procurement.rule_id.action == 'split_procurement': + if procurement.mts_mto_procurement_ids: + return super(ProcurementOrder, self)._run(procurement) uom_obj = self.env['product.uom'] needed_qty = procurement.get_mto_qty_to_order() rule = procurement.rule_id From d57c0eb9e77047b7c0bcbd80e729c215b91e85fd Mon Sep 17 00:00:00 2001 From: jbeficent Date: Tue, 12 Apr 2016 10:44:31 +0200 Subject: [PATCH 09/11] [ADD][9.0] stock_mts_mto_rule --- stock_mts_mto_rule/README.rst | 2 - stock_mts_mto_rule/__openerp__.py | 4 +- stock_mts_mto_rule/model/procurement.py | 24 ++++-------- .../tests/test_mto_mts_route.py | 37 ++++++++++--------- 4 files changed, 29 insertions(+), 38 deletions(-) diff --git a/stock_mts_mto_rule/README.rst b/stock_mts_mto_rule/README.rst index 91c13ea9c..c17580cff 100644 --- a/stock_mts_mto_rule/README.rst +++ b/stock_mts_mto_rule/README.rst @@ -70,8 +70,6 @@ stock-logistics-warehouse/issues/new?body=module:%20 stock_mts_mto_rule%0Aversion:%20 8.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_. -Note: In order to see this option, you must enable "Manage advanced routes for your warehouse" under Settings -> Configuration -> Warehouse. - Credits ======= diff --git a/stock_mts_mto_rule/__openerp__.py b/stock_mts_mto_rule/__openerp__.py index bb2d0911a..67640dd6b 100644 --- a/stock_mts_mto_rule/__openerp__.py +++ b/stock_mts_mto_rule/__openerp__.py @@ -21,7 +21,7 @@ ############################################################################## {'name': 'Stock MTS+MTO Rule', - 'version': '8.0.1.0.0', + 'version': '9.0.1.0.0', 'author': 'Akretion,Odoo Community Association (OCA)', 'website': 'http://www.akretion.com', 'license': 'AGPL-3', @@ -34,5 +34,5 @@ 'view/pull_rule.xml', 'view/warehouse.xml', ], - 'installable': False, + 'installable': True, } diff --git a/stock_mts_mto_rule/model/procurement.py b/stock_mts_mto_rule/model/procurement.py index 2a8586c57..14d66b2cf 100644 --- a/stock_mts_mto_rule/model/procurement.py +++ b/stock_mts_mto_rule/model/procurement.py @@ -19,7 +19,7 @@ # along with this program. If not, see . # ############################################################################### -from openerp import models, api, fields +from openerp import api, fields, models class ProcurementOrder(models.Model): @@ -52,14 +52,13 @@ class ProcurementOrder(models.Model): return self.product_qty @api.model - def _get_mts_mto_procurement(self, proc, rule, qty, uos_qty): + def _get_mts_mto_procurement(self, proc, rule, qty): origin = (proc.group_id and (proc.group_id.name + ":") or "") + \ (proc.rule_id and proc.rule_id.name or proc.origin or "/") return { 'name': proc.name, 'origin': origin, 'product_qty': qty, - 'product_uos_qty': uos_qty, 'rule_id': rule.id, 'mts_mto_procurement_id': proc.id, } @@ -94,37 +93,28 @@ class ProcurementOrder(models.Model): procurement.rule_id.action == 'split_procurement': if procurement.mts_mto_procurement_ids: return super(ProcurementOrder, self)._run(procurement) - uom_obj = self.env['product.uom'] needed_qty = procurement.get_mto_qty_to_order() rule = procurement.rule_id if needed_qty == 0.0: mts_vals = self._get_mts_mto_procurement( - procurement, rule.mts_rule_id, procurement.product_qty, - procurement.product_uos_qty) + procurement, rule.mts_rule_id, procurement.product_qty) mts_proc = procurement.copy(mts_vals) mts_proc.run() elif needed_qty == procurement.product_qty: mto_vals = self._get_mts_mto_procurement( - procurement, rule.mto_rule_id, procurement.product_qty, - procurement.product_uos_qty) + procurement, rule.mto_rule_id, procurement.product_qty) mto_proc = procurement.copy(mto_vals) mto_proc.run() else: mts_qty = procurement.product_qty - needed_qty - mts_uos_qty = uom_obj._compute_qty( - procurement.product_uom.id, - mts_qty, - procurement.product_uos.id) mts_vals = self._get_mts_mto_procurement( - procurement, rule.mts_rule_id, mts_qty, mts_uos_qty) + procurement, rule.mts_rule_id, mts_qty) mts_proc = procurement.copy(mts_vals) mts_proc.run() - uos_qty = procurement.product_uos_qty mto_vals = self._get_mts_mto_procurement( - procurement, rule.mto_rule_id, needed_qty, - uos_qty - mts_uos_qty) - + procurement, rule.mto_rule_id, needed_qty) mto_proc = procurement.copy(mto_vals) mto_proc.run() + return super(ProcurementOrder, self)._run(procurement) diff --git a/stock_mts_mto_rule/tests/test_mto_mts_route.py b/stock_mts_mto_rule/tests/test_mto_mts_route.py index eacf3c3e4..838c3a0c3 100644 --- a/stock_mts_mto_rule/tests/test_mto_mts_route.py +++ b/stock_mts_mto_rule/tests/test_mto_mts_route.py @@ -19,10 +19,24 @@ from datetime import datetime class TestMtoMtsRoute(TransactionCase): + def _procurement_create(self): + self.procurement = self.env['procurement.order'].create({ + 'location_id': self.env.ref('stock.stock_location_customers').id, + 'product_id': self.product.id, + 'product_qty': 2.0, + 'product_uom': 1, + 'warehouse_id': self.warehouse.id, + 'priority': '1', + 'date_planned': datetime.now().strftime("%Y-%m-%d %H:%M:%S"), + 'name': self.product.name, + 'origin': 'test', + 'group_id': self.group.id, + }) + def test_standard_mto_route(self): mto_route = self.env.ref('stock.route_warehouse0_mto') self.product.route_ids = [(6, 0, [mto_route.id])] - self.procurement.run() + self._procurement_create() self.assertEqual(self.warehouse.mto_pull_id, self.procurement.rule_id) self.assertEqual('make_to_order', @@ -33,7 +47,7 @@ class TestMtoMtsRoute(TransactionCase): self.procurement.move_ids[0].state) def test_standard_mts_route(self): - self.procurement.run() + self._procurement_create() procurement_id = self.procurement_obj.search([ ('group_id', '=', self.procurement.group_id.id), ('move_ids', '!=', False)], limit=1) @@ -48,7 +62,7 @@ class TestMtoMtsRoute(TransactionCase): mto_mts_route = self.env.ref('stock_mts_mto_rule.route_mto_mts') self.product.route_ids = [(6, 0, [mto_mts_route.id])] self.quant.qty = 1.0 - self.procurement.run() + self._procurement_create() moves = self.env['stock.move'].search( [('group_id', '=', self.group.id)]) self.assertEqual(2, len(moves)) @@ -58,7 +72,7 @@ class TestMtoMtsRoute(TransactionCase): mto_mts_route = self.env.ref('stock_mts_mto_rule.route_mto_mts') self.product.route_ids = [(6, 0, [mto_mts_route.id])] self.quant.qty = 0.0 - self.procurement.run() + self._procurement_create() moves = self.env['stock.move'].search( [('group_id', '=', self.group.id)]) self.assertEqual(1, len(moves)) @@ -70,7 +84,7 @@ class TestMtoMtsRoute(TransactionCase): mto_mts_route = self.env.ref('stock_mts_mto_rule.route_mto_mts') self.product.route_ids = [(6, 0, [mto_mts_route.id])] self.quant.qty = 3.0 - self.procurement.run() + self._procurement_create() moves = self.env['stock.move'].search( [('group_id', '=', self.group.id)]) self.assertEqual(1, len(moves)) @@ -88,18 +102,7 @@ class TestMtoMtsRoute(TransactionCase): self.group = self.env['procurement.group'].create({ 'name': 'test', }) - self.procurement = self.env['procurement.order'].create({ - 'location_id': self.env.ref('stock.stock_location_customers').id, - 'product_id': self.product.id, - 'product_qty': 2.0, - 'product_uom': 1, - 'warehouse_id': self.warehouse.id, - 'priority': '1', - 'date_planned': datetime.now().strftime("%Y-%m-%d %H:%M:%S"), - 'name': self.product.name, - 'origin': 'test', - 'group_id': self.group.id, - }) + self.quant = self.env['stock.quant'].create({ 'owner_id': self.company_partner.id, 'location_id': self.env.ref('stock.stock_location_stock').id, From 6844e9c4fe176fe8658293ffe4e943ffeea05ef4 Mon Sep 17 00:00:00 2001 From: Sylvain GARANCHER Date: Fri, 14 Oct 2016 10:45:30 +0200 Subject: [PATCH 10/11] [IMP] stock_mts_mto_rule : Updated README.rst for v9.0 --- stock_mts_mto_rule/README.rst | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/stock_mts_mto_rule/README.rst b/stock_mts_mto_rule/README.rst index c17580cff..aaf57fbb9 100644 --- a/stock_mts_mto_rule/README.rst +++ b/stock_mts_mto_rule/README.rst @@ -42,7 +42,7 @@ You should not select both the mts+mto route and the mto route. .. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas :alt: Try me on Runbot - :target: https://runbot.odoo-community.org/runbot/153/8.0 + :target: https://runbot.odoo-community.org/runbot/153/9.0 Configuration ============= @@ -64,11 +64,7 @@ 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 -`_. +help us smashing it by providing a detailed and welcomed feedback. Credits ======= From 30ce9929a637aba9a10c4064159327c1a7132df1 Mon Sep 17 00:00:00 2001 From: Sylvain GARANCHER Date: Mon, 17 Oct 2016 12:42:22 +0200 Subject: [PATCH 11/11] [IMP] stock_mts_mto_rule : Added some unit tests --- .../tests/test_mto_mts_route.py | 78 +++++++++++++++++++ 1 file changed, 78 insertions(+) diff --git a/stock_mts_mto_rule/tests/test_mto_mts_route.py b/stock_mts_mto_rule/tests/test_mto_mts_route.py index 838c3a0c3..f603b74c3 100644 --- a/stock_mts_mto_rule/tests/test_mto_mts_route.py +++ b/stock_mts_mto_rule/tests/test_mto_mts_route.py @@ -13,6 +13,8 @@ # # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . + +from openerp import exceptions from openerp.tests.common import TransactionCase from datetime import datetime @@ -68,6 +70,26 @@ class TestMtoMtsRoute(TransactionCase): self.assertEqual(2, len(moves)) self.assertEqual(1.0, moves[0].product_uom_qty) + def test_mts_mto_route_split_done(self): + mto_mts_route = self.env.ref('stock_mts_mto_rule.route_mto_mts') + self.product.route_ids = [(6, 0, [mto_mts_route.id])] + self.quant.qty = 1.0 + self._procurement_create() + self.assertEqual(self.procurement.state, 'running') + self.procurement.mts_mto_procurement_ids.mapped( + 'move_ids').action_done() + self.assertEqual(self.procurement.state, 'done') + + def test_mts_mto_route_split_cancel(self): + mto_mts_route = self.env.ref('stock_mts_mto_rule.route_mto_mts') + self.product.route_ids = [(6, 0, [mto_mts_route.id])] + self.quant.qty = 1.0 + self._procurement_create() + self.procurement.mts_mto_procurement_ids.cancel() + self.assertEqual(self.procurement.state, 'running') + self.procurement.check() + self.assertEqual(self.procurement.state, 'cancel') + def test_mts_mto_route_mts_only(self): mto_mts_route = self.env.ref('stock_mts_mto_rule.route_mto_mts') self.product.route_ids = [(6, 0, [mto_mts_route.id])] @@ -92,6 +114,62 @@ class TestMtoMtsRoute(TransactionCase): self.assertEqual('make_to_stock', moves[0].procure_method) + def test_mts_mto_route_mto_removed(self): + self.env.ref('stock_mts_mto_rule.route_mto_mts').unlink() + self.warehouse.mts_mto_rule_id = False + with self.assertRaises(exceptions.Warning): + self.warehouse.mto_mts_management = True + + def test_mts_mto_route_mts_removed(self): + self.warehouse.mto_mts_management = True + self.env['procurement.rule'].search([ + ('location_src_id', '=', self.warehouse.lot_stock_id.id), + ('route_id', '=', self.warehouse.delivery_route_id.id), + ]).unlink() + self.warehouse.mts_mto_rule_id = False + with self.assertRaises(exceptions.Warning): + self.warehouse.mto_mts_management = True + + def test_mts_mto_route_mto_no_mts_rule(self): + self.warehouse.mts_mto_rule_id = False + self.warehouse.mto_pull_id = False + with self.assertRaises(exceptions.Warning): + self.warehouse.mto_mts_management = True + + def test_create_routes(self): + rule_obj = self.env['procurement.rule'] + created_routes = self.warehouse.create_routes(self.warehouse) + mts_mto_route = rule_obj.browse(created_routes['mts_mto_rule_id']) + self.assertEqual(mts_mto_route.warehouse_id, self.warehouse) + self.assertEqual( + mts_mto_route.location_id, self.warehouse.mto_pull_id.location_id) + self.assertEqual( + mts_mto_route.picking_type_id, + self.warehouse.mto_pull_id.picking_type_id) + self.assertEqual( + mts_mto_route.route_id, + self.env.ref('stock_mts_mto_rule.route_mto_mts')) + + def test_remove_mts_mto_management(self): + warehouse_rule = self.warehouse.mts_mto_rule_id + self.assertTrue(self.warehouse.mts_mto_rule_id) + self.warehouse.mto_mts_management = False + self.assertFalse(warehouse_rule.exists()) + self.assertFalse(self.warehouse.mts_mto_rule_id) + + def test_get_all_routes_for_wh(self): + routes = self.warehouse.get_all_routes_for_wh(self.warehouse) + self.assertTrue(self.warehouse.mts_mto_rule_id) + self.assertTrue(self.warehouse.mts_mto_rule_id.route_id.id in routes) + + def test_rename_warehouse(self): + rule_name = self.warehouse.mts_mto_rule_id.name + new_warehouse_name = 'NewName' + new_rule_name = rule_name.replace( + self.warehouse.name, new_warehouse_name, 1) + self.warehouse.name = new_warehouse_name + self.assertEqual(new_rule_name, self.warehouse.mts_mto_rule_id.name) + def setUp(self): super(TestMtoMtsRoute, self).setUp() self.warehouse = self.env.ref('stock.warehouse0')