From e8df854728906dabb1ce71cbe22f6bf5e15654d3 Mon Sep 17 00:00:00 2001 From: Guewen Baconnier Date: Tue, 13 Aug 2013 21:00:02 +0200 Subject: [PATCH] [MRG] from master branch (../trunk-generic/ rev 29.1.1) --- sale_cancel_reason/__init__.py | 23 +++++++ sale_cancel_reason/__openerp__.py | 50 +++++++++++++++ .../data/sale_order_cancel_reason.xml | 14 ++++ sale_cancel_reason/model/__init__.py | 22 +++++++ sale_cancel_reason/model/sale.py | 44 +++++++++++++ .../security/ir.model.access.csv | 3 + sale_cancel_reason/test/sale_order_cancel.yml | 33 ++++++++++ sale_cancel_reason/view/sale_view.xml | 61 ++++++++++++++++++ sale_cancel_reason/wizard/__init__.py | 22 +++++++ sale_cancel_reason/wizard/cancel_reason.py | 64 +++++++++++++++++++ .../wizard/cancel_reason_view.xml | 39 +++++++++++ 11 files changed, 375 insertions(+) create mode 100644 sale_cancel_reason/__init__.py create mode 100644 sale_cancel_reason/__openerp__.py create mode 100644 sale_cancel_reason/data/sale_order_cancel_reason.xml create mode 100644 sale_cancel_reason/model/__init__.py create mode 100644 sale_cancel_reason/model/sale.py create mode 100644 sale_cancel_reason/security/ir.model.access.csv create mode 100644 sale_cancel_reason/test/sale_order_cancel.yml create mode 100644 sale_cancel_reason/view/sale_view.xml create mode 100644 sale_cancel_reason/wizard/__init__.py create mode 100644 sale_cancel_reason/wizard/cancel_reason.py create mode 100644 sale_cancel_reason/wizard/cancel_reason_view.xml diff --git a/sale_cancel_reason/__init__.py b/sale_cancel_reason/__init__.py new file mode 100644 index 00000000000..a75b125293b --- /dev/null +++ b/sale_cancel_reason/__init__.py @@ -0,0 +1,23 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# Author: Guewen Baconnier +# Copyright 2013 Camptocamp SA +# +# 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 wizard +from . import model diff --git a/sale_cancel_reason/__openerp__.py b/sale_cancel_reason/__openerp__.py new file mode 100644 index 00000000000..0189bd2afac --- /dev/null +++ b/sale_cancel_reason/__openerp__.py @@ -0,0 +1,50 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# Author: Guewen Baconnier +# Copyright 2013 Camptocamp SA +# +# 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 Cancel Reason', + 'version': '1.0', + 'author': 'Camptocamp', + 'category': 'Sale', + 'license': 'AGPL-3', + 'complexity': 'normal', + 'images': [], + 'website': "http://www.camptocamp.com", + 'description': """ +Sale Cancel Reason +================== + +When a sale order is canceled, a reason must be given, +it is choosed from a configured list. + +""", + 'depends': ['sale', + ], + 'demo': [], + 'data': ['wizard/cancel_reason_view.xml', + 'view/sale_view.xml', + 'security/ir.model.access.csv', + 'data/sale_order_cancel_reason.xml', + ], + 'auto_install': False, + 'test': ['test/sale_order_cancel.yml', + ], + 'installable': True, + } diff --git a/sale_cancel_reason/data/sale_order_cancel_reason.xml b/sale_cancel_reason/data/sale_order_cancel_reason.xml new file mode 100644 index 00000000000..c8eeb6f6b0f --- /dev/null +++ b/sale_cancel_reason/data/sale_order_cancel_reason.xml @@ -0,0 +1,14 @@ + + + + + Just for Quotation + + + No service needed anymore + + + Other Service Provider selected + + + diff --git a/sale_cancel_reason/model/__init__.py b/sale_cancel_reason/model/__init__.py new file mode 100644 index 00000000000..d65199e72a4 --- /dev/null +++ b/sale_cancel_reason/model/__init__.py @@ -0,0 +1,22 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# Author: Guewen Baconnier +# Copyright 2013 Camptocamp SA +# +# 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_cancel_reason/model/sale.py b/sale_cancel_reason/model/sale.py new file mode 100644 index 00000000000..c5b9b01eb96 --- /dev/null +++ b/sale_cancel_reason/model/sale.py @@ -0,0 +1,44 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# Author: Guewen Baconnier +# Copyright 2013 Camptocamp SA +# +# 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, fields +from openerp.tools.translate import _ + + +class sale_order(orm.Model): + _inherit = 'sale.order' + + _columns = { + 'cancel_reason_id': fields.many2one( + 'sale.order.cancel.reason', + string="Reason for cancellation", + readonly=True, + ondelete="restrict" + ), + } + + +class sale_order_cancel_reason(orm.Model): + _name = 'sale.order.cancel.reason' + _description = 'Sale Order Cancel Reason' + _columns = { + 'name': fields.char('Reason', required=True, translate=True), + } diff --git a/sale_cancel_reason/security/ir.model.access.csv b/sale_cancel_reason/security/ir.model.access.csv new file mode 100644 index 00000000000..032043ac33a --- /dev/null +++ b/sale_cancel_reason/security/ir.model.access.csv @@ -0,0 +1,3 @@ +id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink +access_sale_order_cancel_reason_user,access_sale_order_cancel_reason user,model_sale_order_cancel_reason,base.group_sale_salesman,1,0,0,0 +access_sale_order_cancel_reason_manager,access_sale_order_cancel_reason manager,model_sale_order_cancel_reason,base.group_sale_manager,1,1,1,1 diff --git a/sale_cancel_reason/test/sale_order_cancel.yml b/sale_cancel_reason/test/sale_order_cancel.yml new file mode 100644 index 00000000000..bd84000755e --- /dev/null +++ b/sale_cancel_reason/test/sale_order_cancel.yml @@ -0,0 +1,33 @@ +- + In order to test the choice of a cancel reason when canceling a sale order + I create a new cancel reason +- + !record {model: sale.order.cancel.reason, id: cancel_reason_test}: + name: Canceled for tests +- + Given I create a sale order +- + !record {model: sale.order, id: sale_order_cancel_01}: + partner_id: base.res_partner_2 + order_line: + - product_id: product.product_product_7 + product_uom_qty: 8 +- + When I cancel it with the wizard asking for the reason +- + !python {model: sale.order.cancel}: | + context = {'active_model': 'sale.order', + 'active_ids': [ref('sale_order_cancel_01')], + } + reason_id = ref('cancel_reason_test') + wizard_id = self.create(cr, uid, + {'reason_id': reason_id}, + context=context) + self.confirm_cancel(cr, uid, wizard_id, context=context) +- + Then the sale order should be canceled + and the reason stored +- + !assert {model: sale.order, id: sale_order_cancel_01, string: the sale order should be canceled}: + - state == 'cancel' + - cancel_reason_id.id == ref('cancel_reason_test') diff --git a/sale_cancel_reason/view/sale_view.xml b/sale_cancel_reason/view/sale_view.xml new file mode 100644 index 00000000000..664477999a8 --- /dev/null +++ b/sale_cancel_reason/view/sale_view.xml @@ -0,0 +1,61 @@ + + + + + sale.order.form + sale.order + + + + action + %(action_sale_order_cancel)d + + + action + %(action_sale_order_cancel)d + + +

+

+
+
+
+ + + Sale Order Cancel Reason + sale.order.cancel.reason + +
+ + +
+
+ + + Sale Order Cancel Reason + sale.order.cancel.reason + + + + + + + + + Sale Order Cancel Reason + sale.order.cancel.reason + form + tree,form + + + +
+
diff --git a/sale_cancel_reason/wizard/__init__.py b/sale_cancel_reason/wizard/__init__.py new file mode 100644 index 00000000000..5d55d1468a2 --- /dev/null +++ b/sale_cancel_reason/wizard/__init__.py @@ -0,0 +1,22 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# Author: Guewen Baconnier +# Copyright 2013 Camptocamp SA +# +# 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 cancel_reason diff --git a/sale_cancel_reason/wizard/cancel_reason.py b/sale_cancel_reason/wizard/cancel_reason.py new file mode 100644 index 00000000000..37a5c7685f0 --- /dev/null +++ b/sale_cancel_reason/wizard/cancel_reason.py @@ -0,0 +1,64 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# Author: Guewen Baconnier +# Copyright 2013 Camptocamp SA +# +# 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, fields +from openerp import netsvc + + +class logistic_requisition_cancel(orm.TransientModel): + """ Ask a reason for the sale order cancellation.""" + _name = 'sale.order.cancel' + _description = __doc__ + + quotation_states = ['draft', 'sent'] + + _columns = { + 'reason_id': fields.many2one('sale.order.cancel.reason', + string='Reason', + required=True), + } + + def confirm_cancel(self, cr, uid, ids, context=None): + if context is None: + context = {} + if isinstance(ids, (list, tuple)): + assert len(ids) == 1, "1 ID expected" + ids = ids[0] + act_close = {'type': 'ir.actions.act_window_close'} + sale_ids = context.get('active_ids') + if sale_ids is None: + return act_close + assert len(sale_ids) == 1, "Only 1 sale ID expected" + form = self.browse(cr, uid, ids, context=context) + sale_obj = self.pool.get('sale.order') + sale_obj.write(cr, uid, sale_ids, + {'cancel_reason_id': form.reason_id.id}, + context=context) + sale = sale_obj.browse(cr, uid, sale_ids[0], context=context) + # in the official addons, they call the signal on quotations + # but directly call action_cancel on sales orders + if sale.state in self.quotation_states: + wf_service = netsvc.LocalService("workflow") + wf_service.trg_validate(uid, 'sale.order', + sale_ids[0], 'cancel', cr) + else: + sale_obj.action_cancel(cr, uid, sale_ids, context=context) + return act_close diff --git a/sale_cancel_reason/wizard/cancel_reason_view.xml b/sale_cancel_reason/wizard/cancel_reason_view.xml new file mode 100644 index 00000000000..2b1d56cbb4e --- /dev/null +++ b/sale_cancel_reason/wizard/cancel_reason_view.xml @@ -0,0 +1,39 @@ + + + + + Reason for the cancellation + sale.order.cancel + +
+

+ Choose the reason for the cancellation of the + sale order. +

+ + + +
+
+
+
+
+ + + Reason for the cancellation + ir.actions.act_window + sale.order.cancel + form + form + + new + +
+
+