[FIX] account_voucher: pay invoice propose the good partner (parent if not a company)

bzr revid: qdp-launchpad@openerp.com-20121130163528-zjjncja58hhnyflh
This commit is contained in:
Quentin (OpenERP) 2012-11-30 17:35:28 +01:00
parent 4d3260d92b
commit 73c53b4071
2 changed files with 14 additions and 6 deletions

View File

@ -294,6 +294,18 @@ class account_invoice(osv.osv):
('number_uniq', 'unique(number, company_id, journal_id, type)', 'Invoice Number must be unique per Company!'),
]
def _find_partner(self, inv):
'''
Find the partner for which the accounting entries will be created
'''
#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
return part
def fields_view_get(self, cr, uid, view_id=None, view_type=False, context=None, toolbar=False, submenu=False):
journal_obj = self.pool.get('account.journal')
if context is None:
@ -959,11 +971,7 @@ class account_invoice(osv.osv):
date = inv.date_invoice or time.strftime('%Y-%m-%d')
#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
part = self._find_partner(inv)
line = map(lambda x:(0,0,self.line_get_convert(cr, uid, x, part.id, date, context=ctx)),iml)

View File

@ -40,7 +40,7 @@ class invoice(osv.osv):
'target': 'new',
'domain': '[]',
'context': {
'default_partner_id': inv.partner_id.id,
'default_partner_id': self._find_partner(inv),
'default_amount': inv.type in ('out_refund', 'in_refund') and -inv.residual or inv.residual,
'default_number':inv.name,
'close_after_process': True,