summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorced <>2008-01-11 14:46:53 +0000
committerced <>2008-01-11 14:46:53 +0000
commit0dd50c7aa9aad5e8bdf8e8d869bb07cff2d7d42f (patch)
tree2ae69a79c930b3ed72611873bdaee939e23f07b0
parent248b0a2311a4ce0fe207a1c8b0d5f040089328f4 (diff)
Use all open fiscal year if no fiscal year is selected
bzr revid: ced-4e35c8995c3ad81fb345561ea235bff2e39b473b
-rw-r--r--addons/account/account.py13
-rw-r--r--addons/account/account_move_line.py12
-rw-r--r--addons/account/report/aged_trial_balance.py142
-rw-r--r--addons/account/report/partner_balance.py191
-rw-r--r--addons/account/report/third_party_ledger.py131
-rw-r--r--addons/account/wizard/wizard_account_balance_report.py3
-rw-r--r--addons/account/wizard/wizard_account_chart.py7
-rw-r--r--addons/account/wizard/wizard_aged_trial_balance.py3
-rw-r--r--addons/account/wizard/wizard_general_ledger_report.py3
-rw-r--r--addons/account/wizard/wizard_move_line_select.py16
-rw-r--r--addons/account/wizard/wizard_partner_balance_report.py3
-rw-r--r--addons/account/wizard/wizard_third_party_ledger.py3
12 files changed, 323 insertions, 204 deletions
diff --git a/addons/account/account.py b/addons/account/account.py
index bcabf37e6c4..76a85b173fd 100644
--- a/addons/account/account.py
+++ b/addons/account/account.py
@@ -149,10 +149,6 @@ class account_account(osv.osv):
order, context=context, count=count)
def _credit(self, cr, uid, ids, field_name, arg, context={}):
- if not 'fiscalyear' in context:
- context['fiscalyear'] = self.pool.get('account.fiscalyear').find(cr, uid,
- exception=False)
-
acc_set = ",".join(map(str, ids))
query = self.pool.get('account.move.line')._query_get(cr, uid, context=context)
cr.execute(("SELECT a.id, " \
@@ -174,10 +170,6 @@ class account_account(osv.osv):
return res
def _debit(self, cr, uid, ids, field_name, arg, context={}):
- if not 'fiscalyear' in context:
- context['fiscalyear'] = self.pool.get('account.fiscalyear').find(cr, uid,
- exception=False)
-
acc_set = ",".join(map(str, ids))
query = self.pool.get('account.move.line')._query_get(cr, uid, context=context)
cr.execute(("SELECT a.id, " \
@@ -199,11 +191,6 @@ class account_account(osv.osv):
return res
def _balance(self, cr, uid, ids, field_name, arg, context={}):
- fiscalyear_obj = self.pool.get('account.fiscalyear')
- if not 'fiscalyear' in context:
- context['fiscalyear'] = fiscalyear_obj.find(cr, uid,
- exception=False)
-
ids2 = self.search(cr, uid, [('parent_id', 'child_of', ids)])
ids2 = {}.fromkeys(ids + ids2).keys()
acc_set = ",".join(map(str, ids2))
diff --git a/addons/account/account_move_line.py b/addons/account/account_move_line.py
index fff29c6c63c..fca0007afff 100644
--- a/addons/account/account_move_line.py
+++ b/addons/account/account_move_line.py
@@ -38,13 +38,17 @@ class account_move_line(osv.osv):
_description = "Entry lines"
def _query_get(self, cr, uid, obj='l', context={}):
- if not 'fiscalyear' in context:
- context['fiscalyear'] = self.pool.get('account.fiscalyear').find(cr, uid, exception=False)
+ fiscalyear_obj = self.pool.get('account.fiscalyear')
+ if not context.get('fiscalyear', False):
+ fiscalyear_ids = fiscalyear_obj.search(cr, uid, [('state', '=', 'draft')])
+ fiscalyear_clause = ','.join([str(x) for x in fiscalyear_ids])
+ else:
+ fiscalyear_clause = '%s' % context['fiscalyear']
if context.get('periods', False):
ids = ','.join([str(x) for x in context['periods']])
- return obj+".active AND "+obj+".state<>'draft' AND "+obj+".period_id in (SELECT id from account_period WHERE fiscalyear_id=%d AND id in (%s))" % (context['fiscalyear'], ids)
+ return obj+".active AND "+obj+".state<>'draft' AND "+obj+".period_id in (SELECT id from account_period WHERE fiscalyear_id in (%s) AND id in (%s))" % (fiscalyear_clause, ids)
else:
- return obj+".active AND "+obj+".state<>'draft' AND "+obj+".period_id in (SELECT id from account_period WHERE fiscalyear_id=%d)" % (context['fiscalyear'],)
+ return obj+".active AND "+obj+".state<>'draft' AND "+obj+".period_id in (SELECT id from account_period WHERE fiscalyear_id in (%s))" % (fiscalyear_clause,)
def default_get(self, cr, uid, fields, context={}):
data = self._default_get(cr, uid, fields, context)
diff --git a/addons/account/report/aged_trial_balance.py b/addons/account/report/aged_trial_balance.py
index 3a4720f71b4..04ebb3c5388 100644
--- a/addons/account/report/aged_trial_balance.py
+++ b/addons/account/report/aged_trial_balance.py
@@ -48,47 +48,60 @@ class aged_trial_report(report_sxw.rml_parse):
def _get_lines(self, form):
self.form=form
res = []
- self.cr.execute("SELECT DISTINCT res_partner.id AS id, res_partner.name AS name, res_partner.ref AS code \
- FROM res_partner, account_move_line AS line, account_account \
- WHERE (line.account_id=account_account.id) AND (line.reconcile_id IS NULL) \
- AND (line.partner_id=res_partner.id) AND (line.state<>'draft') \
- AND (line.period_id in (SELECT id FROM account_period WHERE fiscalyear_id=%d))\
- AND (account_account.company_id = %d) AND account_account.active \
- ORDER BY res_partner.name", (form['fiscalyear'], form['company_id']))
+ account_move_line_obj = pooler.get_pool(self.cr.dbname).get('account.move.line')
+ line_query = account_move_line_obj._query_get(self.cr, self.uid, obj='line',
+ context={'fiscalyear': form['fiscalyear']})
+ self.cr.execute("SELECT DISTINCT res_partner.id AS id, " \
+ "res_partner.name AS name, res_partner.ref AS code " \
+ "FROM res_partner, account_move_line AS line, account_account " \
+ "WHERE (line.account_id=account_account.id) " \
+ "AND (line.reconcile_id IS NULL) " \
+ "AND (line.partner_id=res_partner.id) " \
+ "AND " + line_query + " " \
+ "AND (account_account.company_id = %d) " \
+ "AND account_account.active " \
+ "ORDER BY res_partner.name", (form['company_id'],))
partners = self.cr.dictfetchall()
for partner in partners:
values = {}
- a1 = "SELECT SUM(debit-credit) \
- FROM account_move_line AS line, account_account \
- WHERE (line.account_id=account_account.id) AND (account_account.type IN (%s)) \
- AND (date<'%s') AND (partner_id=%d) \
- AND (reconcile_id IS NULL) AND (line.state<>'draft') \
- AND (line.period_id in (SELECT id FROM account_period WHERE fiscalyear_id=%d)) \
- AND (account_account.company_id = %d) AND account_account.active" %(form['computation'], form['0']['start'], partner['id'], form['fiscalyear'], form['company_id'])
- self.cr.execute(a1)
+ self.cr.execute("SELECT SUM(debit-credit) " \
+ "FROM account_move_line AS line, account_account " \
+ "WHERE (line.account_id=account_account.id) " \
+ "AND (account_account.type IN (" + form['computation'] +")) " \
+ "AND (date < %s) AND (partner_id=%d) " \
+ "AND (reconcile_id IS NULL) " \
+ "AND " + line_query + " " \
+ "AND (account_account.company_id = %d) " \
+ "AND account_account.active",
+ (form['0']['start'], partner['id'], form['company_id']))
before = self.cr.fetchone()
values['before'] = before and before[0] or ""
for i in range(5):
- a2 = "SELECT SUM(debit-credit) \
- FROM account_move_line AS line, account_account \
- WHERE (line.account_id=account_account.id) AND (account_account.type IN (%s)) \
- AND (date >= '%s') AND (date <= '%s') \
- AND (partner_id=%d) AND (reconcile_id IS NULL) \
- AND line.state<>'draft' AND (line.period_id in (SELECT id FROM account_period WHERE fiscalyear_id=%d)) \
- AND (account_account.company_id = %d) AND account_account.active" %(form['computation'], form[str(i)]['start'], form[str(i)]['stop'], partner['id'], form['fiscalyear'], form['company_id'])
- self.cr.execute(a2)
+ self.cr.execute("SELECT SUM(debit-credit) " \
+ "FROM account_move_line AS line, account_account " \
+ "WHERE (line.account_id=account_account.id) " \
+ "AND (account_account.type IN (" + form['computation'] + ")) " \
+ "AND (date >= %s) AND (date <= %s) " \
+ "AND (partner_id = %d) " \
+ "AND (reconcile_id IS NULL) " \
+ "AND " + line_query + " " \
+ "AND (account_account.company_id = %d) " \
+ "AND account_account.active",
+ (form[str(i)]['start'], form[str(i)]['stop'],
+ partner['id'], form['company_id']))
during = self.cr.fetchone()
values[str(i)] = during and during[0] or ""
-
- a3 = "SELECT SUM(debit-credit) \
- FROM account_move_line AS line, account_account \
- WHERE (line.account_id=account_account.id) AND (account_account.type IN (%s)) \
- AND (partner_id = %d) AND (reconcile_id IS NULL) \
- AND (line.state <> 'draft') AND (line.period_id in (SELECT id FROM account_period WHERE fiscalyear_id=%d)) \
- AND (account_account.company_id = %d) AND account_account.active" %(form['computation'], partner['id'], form['fiscalyear'], form['company_id'])
-
- self.cr.execute(a3)
+ self.cr.execute("SELECT SUM(debit-credit) " \
+ "FROM account_move_line AS line, account_account " \
+ "WHERE (line.account_id = account_account.id) " \
+ "AND (account_account.type IN (" + form['computation'] + ")) " \
+ "AND (partner_id = %d) " \
+ "AND (reconcile_id IS NULL) " \
+ "AND " + line_query + " " \
+ "AND (account_account.company_id = %d) " \
+ "AND account_account.active",
+ (partner['id'], form['company_id']))
total = self.cr.fetchone()
values['total'] = total and total[0] or 0.0
values['name'] = partner['name']
@@ -110,37 +123,56 @@ class aged_trial_report(report_sxw.rml_parse):
return res
def _get_total(self, fiscalyear, company_id):
- tot = "SELECT SUM(debit-credit) \
- FROM account_move_line AS line, account_account \
- WHERE (line.account_id=account_account.id) AND (account_account.type IN (%s)) \
- AND reconcile_id IS NULL AND (line.state<>'draft') \
- AND partner_id is not null AND (line.period_id in (SELECT id FROM account_period WHERE fiscalyear_id=%d)) \
- AND (account_account.company_id = %d) AND account_account.active" %(self.form['computation'], fiscalyear, company_id)
- self.cr.execute(tot)
+ account_move_line_obj = pooler.get_pool(self.cr.dbname).get('account.move.line')
+ line_query = account_move_line_obj._query_get(self.cr, self.uid, obj='line',
+ context={'fiscalyear': fiscalyear})
+ self.cr.execute("SELECT SUM(debit - credit) " \
+ "FROM account_move_line AS line, account_account " \
+ "WHERE (line.account_id = account_account.id) " \
+ "AND (account_account.type IN (" + self.form['computation'] + ")) "\
+ "AND reconcile_id IS NULL " \
+ "AND partner_id is NOT NULL " \
+ "AND " + line_query + " " \
+ "AND (account_account.company_id = %d) " \
+ "AND account_account.active",
+ (company_id,))
total = self.cr.fetchone()
return total and total[0] or 0.0
def _get_before(self, date, fiscalyear, company_id):
- bef = "SELECT SUM(debit-credit) \
- FROM account_move_line AS line, account_account \
- WHERE (line.account_id=account_account.id) AND (account_account.type IN (%s)) \
- AND reconcile_id IS NULL AND (date < '%s') \
- AND (line.state <> 'draft') AND partner_id is not null \
- AND (line.period_id in (SELECT id FROM account_period WHERE fiscalyear_id = %d)) \
- AND (account_account.company_id = %d) AND account_account.active" %(self.form['computation'], date, fiscalyear, company_id)
- self.cr.execute(bef)
+ account_move_line_obj = pooler.get_pool(self.cr.dbname).get('account.move.line')
+ line_query = account_move_line_obj._query_get(self.cr, self.uid, obj='line',
+ context={'fiscalyear': fiscalyear})
+ self.cr.execute("SELECT SUM(debit - credit) " \
+ "FROM account_move_line AS line, account_account " \
+ "WHERE (line.account_id = account_account.id) " \
+ "AND (account_account.type IN (" + self.form['computation'] + ")) " \
+ "AND reconcile_id IS NULL " \
+ "AND (date < %s) " \
+ "AND partner_id IS NOT NULL " \
+ "AND " + line_query + " " \
+ "AND (account_account.company_id = %d) " \
+ "AND account_account.active",
+ (date, company_id))
before = self.cr.fetchone()
return before and before[0] or 0.0
def _get_for_period(self, period, fiscalyear, company_id):
- per = "SELECT SUM(debit-credit) \
- FROM account_move_line AS line, account_account \
- WHERE (line.account_id=account_account.id) AND (account_account.type IN (%s)) \
- AND reconcile_id IS NULL AND (date >= '%s') AND (date <= '%s') \
- AND (line.state<>'draft') AND partner_id is not null \
- AND (line.period_id in (SELECT id FROM account_period WHERE fiscalyear_id = %d)) \
- AND (account_account.company_id = %d) AND account_account.active" %(self.form['computation'], period['start'], period['stop'], fiscalyear, company_id)
- self.cr.execute(per)
+ account_move_line_obj = pooler.get_pool(self.cr.dbname).get('account.move.line')
+ line_query = account_move_line_obj._query_get(self.cr, self.uid, obj='line',
+ context={'fiscalyear': fiscalyear})
+ self.cr.execute("SELECT SUM(debit - credit) " \
+ "FROM account_move_line AS line, account_account " \
+ "WHERE (line.account_id = account_account.id) " \
+ "AND (account_account.type IN (" + self.form['computation'] + ")) " \
+ "AND reconcile_id IS NULL " \
+ "AND (date >= %s) " \
+ "AND (date <= %s) " \
+ "AND partner_id IS NOT NULL " \
+ "AND " + line_query + " " \
+ "AND (account_account.company_id = %d) " \
+ "AND account_account.active",
+ (period['start'], period['stop'], company_id))
period = self.cr.fetchone()
return period and period[0] or 0.0
diff --git a/addons/account/report/partner_balance.py b/addons/account/report/partner_balance.py
index cd9c4f25aa2..ac92ab8c804 100644
--- a/addons/account/report/partner_balance.py
+++ b/addons/account/report/partner_balance.py
@@ -47,13 +47,28 @@ class partner_balance(report_sxw.rml_parse):
})
def preprocess(self, objects, data, ids):
- self.cr.execute('select distinct line.partner_id \
- from account_move_line AS line, account_account AS account \
- where line.partner_id is not null and line.date>=%s and line.date<=%s \
- and line.period_id in (SELECT id FROM account_period WHERE fiscalyear_id=%d) \
- AND line.account_id = account.id AND account.company_id = %d AND account.active', (data['form']['date1'], data['form']['date2'], data['form']['fiscalyear'], data['form']['company_id']))
+ account_move_line_obj = pooler.get_pool(self.cr.dbname).get('account.move.line')
+ line_query = account_move_line_obj._query_get(self.cr, self.uid, obj='line',
+ context={'fiscalyear': data['form']['fiscalyear']})
+ self.cr.execute('SELECT DISTINCT line.partner_id ' \
+ 'FROM account_move_line AS line, account_account AS account ' \
+ 'WHERE line.partner_id IS NOT NULL ' \
+ 'AND line.date >= %s ' \
+ 'AND line.date <= %s ' \
+ 'AND ' + line_query + ' ' \
+ 'AND line.account_id = account.id ' \
+ 'AND account.company_id = %d ' \
+ 'AND account.active',
+ (data['form']['date1'], data['form']['date2'],
+ data['form']['company_id']))
new_ids = [id for (id,) in self.cr.fetchall()]
- self.cr.execute("SELECT a.id FROM account_account a LEFT JOIN account_account_type t ON (a.type=t.code) WHERE t.partner_account=TRUE AND a.company_id = %d AND a.active", (data['form']['company_id'],))
+ self.cr.execute('SELECT a.id ' \
+ 'FROM account_account a ' \
+ 'LEFT JOIN account_account_type t ' \
+ 'ON (a.type = t.code) ' \
+ 'WHERE t.partner_account = TRUE ' \
+ 'AND a.company_id = %d ' \
+ 'AND a.active', (data['form']['company_id'],))
self.account_ids = ','.join([str(a) for (a,) in self.cr.fetchall()])
self.partner_ids = ','.join(map(str, new_ids))
objects = self.pool.get('res.partner').browse(self.cr, self.uid, new_ids)
@@ -62,109 +77,137 @@ class partner_balance(report_sxw.rml_parse):
def lines(self):
if not self.partner_ids:
return []
-
-#TODO: use an SQL CASE to compute sdebit and scredit
+ account_move_line_obj = pooler.get_pool(self.cr.dbname).get('account.move.line')
+ line_query = account_move_line_obj._query_get(self.cr, self.uid, obj='l',
+ context={'fiscalyear': self.datas['form']['fiscalyear']})
self.cr.execute(
"SELECT p.ref, p.name, sum(debit) as debit, sum(credit) as credit, " \
- "(SELECT sum(debit-credit) FROM account_move_line WHERE partner_id=p.id AND date>=%s AND date<=%s AND blocked=TRUE AND state <>'draft' AND period_id in (SELECT id FROM account_period WHERE fiscalyear_id=%d)) as enlitige " \
+ "CASE WHEN sum(debit) > sum(credit) " \
+ "THEN sum(debit) - sum(credit) " \
+ "ELSE 0 " \
+ "END AS sdebit, " \
+ "CASE WHEN sum(debit) < sum(credit) " \
+ "THEN sum(credit) - sum(debit) " \
+ "ELSE 0 " \
+ "END AS scredit, " \
+ "(SELECT sum(debit-credit) " \
+ "FROM account_move_line l " \
+ "WHERE partner_id = p.id " \
+ "AND date >= %s " \
+ "AND date <= %s " \
+ "AND blocked = TRUE " \
+ "AND " + line_query + " " \
+ ") AS enlitige " \
"FROM account_move_line l LEFT JOIN res_partner p ON (l.partner_id=p.id) " \
"WHERE partner_id IN (" + self.partner_ids + ") " \
- "AND account_id IN (" + self.account_ids + ") " \
- "AND l.date>=%s AND l.date<=%s " \
- "AND l.state<>'draft' " \
- "AND l.period_id in (SELECT id FROM account_period WHERE fiscalyear_id=%d) " \
+ "AND account_id IN (" + self.account_ids + ") " \
+ "AND l.date >= %s " \
+ "AND l.date <= %s " \
+ "AND " + line_query + " " \
"GROUP BY p.id, p.ref, p.name " \
"ORDER BY p.ref, p.name",
- (self.datas['form']['date1'], self.datas['form']['date2'], self.datas['form']['fiscalyear'], self.datas['form']['date1'], self.datas['form']['date2'], self.datas['form']['fiscalyear']))
+ (self.datas['form']['date1'], self.datas['form']['date2'],
+ self.datas['form']['date1'], self.datas['form']['date2']))
res = self.cr.dictfetchall()
- for r in res:
- r['sdebit'] = r['debit'] > r['credit'] and r['debit'] - r['credit']
- r['scredit'] = r['credit'] > r['debit'] and r['credit'] - r['debit']
return res
-
+
def _sum_debit(self):
if not self.ids:
return 0.0
-
+ account_move_line_obj = pooler.get_pool(self.cr.dbname).get('account.move.line')
+ line_query = account_move_line_obj._query_get(self.cr, self.uid,
+ obj='account_move_line',
+ context={'fiscalyear': self.datas['form']['fiscalyear']})
self.cr.execute(
- 'SELECT sum(debit) ' \
- 'FROM account_move_line ' \
- 'WHERE partner_id IN (' + self.partner_ids + ') ' \
- 'AND account_id IN (' + self.account_ids + ') ' \
- "AND state<>'draft' " \
- 'AND date>=%s AND date<=%s ' \
- "AND period_id in (SELECT id FROM account_period WHERE fiscalyear_id=%d)",
- (self.datas['form']['date1'], self.datas['form']['date2'], self.datas['form']['fiscalyear']))
+ 'SELECT sum(debit) ' \
+ 'FROM account_move_line ' \
+ 'WHERE partner_id IN (' + self.partner_ids + ') ' \
+ 'AND account_id IN (' + self.account_ids + ') ' \
+ 'AND date >=%s ' \
+ 'AND date <= %s ' \
+ 'AND ' + line_query,
+ (self.datas['form']['date1'], self.datas['form']['date2']))
return self.cr.fetchone()[0] or 0.0
-
+
def _sum_credit(self):
if not self.ids:
return 0.0
-
+ account_move_line_obj = pooler.get_pool(self.cr.dbname).get('account.move.line')
+ line_query = account_move_line_obj._query_get(self.cr, self.uid,
+ obj='account_move_line',
+ context={'fiscalyear': self.datas['form']['fiscalyear']})
self.cr.execute(
- 'SELECT sum(credit) ' \
- 'FROM account_move_line ' \
- 'WHERE partner_id IN (' + self.partner_ids + ') ' \
- 'AND account_id IN (' + self.account_ids + ') ' \
- "AND state<>'draft' " \
- 'AND date>=%s AND date<=%s ' \
- 'AND period_id in (SELECT id FROM account_period WHERE fiscalyear_id=%d)',
- (self.datas['form']['date1'], self.datas['form']['date2'], self.datas['form']['fiscalyear']))
+ 'SELECT sum(credit) ' \
+ 'FROM account_move_line ' \
+ 'WHERE partner_id IN (' + self.partner_ids + ') ' \
+ 'AND account_id IN (' + self.account_ids + ') ' \
+ 'AND date >= %s ' \
+ 'AND date <= %s ' \
+ 'AND ' + line_query,
+ (self.datas['form']['date1'], self.datas['form']['date2']))
return self.cr.fetchone()[0] or 0.0
def _sum_litige(self):
if not self.ids:
return 0.0
-
+ account_move_line_obj = pooler.get_pool(self.cr.dbname).get('account.move.line')
+ line_query = account_move_line_obj._query_get(self.cr, self.uid,
+ obj='account_move_line',
+ context={'fiscalyear': self.datas['form']['fiscalyear']})
self.cr.execute(
- 'SELECT sum(debit-credit) ' \
- 'FROM account_move_line ' \
- 'WHERE partner_id IN (' + self.partner_ids + ') ' \
- 'AND account_id IN (' + self.account_ids + ') ' \
- "AND state<>'draft' " \
- 'AND date>=%s AND date<=%s AND blocked=TRUE ' \
- 'AND period_id in (SELECT id FROM account_period WHERE fiscalyear_id=%d)',
- (self.datas['form']['date1'], self.datas['form']['date2'], self.datas['form']['fiscalyear']))
+ 'SELECT sum(debit-credit) ' \
+ 'FROM account_move_line ' \
+ 'WHERE partner_id IN (' + self.partner_ids + ') ' \
+ 'AND account_id IN (' + self.account_ids + ') ' \
+ 'AND date >= %s ' \
+ 'AND date <= %s ' \
+ 'AND blocked=TRUE ' \
+ 'AND ' + line_query,
+ (self.datas['form']['date1'], self.datas['form']['date2']))
return self.cr.fetchone()[0] or 0.0
-
+
def _sum_sdebit(self):
if not self.ids:
return 0.0
-
+ account_move_line_obj = pooler.get_pool(self.cr.dbname).get('account.move.line')
+ line_query = account_move_line_obj._query_get(self.cr, self.uid,
+ obj='account_move_line',
+ context={'fiscalyear': self.datas['form']['fiscalyear']})
self.cr.execute(
- 'SELECT sum(debit-credit) ' \
- 'FROM (' \
- 'SELECT sum(debit), sum(credit) ' \
- 'FROM account_move_line ' \
- 'WHERE partner_id IN (' + self.partner_ids + ') ' \
+ 'SELECT CASE WHEN sum(debit) > sum(credit) ' \
+ 'THEN sum(debit - credit) ' \
+ 'ELSE 0 ' \
+ 'END ' \
+ 'FROM account_move_line ' \
+ 'WHERE partner_id IN (' + self.partner_ids + ') ' \
'AND account_id IN (' + self.account_ids + ') ' \
- 'AND date>=%s AND date<=%s ' \
- "AND state<>'draft' " \
- "AND period_id in (SELECT id FROM account_period WHERE fiscalyear_id=%d) " \
- 'GROUP BY partner_id' \
- ') AS dc (debit,credit) ' \
- 'WHERE debit>credit',
- (self.datas['form']['date1'], self.datas['form']['date2'], self.datas['form']['fiscalyear']))
+ 'AND date >= %s ' \
+ 'AND date <= %s ' \
+ 'AND ' + line_query + ' ' \
+ 'GROUP BY partner_id',
+ (self.datas['form']['date1'], self.datas['form']['date2']))
return self.cr.fetchone()[0] or 0.0
-
+
def _sum_scredit(self):
if not self.ids:
return 0.0
-
+ account_move_line_obj = pooler.get_pool(self.cr.dbname).get('account.move.line')
+ line_query = account_move_line_obj._query_get(self.cr, self.uid,
+ obj='account_move_line',
+ context={'fiscalyear': self.datas['form']['fiscalyear']})
self.cr.execute(
- 'SELECT sum(credit-debit) ' \
- 'FROM (' \
- 'SELECT sum(debit), sum(credit) ' \
- 'FROM account_move_line ' \
- 'WHERE partner_id IN (' + self.partner_ids + ') ' \
+ 'SELECT CASE WHEN sum(debit) < sum(credit) ' \
+ 'THEN sum(credit - debit) ' \
+ 'ELSE 0 ' \
+ 'END ' \
+ 'FROM account_move_line ' \
+ 'WHERE partner_id IN (' + self.partner_ids + ') ' \
'AND account_id IN (' + self.account_ids + ') ' \
- 'AND date>=%s AND date<=%s ' \
- "AND state<>'draft' " \
- "AND period_id in (SELECT id FROM account_period WHERE fiscalyear_id=%d) " \
- 'GROUP BY partner_id' \
- ') AS dc (debit,credit) ' \
- 'WHERE credit>debit',
- (self.datas['form']['date1'], self.datas['form']['date2'], self.datas['form']['fiscalyear']))
+ 'AND date >= %s ' \
+ 'AND date <= %s ' \
+ 'AND ' + line_query + ' ' \
+ 'GROUP BY partner_id',
+ (self.datas['form']['date1'], self.datas['form']['date2']))
return self.cr.fetchone()[0] or 0.0
def _solde_balance_debit(self):
diff --git a/addons/account/report/third_party_ledger.py b/addons/account/report/third_party_ledger.py
index efae4c55dcf..c9e760fd623 100644
--- a/addons/account/report/third_party_ledger.py
+++ b/addons/account/report/third_party_ledger.py
@@ -44,87 +44,124 @@ class third_party_ledger(report_sxw.rml_parse):
})
def preprocess(self, objects, data, ids):
+ account_move_line_obj = pooler.get_pool(self.cr.dbname).get('account.move.line')
+ line_query = account_move_line_obj._query_get(self.cr, self.uid, obj='line',
+ context={'fiscalyear': data['form']['fiscalyear']})
self.cr.execute(
- "SELECT DISTINCT line.partner_id " \
- "FROM account_move_line AS line, account_account AS account " \
- "WHERE line.partner_id IS NOT NULL AND line.date>=%s AND line.date<=%s AND line.state<>'draft' AND line.period_id in (SELECT id FROM account_period WHERE fiscalyear_id=%d) " \
- "AND line.account_id = account.id AND account.company_id = %d AND account.active",
- (data['form']['date1'], data['form']['date2'], data['form']['fiscalyear'], data['form']['company_id']))
+ "SELECT DISTINCT line.partner_id " \
+ "FROM account_move_line AS line, account_account AS account " \
+ "WHERE line.partner_id IS NOT NULL " \
+ "AND line.date >= %s " \
+ "AND line.date <= %s " \
+ "AND " + line_query + " " \
+ "AND line.account_id = account.id " \
+ "AND account.company_id = %d " \
+ "AND account.active",
+ (data['form']['date1'], data['form']['date2'],
+ data['form']['company_id']))
new_ids = [id for (id,) in self.cr.fetchall()]
self.cr.execute(
"SELECT a.id " \
- "FROM account_account a LEFT JOIN account_account_type t ON (a.type=t.code) " \
- "WHERE t.partner_account=TRUE AND a.company_id = %d AND a.active", (data['form']['company_id'],))
+ "FROM account_account a " \
+ "LEFT JOIN account_account_type t " \
+ "ON (a.type=t.code) " \
+ "WHERE t.partner_account=TRUE " \
+ "AND a.company_id = %d " \
+ "AND a.active", (data['form']['company_id'],))
self.account_ids = ','.join([str(a) for (a,) in self.cr.fetchall()])
self.partner_ids = ','.join(map(str, new_ids))
objects = self.pool.get('res.partner').browse(self.cr, self.uid, new_ids)
super(third_party_ledger, self).preprocess(objects, data, new_ids)
def lines(self, partner):
+ account_move_line_obj = pooler.get_pool(self.cr.dbname).get('account.move.line')
+ line_query = account_move_line_obj._query_get(self.cr, self.uid, obj='l',
+ context={'fiscalyear': self.datas['form']['fiscalyear']})
self.cr.execute(
- "SELECT l.date, j.code, l.ref, l.name, l.debit, l.credit " \
- "FROM account_move_line l LEFT JOIN account_journal j ON (l.journal_id=j.id) " \
- "WHERE l.partner_id=%d " \
- "AND l.account_id IN (" + self.account_ids + ") " \
- "AND l.date>=%s AND l.date<=%s AND state<>'draft' " \
- "AND l.period_id in (SELECT id FROM account_period WHERE fiscalyear_id=%d) "\
- "ORDER BY l.id",
- (partner.id, self.datas['form']['date1'], self.datas['form']['date2'], self.datas['form']['fiscalyear']))
+ "SELECT l.date, j.code, l.ref, l.name, l.debit, l.credit " \
+ "FROM account_move_line l " \
+ "LEFT JOIN account_journal j " \
+ "ON (l.journal_id = j.id) " \
+ "WHERE l.partner_id = %d " \
+ "AND l.account_id IN (" + self.account_ids + ") " \
+ "AND l.date >= %s " \
+ "AND l.date <= %s "
+ "AND " + line_query + " " \
+ "ORDER BY l.id",
+ (partner.id, self.datas['form']['date1'], self.datas['form']['date2']))
res = self.cr.dictfetchall()
sum = 0.0
for r in res:
sum += r['debit'] - r['credit']
- r['progress'] = sum
+ r['progress'] = sum
return res
-
+
def _sum_debit_partner(self, partner):
+ account_move_line_obj = pooler.get_pool(self.cr.dbname).get('account.move.line')
+ line_query = account_move_line_obj._query_get(self.cr, self.uid,
+ obj='account_move_line',
+ context={'fiscalyear': self.datas['form']['fiscalyear']})
self.cr.execute(
- "SELECT sum(debit) " \
- "FROM account_move_line " \
- "WHERE partner_id=%d " \
- "AND account_id IN (" + self.account_ids + ") " \
- "AND date>=%s AND date<=%s AND state<>'draft' " \
- "AND period_id in (SELECT id FROM account_period WHERE fiscalyear_id=%d)",
- (partner.id, self.datas['form']['date1'], self.datas['form']['date2'], self.datas['form']['fiscalyear']))
+ "SELECT sum(debit) " \
+ "FROM account_move_line " \
+ "WHERE partner_id = %d " \
+ "AND account_id IN (" + self.account_ids + ") " \
+ "AND date >= %s " \
+ "AND date <= %s " \
+ "AND " + line_query,
+ (partner.id, self.datas['form']['date1'], self.datas['form']['date2']))
return self.cr.fetchone()[0] or 0.0
def _sum_credit_partner(self, partner):
+ account_move_line_obj = pooler.get_pool(self.cr.dbname).get('account.move.line')
+ line_query = account_move_line_obj._query_get(self.cr, self.uid,
+ obj='account_move_line',
+ context={'fiscalyear': self.datas['form']['fiscalyear']})
self.cr.execute(
- "SELECT sum(credit) " \
- "FROM account_move_line " \
- "WHERE partner_id=%d " \
- "AND account_id IN (" + self.account_ids + ") " \
- "AND date>=%s AND date<=%s AND state<>'draft' " \
- "AND period_id in (SELECT id FROM account_period WHERE fiscalyear_id=%d)",
- (partner.id, self.datas["form"]["date1"], self.datas["form"]["date2"], self.datas['form']['fiscalyear']))
+ "SELECT sum(credit) " \
+ "FROM account_move_line " \
+ "WHERE partner_id=%d " \
+ "AND account_id IN (" + self.account_ids + ") " \
+ "AND date >= %s " \
+ "AND date <= %s " \
+ "AND " + line_query,
+ (partner.id, self.datas["form"]["date1"], self.datas["form"]["date2"]))
return self.cr.fetchone()[0] or 0.0
def _sum_debit(self):
if not self.ids:
return 0.0
-
+ account_move_line_obj = pooler.get_pool(self.cr.dbname).get('account.move.line')
+ line_query = account_move_line_obj._query_get(self.cr, self.uid,
+ obj='account_move_line',
+ context={'fiscalyear': self.datas['form']['fiscalyear']})
self.cr.execute(
- "SELECT sum(debit) " \
- "FROM account_move_line " \
- "WHERE partner_id IN (" + self.partner_ids + ") " \
- "AND account_id IN (" + self.account_ids + ") " \
- "AND date>=%s AND date<=%s AND state<>'draft'" \
- "AND period_id in (SELECT id FROM account_period WHERE fiscalyear_id=%d)",
- (self.datas['form']['date1'], self.datas['form']['date2'], self.datas['form']['fiscalyear']))
+ "SELECT sum(debit) " \
+ "FROM account_move_line " \
+ "WHERE partner_id IN (" + self.partner_ids + ") " \
+ "AND account_id IN (" + self.account_ids + ") " \
+ "AND date >= %s " \
+ "AND date <= %s " \
+ "AND " + line_query,
+ (self.datas['form']['date1'], self.datas['form']['date2']))
return self.cr.fetchone()[0] or 0.0
def _sum_credit(self):
if not self.ids:
return 0.0
-
+ account_move_line_obj = pooler.get_pool(self.cr.dbname).get('account.move.line')
+ line_query = account_move_line_obj._query_get(self.cr, self.uid,
+ obj='account_move_line',
+ context={'fiscalyear': self.datas['form']['fiscalyear']})
self.cr.execute(
- "SELECT sum(credit) " \
- "FROM account_move_line " \
- "WHERE partner_id IN (" + self.partner_ids + ") " \
- "AND account_id IN (" + self.account_ids + ") " \
- "AND date>=%s AND date<=%s AND state<>'draft'" \
- "AND period_id in (SELECT id FROM account_period WHERE fiscalyear_id=%d)",
- (self.datas['form']['date1'], self.datas['form']['date2'], self.datas['form']['fiscalyear']))
+ "SELECT sum(credit) " \
+ "FROM account_move_line " \
+ "WHERE partner_id IN (" + self.partner_ids + ") " \
+ "AND account_id IN (" + self.account_ids + ") " \
+ "AND date >= %s " \
+ "AND date <= %s " \
+ "AND " + line_query,
+ (self.datas['form']['date1'], self.datas['form']['date2']))
return self.cr.fetchone()[0] or 0.0
def _get_company(self, form):
diff --git a/addons/account/wizard/wizard_account_balance_report.py b/addons/account/wizard/wizard_account_balance_report.py
index 74879a5abc0..f8f799f1ca1 100644
--- a/addons/account/wizard/wizard_account_balance_report.py
+++ b/addons/account/wizard/wizard_account_balance_report.py
@@ -35,7 +35,8 @@ dates_form = '''<?xml version="1.0"?>
</form>'''
dates_fields = {
- 'fiscalyear': {'string': 'Fiscal year', 'type': 'many2one', 'relation': 'account.fiscalyear', 'required': True},
+ 'fiscalyear': {'string': 'Fiscal year', 'type': 'many2one', 'relation': 'account.fiscalyear',
+ 'help': 'Keep empty for all open fiscal year'},
'periods': {'string': 'Periods', 'type': 'many2many', 'relation': 'account.period', 'help': 'All periods if empty'}
}
diff --git a/addons/account/wizard/wizard_account_chart.py b/addons/account/wizard/wizard_account_chart.py
index 9a67211a345..a1693a35555 100644
--- a/addons/account/wizard/wizard_account_chart.py
+++ b/addons/account/wizard/wizard_account_chart.py
@@ -36,7 +36,12 @@ class wizard_account_chart(wizard.interface):
</form>'''
_account_chart_fields = {
- 'fiscalyear': {'string': 'Fiscal year', 'type': 'many2one', 'relation': 'account.fiscalyear', 'required': True },
+ 'fiscalyear': {
+ 'string': 'Fiscal year',
+ 'type': 'many2one',
+ 'relation': 'account.fiscalyear',
+ 'help': 'Keep empty for all open fiscal year',
+ },
}
def _get_defaults(self, cr, uid, data, context):
diff --git a/addons/account/wizard/wizard_aged_trial_balance.py b/addons/account/wizard/wizard_aged_trial_balance.py
index 0b8af52270a..549fc2967e2 100644
--- a/addons/account/wizard/wizard_aged_trial_balance.py
+++ b/addons/account/wizard/wizard_aged_trial_balance.py
@@ -48,7 +48,8 @@ _aged_trial_form = """<?xml version="1.0"?>
_aged_trial_fields = {
'company_id': {'string': 'Company', 'type': 'many2one', 'relation': 'res.company', 'required': True},
- 'fiscalyear': {'string': 'Fiscal year', 'type': 'many2one', 'relation': 'account.fiscalyear', 'required': True},
+ 'fiscalyear': {'string': 'Fiscal year', 'type': 'many2one', 'relation': 'account.fiscalyear',
+ 'help': 'Keep empty for all open fiscal year'},
'period_length': {'string': 'Period length (days)', 'type': 'integer', 'required': True, 'default': lambda *a:30},
'sorting_on':{'string': 'Sorting On', 'type': 'selection', 'selection': [('partner','By Partner Name (asc)'), ('amount','By Amount (desc)')],'required': True, 'default': lambda *a:'partner'},
'computation':{'string': 'Computational Method', 'type': 'selection', 'selection': [("\'receivable\'",'On Receivables Only'), ("\'payable\'",'On Payables Only'), ("\'receivable\',\'payable\'",'On Receivables & Payables')], 'required': True, 'default': lambda *a:"\'receivable\'"}
diff --git a/addons/account/wizard/wizard_general_ledger_report.py b/addons/account/wizard/wizard_general_ledger_report.py
index c6e420aa4d6..2c4332e6be2 100644
--- a/addons/account/wizard/wizard_general_ledger_report.py
+++ b/addons/account/wizard/wizard_general_ledger_report.py
@@ -35,7 +35,8 @@ dates_form = '''<?xml version="1.0"?>
</form>'''
dates_fields = {
- 'fiscalyear': {'string': 'Fiscal year', 'type': 'many2one', 'relation': 'account.fiscalyear', 'required': True},
+ 'fiscalyear': {'string': 'Fiscal year', 'type': 'many2one', 'relation': 'account.fiscalyear',
+ 'help': 'Keep empty for all open fiscal year'},
'periods': {'string': 'Periods', 'type': 'many2many', 'relation': 'account.period', 'help': 'All periods if empty'}
}
diff --git a/addons/account/wizard/wizard_move_line_select.py b/addons/account/wizard/wizard_move_line_select.py
index a2d6abe7f45..a2f8e5346b5 100644
--- a/addons/account/wizard/wizard_move_line_select.py
+++ b/addons/account/wizard/wizard_move_line_select.py
@@ -35,16 +35,22 @@ class wizard_move_line_select(wizard.interface):
act_obj = pooler.get_pool(cr.dbname).get('ir.actions.act_window')
fiscalyear_obj = pooler.get_pool(cr.dbname).get('account.fiscalyear')
- if not 'fiscalyear' in context:
- context['fiscalyear'] = fiscalyear_obj.find(cr, uid)
+ if not context.get('fiscalyear', False):
+ fiscalyear_ids = fiscalyear_obj.search(cr, uid, [('state', '=', 'draft')])
+ else:
+ fiscalyear_ids = [context['fiscalyear']]
- fy = fiscalyear_obj.browse(cr, uid, [context['fiscalyear']])[0]
- domain = str(('period_id', 'in', [x.id for x in fy.period_ids]))
+ fiscalyears = fiscalyear_obj.browse(cr, uid, fiscalyear_ids)
+ period_ids = []
+ for fiscalyear in fiscalyears:
+ for period in fiscalyear.period_ids:
+ period_ids.append(period.id)
+ domain = str(('period_id', 'in', period_ids))
result = mod_obj._get_id(cr, uid, 'account', 'action_move_line_tree1')
id = mod_obj.read(cr, uid, [result], ['res_id'])[0]['res_id']
result = act_obj.read(cr, uid, [id])[0]
- result['context'] = str({'fiscalyear': context['fiscalyear']})
+ result['context'] = str({'fiscalyear': context.get('fiscalyear', False)})
result['domain']=result['domain'][0:-1]+','+domain+result['domain'][-1]
return result
diff --git a/addons/account/wizard/wizard_partner_balance_report.py b/addons/account/wizard/wizard_partner_balance_report.py
index 0112639b86c..2414e102fc9 100644
--- a/addons/account/wizard/wizard_partner_balance_report.py
+++ b/addons/account/wizard/wizard_partner_balance_report.py
@@ -41,7 +41,8 @@ dates_form = '''<?xml version="1.0"?>
dates_fields = {
'company_id': {'string': 'Company', 'type': 'many2one', 'relation': 'res.company', 'required': True},
- 'fiscalyear': {'string': 'Fiscal year', 'type': 'many2one', 'relation': 'account.fiscalyear', 'required': True},
+ 'fiscalyear': {'string': 'Fiscal year', 'type': 'many2one', 'relation': 'account.fiscalyear',
+ 'help': 'Keep empty for all open fiscal year'},
'date1': {'string':'Start of period', 'type':'date', 'required':True, 'default': lambda *a: time.strftime('%Y-01-01')},
'date2': {'string':'End of period', 'type':'date', 'required':True, 'default': lambda *a: time.strftime('%Y-%m-%d')},
}
diff --git a/addons/account/wizard/wizard_third_party_ledger.py b/addons/account/wizard/wizard_third_party_ledger.py
index 4e492b4393a..0c8d7aa2ba0 100644
--- a/addons/account/wizard/wizard_third_party_ledger.py
+++ b/addons/account/wizard/wizard_third_party_ledger.py
@@ -40,7 +40,8 @@ dates_form = '''<?xml version="1.0"?>
dates_fields = {
'company_id': {'string': 'Company', 'type': 'many2one', 'relation': 'res.company', 'required': True},
- 'fiscalyear': {'string': 'Fiscal year', 'type': 'many2one', 'relation': 'account.fiscalyear', 'required': True},
+ 'fiscalyear': {'string': 'Fiscal year', 'type': 'many2one', 'relation': 'account.fiscalyear',
+ 'help': 'Keep empty for all open fiscal year'},
'date1': {'string':'Start of period', 'type':'date', 'required':True, 'default': lambda *a: time.strftime('%Y-01-01')},
'date2': {'string':'End of period', 'type':'date', 'required':True, 'default': lambda *a: time.strftime('%Y-%m-%d')},
}