[MERGE] context propagation in account
bzr revid: qdp-launchpad@openerp.com-20120103123339-r2vtd1r4s99p396w
This commit is contained in:
commit
fb1d37b1a8
|
@ -794,29 +794,33 @@ class account_invoice(osv.osv):
|
|||
line.append((0,0,val))
|
||||
return line
|
||||
|
||||
def action_move_create(self, cr, uid, ids, *args):
|
||||
def action_move_create(self, cr, uid, ids, context=None):
|
||||
"""Creates invoice related analytics and financial move lines"""
|
||||
ait_obj = self.pool.get('account.invoice.tax')
|
||||
cur_obj = self.pool.get('res.currency')
|
||||
period_obj = self.pool.get('account.period')
|
||||
context = {}
|
||||
for inv in self.browse(cr, uid, ids):
|
||||
payment_term_obj = self.pool.get('account.payment.term')
|
||||
journal_obj = self.pool.get('account.journal')
|
||||
move_obj = self.pool.get('account.move')
|
||||
if context is None:
|
||||
context = {}
|
||||
for inv in self.browse(cr, uid, ids, context=context):
|
||||
if not inv.journal_id.sequence_id:
|
||||
raise osv.except_osv(_('Error !'), _('Please define sequence on the journal related to this invoice.'))
|
||||
if not inv.invoice_line:
|
||||
raise osv.except_osv(_('No Invoice Lines !'), _('Please create some invoice lines.'))
|
||||
if inv.move_id:
|
||||
continue
|
||||
|
||||
|
||||
ctx = context.copy()
|
||||
ctx.update({'lang': inv.partner_id.lang})
|
||||
if not inv.date_invoice:
|
||||
self.write(cr, uid, [inv.id], {'date_invoice':time.strftime('%Y-%m-%d')})
|
||||
self.write(cr, uid, [inv.id], {'date_invoice':time.strftime('%Y-%m-%d')}, context=ctx)
|
||||
company_currency = inv.company_id.currency_id.id
|
||||
# create the analytical lines
|
||||
# one move line per invoice line
|
||||
iml = self._get_analytic_lines(cr, uid, inv.id)
|
||||
iml = self._get_analytic_lines(cr, uid, inv.id, context=ctx)
|
||||
# check if taxes are all computed
|
||||
ctx = context.copy()
|
||||
ctx.update({'lang': inv.partner_id.lang})
|
||||
compute_taxes = ait_obj.compute(cr, uid, inv.id, context=ctx)
|
||||
self.check_tax_lines(cr, uid, inv, compute_taxes, ait_obj)
|
||||
|
||||
|
@ -859,8 +863,8 @@ class account_invoice(osv.osv):
|
|||
name = inv['name'] or '/'
|
||||
totlines = False
|
||||
if inv.payment_term:
|
||||
totlines = self.pool.get('account.payment.term').compute(cr,
|
||||
uid, inv.payment_term.id, total, inv.date_invoice or False)
|
||||
totlines = payment_term_obj.compute(cr,
|
||||
uid, inv.payment_term.id, total, inv.date_invoice or False, context=ctx)
|
||||
if totlines:
|
||||
res_amount_currency = total_currency
|
||||
i = 0
|
||||
|
@ -906,12 +910,12 @@ 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={})),iml)
|
||||
line = map(lambda x:(0,0,self.line_get_convert(cr, uid, x, part, date, context=ctx)),iml)
|
||||
|
||||
line = self.group_lines(cr, uid, iml, line, inv)
|
||||
|
||||
journal_id = inv.journal_id.id
|
||||
journal = self.pool.get('account.journal').browse(cr, uid, journal_id)
|
||||
journal = journal_obj.browse(cr, uid, journal_id, context=ctx)
|
||||
if journal.centralisation:
|
||||
raise osv.except_osv(_('UserError'),
|
||||
_('You cannot create an invoice on a centralised journal. Uncheck the centralised counterpart box in the related journal from the configuration menu.'))
|
||||
|
@ -935,13 +939,14 @@ class account_invoice(osv.osv):
|
|||
for i in line:
|
||||
i[2]['period_id'] = period_id
|
||||
|
||||
move_id = self.pool.get('account.move').create(cr, uid, move, context=context)
|
||||
new_move_name = self.pool.get('account.move').browse(cr, uid, move_id).name
|
||||
move_id = move_obj.create(cr, uid, move, context=ctx)
|
||||
new_move_name = move_obj.browse(cr, uid, move_id, context=ctx).name
|
||||
# make the invoice point to that move
|
||||
self.write(cr, uid, [inv.id], {'move_id': move_id,'period_id':period_id, 'move_name':new_move_name})
|
||||
self.write(cr, uid, [inv.id], {'move_id': move_id,'period_id':period_id, 'move_name':new_move_name}, context=ctx)
|
||||
# Pass invoice in context in method post: used if you want to get the same
|
||||
# account move reference when creating the same invoice after a cancelled one:
|
||||
self.pool.get('account.move').post(cr, uid, [move_id], context={'invoice':inv})
|
||||
ctx.update({'invoice':inv})
|
||||
move_obj.post(cr, uid, [move_id], context=ctx)
|
||||
self._log_event(cr, uid, ids)
|
||||
return True
|
||||
|
||||
|
|
|
@ -380,7 +380,7 @@ class account_invoice(osv.osv):
|
|||
res['analytics_id'] = x.get('analytics_id', False)
|
||||
return res
|
||||
|
||||
def _get_analytic_lines(self, cr, uid, id):
|
||||
def _get_analytic_lines(self, cr, uid, id, context=None):
|
||||
inv = self.browse(cr, uid, [id])[0]
|
||||
cur_obj = self.pool.get('res.currency')
|
||||
invoice_line_obj = self.pool.get('account.invoice.line')
|
||||
|
@ -391,7 +391,7 @@ class account_invoice(osv.osv):
|
|||
else:
|
||||
sign = -1
|
||||
|
||||
iml = invoice_line_obj.move_line_get(cr, uid, inv.id)
|
||||
iml = invoice_line_obj.move_line_get(cr, uid, inv.id, context=context)
|
||||
|
||||
for il in iml:
|
||||
if il.get('analytics_id', False):
|
||||
|
@ -400,8 +400,10 @@ class account_invoice(osv.osv):
|
|||
ref = inv.reference
|
||||
else:
|
||||
ref = self._convert_ref(cr, uid, inv.number)
|
||||
obj_move_line = acct_ins_obj.browse(cr, uid, il['analytics_id'])
|
||||
amount_calc = cur_obj.compute(cr, uid, inv.currency_id.id, company_currency, il['price'], context={'date': inv.date_invoice}) * sign
|
||||
obj_move_line = acct_ins_obj.browse(cr, uid, il['analytics_id'], context=context)
|
||||
ctx = context.copy()
|
||||
ctx.update({'date': inv.date_invoice})
|
||||
amount_calc = cur_obj.compute(cr, uid, inv.currency_id.id, company_currency, il['price'], context=ctx) * sign
|
||||
qty = il['quantity']
|
||||
il['analytic_lines'] = []
|
||||
for line2 in obj_move_line.account_ids:
|
||||
|
|
|
@ -100,8 +100,8 @@ hr_analytic_timesheet()
|
|||
class account_invoice(osv.osv):
|
||||
_inherit = "account.invoice"
|
||||
|
||||
def _get_analytic_lines(self, cr, uid, id):
|
||||
iml = super(account_invoice, self)._get_analytic_lines(cr, uid, id)
|
||||
def _get_analytic_lines(self, cr, uid, id, context=None):
|
||||
iml = super(account_invoice, self)._get_analytic_lines(cr, uid, id, context=context)
|
||||
for il in iml:
|
||||
if il['account_analytic_id'] and il.get('analytic_lines', False):
|
||||
|
||||
|
@ -109,10 +109,10 @@ class account_invoice(osv.osv):
|
|||
journal_id = il['analytic_lines'][0][2]['journal_id']
|
||||
account_id = il['analytic_lines'][0][2]['account_id']
|
||||
if journal_id and account_id:
|
||||
temp = self.pool.get('analytic_journal_rate_grid').search(cr, uid, [('journal_id', '=', journal_id),('account_id', '=', account_id) ])
|
||||
temp = self.pool.get('analytic_journal_rate_grid').search(cr, uid, [('journal_id', '=', journal_id),('account_id', '=', account_id)], context=context)
|
||||
|
||||
if temp:
|
||||
r = self.pool.get('analytic_journal_rate_grid').browse(cr, uid, temp)[0]
|
||||
r = self.pool.get('analytic_journal_rate_grid').browse(cr, uid, temp, context=context)[0]
|
||||
il['analytic_lines'][0][2]['to_invoice'] = r.rate_id.id
|
||||
return iml
|
||||
|
||||
|
|
|
@ -170,16 +170,16 @@ hr_analytic_timesheet()
|
|||
class account_invoice(osv.osv):
|
||||
_inherit = "account.invoice"
|
||||
|
||||
def _get_analytic_lines(self, cr, uid, id):
|
||||
iml = super(account_invoice, self)._get_analytic_lines(cr, uid, id)
|
||||
def _get_analytic_lines(self, cr, uid, id, context=None):
|
||||
iml = super(account_invoice, self)._get_analytic_lines(cr, uid, id, context=context)
|
||||
|
||||
inv = self.browse(cr, uid, [id])[0]
|
||||
inv = self.browse(cr, uid, [id], context=context)[0]
|
||||
if inv.type == 'in_invoice':
|
||||
obj_analytic_account = self.pool.get('account.analytic.account')
|
||||
for il in iml:
|
||||
if il['account_analytic_id']:
|
||||
# *-* browse (or refactor to avoid read inside the loop)
|
||||
to_invoice = obj_analytic_account.read(cr, uid, [il['account_analytic_id']], ['to_invoice'])[0]['to_invoice']
|
||||
to_invoice = obj_analytic_account.read(cr, uid, [il['account_analytic_id']], ['to_invoice'], context=context)[0]['to_invoice']
|
||||
if to_invoice:
|
||||
il['analytic_lines'][0][2]['to_invoice'] = to_invoice[0]
|
||||
return iml
|
||||
|
|
Loading…
Reference in New Issue