1
# -*- coding: utf-8 -*-
2
##############################################################################
4
# OpenERP, Open Source Management Solution
5
# Copyright (C) 2011 TeMPO Consulting, MSF
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.
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.
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/>.
20
##############################################################################
23
from osv import fields
25
from tools.translate import _
28
class delivery_process_setup(osv.osv_memory):
29
_name = 'delivery.process.setup'
30
_inherit = 'res.config'
33
'delivery_process': fields.selection([('simple', 'Simple OUT'), ('complex', 'PICK/PACK/SHIP')], string='Delivery process', required=True),
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'])])
40
return (picking_ids or shipment_ids) and True or False
42
def delivery_process_on_change(self, cr, uid, ids, process, context=None):
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 !'''}})
53
def default_get(self, cr, uid, fields, context=None):
55
Display the default value for delivery process
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
64
def execute(self, cr, uid, ids, context=None):
66
Fill the delivery process field in company
68
assert len(ids) == 1, "We should only get one object from the form"
69
payload = self.browse(cr, uid, ids[0], context=context)
71
setup_obj = self.pool.get('unifield.setup.configuration')
72
data_obj = self.pool.get('ir.model.data')
74
setup_id = setup_obj.get_config(cr, uid)
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]
82
menu_ids = [picking_menu_id,
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)
94
# In complex configuration, added the menu entries
95
self.pool.get('ir.ui.menu').write(cr, uid, menu_ids, {'active': True}, context=context)
97
setup_obj.write(cr, uid, [setup_id.id], {'delivery_process': payload.delivery_process}, context=context)
100
delivery_process_setup()
103
class ir_ui_menu(osv.osv):
105
_inherit = 'ir.ui.menu'
108
'active': fields.boolean(string='Active'),
112
'active': lambda *a: True,
b'\\ No newline at end of file'