[IMP] stock: setting a warehouse partner on a picking can put the from/to location to transit
The onchange for location zones in picking takes into account partner locations on partner of the picking. (e.g. Suppliers/IT Vendors instead of Suppliers) This is only the case when the default location of the picking type is empty. If a partner is assigned to a warehouse, its default supplier/customer location becomes the Transit location of the company. That way, when you set a partner on a picking that is the address of a warehouse, the default source/destination location (depending if it in/out) will be automatically set to the Transit Location.
This commit is contained in:
+36
-6
@@ -876,13 +876,24 @@ class stock_picking(models.Model):
|
||||
packop_ids = [op.id for op in picking.pack_operation_ids]
|
||||
self.pool.get('stock.pack.operation').write(cr, uid, packop_ids, {'owner_id': picking.owner_id.id}, context=context)
|
||||
|
||||
def onchange_picking_type(self, cr, uid, ids, picking_type_id):
|
||||
def onchange_picking_type(self, cr, uid, ids, picking_type_id, partner_id):
|
||||
res = {}
|
||||
if picking_type_id:
|
||||
picking_type = self.pool['stock.picking.type'].browse(cr, uid, picking_type_id)
|
||||
res['value'] = {'location_id': picking_type.default_location_src_id.id,
|
||||
'location_dest_id': picking_type.default_location_dest_id.id,
|
||||
}
|
||||
if not picking_type.default_location_src_id and partner_id:
|
||||
partner = self.pool['res.partner'].browse(cr, uid, partner_id)
|
||||
location_id = partner.property_stock_supplier.id
|
||||
else:
|
||||
location_id = picking_type.default_location_src_id.id
|
||||
|
||||
if not picking_type.default_location_dest_id and partner_id:
|
||||
partner = self.pool['res.partner'].browse(cr, uid, partner_id)
|
||||
location_dest_id = partner.property_stock_customer.id
|
||||
else:
|
||||
location_dest_id = picking_type.default_location_dest_id.id
|
||||
|
||||
res['value'] = {'location_id': location_id,
|
||||
'location_dest_id': location_dest_id,}
|
||||
return res
|
||||
|
||||
def _default_location_destination(self):
|
||||
@@ -3710,6 +3721,16 @@ class stock_warehouse(osv.osv):
|
||||
#create routes and push/procurement rules
|
||||
new_objects_dict = self.create_routes(cr, uid, new_id, warehouse, context=context)
|
||||
self.write(cr, uid, warehouse.id, new_objects_dict, context=context)
|
||||
|
||||
# If partner assigned
|
||||
if vals.get('partner_id'):
|
||||
comp_obj = self.pool['res.company']
|
||||
if vals.get('company_id'):
|
||||
transit_loc = comp_obj.browse(cr, uid, vals.get('company_id'), context=context).internal_transit_location_id.id
|
||||
else:
|
||||
transit_loc = comp_obj.browse(cr, uid, comp_obj._company_default_get(cr, uid, 'stock.warehouse', context=context)).internal_transit_location_id.id
|
||||
self.pool['res.partner'].write(cr, uid, [vals['partner_id']], {'property_stock_customer': transit_loc,
|
||||
'property_stock_supplier': transit_loc}, context=context)
|
||||
return new_id
|
||||
|
||||
def _format_rulename(self, cr, uid, obj, from_loc, dest_loc, context=None):
|
||||
@@ -3872,6 +3893,15 @@ class stock_warehouse(osv.osv):
|
||||
for inter_wh_route_id in to_assign_route_ids:
|
||||
self.write(cr, uid, [warehouse.id], {'route_ids': [(4, inter_wh_route_id)]})
|
||||
|
||||
# If another partner assigned
|
||||
if vals.get('partner_id'):
|
||||
if not vals.get('company_id'):
|
||||
company = self.browse(cr, uid, ids[0], context=context).company_id
|
||||
else:
|
||||
company = self.pool['res.company'].browse(cr, uid, vals['company_id'])
|
||||
transit_loc = company.internal_transit_location_id.id
|
||||
self.pool['res.partner'].write(cr, uid, [vals['partner_id']], {'property_stock_customer': transit_loc,
|
||||
'property_stock_supplier': transit_loc}, context=context)
|
||||
return super(stock_warehouse, self).write(cr, uid, ids, vals=vals, context=context)
|
||||
|
||||
def get_all_routes_for_wh(self, cr, uid, warehouse, context=None):
|
||||
@@ -4739,8 +4769,8 @@ class stock_picking_type(osv.osv):
|
||||
'color': fields.integer('Color'),
|
||||
'sequence': fields.integer('Sequence', help="Used to order the 'All Operations' kanban view"),
|
||||
'sequence_id': fields.many2one('ir.sequence', 'Reference Sequence', required=True),
|
||||
'default_location_src_id': fields.many2one('stock.location', 'Default Source Location'),
|
||||
'default_location_dest_id': fields.many2one('stock.location', 'Default Destination Location'),
|
||||
'default_location_src_id': fields.many2one('stock.location', 'Default Source Location', help="This is the default source location when you create a picking manually with this picking type. It is possible however to change it or that the routes put another location. If it is empty, it will check for the supplier location on the partner. "),
|
||||
'default_location_dest_id': fields.many2one('stock.location', 'Default Destination Location', help="This is the default destination location when you create a picking manually with this picking type. It is possible however to change it or that the routes put another location. If it is empty, it will check for the customer location on the partner. "),
|
||||
'code': fields.selection([('incoming', 'Suppliers'), ('outgoing', 'Customers'), ('internal', 'Internal')], 'Type of Operation', required=True),
|
||||
'return_picking_type_id': fields.many2one('stock.picking.type', 'Picking Type for Returns'),
|
||||
'show_entire_packs': fields.boolean('Allow moving packs'),
|
||||
|
||||
@@ -822,7 +822,7 @@
|
||||
</h1>
|
||||
<group>
|
||||
<group>
|
||||
<field name="partner_id" attrs="{'invisible': [('picking_type_code', '=', 'internal')]}"/>
|
||||
<field name="partner_id" attrs="{'invisible': [('picking_type_code', '=', 'internal')]}" on_change="onchange_picking_type(picking_type_id,partner_id)"/>
|
||||
<field name="location_id" groups="stock.group_locations" attrs="{'invisible': [('picking_type_code', '=', 'incoming')]}"/>
|
||||
<field name="location_dest_id" groups="stock.group_locations" attrs="{'invisible': [('picking_type_code', '=', 'outgoing')]}"/>
|
||||
<field name="backorder_id" readonly="1" attrs="{'invisible': [('backorder_id','=',False)]}"/>
|
||||
@@ -923,7 +923,7 @@
|
||||
<group>
|
||||
<group>
|
||||
<field name="move_type"/>
|
||||
<field name="picking_type_id" on_change="onchange_picking_type(picking_type_id)"/>
|
||||
<field name="picking_type_id" on_change="onchange_picking_type(picking_type_id,partner_id)"/>
|
||||
<field name="picking_type_code" invisible="1"/>
|
||||
<field name="quant_reserved_exist" invisible="1"/>
|
||||
</group>
|
||||
|
||||
Reference in New Issue
Block a user