[MERGE] fix of bad partner chosen for accounting entries when doing stock valuation (imply a small refactoring of the function that moves on the partner instead of being of the invoice)
bzr revid: qdp-launchpad@openerp.com-20130306150142-oyjyn3s7scfc31yw
This commit is contained in:
@@ -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_accounting_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_accounting_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' : []})
|
||||
|
||||
@@ -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_accounting_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,
|
||||
|
||||
@@ -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 self.pool.get('res.partner')._find_accounting_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,
|
||||
|
||||
Reference in New Issue
Block a user