[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))
|
line.append((0,0,val))
|
||||||
return line
|
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"""
|
"""Creates invoice related analytics and financial move lines"""
|
||||||
ait_obj = self.pool.get('account.invoice.tax')
|
ait_obj = self.pool.get('account.invoice.tax')
|
||||||
cur_obj = self.pool.get('res.currency')
|
cur_obj = self.pool.get('res.currency')
|
||||||
period_obj = self.pool.get('account.period')
|
period_obj = self.pool.get('account.period')
|
||||||
context = {}
|
payment_term_obj = self.pool.get('account.payment.term')
|
||||||
for inv in self.browse(cr, uid, ids):
|
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:
|
if not inv.journal_id.sequence_id:
|
||||||
raise osv.except_osv(_('Error !'), _('Please define sequence on the journal related to this invoice.'))
|
raise osv.except_osv(_('Error !'), _('Please define sequence on the journal related to this invoice.'))
|
||||||
if not inv.invoice_line:
|
if not inv.invoice_line:
|
||||||
raise osv.except_osv(_('No Invoice Lines !'), _('Please create some invoice lines.'))
|
raise osv.except_osv(_('No Invoice Lines !'), _('Please create some invoice lines.'))
|
||||||
if inv.move_id:
|
if inv.move_id:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
ctx = context.copy()
|
||||||
|
ctx.update({'lang': inv.partner_id.lang})
|
||||||
if not inv.date_invoice:
|
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
|
company_currency = inv.company_id.currency_id.id
|
||||||
# create the analytical lines
|
# create the analytical lines
|
||||||
# one move line per invoice line
|
# 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
|
# 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)
|
compute_taxes = ait_obj.compute(cr, uid, inv.id, context=ctx)
|
||||||
self.check_tax_lines(cr, uid, inv, compute_taxes, ait_obj)
|
self.check_tax_lines(cr, uid, inv, compute_taxes, ait_obj)
|
||||||
|
|
||||||
|
@ -859,8 +863,8 @@ class account_invoice(osv.osv):
|
||||||
name = inv['name'] or '/'
|
name = inv['name'] or '/'
|
||||||
totlines = False
|
totlines = False
|
||||||
if inv.payment_term:
|
if inv.payment_term:
|
||||||
totlines = self.pool.get('account.payment.term').compute(cr,
|
totlines = payment_term_obj.compute(cr,
|
||||||
uid, inv.payment_term.id, total, inv.date_invoice or False)
|
uid, inv.payment_term.id, total, inv.date_invoice or False, context=ctx)
|
||||||
if totlines:
|
if totlines:
|
||||||
res_amount_currency = total_currency
|
res_amount_currency = total_currency
|
||||||
i = 0
|
i = 0
|
||||||
|
@ -906,12 +910,12 @@ class account_invoice(osv.osv):
|
||||||
date = inv.date_invoice or time.strftime('%Y-%m-%d')
|
date = inv.date_invoice or time.strftime('%Y-%m-%d')
|
||||||
part = inv.partner_id.id
|
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)
|
line = self.group_lines(cr, uid, iml, line, inv)
|
||||||
|
|
||||||
journal_id = inv.journal_id.id
|
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:
|
if journal.centralisation:
|
||||||
raise osv.except_osv(_('UserError'),
|
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.'))
|
_('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:
|
for i in line:
|
||||||
i[2]['period_id'] = period_id
|
i[2]['period_id'] = period_id
|
||||||
|
|
||||||
move_id = self.pool.get('account.move').create(cr, uid, move, context=context)
|
move_id = move_obj.create(cr, uid, move, context=ctx)
|
||||||
new_move_name = self.pool.get('account.move').browse(cr, uid, move_id).name
|
new_move_name = move_obj.browse(cr, uid, move_id, context=ctx).name
|
||||||
# make the invoice point to that move
|
# 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
|
# 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:
|
# 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)
|
self._log_event(cr, uid, ids)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
|
@ -380,7 +380,7 @@ class account_invoice(osv.osv):
|
||||||
res['analytics_id'] = x.get('analytics_id', False)
|
res['analytics_id'] = x.get('analytics_id', False)
|
||||||
return res
|
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]
|
inv = self.browse(cr, uid, [id])[0]
|
||||||
cur_obj = self.pool.get('res.currency')
|
cur_obj = self.pool.get('res.currency')
|
||||||
invoice_line_obj = self.pool.get('account.invoice.line')
|
invoice_line_obj = self.pool.get('account.invoice.line')
|
||||||
|
@ -391,7 +391,7 @@ class account_invoice(osv.osv):
|
||||||
else:
|
else:
|
||||||
sign = -1
|
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:
|
for il in iml:
|
||||||
if il.get('analytics_id', False):
|
if il.get('analytics_id', False):
|
||||||
|
@ -400,8 +400,10 @@ class account_invoice(osv.osv):
|
||||||
ref = inv.reference
|
ref = inv.reference
|
||||||
else:
|
else:
|
||||||
ref = self._convert_ref(cr, uid, inv.number)
|
ref = self._convert_ref(cr, uid, inv.number)
|
||||||
obj_move_line = acct_ins_obj.browse(cr, uid, il['analytics_id'])
|
obj_move_line = acct_ins_obj.browse(cr, uid, il['analytics_id'], context=context)
|
||||||
amount_calc = cur_obj.compute(cr, uid, inv.currency_id.id, company_currency, il['price'], context={'date': inv.date_invoice}) * sign
|
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']
|
qty = il['quantity']
|
||||||
il['analytic_lines'] = []
|
il['analytic_lines'] = []
|
||||||
for line2 in obj_move_line.account_ids:
|
for line2 in obj_move_line.account_ids:
|
||||||
|
|
|
@ -100,8 +100,8 @@ hr_analytic_timesheet()
|
||||||
class account_invoice(osv.osv):
|
class account_invoice(osv.osv):
|
||||||
_inherit = "account.invoice"
|
_inherit = "account.invoice"
|
||||||
|
|
||||||
def _get_analytic_lines(self, cr, uid, id):
|
def _get_analytic_lines(self, cr, uid, id, context=None):
|
||||||
iml = super(account_invoice, self)._get_analytic_lines(cr, uid, id)
|
iml = super(account_invoice, self)._get_analytic_lines(cr, uid, id, context=context)
|
||||||
for il in iml:
|
for il in iml:
|
||||||
if il['account_analytic_id'] and il.get('analytic_lines', False):
|
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']
|
journal_id = il['analytic_lines'][0][2]['journal_id']
|
||||||
account_id = il['analytic_lines'][0][2]['account_id']
|
account_id = il['analytic_lines'][0][2]['account_id']
|
||||||
if journal_id and 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:
|
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
|
il['analytic_lines'][0][2]['to_invoice'] = r.rate_id.id
|
||||||
return iml
|
return iml
|
||||||
|
|
||||||
|
|
|
@ -170,16 +170,16 @@ hr_analytic_timesheet()
|
||||||
class account_invoice(osv.osv):
|
class account_invoice(osv.osv):
|
||||||
_inherit = "account.invoice"
|
_inherit = "account.invoice"
|
||||||
|
|
||||||
def _get_analytic_lines(self, cr, uid, id):
|
def _get_analytic_lines(self, cr, uid, id, context=None):
|
||||||
iml = super(account_invoice, self)._get_analytic_lines(cr, uid, id)
|
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':
|
if inv.type == 'in_invoice':
|
||||||
obj_analytic_account = self.pool.get('account.analytic.account')
|
obj_analytic_account = self.pool.get('account.analytic.account')
|
||||||
for il in iml:
|
for il in iml:
|
||||||
if il['account_analytic_id']:
|
if il['account_analytic_id']:
|
||||||
# *-* browse (or refactor to avoid read inside the loop)
|
# *-* 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:
|
if to_invoice:
|
||||||
il['analytic_lines'][0][2]['to_invoice'] = to_invoice[0]
|
il['analytic_lines'][0][2]['to_invoice'] = to_invoice[0]
|
||||||
return iml
|
return iml
|
||||||
|
|
Loading…
Reference in New Issue