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
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():
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):
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':
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()
"""
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'] = {}