[IMP] Make it possible to create sequences in a separate function + change names when some types are not created yet
This commit is contained in:
parent
6b63d40145
commit
0171fba1ce
|
@ -3114,6 +3114,109 @@ class stock_warehouse(osv.osv):
|
||||||
pull_obj.write(cr, uid, warehouse.mto_pull_id.id, mto_pull_vals, context=context)
|
pull_obj.write(cr, uid, warehouse.mto_pull_id.id, mto_pull_vals, context=context)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
def create_sequences_and_picking_types(self, cr, uid, warehouse, context=None):
|
||||||
|
seq_obj = self.pool.get('ir.sequence')
|
||||||
|
picking_type_obj = self.pool.get('stock.picking.type')
|
||||||
|
#create new sequences
|
||||||
|
in_seq_id = seq_obj.create(cr, SUPERUSER_ID, values={'name': warehouse.name + _(' Sequence in'), 'prefix': warehouse.code + '/IN/', 'padding': 5}, context=context)
|
||||||
|
out_seq_id = seq_obj.create(cr, SUPERUSER_ID, values={'name': warehouse.name + _(' Sequence out'), 'prefix': warehouse.code + '/OUT/', 'padding': 5}, context=context)
|
||||||
|
pack_seq_id = seq_obj.create(cr, SUPERUSER_ID, values={'name': warehouse.name + _(' Sequence packing'), 'prefix': warehouse.code + '/PACK/', 'padding': 5}, context=context)
|
||||||
|
pick_seq_id = seq_obj.create(cr, SUPERUSER_ID, values={'name': warehouse.name + _(' Sequence picking'), 'prefix': warehouse.code + '/PICK/', 'padding': 5}, context=context)
|
||||||
|
int_seq_id = seq_obj.create(cr, SUPERUSER_ID, values={'name': warehouse.name + _(' Sequence internal'), 'prefix': warehouse.code + '/INT/', 'padding': 5}, context=context)
|
||||||
|
|
||||||
|
wh_stock_loc = warehouse.lot_stock_id
|
||||||
|
wh_input_stock_loc = warehouse.wh_input_stock_loc_id
|
||||||
|
wh_output_stock_loc = warehouse.wh_output_stock_loc_id
|
||||||
|
wh_pack_stock_loc = warehouse.wh_pack_stock_loc_id
|
||||||
|
|
||||||
|
#fetch customer and supplier locations, for references
|
||||||
|
customer_loc, supplier_loc = self._get_partner_locations(cr, uid, warehouse.id, context=context)
|
||||||
|
|
||||||
|
#create in, out, internal picking types for warehouse
|
||||||
|
input_loc = wh_input_stock_loc
|
||||||
|
if warehouse.reception_steps == 'one_step':
|
||||||
|
input_loc = wh_stock_loc
|
||||||
|
output_loc = wh_output_stock_loc
|
||||||
|
if warehouse.delivery_steps == 'ship_only':
|
||||||
|
output_loc = wh_stock_loc
|
||||||
|
|
||||||
|
#choose the next available color for the picking types of this warehouse
|
||||||
|
color = 0
|
||||||
|
available_colors = [c%9 for c in range(3, 12)] # put flashy colors first
|
||||||
|
all_used_colors = self.pool.get('stock.picking.type').search_read(cr, uid, [('warehouse_id', '!=', False), ('color', '!=', False)], ['color'], order='color')
|
||||||
|
#don't use sets to preserve the list order
|
||||||
|
for x in all_used_colors:
|
||||||
|
if x['color'] in available_colors:
|
||||||
|
available_colors.remove(x['color'])
|
||||||
|
if available_colors:
|
||||||
|
color = available_colors[0]
|
||||||
|
|
||||||
|
#order the picking types with a sequence allowing to have the following suit for each warehouse: reception, internal, pick, pack, ship.
|
||||||
|
max_sequence = self.pool.get('stock.picking.type').search_read(cr, uid, [], ['sequence'], order='sequence desc')
|
||||||
|
max_sequence = max_sequence and max_sequence[0]['sequence'] or 0
|
||||||
|
|
||||||
|
in_type_id = picking_type_obj.create(cr, uid, vals={
|
||||||
|
'name': _('Receptions'),
|
||||||
|
'warehouse_id': warehouse.id,
|
||||||
|
'code': 'incoming',
|
||||||
|
'sequence_id': in_seq_id,
|
||||||
|
'default_location_src_id': supplier_loc.id,
|
||||||
|
'default_location_dest_id': input_loc.id,
|
||||||
|
'sequence': max_sequence + 1,
|
||||||
|
'color': color}, context=context)
|
||||||
|
out_type_id = picking_type_obj.create(cr, uid, vals={
|
||||||
|
'name': _('Delivery Orders'),
|
||||||
|
'warehouse_id': warehouse.id,
|
||||||
|
'code': 'outgoing',
|
||||||
|
'sequence_id': out_seq_id,
|
||||||
|
'return_picking_type_id': in_type_id,
|
||||||
|
'default_location_src_id': output_loc.id,
|
||||||
|
'default_location_dest_id': customer_loc.id,
|
||||||
|
'sequence': max_sequence + 4,
|
||||||
|
'color': color}, context=context)
|
||||||
|
picking_type_obj.write(cr, uid, [in_type_id], {'return_picking_type_id': out_type_id}, context=context)
|
||||||
|
int_type_id = picking_type_obj.create(cr, uid, vals={
|
||||||
|
'name': _('Internal Transfers'),
|
||||||
|
'warehouse_id': warehouse.id,
|
||||||
|
'code': 'internal',
|
||||||
|
'sequence_id': int_seq_id,
|
||||||
|
'default_location_src_id': wh_stock_loc.id,
|
||||||
|
'default_location_dest_id': wh_stock_loc.id,
|
||||||
|
'active': True,
|
||||||
|
'sequence': max_sequence + 2,
|
||||||
|
'color': color}, context=context)
|
||||||
|
pack_type_id = picking_type_obj.create(cr, uid, vals={
|
||||||
|
'name': _('Pack'),
|
||||||
|
'warehouse_id': warehouse.id,
|
||||||
|
'code': 'internal',
|
||||||
|
'sequence_id': pack_seq_id,
|
||||||
|
'default_location_src_id': wh_pack_stock_loc.id,
|
||||||
|
'default_location_dest_id': output_loc.id,
|
||||||
|
'active': warehouse.delivery_steps == 'pick_pack_ship',
|
||||||
|
'sequence': max_sequence + 3,
|
||||||
|
'color': color}, context=context)
|
||||||
|
pick_type_id = picking_type_obj.create(cr, uid, vals={
|
||||||
|
'name': _('Pick'),
|
||||||
|
'warehouse_id': warehouse.id,
|
||||||
|
'code': 'internal',
|
||||||
|
'sequence_id': pick_seq_id,
|
||||||
|
'default_location_src_id': wh_stock_loc.id,
|
||||||
|
'default_location_dest_id': wh_pack_stock_loc.id,
|
||||||
|
'active': warehouse.delivery_steps != 'ship_only',
|
||||||
|
'sequence': max_sequence + 2,
|
||||||
|
'color': color}, context=context)
|
||||||
|
|
||||||
|
#write picking types on WH
|
||||||
|
vals = {
|
||||||
|
'in_type_id': in_type_id,
|
||||||
|
'out_type_id': out_type_id,
|
||||||
|
'pack_type_id': pack_type_id,
|
||||||
|
'pick_type_id': pick_type_id,
|
||||||
|
'int_type_id': int_type_id,
|
||||||
|
}
|
||||||
|
super(stock_warehouse, self).write(cr, uid, warehouse.id, vals=vals, context=context)
|
||||||
|
|
||||||
|
|
||||||
def create(self, cr, uid, vals, context=None):
|
def create(self, cr, uid, vals, context=None):
|
||||||
if context is None:
|
if context is None:
|
||||||
context = {}
|
context = {}
|
||||||
|
@ -3153,108 +3256,10 @@ class stock_warehouse(osv.osv):
|
||||||
}, context=context_with_inactive)
|
}, context=context_with_inactive)
|
||||||
vals[values['field']] = location_id
|
vals[values['field']] = location_id
|
||||||
|
|
||||||
#create new sequences
|
|
||||||
in_seq_id = seq_obj.create(cr, SUPERUSER_ID, values={'name': vals.get('name', '') + _(' Sequence in'), 'prefix': vals.get('code', '') + '/IN/', 'padding': 5}, context=context)
|
|
||||||
out_seq_id = seq_obj.create(cr, SUPERUSER_ID, values={'name': vals.get('name', '') + _(' Sequence out'), 'prefix': vals.get('code', '') + '/OUT/', 'padding': 5}, context=context)
|
|
||||||
pack_seq_id = seq_obj.create(cr, SUPERUSER_ID, values={'name': vals.get('name', '') + _(' Sequence packing'), 'prefix': vals.get('code', '') + '/PACK/', 'padding': 5}, context=context)
|
|
||||||
pick_seq_id = seq_obj.create(cr, SUPERUSER_ID, values={'name': vals.get('name', '') + _(' Sequence picking'), 'prefix': vals.get('code', '') + '/PICK/', 'padding': 5}, context=context)
|
|
||||||
int_seq_id = seq_obj.create(cr, SUPERUSER_ID, values={'name': vals.get('name', '') + _(' Sequence internal'), 'prefix': vals.get('code', '') + '/INT/', 'padding': 5}, context=context)
|
|
||||||
|
|
||||||
#create WH
|
#create WH
|
||||||
new_id = super(stock_warehouse, self).create(cr, uid, vals=vals, context=context)
|
new_id = super(stock_warehouse, self).create(cr, uid, vals=vals, context=context)
|
||||||
|
|
||||||
warehouse = self.browse(cr, uid, new_id, context=context)
|
warehouse = self.browse(cr, uid, new_id, context=context)
|
||||||
wh_stock_loc = warehouse.lot_stock_id
|
self.create_sequences_and_picking_types(cr, uid, warehouse, context=context)
|
||||||
wh_input_stock_loc = warehouse.wh_input_stock_loc_id
|
|
||||||
wh_output_stock_loc = warehouse.wh_output_stock_loc_id
|
|
||||||
wh_pack_stock_loc = warehouse.wh_pack_stock_loc_id
|
|
||||||
|
|
||||||
#fetch customer and supplier locations, for references
|
|
||||||
customer_loc, supplier_loc = self._get_partner_locations(cr, uid, new_id, context=context)
|
|
||||||
|
|
||||||
#create in, out, internal picking types for warehouse
|
|
||||||
input_loc = wh_input_stock_loc
|
|
||||||
if warehouse.reception_steps == 'one_step':
|
|
||||||
input_loc = wh_stock_loc
|
|
||||||
output_loc = wh_output_stock_loc
|
|
||||||
if warehouse.delivery_steps == 'ship_only':
|
|
||||||
output_loc = wh_stock_loc
|
|
||||||
|
|
||||||
#choose the next available color for the picking types of this warehouse
|
|
||||||
color = 0
|
|
||||||
available_colors = [c%9 for c in range(3, 12)] # put flashy colors first
|
|
||||||
all_used_colors = self.pool.get('stock.picking.type').search_read(cr, uid, [('warehouse_id', '!=', False), ('color', '!=', False)], ['color'], order='color')
|
|
||||||
#don't use sets to preserve the list order
|
|
||||||
for x in all_used_colors:
|
|
||||||
if x['color'] in available_colors:
|
|
||||||
available_colors.remove(x['color'])
|
|
||||||
if available_colors:
|
|
||||||
color = available_colors[0]
|
|
||||||
|
|
||||||
#order the picking types with a sequence allowing to have the following suit for each warehouse: reception, internal, pick, pack, ship.
|
|
||||||
max_sequence = self.pool.get('stock.picking.type').search_read(cr, uid, [], ['sequence'], order='sequence desc')
|
|
||||||
max_sequence = max_sequence and max_sequence[0]['sequence'] or 0
|
|
||||||
|
|
||||||
in_type_id = picking_type_obj.create(cr, uid, vals={
|
|
||||||
'name': _('Receptions'),
|
|
||||||
'warehouse_id': new_id,
|
|
||||||
'code': 'incoming',
|
|
||||||
'sequence_id': in_seq_id,
|
|
||||||
'default_location_src_id': supplier_loc.id,
|
|
||||||
'default_location_dest_id': input_loc.id,
|
|
||||||
'sequence': max_sequence + 1,
|
|
||||||
'color': color}, context=context)
|
|
||||||
out_type_id = picking_type_obj.create(cr, uid, vals={
|
|
||||||
'name': _('Delivery Orders'),
|
|
||||||
'warehouse_id': new_id,
|
|
||||||
'code': 'outgoing',
|
|
||||||
'sequence_id': out_seq_id,
|
|
||||||
'return_picking_type_id': in_type_id,
|
|
||||||
'default_location_src_id': output_loc.id,
|
|
||||||
'default_location_dest_id': customer_loc.id,
|
|
||||||
'sequence': max_sequence + 4,
|
|
||||||
'color': color}, context=context)
|
|
||||||
picking_type_obj.write(cr, uid, [in_type_id], {'return_picking_type_id': out_type_id}, context=context)
|
|
||||||
int_type_id = picking_type_obj.create(cr, uid, vals={
|
|
||||||
'name': _('Internal Transfers'),
|
|
||||||
'warehouse_id': new_id,
|
|
||||||
'code': 'internal',
|
|
||||||
'sequence_id': int_seq_id,
|
|
||||||
'default_location_src_id': wh_stock_loc.id,
|
|
||||||
'default_location_dest_id': wh_stock_loc.id,
|
|
||||||
'active': True,
|
|
||||||
'sequence': max_sequence + 2,
|
|
||||||
'color': color}, context=context)
|
|
||||||
pack_type_id = picking_type_obj.create(cr, uid, vals={
|
|
||||||
'name': _('Pack'),
|
|
||||||
'warehouse_id': new_id,
|
|
||||||
'code': 'internal',
|
|
||||||
'sequence_id': pack_seq_id,
|
|
||||||
'default_location_src_id': wh_pack_stock_loc.id,
|
|
||||||
'default_location_dest_id': output_loc.id,
|
|
||||||
'active': delivery_steps == 'pick_pack_ship',
|
|
||||||
'sequence': max_sequence + 3,
|
|
||||||
'color': color}, context=context)
|
|
||||||
pick_type_id = picking_type_obj.create(cr, uid, vals={
|
|
||||||
'name': _('Pick'),
|
|
||||||
'warehouse_id': new_id,
|
|
||||||
'code': 'internal',
|
|
||||||
'sequence_id': pick_seq_id,
|
|
||||||
'default_location_src_id': wh_stock_loc.id,
|
|
||||||
'default_location_dest_id': wh_pack_stock_loc.id,
|
|
||||||
'active': delivery_steps != 'ship_only',
|
|
||||||
'sequence': max_sequence + 2,
|
|
||||||
'color': color}, context=context)
|
|
||||||
|
|
||||||
#write picking types on WH
|
|
||||||
vals = {
|
|
||||||
'in_type_id': in_type_id,
|
|
||||||
'out_type_id': out_type_id,
|
|
||||||
'pack_type_id': pack_type_id,
|
|
||||||
'pick_type_id': pick_type_id,
|
|
||||||
'int_type_id': int_type_id,
|
|
||||||
}
|
|
||||||
super(stock_warehouse, self).write(cr, uid, new_id, vals=vals, context=context)
|
|
||||||
warehouse.refresh()
|
warehouse.refresh()
|
||||||
|
|
||||||
#create routes and push/pull rules
|
#create routes and push/pull rules
|
||||||
|
@ -3298,6 +3303,7 @@ class stock_warehouse(osv.osv):
|
||||||
for push in route.push_ids:
|
for push in route.push_ids:
|
||||||
push_obj.write(cr, uid, push.id, {'name': pull.name.replace(warehouse.name, name, 1)}, context=context)
|
push_obj.write(cr, uid, push.id, {'name': pull.name.replace(warehouse.name, name, 1)}, context=context)
|
||||||
#change the mto pull rule name
|
#change the mto pull rule name
|
||||||
|
if warehouse.mto_pull_id.id:
|
||||||
pull_obj.write(cr, uid, warehouse.mto_pull_id.id, {'name': warehouse.mto_pull_id.name.replace(warehouse.name, name, 1)}, context=context)
|
pull_obj.write(cr, uid, warehouse.mto_pull_id.id, {'name': warehouse.mto_pull_id.name.replace(warehouse.name, name, 1)}, context=context)
|
||||||
|
|
||||||
def _check_delivery_resupply(self, cr, uid, warehouse, new_location, change_to_multiple, context=None):
|
def _check_delivery_resupply(self, cr, uid, warehouse, new_location, change_to_multiple, context=None):
|
||||||
|
@ -3380,6 +3386,7 @@ class stock_warehouse(osv.osv):
|
||||||
if vals.get('name'):
|
if vals.get('name'):
|
||||||
name = vals.get('name', warehouse.name)
|
name = vals.get('name', warehouse.name)
|
||||||
self._handle_renaming(cr, uid, warehouse, name, vals.get('code', warehouse.code), context=context_with_inactive)
|
self._handle_renaming(cr, uid, warehouse, name, vals.get('code', warehouse.code), context=context_with_inactive)
|
||||||
|
if warehouse.in_type_id:
|
||||||
seq_obj.write(cr, uid, warehouse.in_type_id.sequence_id.id, {'name': name + _(' Sequence in'), 'prefix': vals.get('code', warehouse.code) + '\IN\\'}, context=context)
|
seq_obj.write(cr, uid, warehouse.in_type_id.sequence_id.id, {'name': name + _(' Sequence in'), 'prefix': vals.get('code', warehouse.code) + '\IN\\'}, context=context)
|
||||||
seq_obj.write(cr, uid, warehouse.out_type_id.sequence_id.id, {'name': name + _(' Sequence out'), 'prefix': vals.get('code', warehouse.code) + '\OUT\\'}, context=context)
|
seq_obj.write(cr, uid, warehouse.out_type_id.sequence_id.id, {'name': name + _(' Sequence out'), 'prefix': vals.get('code', warehouse.code) + '\OUT\\'}, context=context)
|
||||||
seq_obj.write(cr, uid, warehouse.pack_type_id.sequence_id.id, {'name': name + _(' Sequence packing'), 'prefix': vals.get('code', warehouse.code) + '\PACK\\'}, context=context)
|
seq_obj.write(cr, uid, warehouse.pack_type_id.sequence_id.id, {'name': name + _(' Sequence packing'), 'prefix': vals.get('code', warehouse.code) + '\PACK\\'}, context=context)
|
||||||
|
|
Loading…
Reference in New Issue