Skip to content

Commit

Permalink
Merge remote-tracking branch 'odoo/8.0' into 8.0
Browse files Browse the repository at this point in the history
  • Loading branch information
OCA git bot authored and OCA git bot committed May 21, 2015
2 parents e45e8f9 + d8d49ef commit 4428226
Show file tree
Hide file tree
Showing 292 changed files with 48,199 additions and 8,635 deletions.
7 changes: 4 additions & 3 deletions addons/account/account.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
from openerp.osv import fields, osv, expression
from openerp.tools.translate import _
from openerp.tools.float_utils import float_round as round
from openerp.tools.safe_eval import safe_eval as eval

import openerp.addons.decimal_precision as dp

Expand Down Expand Up @@ -2001,7 +2002,7 @@ def _applicable(self, cr, uid, taxes, price_unit, product=None, partner=None):
for tax in taxes:
if tax.applicable_type=='code':
localdict = {'price_unit':price_unit, 'product':product, 'partner':partner}
exec tax.python_applicable in localdict
eval(tax.python_applicable, localdict, mode="exec", nocopy=True)
if localdict.get('result', False):
res.append(tax)
else:
Expand Down Expand Up @@ -2042,7 +2043,7 @@ def _unit_compute(self, cr, uid, taxes, price_unit, product=None, partner=None,
# data['amount'] = quantity
elif tax.type=='code':
localdict = {'price_unit':cur_price_unit, 'product':product, 'partner':partner, 'quantity': quantity}
exec tax.python_compute in localdict
eval(tax.python_compute, localdict, mode="exec", nocopy=True)
amount = localdict['result']
data['amount'] = amount
elif tax.type=='balance':
Expand Down Expand Up @@ -2190,7 +2191,7 @@ def _unit_compute_inv(self, cr, uid, taxes, price_unit, product=None, partner=No

elif tax.type=='code':
localdict = {'price_unit':cur_price_unit, 'product':product, 'partner':partner}
exec tax.python_compute_inv in localdict
eval(tax.python_compute_inv, localdict, mode="exec", nocopy=True)
amount = localdict['result']
elif tax.type=='balance':
amount = cur_price_unit - reduce(lambda x,y: y.get('amount',0.0)+x, res, 0.0)
Expand Down
61 changes: 35 additions & 26 deletions addons/account/account_move_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,68 +42,77 @@ def _query_get(self, cr, uid, obj='l', context=None):
context = dict(context or {})
initial_bal = context.get('initial_bal', False)
company_clause = " "
if context.get('company_id', False):
company_clause = " AND " +obj+".company_id = %s" % context.get('company_id', False)
if not context.get('fiscalyear', False):
if context.get('all_fiscalyear', False):
query = ''
query_params = {}
if context.get('company_id'):
company_clause = " AND " +obj+".company_id = %(company_id)s"
query_params['company_id'] = context['company_id']
if not context.get('fiscalyear'):
if context.get('all_fiscalyear'):
#this option is needed by the aged balance report because otherwise, if we search only the draft ones, an open invoice of a closed fiscalyear won't be displayed
fiscalyear_ids = fiscalyear_obj.search(cr, uid, [])
else:
fiscalyear_ids = fiscalyear_obj.search(cr, uid, [('state', '=', 'draft')])
else:
#for initial balance as well as for normal query, we check only the selected FY because the best practice is to generate the FY opening entries
fiscalyear_ids = [context['fiscalyear']]
fiscalyear_ids = context['fiscalyear']
if isinstance(context['fiscalyear'], (int, long)):
fiscalyear_ids = [fiscalyear_ids]

fiscalyear_clause = (','.join([str(x) for x in fiscalyear_ids])) or '0'
query_params['fiscalyear_ids'] = tuple(fiscalyear_ids) or (0,)
state = context.get('state', False)
where_move_state = ''
where_move_lines_by_date = ''

if context.get('date_from', False) and context.get('date_to', False):
if context.get('date_from') and context.get('date_to'):
query_params['date_from'] = context['date_from']
query_params['date_to'] = context['date_to']
if initial_bal:
where_move_lines_by_date = " AND " +obj+".move_id IN (SELECT id FROM account_move WHERE date < '" +context['date_from']+"')"
where_move_lines_by_date = " AND " +obj+".move_id IN (SELECT id FROM account_move WHERE date < %(date_from)s)"
else:
where_move_lines_by_date = " AND " +obj+".move_id IN (SELECT id FROM account_move WHERE date >= '" +context['date_from']+"' AND date <= '"+context['date_to']+"')"
where_move_lines_by_date = " AND " +obj+".move_id IN (SELECT id FROM account_move WHERE date >= %(date_from)s AND date <= %(date_to)s)"

if state:
if state.lower() not in ['all']:
where_move_state= " AND "+obj+".move_id IN (SELECT id FROM account_move WHERE account_move.state = '"+state+"')"
if context.get('period_from', False) and context.get('period_to', False) and not context.get('periods', False):
query_params['state'] = state
where_move_state= " AND "+obj+".move_id IN (SELECT id FROM account_move WHERE account_move.state = %(state)s)"
if context.get('period_from') and context.get('period_to') and not context.get('periods'):
if initial_bal:
period_company_id = fiscalperiod_obj.browse(cr, uid, context['period_from'], context=context).company_id.id
first_period = fiscalperiod_obj.search(cr, uid, [('company_id', '=', period_company_id)], order='date_start', limit=1)[0]
context['periods'] = fiscalperiod_obj.build_ctx_periods(cr, uid, first_period, context['period_from'])
else:
context['periods'] = fiscalperiod_obj.build_ctx_periods(cr, uid, context['period_from'], context['period_to'])
if context.get('periods', False):
if context.get('periods'):
query_params['period_ids'] = tuple(context['periods'])
if initial_bal:
query = obj+".state <> 'draft' AND "+obj+".period_id IN (SELECT id FROM account_period WHERE fiscalyear_id IN (%s)) %s %s" % (fiscalyear_clause, where_move_state, where_move_lines_by_date)
query = obj+".state <> 'draft' AND "+obj+".period_id IN (SELECT id FROM account_period WHERE fiscalyear_id IN %(fiscalyear_ids)s)" + where_move_state + where_move_lines_by_date
period_ids = fiscalperiod_obj.search(cr, uid, [('id', 'in', context['periods'])], order='date_start', limit=1)
if period_ids and period_ids[0]:
first_period = fiscalperiod_obj.browse(cr, uid, period_ids[0], context=context)
ids = ','.join([str(x) for x in context['periods']])
query = obj+".state <> 'draft' AND "+obj+".period_id IN (SELECT id FROM account_period WHERE fiscalyear_id IN (%s) AND date_start <= '%s' AND id NOT IN (%s)) %s %s" % (fiscalyear_clause, first_period.date_start, ids, where_move_state, where_move_lines_by_date)
query_params['date_start'] = first_period.date_start
query = obj+".state <> 'draft' AND "+obj+".period_id IN (SELECT id FROM account_period WHERE fiscalyear_id IN %(fiscalyear_ids)s AND date_start <= %(date_start)s AND id NOT IN %(period_ids)s)" + where_move_state + where_move_lines_by_date
else:
ids = ','.join([str(x) for x in context['periods']])
query = obj+".state <> 'draft' AND "+obj+".period_id IN (SELECT id FROM account_period WHERE fiscalyear_id IN (%s) AND id IN (%s)) %s %s" % (fiscalyear_clause, ids, where_move_state, where_move_lines_by_date)
query = obj+".state <> 'draft' AND "+obj+".period_id IN (SELECT id FROM account_period WHERE fiscalyear_id IN %(fiscalyear_ids)s AND id IN %(period_ids)s)" + where_move_state + where_move_lines_by_date
else:
query = obj+".state <> 'draft' AND "+obj+".period_id IN (SELECT id FROM account_period WHERE fiscalyear_id IN (%s)) %s %s" % (fiscalyear_clause, where_move_state, where_move_lines_by_date)
query = obj+".state <> 'draft' AND "+obj+".period_id IN (SELECT id FROM account_period WHERE fiscalyear_id IN %(fiscalyear_ids)s)" + where_move_state + where_move_lines_by_date

if initial_bal and not context.get('periods', False) and not where_move_lines_by_date:
if initial_bal and not context.get('periods') and not where_move_lines_by_date:
#we didn't pass any filter in the context, and the initial balance can't be computed using only the fiscalyear otherwise entries will be summed twice
#so we have to invalidate this query
raise osv.except_osv(_('Warning!'),_("You have not supplied enough arguments to compute the initial balance, please select a period and a journal in the context."))

if context.get('journal_ids'):
query_params['journal_ids'] = tuple(context['journal_ids'])
query += ' AND '+obj+'.journal_id IN %(journal_ids)s'

if context.get('journal_ids', False):
query += ' AND '+obj+'.journal_id IN (%s)' % ','.join(map(str, context['journal_ids']))

if context.get('chart_account_id', False):
if context.get('chart_account_id'):
child_ids = account_obj._get_children_and_consol(cr, uid, [context['chart_account_id']], context=context)
query += ' AND '+obj+'.account_id IN (%s)' % ','.join(map(str, child_ids))
query_params['child_ids'] = tuple(child_ids)
query += ' AND '+obj+'.account_id IN %(child_ids)s'

query += company_clause
return query
return cr.mogrify(query, query_params)

def _amount_residual(self, cr, uid, ids, field_names, args, context=None):
"""
Expand Down Expand Up @@ -1234,7 +1243,7 @@ def _update_journal_check(self, cr, uid, journal_id, period_id, context=None):
period = period_obj.browse(cr, uid, period_id, context=context)
for (state,) in result:
if state == 'done':
raise osv.except_osv(_('Error!'), _('You can not add/modify entries in a closed period %s of journal %s.') % (period.name,journal.name))
raise osv.except_osv(_('Error!'), _('You can not add/modify entries in a closed period %s of journal %s.') % (period.name, journal.name))
if not result:
jour_period_obj.create(cr, uid, {
'name': (journal.code or journal.name)+':'+(period.name or ''),
Expand Down
Loading

0 comments on commit 4428226

Please sign in to comment.