~unifield-team/unifield-wm/wm-2418-rw-fix

« back to all changes in this revision

Viewing changes to unifield_setup/installer/delivery_process.py

  • Committer: pierre-marie
  • Date: 2012-07-25 14:13:53 UTC
  • mfrom: (1038 unifield-wm)
  • mto: This revision was merged to the branch mainline in revision 1060.
  • Revision ID: pierre-marie@pierre-marie-laptop-20120725141353-9iwjdr1kltbei90e
Merge

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- coding: utf-8 -*-
 
2
##############################################################################
 
3
#
 
4
#    OpenERP, Open Source Management Solution
 
5
#    Copyright (C) 2011 TeMPO Consulting, MSF
 
6
#
 
7
#    This program is free software: you can redistribute it and/or modify
 
8
#    it under the terms of the GNU Affero General Public License as
 
9
#    published by the Free Software Foundation, either version 3 of the
 
10
#    License, or (at your option) any later version.
 
11
#
 
12
#    This program is distributed in the hope that it will be useful,
 
13
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
15
#    GNU Affero General Public License for more details.
 
16
#
 
17
#    You should have received a copy of the GNU Affero General Public License
 
18
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
19
 
20
##############################################################################
 
21
 
 
22
from osv import osv
 
23
from osv import fields
 
24
 
 
25
from tools.translate import _
 
26
 
 
27
 
 
28
class delivery_process_setup(osv.osv_memory):
 
29
    _name = 'delivery.process.setup'
 
30
    _inherit = 'res.config'
 
31
    
 
32
    _columns = {
 
33
        'delivery_process': fields.selection([('simple', 'Simple OUT'), ('complex', 'PICK/PACK/SHIP')], string='Delivery process', required=True),
 
34
    }
 
35
    
 
36
    def _check_not_done_picking(self, cr, uid):
 
37
        shipment_ids = self.pool.get('shipment').search(cr, uid, [('state', 'not in', ['delivered', 'cancel'])])
 
38
        picking_ids = self.pool.get('stock.picking').search(cr, uid, [('subtype', '!=', 'standard'), ('state', 'not in', ['cancel', 'done'])])
 
39
        
 
40
        return (picking_ids or shipment_ids) and True or False
 
41
    
 
42
    def delivery_process_on_change(self, cr, uid, ids, process, context=None):
 
43
        res = {}
 
44
        
 
45
        if process == 'simple':
 
46
            if self._check_not_done_picking(cr, uid):
 
47
                res.update({'warning': {'title': 'Warning',
 
48
                                        'message': '''You have some Picking Tickets, Packing Lists or Shipments not done or cancelled. 
 
49
So, you cannot choose 'Simple OUT' as Delivery process while these documents are not done/cancelled !'''}})
 
50
        
 
51
        return res
 
52
    
 
53
    def default_get(self, cr, uid, fields, context=None):
 
54
        '''
 
55
        Display the default value for delivery process
 
56
        '''
 
57
        setup_id = self.pool.get('unifield.setup.configuration').get_config(cr, uid)
 
58
        res = super(delivery_process_setup, self).default_get(cr, uid, fields, context=context)
 
59
        res['delivery_process'] = setup_id.delivery_process
 
60
        
 
61
        return res
 
62
        
 
63
    
 
64
    def execute(self, cr, uid, ids, context=None):
 
65
        '''
 
66
        Fill the delivery process field in company
 
67
        '''
 
68
        assert len(ids) == 1, "We should only get one object from the form"
 
69
        payload = self.browse(cr, uid, ids[0], context=context)
 
70
        
 
71
        setup_obj = self.pool.get('unifield.setup.configuration')
 
72
        data_obj = self.pool.get('ir.model.data')
 
73
        
 
74
        setup_id = setup_obj.get_config(cr, uid)
 
75
            
 
76
        # Get all menu ids concerned by this modification
 
77
        picking_menu_id = data_obj.get_object_reference(cr, uid, 'msf_outgoing', 'menu_action_picking_ticket')[1]
 
78
        pre_packing_menu_id = data_obj.get_object_reference(cr, uid, 'msf_outgoing', 'menu_action_ppl')[1]
 
79
        pack_menu_id = data_obj.get_object_reference(cr, uid, 'msf_outgoing', 'menu_action_pack_type_tree')[1]
 
80
        packing_menu_id = data_obj.get_object_reference(cr, uid, 'msf_outgoing', 'menu_action_shipment')[1]
 
81
        
 
82
        menu_ids = [picking_menu_id, 
 
83
                    pre_packing_menu_id, 
 
84
                    pack_menu_id, 
 
85
                    packing_menu_id]
 
86
            
 
87
        if payload.delivery_process == 'simple':
 
88
            if self._check_not_done_picking(cr, uid):
 
89
                raise osv.except_osv(_('Error'), _('''You have some Picking Tickets, Packing Lists or Shipments not done or cancelled. 
 
90
So, you cannot choose 'Simple OUT' as Delivery process while these documents are not done/cancelled !'''))
 
91
            # In simple configuration, remove the menu entries
 
92
            self.pool.get('ir.ui.menu').write(cr, uid, menu_ids, {'active': False}, context=context)
 
93
        else:
 
94
            # In complex configuration, added the menu entries
 
95
            self.pool.get('ir.ui.menu').write(cr, uid, menu_ids, {'active': True}, context=context)
 
96
    
 
97
        setup_obj.write(cr, uid, [setup_id.id], {'delivery_process': payload.delivery_process}, context=context)
 
98
 
 
99
        
 
100
delivery_process_setup()
 
101
 
 
102
 
 
103
class ir_ui_menu(osv.osv):
 
104
    _name = 'ir.ui.menu'
 
105
    _inherit = 'ir.ui.menu'
 
106
    
 
107
    _columns = {
 
108
        'active': fields.boolean(string='Active'),
 
109
    }
 
110
    
 
111
    _defaults = {
 
112
        'active': lambda *a: True,
 
113
    }
 
114
    
 
115
ir_ui_menu() 
 
 
b'\\ No newline at end of file'