From 47e7f5d9bd47fc01bc93a7680d76f7375932d41c Mon Sep 17 00:00:00 2001 From: Goffin Simon Date: Fri, 11 Dec 2015 12:02:45 +0100 Subject: [PATCH] [FIX] stock_account, sale_stock: _get_partner_to_invoice When getting the partner to invoice, the function _get_partner_to_invoice must check the type of the invoice to create. opw:658460 --- addons/sale_stock/sale_stock.py | 13 +++++++------ addons/stock_account/stock.py | 2 +- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/addons/sale_stock/sale_stock.py b/addons/sale_stock/sale_stock.py index 980e932b80e..60bea3e4ff5 100644 --- a/addons/sale_stock/sale_stock.py +++ b/addons/sale_stock/sale_stock.py @@ -447,12 +447,13 @@ class stock_picking(osv.osv): """ Inherit the original function of the 'stock' module We select the partner of the sales order as the partner of the customer invoice """ - if picking.sale_id: - saleorder_ids = self.pool['sale.order'].search(cr, uid, [('procurement_group_id' ,'=', picking.group_id.id)], context=context) - saleorders = self.pool['sale.order'].browse(cr, uid, saleorder_ids, context=context) - if saleorders and saleorders[0] and saleorders[0].order_policy == 'picking': - saleorder = saleorders[0] - return saleorder.partner_invoice_id.id + if context.get('inv_type') and context['inv_type'] in ('out_invoice', 'out_refund'): + if picking.sale_id: + saleorder_ids = self.pool['sale.order'].search(cr, uid, [('procurement_group_id' ,'=', picking.group_id.id)], context=context) + saleorders = self.pool['sale.order'].browse(cr, uid, saleorder_ids, context=context) + if saleorders and saleorders[0] and saleorders[0].order_policy == 'picking': + saleorder = saleorders[0] + return saleorder.partner_invoice_id.id return super(stock_picking, self)._get_partner_to_invoice(cr, uid, picking, context=context) def _get_sale_id(self, cr, uid, ids, name, args, context=None): diff --git a/addons/stock_account/stock.py b/addons/stock_account/stock.py index 4d2d5e72c1f..2cc7965e053 100644 --- a/addons/stock_account/stock.py +++ b/addons/stock_account/stock.py @@ -252,7 +252,7 @@ class stock_picking(osv.osv): context = context or {} todo = {} for picking in self.browse(cr, uid, ids, context=context): - partner = self._get_partner_to_invoice(cr, uid, picking, context) + partner = self._get_partner_to_invoice(cr, uid, picking, dict(context, type=type)) #grouping is based on the invoiced partner if group: key = partner