Skip to content
Snippets Groups Projects
Commit e4d64afc authored by Arnold Moyaux's avatar Arnold Moyaux Committed by Simon Lejeune
Browse files

[REF] purchase_stock: multi company

parent a5f07e16
No related branches found
No related tags found
No related merge requests found
......@@ -14,12 +14,7 @@ class PurchaseOrder(models.Model):
@api.model
def _default_picking_type(self):
type_obj = self.env['stock.picking.type']
company_id = self.env.context.get('company_id') or self.env.company.id
types = type_obj.search([('code', '=', 'incoming'), ('warehouse_id.company_id', '=', company_id)])
if not types:
types = type_obj.search([('code', '=', 'incoming'), ('warehouse_id', '=', False)])
return types[:1]
return self._get_picking_type(self.env.context.get('company_id') or self.env.company.id)
incoterm_id = fields.Many2one('account.incoterms', 'Incoterm', states={'done': [('readonly', True)]}, help="International Commercial Terms are a series of predefined commercial terms used in international transactions.")
......@@ -60,6 +55,10 @@ class PurchaseOrder(models.Model):
if self.picking_type_id.default_location_dest_id.usage != 'customer':
self.dest_address_id = False
@api.onchange('company_id')
def _onchange_company_id(self):
self.picking_type_id = self._get_picking_type(self.company_id.id)
# --------------------------------------------------
# CRUD
# --------------------------------------------------
......@@ -175,6 +174,13 @@ class PurchaseOrder(models.Model):
return self.dest_address_id.property_stock_customer.id
return self.picking_type_id.default_location_dest_id.id
@api.model
def _get_picking_type(self, company_id):
picking_type = self.env['stock.picking.type'].search([('code', '=', 'incoming'), ('warehouse_id.company_id', '=', company_id)])
if not picking_type:
picking_type = self.env['stock.picking.type'].search([('code', '=', 'incoming'), ('warehouse_id', '=', False)])
return picking_type[:1]
@api.model
def _prepare_picking(self):
if not self.group_id:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment