Skip to content

Commit

Permalink
[FIX] stock: customer/vendor location empty
Browse files Browse the repository at this point in the history
When creating a new company, the fields customer/vendor location
were empty.

Now, these fields are set with the internal transit location for the company
of the partner and set with Partners Locations/Customers and Partners Locations/Vendors
for the other companies.

opw:1845753
  • Loading branch information
jco-odoo authored and simongoffin committed May 17, 2018
1 parent eac4c0b commit 4e71bd5
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
5 changes: 3 additions & 2 deletions addons/stock/data/stock_data.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
-
!python {model: res.partner, id: base.main_partner}: |
main_warehouse = self.env['stock.warehouse'].browse(ref('warehouse0'))
self.write({'property_stock_customer':main_warehouse.lot_stock_id.id})

-
!python {model: ir.model.data, id: False}: |
main_warehouse = self.env['stock.warehouse'].browse(ref('warehouse0'))
Expand Down Expand Up @@ -30,4 +28,7 @@
companies = self.search([('internal_transit_location_id', '=', False)])
for company in companies:
company.create_transit_location()
internal_transit = company.internal_transit_location_id.id
warehouses = self.env['stock.warehouse'].search([('partner_id', '=', company.partner_id.id)])
warehouses.mapped('partner_id').with_context(force_company=company.id).write({'property_stock_customer': internal_transit, 'property_stock_supplier': internal_transit})

4 changes: 2 additions & 2 deletions addons/stock/models/res_company.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ def create_transit_location(self):
def create(self, vals):
company = super(Company, self).create(vals)

# multi-company rules prevents creating warehouse and sub-locations
company.create_transit_location()
# mutli-company rules prevents creating warehouse and sub-locations
self.env['stock.warehouse'].check_access_rights('create')
self.env['stock.warehouse'].sudo().create({'name': company.name, 'code': company.name[:5], 'company_id': company.id, 'partner_id': company.partner_id.id})
company.create_transit_location()
return company
3 changes: 2 additions & 1 deletion addons/stock/models/stock_warehouse.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,10 @@ def _update_partner_data(self, partner_id, company_id):
ResCompany = self.env['res.company']
if company_id:
transit_loc = ResCompany.browse(company_id).internal_transit_location_id.id
self.env['res.partner'].browse(partner_id).with_context(force_company=company_id).write({'property_stock_customer': transit_loc, 'property_stock_supplier': transit_loc})
else:
transit_loc = ResCompany._company_default_get('stock.warehouse').internal_transit_location_id.id
self.env['res.partner'].browse(partner_id).write({'property_stock_customer': transit_loc, 'property_stock_supplier': transit_loc})
self.env['res.partner'].browse(partner_id).write({'property_stock_customer': transit_loc, 'property_stock_supplier': transit_loc})

def create_sequences_and_picking_types(self):
IrSequenceSudo = self.env['ir.sequence'].sudo()
Expand Down

0 comments on commit 4e71bd5

Please sign in to comment.