From 5f0d90d807239676f9b19a1ae6996da3023fdf39 Mon Sep 17 00:00:00 2001 From: Denis Ledoux Date: Fri, 25 Sep 2015 11:25:30 +0200 Subject: [PATCH] [FIX] purchase, inter_company_rules: correct picking type This revision is related to 9047db401dbdb7c849db9bd172af3a8f7611a931. 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 --- addons/inter_company_rules/models/sale_order.py | 12 +++++++++--- addons/purchase/purchase.py | 1 + 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/addons/inter_company_rules/models/sale_order.py b/addons/inter_company_rules/models/sale_order.py index 473dea16b0c..64542b7a95a 100644 --- a/addons/inter_company_rules/models/sale_order.py +++ b/addons/inter_company_rules/models/sale_order.py @@ -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): diff --git a/addons/purchase/purchase.py b/addons/purchase/purchase.py index 4ce14d225a2..63825911a9f 100644 --- a/addons/purchase/purchase.py +++ b/addons/purchase/purchase.py @@ -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)