[FIX] _find_partner refactoring for res_partner and using it in creation of stock account moves

bzr revid: jco@openerp.com-20130305162015-lndgz2f0z4xtd62z
This commit is contained in:
Josse Colpaert 2013-03-05 17:20:15 +01:00
parent 64e0800251
commit 76ca410f82
3 changed files with 14 additions and 13 deletions

View File

@ -305,16 +305,7 @@ 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):
@ -980,7 +971,7 @@ class account_invoice(osv.osv):
date = inv.date_invoice or time.strftime('%Y-%m-%d')
part = self._find_partner(inv)
part = self.pool.get("res.partner")._find_partner(inv.partner_id)
line = map(lambda x:(0,0,self.line_get_convert(cr, uid, x, part.id, date, context=ctx)),iml)
@ -1752,6 +1743,16 @@ class res_partner(osv.osv):
'invoice_ids': fields.one2many('account.invoice.line', 'partner_id', 'Invoices', readonly=True),
}
def _find_partner(self, part):
'''
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'
if part.parent_id and not part.is_company:
part = part.parent_id
return part
def copy(self, cr, uid, id, default=None, context=None):
default = default or {}
default.update({'invoice_ids' : []})

View File

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

View File

@ -2396,7 +2396,7 @@ class stock_move(osv.osv):
processing of the given stock move.
"""
# prepare default values considering that the destination accounts have the reference_currency_id as their main currency
partner_id = (move.picking_id.partner_id and move.picking_id.partner_id.id and move.picking_id.partner_id.id) or False
partner_id = (move.picking_id.partner_id and move.picking_id.partner_id.id and self.pool.get('res.partner')._find_partner(move.picking_id.partner_id).id) or False
debit_line_vals = {
'name': move.name,
'product_id': move.product_id and move.product_id.id or False,