diff --git a/stock_mts_mto_rule/README.rst b/stock_mts_mto_rule/README.rst index c17580cff..7ff843b93 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/10.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 ======= diff --git a/stock_mts_mto_rule/__manifest__.py b/stock_mts_mto_rule/__manifest__.py index 67640dd6b..ecccd1339 100644 --- a/stock_mts_mto_rule/__manifest__.py +++ b/stock_mts_mto_rule/__manifest__.py @@ -1,27 +1,8 @@ # -*- coding: utf-8 -*- - -############################################################################## -# -# OpenERP, Open Source Management Solution -# Copyright (C) 2015 Akretion (). -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . -# -############################################################################## +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). {'name': 'Stock MTS+MTO Rule', - 'version': '9.0.1.0.0', + 'version': '10.0.1.0.0', 'author': 'Akretion,Odoo Community Association (OCA)', 'website': 'http://www.akretion.com', 'license': 'AGPL-3', diff --git a/stock_mts_mto_rule/data/stock_data.xml b/stock_mts_mto_rule/data/stock_data.xml index 8297d5a83..7b7dfb257 100644 --- a/stock_mts_mto_rule/data/stock_data.xml +++ b/stock_mts_mto_rule/data/stock_data.xml @@ -1,17 +1,14 @@ - - + - - - - Make To Order + Make To Stock - 5 - - + + + Make To Order + Make To Stock + 5 + + - - + diff --git a/stock_mts_mto_rule/model/procurement.py b/stock_mts_mto_rule/model/procurement.py index 14d66b2cf..6e70c23ff 100644 --- a/stock_mts_mto_rule/model/procurement.py +++ b/stock_mts_mto_rule/model/procurement.py @@ -1,25 +1,7 @@ # -*- coding: utf-8 -*- -############################################################################### -# -# Module for OpenERP -# Copyright (C) 2015 Akretion (http://www.akretion.com). All Rights Reserved -# @author Florian DA COSTA -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . -# -############################################################################### -from openerp import api, fields, models +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import api, fields, models class ProcurementOrder(models.Model): @@ -37,13 +19,12 @@ class ProcurementOrder(models.Model): @api.multi def get_mto_qty_to_order(self): self.ensure_one() - uom_obj = self.env['product.uom'] stock_location = self.warehouse_id.lot_stock_id.id proc_warehouse = self.with_context(location=stock_location) virtual_available = proc_warehouse.product_id.virtual_available - qty_available = uom_obj._compute_qty(self.product_id.uom_id.id, - virtual_available, - self.product_uom.id) + qty_available = self.product_id.uom_id._compute_quantity( + virtual_available, self.product_uom) + if qty_available > 0: if qty_available >= self.product_qty: return 0.0 @@ -51,16 +32,17 @@ class ProcurementOrder(models.Model): return self.product_qty - qty_available return self.product_qty - @api.model - 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 "/") + @api.multi + def _get_mts_mto_procurement(self, rule, qty): + self.ensure_one() + origin = (self.group_id and (self.group_id.name + ":") or "") + \ + (self.rule_id and self.rule_id.name or self.origin or "/") return { - 'name': proc.name, + 'name': self.name, 'origin': origin, 'product_qty': qty, 'rule_id': rule.id, - 'mts_mto_procurement_id': proc.id, + 'mts_mto_procurement_id': self.id, } @api.model @@ -87,34 +69,34 @@ class ProcurementOrder(models.Model): autocommit=autocommit) return res - @api.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) - needed_qty = procurement.get_mto_qty_to_order() - rule = procurement.rule_id + @api.multi + def _run(self): + self.ensure_one() + if self.rule_id and self.rule_id.action == 'split_procurement': + if self.mts_mto_procurement_ids: + return super(ProcurementOrder, self)._run() + needed_qty = self.get_mto_qty_to_order() + rule = self.rule_id if needed_qty == 0.0: mts_vals = self._get_mts_mto_procurement( - procurement, rule.mts_rule_id, procurement.product_qty) - mts_proc = procurement.copy(mts_vals) + rule.mts_rule_id, self.product_qty) + mts_proc = self.copy(mts_vals) mts_proc.run() - elif needed_qty == procurement.product_qty: + elif needed_qty == self.product_qty: mto_vals = self._get_mts_mto_procurement( - procurement, rule.mto_rule_id, procurement.product_qty) - mto_proc = procurement.copy(mto_vals) + rule.mto_rule_id, self.product_qty) + mto_proc = self.copy(mto_vals) mto_proc.run() else: - mts_qty = procurement.product_qty - needed_qty + mts_qty = self.product_qty - needed_qty mts_vals = self._get_mts_mto_procurement( - procurement, rule.mts_rule_id, mts_qty) - mts_proc = procurement.copy(mts_vals) + rule.mts_rule_id, mts_qty) + mts_proc = self.copy(mts_vals) mts_proc.run() mto_vals = self._get_mts_mto_procurement( - procurement, rule.mto_rule_id, needed_qty) - mto_proc = procurement.copy(mto_vals) + rule.mto_rule_id, needed_qty) + mto_proc = self.copy(mto_vals) mto_proc.run() - return super(ProcurementOrder, self)._run(procurement) + return super(ProcurementOrder, self)._run() diff --git a/stock_mts_mto_rule/model/rule.py b/stock_mts_mto_rule/model/rule.py index 481ffedce..38c22b4c4 100644 --- a/stock_mts_mto_rule/model/rule.py +++ b/stock_mts_mto_rule/model/rule.py @@ -1,26 +1,8 @@ # -*- coding: utf-8 -*- -############################################################################### -# -# Module for OpenERP -# Copyright (C) 2015 Akretion (http://www.akretion.com). All Rights Reserved -# @author Florian DA COSTA -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . -# -############################################################################### -from openerp import models, api, fields -from openerp.tools.translate import _ +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import models, api, fields +from odoo.tools.translate import _ class ProcurementRule(models.Model): diff --git a/stock_mts_mto_rule/model/warehouse.py b/stock_mts_mto_rule/model/warehouse.py index 0c10b17aa..cbb62ab7d 100644 --- a/stock_mts_mto_rule/model/warehouse.py +++ b/stock_mts_mto_rule/model/warehouse.py @@ -1,26 +1,8 @@ # -*- coding: utf-8 -*- -############################################################################### -# -# Module for OpenERP -# Copyright (C) 2015 Akretion (http://www.akretion.com). All Rights Reserved -# @author Florian DA COSTA -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . -# -############################################################################### -from openerp import models, api, fields, exceptions -from openerp.tools.translate import _ +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import models, api, fields, exceptions +from odoo.tools.translate import _ class Warehouse(models.Model): @@ -60,7 +42,7 @@ class Warehouse(models.Model): raise exceptions.Warning(_( 'Can\'t find MTS Rule on the warehouse')) return { - 'name': self._format_routename(warehouse, _('MTS+MTO')), + 'name': warehouse._format_routename(route_type='mts_mto'), 'route_id': mts_mto_route.id, 'action': 'split_procurement', 'mto_rule_id': warehouse.mto_pull_id.id, @@ -116,8 +98,7 @@ class Warehouse(models.Model): warehouse.mts_mto_rule_id.unlink() 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) + self.with_context({'active_test': False})._update_routes() return res @api.model @@ -141,21 +122,24 @@ class Warehouse(models.Model): ) return res - @api.multi - def change_route(self, warehouse, new_reception_step=False, - new_delivery_step=False): - res = super(Warehouse, self).change_route( - warehouse, - new_reception_step=new_reception_step, - new_delivery_step=new_delivery_step) + def _get_route_name(self, route_type): + names = {'mts_mto': _('MTS+MTO')} + if route_type in names: + return names[route_type] - mts_mto_rule_id = warehouse.mts_mto_rule_id - if new_delivery_step and mts_mto_rule_id: + return super(Warehouse, self)._get_route_name(route_type) + + @api.multi + def _update_routes(self): + res = super(Warehouse, self)._update_routes() + + mts_mto_rule_id = self.mts_mto_rule_id + if self.delivery_steps and mts_mto_rule_id: pull_model = self.env['procurement.rule'] - warehouse.mts_mto_rule_id.location_id = ( - warehouse.mto_pull_id.location_id) - mts_rules = pull_model.search( - [('location_src_id', '=', warehouse.lot_stock_id.id), - ('route_id', '=', warehouse.delivery_route_id.id)]) - warehouse.mts_mto_rule_id.mts_rule_id = mts_rules[0].id + self.mts_mto_rule_id.location_id = self.mto_pull_id.location_id + mts_rules = pull_model.search([ + ('location_src_id', '=', self.lot_stock_id.id), + ('route_id', '=', self.delivery_route_id.id), + ]) + self.mts_mto_rule_id.mts_rule_id = mts_rules[0].id return res 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..c9d8e6563 100644 --- a/stock_mts_mto_rule/tests/test_mto_mts_route.py +++ b/stock_mts_mto_rule/tests/test_mto_mts_route.py @@ -1,19 +1,7 @@ -# Author: Florian da Costa -# Copyright 2015 Akretion -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . -from openerp.tests.common import TransactionCase +# -*- coding: utf-8 -*- +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo.tests.common import TransactionCase from datetime import datetime diff --git a/stock_mts_mto_rule/view/pull_rule.xml b/stock_mts_mto_rule/view/pull_rule.xml index e21a59ff8..9504f205a 100644 --- a/stock_mts_mto_rule/view/pull_rule.xml +++ b/stock_mts_mto_rule/view/pull_rule.xml @@ -1,21 +1,20 @@ - - - - procurement.rule.mts.mto - procurement.rule - - - - - - - - + - - + + procurement.rule.mts.mto + procurement.rule + + + + + + + + + + diff --git a/stock_mts_mto_rule/view/warehouse.xml b/stock_mts_mto_rule/view/warehouse.xml index 5dc891581..a0368b30c 100644 --- a/stock_mts_mto_rule/view/warehouse.xml +++ b/stock_mts_mto_rule/view/warehouse.xml @@ -1,17 +1,15 @@ - - + - view_warehouse_inherited - stock.warehouse - - - - - - + view_warehouse_inherited + stock.warehouse + + + + + + - - +