diff --git a/addons/account/account_invoice.py b/addons/account/account_invoice.py index b0671e501ae..60c8b3a3d22 100644 --- a/addons/account/account_invoice.py +++ b/addons/account/account_invoice.py @@ -958,9 +958,14 @@ class account_invoice(osv.osv): }) date = inv.date_invoice or time.strftime('%Y-%m-%d') - part = inv.partner_id.id - line = map(lambda x:(0,0,self.line_get_convert(cr, uid, x, part, date, context=ctx)),iml) + #if the chosen partner is not a company and has a parent company, use the parent for the journal entries + #because you want to invoice 'Agrolait, accounting department' but the journal items are for 'Agrolait' + part = inv.partner_id + if part.parent_id and not part.is_company: + part = part.parent_id + + line = map(lambda x:(0,0,self.line_get_convert(cr, uid, x, part.id, date, context=ctx)),iml) line = self.group_lines(cr, uid, iml, line, inv) diff --git a/addons/sale/sale.py b/addons/sale/sale.py index 382fe093907..4c0b056025f 100644 --- a/addons/sale/sale.py +++ b/addons/sale/sale.py @@ -295,12 +295,16 @@ class sale_order(osv.osv): } return {'warning': warning, 'value': value} - def onchange_partner_id(self, cr, uid, ids, part): + def onchange_partner_id(self, cr, uid, ids, part, context=None): if not part: return {'value': {'partner_invoice_id': False, 'partner_shipping_id': False, 'payment_term': False, 'fiscal_position': False}} - addr = self.pool.get('res.partner').address_get(cr, uid, [part], ['delivery', 'invoice', 'contact']) - part = self.pool.get('res.partner').browse(cr, uid, part) + part = self.pool.get('res.partner').browse(cr, uid, part, context=context) + #if the chosen partner is not a company and has a parent company, use the parent to choose the delivery, the + #invoicing addresses and all the fields related to the partner. + if part.parent_id and not part.is_company: + part = part.parent_id + addr = self.pool.get('res.partner').address_get(cr, uid, [part.id], ['delivery', 'invoice', 'contact']) pricelist = part.property_product_pricelist and part.property_product_pricelist.id or False payment_term = part.property_payment_term and part.property_payment_term.id or False fiscal_position = part.property_account_position and part.property_account_position.id or False diff --git a/addons/sale/sale_view.xml b/addons/sale/sale_view.xml index 419047dbbd2..98c810aac87 100644 --- a/addons/sale/sale_view.xml +++ b/addons/sale/sale_view.xml @@ -190,7 +190,7 @@ - +