[MERGE] opw 5852
authorQuentin (OpenERP) <qdp-launchpad@openerp.com>
Wed, 3 Aug 2011 08:02:46 +0000 (10:02 +0200)
committerQuentin (OpenERP) <qdp-launchpad@openerp.com>
Wed, 3 Aug 2011 08:02:46 +0000 (10:02 +0200)
bzr revid: qdp-launchpad@openerp.com-20110803080246-0f4bqo94cvh11l90

addons/account/account.py
addons/account_voucher/account_voucher.py

index b93e6b6..6e428ae 100644 (file)
@@ -907,10 +907,17 @@ class account_period(osv.osv):
         return False
 
     def find(self, cr, uid, dt=None, context=None):
+        if context is None: context = {}
         if not dt:
             dt = time.strftime('%Y-%m-%d')
 #CHECKME: shouldn't we check the state of the period?
-        ids = self.search(cr, uid, [('date_start','<=',dt),('date_stop','>=',dt)])
+        args = [('date_start', '<=' ,dt), ('date_stop', '>=', dt)]
+        if context.get('company_id', False):
+            args.append(('company_id', '=', context['company_id']))
+        else:
+            company_id = self.pool.get('res.users').browse(cr, uid, uid, context=context).company_id.id
+            args.append(('company_id', '=', company_id))
+        ids = self.search(cr, uid, args, context=context)
         if not ids:
             raise osv.except_osv(_('Error !'), _('No period defined for this date: %s !\nPlease create a fiscal year.')%dt)
         return ids
@@ -1374,7 +1381,7 @@ class account_move(osv.osv):
         cr.execute('SELECT SUM(%s) FROM account_move_line WHERE move_id=%%s AND id!=%%s' % (mode,), (move.id, line_id2))
         result = cr.fetchone()[0] or 0.0
         cr.execute('update account_move_line set '+mode2+'=%s where id=%s', (result, line_id))
-        
+
         #adjust also the amount in currency if needed
         cr.execute("select currency_id, sum(amount_currency) as amount_currency from account_move_line where move_id = %s and currency_id is not null group by currency_id", (move.id,))
         for row in cr.dictfetchall():
index 455006e..0486b27 100644 (file)
@@ -39,7 +39,10 @@ class account_voucher(osv.osv):
         if context is None: context = {}
         if context.get('period_id', False):
             return context.get('period_id')
-        periods = self.pool.get('account.period').find(cr, uid)
+        if context.get('invoice_id', False):
+            company_id = self.pool.get('account.invoice').browse(cr, uid, context['invoice_id'], context=context).company_id.id
+            context.update({'company_id': company_id})
+        periods = self.pool.get('account.period').find(cr, uid, context=context)
         return periods and periods[0] or False
 
     def _get_journal(self, cr, uid, context=None):
@@ -118,7 +121,7 @@ class account_voucher(osv.osv):
     def fields_view_get(self, cr, uid, view_id=None, view_type=False, context=None, toolbar=False, submenu=False):
         mod_obj = self.pool.get('ir.model.data')
         if context is None: context = {}
-        
+
         def get_res_id(view_type, condition):
             result = False
             if view_type == 'tree':
@@ -466,7 +469,7 @@ class account_voucher(osv.osv):
             domain = [('state','=','valid'), ('account_id.type', '=', account_type), ('reconcile_id', '=', False), ('partner_id', '=', partner_id)]
             if context.get('invoice_id', False):
                    domain.append(('invoice', '=', context['invoice_id']))
-            ids = move_line_pool.search(cr, uid, domain, context=context)    
+            ids = move_line_pool.search(cr, uid, domain, context=context)
         else:
             ids = context['move_line_ids']
         ids.reverse()
@@ -535,7 +538,10 @@ class account_voucher(osv.osv):
         """
         period_pool = self.pool.get('account.period')
         res = self.onchange_partner_id(cr, uid, ids, partner_id, journal_id, price, currency_id, ttype, date, context=context)
-        pids = period_pool.search(cr, uid, [('date_start', '<=', date), ('date_stop', '>=', date)])
+        if context.get('invoice_id', False):
+            company_id = self.pool.get('account.invoice').browse(cr, uid, context['invoice_id'], context=context).company_id.id
+            context.update({'company_id': company_id})
+        pids = period_pool.find(cr, uid, date, context=context)
         if pids:
             if not 'value' in res:
                 res['value'] = {}