From 529b585d073433f0c0b3ce1f4eee04fe06aff689 Mon Sep 17 00:00:00 2001 From: Alexis de Lattre Date: Wed, 8 Jan 2014 23:30:47 +0100 Subject: [PATCH] Add module sale_auto_order_policy. --- sale_auto_order_policy/__init__.py | 23 ++++++++++++++ sale_auto_order_policy/__openerp__.py | 45 +++++++++++++++++++++++++++ sale_auto_order_policy/sale.py | 43 +++++++++++++++++++++++++ 3 files changed, 111 insertions(+) create mode 100644 sale_auto_order_policy/__init__.py create mode 100644 sale_auto_order_policy/__openerp__.py create mode 100644 sale_auto_order_policy/sale.py diff --git a/sale_auto_order_policy/__init__.py b/sale_auto_order_policy/__init__.py new file mode 100644 index 0000000..165a7d6 --- /dev/null +++ b/sale_auto_order_policy/__init__.py @@ -0,0 +1,23 @@ +# -*- encoding: utf-8 -*- +############################################################################## +# +# Sale Auto Order Policy module for OpenERP +# Copyright (C) 2013 Akretion (http://www.akretion.com) +# @author Alexis de Lattre +# +# 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 . import sale diff --git a/sale_auto_order_policy/__openerp__.py b/sale_auto_order_policy/__openerp__.py new file mode 100644 index 0000000..a7808bc --- /dev/null +++ b/sale_auto_order_policy/__openerp__.py @@ -0,0 +1,45 @@ +# -*- encoding: utf-8 -*- +############################################################################## +# +# Sale Auto Order Policy module for OpenERP +# Copyright (C) 2013 Akretion (http://www.akretion.com) +# @author Alexis de Lattre +# +# 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 . +# +############################################################################## + + +{ + 'name': 'Sale Auto Order Policy', + 'version': '0.1', + 'category': 'Sales Management', + 'license': 'AGPL-3', + 'summary': "Order Policy = 'On Delivery Order' by default, switches to 'On Demand' when service-only", + 'description': """ +Sale Auto Order Policy +====================== + +With this module, the Order Policy on Quotations is set to 'On Delivery Order' by default. If the Quotation only contains service lines, the Order Policy is switched to 'On Demand' when the Quotation is confirmed. + +Please contact Alexis de Lattre from Akretion for any help or question about this module. + """, + 'author': 'Akretion', + 'website': 'http://www.akretion.com', + 'depends': ['sale', 'stock'], + 'data': [], + 'images': [], + 'installable': True, + 'active': False, +} diff --git a/sale_auto_order_policy/sale.py b/sale_auto_order_policy/sale.py new file mode 100644 index 0000000..dff6571 --- /dev/null +++ b/sale_auto_order_policy/sale.py @@ -0,0 +1,43 @@ +# -*- encoding: utf-8 -*- +############################################################################## +# +# Sale Auto Order Policy module for OpenERP +# Copyright (C) 2013 Akretion (http://www.akretion.com) +# @author Alexis de Lattre +# +# 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.osv import orm + + +class sale_order(orm.Model): + _inherit = 'sale.order' + + _defaults = { + 'order_policy': 'picking', + } + + def action_button_confirm(self, cr, uid, ids, context=None): + assert len(ids) == 1, 'Only one ID' + so = self.browse(cr, uid, ids[0], context=context) + service_only = True + for line in so.order_line: + if line.product_id and line.product_id.type != 'service': + service_only = False + if service_only: + so.write({'order_policy': 'manual'}) + return super(sale_order, self).action_button_confirm( + cr, uid, ids, context=context)