[FIX] purchase, inter_company_rules: correct picking type

This revision is related to 9047db401d.

With the same environment and use case than the above revision,
the Purchase order picking type was not set using the correct
company, it always used the user current company, instead
of forcing the company to the company for which the PO is created.

Besides, there is an onchange on the picking type
`onchange_picking_type_id`,
which sets values that are important for the continuation
of the flow.

opw-649378
This commit is contained in:
Denis Ledoux
2015-09-25 11:30:07 +02:00
parent 8cb1889baf
commit 5f0d90d807
2 changed files with 10 additions and 3 deletions
@@ -31,7 +31,7 @@ class sale_order(models.Model):
:param company : the company of the created PO
:rtype company : res.company record
"""
self = self.with_context(force_company=company.id)
self = self.with_context(force_company=company.id, company_id=company.id)
PurchaseOrder = self.env['purchase.order']
company_partner = self.company_id and self.company_id.partner_id or False
if not company or not company_partner.id:
@@ -75,15 +75,18 @@ class sale_order(models.Model):
:rtype company : res.company record
"""
# find location and warehouse, pick warehouse from company object
PurchaseOrder = self.env['purchase.order']
warehouse = company.warehouse_id and company.warehouse_id.company_id.id == company.id and company.warehouse_id or False
if not warehouse:
raise Warning(_('Configure correct warehouse for company(%s) from Menu: Settings/companies/companies' % (company.name)))
return {
intercompany_uid = company.intercompany_user_id.id
picking_type_id = PurchaseOrder.sudo(intercompany_uid)._get_picking_in()
res = {
'name': self.env['ir.sequence'].sudo().next_by_code('purchase.order'),
'origin': self.name,
'partner_id': company_partner.id,
'location_id': warehouse.lot_stock_id.id,
'picking_type_id': picking_type_id,
'pricelist_id': company_partner.property_product_pricelist_purchase.id,
'date_order': self.date_order,
'company_id': company.id,
@@ -94,6 +97,9 @@ class sale_order(models.Model):
'partner_ref': self.name,
'dest_address_id': self.partner_shipping_id and self.partner_shipping_id.id or False,
}
picking_values = PurchaseOrder.sudo(intercompany_uid).onchange_picking_type_id(picking_type_id).get('value', {})
res.update(picking_values)
return res
@api.model
def _prepare_purchase_order_line_data(self, so_line, date_order, purchase_id, company):
+1
View File
@@ -168,6 +168,7 @@ class purchase_order(osv.osv):
type_obj = self.pool.get('stock.picking.type')
user_obj = self.pool.get('res.users')
company_id = user_obj.browse(cr, uid, uid, context=context).company_id.id
company_id = context.get('company_id') or company_id
types = type_obj.search(cr, uid, [('code', '=', 'incoming'), ('warehouse_id.company_id', '=', company_id)], context=context)
if not types:
types = type_obj.search(cr, uid, [('code', '=', 'incoming'), ('warehouse_id', '=', False)], context=context)