[MERGE] context propagation in account
authorQuentin (OpenERP) <qdp-launchpad@openerp.com>
Tue, 3 Jan 2012 12:33:39 +0000 (13:33 +0100)
committerQuentin (OpenERP) <qdp-launchpad@openerp.com>
Tue, 3 Jan 2012 12:33:39 +0000 (13:33 +0100)
bzr revid: qdp-launchpad@openerp.com-20120103123339-r2vtd1r4s99p396w

1  2 
addons/account/account_invoice.py
addons/account_analytic_plans/account_analytic_plans.py
addons/analytic_journal_billing_rate/analytic_journal_billing_rate.py
addons/hr_timesheet_invoice/hr_timesheet_invoice.py

@@@ -799,10 -799,14 +799,14 @@@ class account_invoice(osv.osv)
          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 invoice journal'))
 +                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:
                  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).name
++            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
  
@@@ -400,8 -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:
@@@ -109,10 -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 -169,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