Allow to customize stock location

This commit is contained in:
Alexis de Lattre
2016-11-15 14:21:15 +01:00
parent ef85216271
commit cebc0e3b84

View File

@@ -24,7 +24,7 @@ class ResPartner(models.Model):
"for this customer.") "for this customer.")
@api.multi @api.multi
def create_private_location_route(self): def create_private_location_route(self, location_name=False):
self.ensure_one() self.ensure_one()
assert not self.default_sale_route_id,\ assert not self.default_sale_route_id,\
'Already has a default_sale_route_id' 'Already has a default_sale_route_id'
@@ -33,6 +33,8 @@ class ResPartner(models.Model):
pro = self.env['procurement.rule'] pro = self.env['procurement.rule']
slro = self.env['stock.location.route'] slro = self.env['stock.location.route']
company = self.env.user.company_id company = self.env.user.company_id
if not location_name:
location_name = self.name
warehouses = swo.search([ warehouses = swo.search([
('company_id', '=', company.id), ('company_id', '=', company.id),
('private_stock_out_type_id', '!=', False)]) ('private_stock_out_type_id', '!=', False)])
@@ -42,13 +44,13 @@ class ResPartner(models.Model):
"company %s") % company.name) "company %s") % company.name)
warehouse = warehouses[0] warehouse = warehouses[0]
private_stock_loc = slo.create({ private_stock_loc = slo.create({
'name': _('Private stock %s') % self.name, 'name': location_name,
'location_id': warehouse.view_location_id.id, 'location_id': warehouse.view_location_id.id,
'usage': 'internal', 'usage': 'internal',
'company_id': company.id, 'company_id': company.id,
}) })
rule = pro.create({ rule = pro.create({
'name': _('From private stock %s to customer') % self.name, 'name': _('From specific stock %s to customer') % location_name,
'company_id': company.id, 'company_id': company.id,
'warehouse_id': warehouse.id, 'warehouse_id': warehouse.id,
'action': 'move', 'action': 'move',
@@ -59,7 +61,7 @@ class ResPartner(models.Model):
}) })
route = slro.create({ route = slro.create({
'name': _('Take from %s') % self.name, 'name': _('Take from %s') % location_name,
'sequence': 1000, 'sequence': 1000,
'pull_ids': [(6, 0, [rule.id])], 'pull_ids': [(6, 0, [rule.id])],
'product_selectable': False, 'product_selectable': False,