~sebastien.beau/openerp-connector/e-commerce-addons-sale-exception-refactor

« back to all changes in this revision

Viewing changes to exception_rule/wizard/exception_confirm.py

  • Committer: Sébastien Beau
  • Date: 2013-09-02 22:12:00 UTC
  • Revision ID: sebastien.beau@akretion.com-20130902221200-56marmspbfdlla29
[REF] extract exception_rule from sale exception, maybe we should move this module in an other branch

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- coding: utf-8 -*-
 
2
###############################################################################
 
3
#
 
4
#   exception_rule for OpenERP 
 
5
#   Copyright (C) 2013 Akretion (http://www.akretion.com).
 
6
#   @author Sébastien BEAU <sebastien.beau@akretion.com>
 
7
#   Copyright Camptocamp SA
 
8
#   @author: Guewen Baconnier
 
9
#
 
10
#   This program is free software: you can redistribute it and/or modify
 
11
#   it under the terms of the GNU Affero General Public License as
 
12
#   published by the Free Software Foundation, either version 3 of the
 
13
#   License, or (at your option) any later version.
 
14
#
 
15
#   This program is distributed in the hope that it will be useful,
 
16
#   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
17
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
18
#   GNU Affero General Public License for more details.
 
19
#
 
20
#   You should have received a copy of the GNU Affero General Public License
 
21
#   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
22
#
 
23
###############################################################################
 
24
 
 
25
import netsvc
 
26
from openerp.osv import fields, orm
 
27
    
 
28
 
 
29
class WizardExceptionConfirm(orm.TransientModel):
 
30
    _name = 'wizard.exception.confirm'
 
31
 
 
32
    _columns = {
 
33
        #'sale_id': fields.many2one('sale.order', 'Sale'),
 
34
        'exception_ids': fields.many2many('exception.rule', string='Exceptions to resolve', readonly=True),
 
35
        'ignore': fields.boolean('Ignore Exceptions'),
 
36
    }
 
37
 
 
38
    def default_get(self, cr, uid, fields, context=None):
 
39
        res = super(WizardExceptionConfirm, self).default_get(cr, uid, fields, context=context)
 
40
        order_obj = self.pool.get('sale.order')
 
41
        sale_id = context.get('active_id', False)
 
42
        if sale_id:
 
43
            sale = order_obj.browse(cr, uid, sale_id, context=context)
 
44
            exception_ids = [e.id for e in sale.exceptions_ids]
 
45
            res.update({'exception_ids': [(6, 0, exception_ids)]})
 
46
        return res
 
47
 
 
48
    def action_confirm(self, cr, uid, ids, context):
 
49
        form = self.browse(cr, uid, ids[0], context=context)
 
50
        if form.ignore:
 
51
            self.pool.get(context['active_model']).write(cr, uid,
 
52
                    context['active_id'],
 
53
                    {'ignore_exceptions': True},
 
54
                    context=context)
 
55
        return {'type': 'ir.actions.act_window_close'}
 
56