33
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', 'done'])])
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 !'''}})
36
53
def default_get(self, cr, uid, fields, context=None):
38
55
Display the default value for delivery process
40
setup_obj = self.pool.get('unifield.setup.configuration')
57
setup_id = self.pool.get('unifield.setup.configuration').get_config(cr, uid)
42
58
res = super(delivery_process_setup, self).default_get(cr, uid, fields, context=context)
44
setup_ids = setup_obj.search(cr, uid, [], context=context)
46
setup_ids = [setup_obj.create(cr, uid, {}, context=context)]
48
setup_id = setup_obj.browse(cr, uid, setup_ids[0], context=context)
50
59
res['delivery_process'] = setup_id.delivery_process
63
def change_wh_board(self, cr, uid, type='simple', context=None):
65
Update the WH dashboard according to Delivery process choice
67
module_obj = self.pool.get('ir.module.module')
68
data_obj = self.pool.get('ir.model.data')
70
# In simple configuration, only display OUT on WH dashboard
71
module_name = 'useability_dashboard_and_menu'
72
view_xml_id = 'board_warehouse_form_default'
75
view_xml_id = 'board_warehouse_form_default_only_out'
77
module_ok = module_obj.search(cr, uid, [('name', '=', module_name), ('state', '=', 'installed')], context=context)
80
wh_action_id = data_obj.get_object_reference(cr, uid, module_name, 'open_board_warehouse_unifield')[1]
81
wh_view_id = data_obj.get_object_reference(cr, uid, module_name, view_xml_id)[1]
83
self.pool.get('ir.actions.act_window').write(cr, uid, [wh_action_id], {'view_id': wh_view_id}, context=context)
55
89
def execute(self, cr, uid, ids, context=None):
57
91
Fill the delivery process field in company
62
96
setup_obj = self.pool.get('unifield.setup.configuration')
63
97
data_obj = self.pool.get('ir.model.data')
65
setup_ids = setup_obj.search(cr, uid, [], context=context)
67
setup_ids = [setup_obj.create(cr, uid, {}, context=context)]
99
setup_id = setup_obj.get_config(cr, uid)
101
# Get all menu ids concerned by this modification
69
102
picking_menu_id = data_obj.get_object_reference(cr, uid, 'msf_outgoing', 'menu_action_picking_ticket')[1]
70
103
pre_packing_menu_id = data_obj.get_object_reference(cr, uid, 'msf_outgoing', 'menu_action_ppl')[1]
71
104
pack_menu_id = data_obj.get_object_reference(cr, uid, 'msf_outgoing', 'menu_action_pack_type_tree')[1]
72
105
packing_menu_id = data_obj.get_object_reference(cr, uid, 'msf_outgoing', 'menu_action_shipment')[1]
106
# preparation_menu_id = data_obj.get_object_reference(cr, uid, 'msf_outgoing', 'menu_action_pt_ppl')[1]
74
menu_ids = [picking_menu_id, pre_packing_menu_id, pack_menu_id, packing_menu_id]
108
menu_ids = [picking_menu_id,
111
# preparation_menu_id,
76
114
if payload.delivery_process == 'simple':
115
if self._check_not_done_picking(cr, uid):
116
raise osv.except_osv(_('Error'), _('''You have some Picking Tickets, Packing Lists or Shipments not done or cancelled.
117
So, you cannot choose 'Simple OUT' as Delivery process while these documents are not done/cancelled !'''))
118
# In simple configuration, remove the menu entries
77
119
self.pool.get('ir.ui.menu').write(cr, uid, menu_ids, {'active': False}, context=context)
121
# In complex configuration, added the menu entries
79
122
self.pool.get('ir.ui.menu').write(cr, uid, menu_ids, {'active': True}, context=context)
124
# Update the WH dashboard view
125
self.change_wh_board(cr, uid, type=payload.delivery_process, context=context)
81
setup_obj.write(cr, uid, setup_ids, {'delivery_process': payload.delivery_process}, context=context)
127
setup_obj.write(cr, uid, [setup_id.id], {'delivery_process': payload.delivery_process}, context=context)
84
130
delivery_process_setup()