diff --git a/dynamic_accounts_report/__manifest__.py b/dynamic_accounts_report/__manifest__.py
index b99f3247b..fa9f97771 100644
--- a/dynamic_accounts_report/__manifest__.py
+++ b/dynamic_accounts_report/__manifest__.py
@@ -22,7 +22,7 @@
{
'name': 'Dynamic Financial Reports',
- 'version': '15.0.1.0.3',
+ 'version': '15.0.1.0.4',
'category': 'Accounting',
'live_test_url': 'https://www.youtube.com/watch?v=gVQi9q9Rs-E&t=5s',
'summary': """Dynamic Financial Reports with drill
diff --git a/dynamic_accounts_report/doc/RELEASE_NOTES.md b/dynamic_accounts_report/doc/RELEASE_NOTES.md
index e3c721756..efc8ba950 100644
--- a/dynamic_accounts_report/doc/RELEASE_NOTES.md
+++ b/dynamic_accounts_report/doc/RELEASE_NOTES.md
@@ -20,4 +20,9 @@
#### 01.02.2022
#### Version 15.0.1.0.3
#### UPDT AND BUGFIX
-- Multi-company and Translation Update and Bugfix
\ No newline at end of file
+- Multi-company and Translation Update and Bugfix
+
+#### 16.04.2022
+#### Version 15.0.1.0.4
+#### UPDT AND BUGFIX
+- Loading issue and orderby date
\ No newline at end of file
diff --git a/dynamic_accounts_report/static/src/js/general_ledger.js b/dynamic_accounts_report/static/src/js/general_ledger.js
index 75c6d0c9f..425e6532d 100644
--- a/dynamic_accounts_report/static/src/js/general_ledger.js
+++ b/dynamic_accounts_report/static/src/js/general_ledger.js
@@ -105,15 +105,15 @@ odoo.define('dynamic_accounts_report.general_ledger', function (require) {
method: 'view_report',
args: [[this.wizard_id], action_title],
}).then(function(datas) {
- _.each(datas['report_lines'], function(rep_lines) {
- rep_lines.debit = self.format_currency(datas['currency'],rep_lines.debit);
- rep_lines.credit = self.format_currency(datas['currency'],rep_lines.credit);
- rep_lines.balance = self.format_currency(datas['currency'],rep_lines.balance);
-
-
-
-
- });
+// _.each(datas['report_lines'], function(rep_lines) {
+// rep_lines.debit = self.format_currency(datas['currency'],rep_lines.debit);
+// rep_lines.credit = self.format_currency(datas['currency'],rep_lines.credit);
+// rep_lines.balance = self.format_currency(datas['currency'],rep_lines.balance);
+//
+//
+//
+//
+// });
if (initial_render) {
self.$('.filter_view_tb').html(QWeb.render('GLFilterView', {
@@ -273,21 +273,21 @@ odoo.define('dynamic_accounts_report.general_ledger', function (require) {
var action_title = self._title
self._rpc({
model: 'account.general.ledger',
- method: 'view_report',
+ method: 'get_accounts_line',
args: [
- [self.wizard_id], action_title
+ [self.wizard_id], account_id, action_title
],
}).then(function(data) {
- _.each(data['report_lines'], function(rep_lines) {
- _.each(rep_lines['move_lines'], function(move_line) {
-
- move_line.debit = self.format_currency(data['currency'],move_line.debit);
- move_line.credit = self.format_currency(data['currency'],move_line.credit);
- move_line.balance = self.format_currency(data['currency'],move_line.balance);
-
-
- });
- });
+// _.each(data['report_lines'], function(rep_lines) {
+// _.each(rep_lines['move_lines'], function(move_line) {
+//
+// move_line.debit = self.format_currency(data['currency'],move_line.debit);
+// move_line.credit = self.format_currency(data['currency'],move_line.credit);
+// move_line.balance = self.format_currency(data['currency'],move_line.balance);
+//
+//
+// });
+// });
for (var i = 0; i < data['report_lines'].length; i++) {
diff --git a/dynamic_accounts_report/static/src/xml/general_ledger_view.xml b/dynamic_accounts_report/static/src/xml/general_ledger_view.xml
index 9a95ca623..cc1a4f4dd 100644
--- a/dynamic_accounts_report/static/src/xml/general_ledger_view.xml
+++ b/dynamic_accounts_report/static/src/xml/general_ledger_view.xml
@@ -326,6 +326,7 @@
+
@@ -389,8 +390,10 @@
-
+
-
+
+
@@ -421,7 +424,9 @@
-
-
+
+
+
diff --git a/dynamic_accounts_report/views/kit_menus.xml b/dynamic_accounts_report/views/kit_menus.xml
index de2d765c5..14c4fa630 100644
--- a/dynamic_accounts_report/views/kit_menus.xml
+++ b/dynamic_accounts_report/views/kit_menus.xml
@@ -1,30 +1,30 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/dynamic_accounts_report/wizard/balance_sheet.py b/dynamic_accounts_report/wizard/balance_sheet.py
index 6cd8a04a2..efd906b1e 100644
--- a/dynamic_accounts_report/wizard/balance_sheet.py
+++ b/dynamic_accounts_report/wizard/balance_sheet.py
@@ -471,57 +471,59 @@ class BalanceSheetView(models.TransientModel):
tuple(data.get('analytic_tags').ids) + tuple([0]))
# Get move lines base on sql query and Calculate the total balance of move lines
- sql = ('''SELECT l.id AS lid,m.id AS move_id, l.account_id AS account_id,
- l.date AS ldate, j.code AS lcode, l.currency_id, l.amount_currency, l.ref AS lref,
- l.name AS lname, COALESCE(l.debit,0) AS debit, COALESCE(l.credit,0) AS credit,
- COALESCE(SUM(l.balance),0) AS balance,\
- m.name AS move_name, c.symbol AS currency_code,c.position AS currency_position, p.name AS partner_name\
- FROM account_move_line l\
- JOIN account_move m ON (l.move_id=m.id)\
- LEFT JOIN res_currency c ON (l.currency_id=c.id)\
- LEFT JOIN res_partner p ON (l.partner_id=p.id)\
- LEFT JOIN account_analytic_account anl ON (l.analytic_account_id=anl.id)\
- LEFT JOIN account_analytic_tag_account_move_line_rel anltag ON (anltag.account_move_line_id = l.id)\
- JOIN account_journal j ON (l.journal_id=j.id)\
- JOIN account_account acc ON (l.account_id = acc.id) '''
- + WHERE + new_final_filter + ''' GROUP BY l.id, m.id, l.account_id, l.date, j.code, l.currency_id, l.amount_currency, l.ref, l.name, m.name, c.symbol, c.position, p.name''')
+ sql = ('''SELECT l.account_id AS account_id, a.code AS code,a.id AS id, a.name AS name, ROUND(COALESCE(SUM(l.debit),0),2) AS debit, ROUND(COALESCE(SUM(l.credit),0),2) AS credit, ROUND(COALESCE(SUM(l.balance),0),2) AS balance
+
+ FROM account_move_line l\
+ JOIN account_move m ON (l.move_id=m.id)\
+ LEFT JOIN res_currency c ON (l.currency_id=c.id)\
+ LEFT JOIN res_partner p ON (l.partner_id=p.id)\
+ LEFT JOIN account_analytic_account anl ON (l.analytic_account_id=anl.id)
+ LEFT JOIN account_account_tag_account_move_line_rel acc ON (acc.account_move_line_id=l.id)
+ LEFT JOIN account_analytic_tag_account_move_line_rel anltag ON (anltag.account_move_line_id=l.id)
+ JOIN account_journal j ON (l.journal_id=j.id)\
+ JOIN account_account a ON (l.account_id = a.id) '''
+ + WHERE + new_final_filter + ''' GROUP BY l.account_id, a.code, a.name, a.id''')
+
+
if data.get('accounts'):
params = tuple(where_params)
else:
params = (tuple(accounts.ids),) + tuple(where_params)
cr.execute(sql, params)
-
- for row in cr.dictfetchall():
- balance = 0
- for line in move_lines.get(row['account_id']):
- balance += round(line['debit'], 2) - round(line['credit'], 2)
- row['balance'] += (round(balance, 2))
- row['m_id'] = row['account_id']
- move_lines[row.pop('account_id')].append(row)
- # Calculate the debit, credit and balance for Accounts
- account_res = []
- for account in accounts:
- currency = account.currency_id and account.currency_id or account.company_id.currency_id
- res = dict((fn, 0.0) for fn in ['credit', 'debit', 'balance'])
- res['code'] = account.code
- res['name'] = account.name
- res['id'] = account.id
- res['move_lines'] = move_lines[account.id]
- for line in res.get('move_lines'):
- res['debit'] += round(line['debit'], 2)
- res['credit'] += round(line['credit'], 2)
- res['balance'] = round(line['balance'], 2)
- if display_account == 'all':
- account_res.append(res)
- if display_account == 'movement' and res.get('move_lines'):
- account_res.append(res)
- if display_account == 'not_zero' and not currency.is_zero(
- res['balance']):
- account_res.append(res)
-
+ account_res = cr.dictfetchall()
return account_res
+ # for row in cr.dictfetchall():
+ # balance = 0
+ # for line in move_lines.get(row['account_id']):
+ # balance += round(line['debit'], 2) - round(line['credit'], 2)
+ # row['balance'] += (round(balance, 2))
+ # row['m_id'] = row['account_id']
+ # move_lines[row.pop('account_id')].append(row)
+ # # Calculate the debit, credit and balance for Accounts
+ # account_res = []
+ # for account in accounts:
+ # currency = account.currency_id and account.currency_id or account.company_id.currency_id
+ # res = dict((fn, 0.0) for fn in ['credit', 'debit', 'balance'])
+ # res['code'] = account.code
+ # res['name'] = account.name
+ # res['id'] = account.id
+ # res['move_lines'] = move_lines[account.id]
+ # for line in res.get('move_lines'):
+ # res['debit'] += round(line['debit'], 2)
+ # res['credit'] += round(line['credit'], 2)
+ # res['balance'] = round(line['balance'], 2)
+ # if display_account == 'all':
+ # account_res.append(res)
+ # if display_account == 'movement' and res.get('move_lines'):
+ # account_res.append(res)
+ # if display_account == 'not_zero' and not currency.is_zero(
+ # res['balance']):
+ # account_res.append(res)
+ #
+ # return account_res
+
@api.model
def _get_currency(self):
journal = self.env['account.journal'].browse(
diff --git a/dynamic_accounts_report/wizard/general_ledger.py b/dynamic_accounts_report/wizard/general_ledger.py
index 7b555761c..401b86bf7 100644
--- a/dynamic_accounts_report/wizard/general_ledger.py
+++ b/dynamic_accounts_report/wizard/general_ledger.py
@@ -38,9 +38,13 @@ class GeneralView(models.TransientModel):
('all', 'All Entries')],
string='Target Moves', required=True)
+ date_from = fields.Date(string='Start Date')
+ date_to = fields.Date(string='End Date')
+
@api.model
def view_report(self, option, title):
r = self.env['account.general.ledger'].search([('id', '=', option[0])])
+ self = r
new_title = ''
trans_title = self.env['ir.translation'].search([('value', '=', title), ('module', '=', 'dynamic_accounts_report')], limit=1).src
company_id = self.env.companies.ids
@@ -353,7 +357,190 @@ class GeneralView(models.TransientModel):
tuple(data.get('analytic_tags').ids) + tuple([0]))
# Get move lines base on sql query and Calculate the total balance of move lines
- sql = ('''SELECT l.id AS lid,m.id AS move_id, l.account_id AS account_id, l.date AS ldate, j.code AS lcode, l.currency_id, l.amount_currency, l.ref AS lref, l.name AS lname, COALESCE(l.debit,0) AS debit, COALESCE(l.credit,0) AS credit, COALESCE(SUM(l.balance),0) AS balance,\
+ sql = ('''SELECT l.account_id AS account_id, a.code AS code,a.id AS id, a.name AS name, ROUND(COALESCE(SUM(l.debit),0),2) AS debit, ROUND(COALESCE(SUM(l.credit),0),2) AS credit, ROUND(COALESCE(SUM(l.balance),0),2) AS balance
+
+ FROM account_move_line l\
+ JOIN account_move m ON (l.move_id=m.id)\
+ LEFT JOIN res_currency c ON (l.currency_id=c.id)\
+ LEFT JOIN res_partner p ON (l.partner_id=p.id)\
+ LEFT JOIN account_analytic_account anl ON (l.analytic_account_id=anl.id)
+ LEFT JOIN account_account_tag_account_move_line_rel acc ON (acc.account_move_line_id=l.id)
+ LEFT JOIN account_analytic_tag_account_move_line_rel anltag ON (anltag.account_move_line_id=l.id)
+ JOIN account_journal j ON (l.journal_id=j.id)\
+ JOIN account_account a ON (l.account_id = a.id) '''
+ + WHERE + new_final_filter + ''' GROUP BY l.account_id, a.code, a.name, a.id''')
+ if data.get('accounts'):
+ params = tuple(where_params)
+ else:
+ params = (tuple(accounts.ids),) + tuple(where_params)
+ cr.execute(sql, params)
+ account_res = cr.dictfetchall()
+
+ return account_res
+
+ # for row in cr.dictfetchall():
+ # balance = 0
+ # for line in move_lines.get(row['account_id']):
+ # balance += round(line['debit'],2) - round(line['credit'],2)
+ # row['balance'] += round(balance,2)
+ # row['m_id'] = row['account_id']
+ # move_lines[row.pop('account_id')].append(row)
+ #
+ # # Calculate the debit, credit and balance for Accounts
+ # account_res = []
+ # for account in accounts:
+ # currency = account.currency_id and account.currency_id or account.company_id.currency_id
+ # res = dict((fn, 0.0) for fn in ['credit', 'debit', 'balance'])
+ # res['code'] = account.code
+ # res['name'] = account.name
+ # res['id'] = account.id
+ # res['move_lines'] = move_lines[account.id]
+ # for line in res.get('move_lines'):
+ # res['debit'] += round(line['debit'],2)
+ # res['credit'] += round(line['credit'],2)
+ # res['balance'] = round(line['balance'],2)
+ # if display_account == 'all':
+ # account_res.append(res)
+ # if display_account == 'movement' and res.get('move_lines'):
+ # account_res.append(res)
+ # if display_account == 'not_zero' and not currency.is_zero(
+ # res['balance']):
+ # account_res.append(res)
+ #
+ # return account_res
+
+ @api.model
+ def _get_currency(self):
+ journal = self.env['account.journal'].browse(
+ self.env.context.get('default_journal_id', False))
+ if journal.currency_id:
+ return journal.currency_id.id
+ lang = self.env.user.lang
+ if not lang:
+ lang = 'en_US'
+ lang = lang.replace("_", '-')
+ currency_array = [self.env.company.currency_id.symbol,
+ self.env.company.currency_id.position,lang]
+ return currency_array
+
+ def get_accounts_line(self, account_id, title):
+
+ trans_title = self.env['ir.translation'].search([('value', '=', title), ('module', '=', 'dynamic_accounts_report')], limit=1).src
+ company_id = self.env.companies.ids
+ if self.journal_ids:
+ journals = self.journal_ids
+ else:
+ journals = self.env['account.journal'].search([('company_id', 'in', company_id)])
+ if title == 'General Ledger' or trans_title == 'General Ledger':
+ if self.journal_ids:
+ journals = self.journal_ids
+ else:
+ journals = self.env['account.journal'].search([('company_id', 'in', company_id)])
+ if title == 'Bank Book' or trans_title == 'Bank Book':
+ journals = self.env['account.journal'].search([('type', '=', 'bank'), ('company_id', 'in', company_id)])
+ if title == 'Cash Book' or trans_title == 'Cash Book':
+ journals = self.env['account.journal'].search([('type', '=', 'cash'), ('company_id', 'in', company_id)])
+
+ if account_id:
+ accounts = self.env['account.account'].search([('id', '=', account_id)])
+ else:
+ company_id = self.env.companies
+ company_domain = [('company_id', 'in', company_id.ids)]
+ accounts = self.env['account.account'].search(company_domain)
+
+ cr = self.env.cr
+ MoveLine = self.env['account.move.line']
+ move_lines = {x: [] for x in accounts.ids}
+
+ # self.j
+
+ # Prepare initial sql query and Get the initial move lines
+ if self.date_from:
+ init_tables, init_where_clause, init_where_params = MoveLine.with_context(
+ date_from=self.env.context.get('date_from'), date_to=False,
+ initial_bal=True)._query_get()
+ init_wheres = [""]
+ if init_where_clause.strip():
+ init_wheres.append(init_where_clause.strip())
+ init_filters = " AND ".join(init_wheres)
+ filters = init_filters.replace('account_move_line__move_id',
+ 'm').replace('account_move_line',
+ 'l')
+ new_filter = filters
+ if self.target_move == 'posted':
+ new_filter += " AND m.state = 'posted'"
+ else:
+ new_filter += " AND m.state in ('draft','posted')"
+ if self.date_from:
+ new_filter += " AND l.date < '%s'" % self.date_from
+ if journals:
+ new_filter += ' AND j.id IN %s' % str(tuple(journals.ids) + tuple([0]))
+ if accounts:
+ WHERE = "WHERE l.account_id IN %s" % str(tuple(accounts.ids) + tuple([0]))
+ else:
+ WHERE = "WHERE l.account_id IN %s"
+ if self.analytic_ids:
+ WHERE += ' AND anl.id IN %s' % str(tuple(self.analytic_ids.ids) + tuple([0]))
+ if self.analytic_tag_ids:
+ WHERE += ' AND anltag.account_analytic_tag_id IN %s' % str(
+ tuple(self.analytic_tags.ids) + tuple([0]))
+
+ sql = ("""SELECT 0 AS lid, l.account_id AS account_id, '' AS ldate, '' AS lcode, 0.0 AS amount_currency, '' AS lref, 'Initial Balance' AS lname, COALESCE(SUM(l.debit),0.0) AS debit, COALESCE(SUM(l.credit),0.0) AS credit, COALESCE(SUM(l.debit),0) - COALESCE(SUM(l.credit), 0) as balance, '' AS lpartner_id,\
+ '' AS move_name, '' AS mmove_id, '' AS currency_code,\
+ NULL AS currency_id,\
+ '' AS invoice_id, '' AS invoice_type, '' AS invoice_number,\
+ '' AS partner_name\
+ FROM account_move_line l\
+ LEFT JOIN account_move m ON (l.move_id=m.id)\
+ LEFT JOIN res_currency c ON (l.currency_id=c.id)\
+ LEFT JOIN res_partner p ON (l.partner_id=p.id)\
+ LEFT JOIN account_move i ON (m.id =i.id)\
+ LEFT JOIN account_account_tag_account_move_line_rel acc ON (acc.account_move_line_id=l.id)
+ LEFT JOIN account_analytic_account anl ON (l.analytic_account_id=anl.id)
+ LEFT JOIN account_analytic_tag_account_move_line_rel anltag ON (anltag.account_move_line_id=l.id)
+ JOIN account_journal j ON (l.journal_id=j.id)"""
+ + WHERE + new_filter + ' GROUP BY l.account_id')
+ if self.account_ids:
+ params = tuple(init_where_params)
+ else:
+ params = (tuple(accounts.ids),) + tuple(init_where_params)
+ cr.execute(sql, params)
+ for row in cr.dictfetchall():
+ row['m_id'] = row['account_id']
+ move_lines[row.pop('account_id')].append(row)
+
+ tables, where_clause, where_params = MoveLine._query_get()
+ wheres = [""]
+ if where_clause.strip():
+ wheres.append(where_clause.strip())
+ final_filters = " AND ".join(wheres)
+ final_filters = final_filters.replace('account_move_line__move_id', 'm').replace(
+ 'account_move_line', 'l')
+ new_final_filter = final_filters
+ if self.target_move == 'posted':
+ new_final_filter += " AND m.state = 'posted'"
+ else:
+ new_final_filter += " AND m.state in ('draft','posted')"
+ if self.date_from:
+ new_final_filter += " AND l.date >= '%s'" % self.date_from
+ if self.date_to:
+ new_final_filter += " AND l.date <= '%s'" % self.date_to
+
+ if journals:
+ new_final_filter += ' AND j.id IN %s' % str(tuple(journals.ids) + tuple([0]))
+ if accounts:
+ WHERE = "WHERE l.account_id IN %s" % str(tuple(accounts.ids) + tuple([0]))
+ else:
+ WHERE = "WHERE l.account_id IN %s"
+ if self.analytic_ids:
+ WHERE += ' AND anl.id IN %s' % str(tuple(self.analytics.ids) + tuple([0]))
+
+ if self.analytic_tag_ids:
+ WHERE += ' AND anltag.account_analytic_tag_id IN %s' % str(
+ tuple(self.analytic_tags.ids) + tuple([0]))
+
+ # Get move lines base on sql query and Calculate the total balance of move lines
+ sql = ('''SELECT l.id AS lid,m.id AS move_id, l.account_id AS account_id, l.date AS ldate, j.code AS lcode, l.currency_id, l.amount_currency, l.ref AS lref, l.name AS lname, COALESCE(SUM(l.debit),0) AS debit, COALESCE(SUM(l.credit),0) AS credit, COALESCE(SUM(l.balance),0) AS balance,\
m.name AS move_name, c.symbol AS currency_code, p.name AS partner_name\
FROM account_move_line l\
JOIN account_move m ON (l.move_id=m.id)\
@@ -364,21 +551,14 @@ class GeneralView(models.TransientModel):
LEFT JOIN account_analytic_tag_account_move_line_rel anltag ON (anltag.account_move_line_id=l.id)
JOIN account_journal j ON (l.journal_id=j.id)\
JOIN account_account a ON (l.account_id = a.id) '''
- + WHERE + new_final_filter + ''' GROUP BY l.id, m.id, l.account_id, l.date, j.code, l.currency_id, l.amount_currency, l.ref, l.name, m.name, c.symbol, c.position, p.name''' )
- if data.get('accounts'):
- params = tuple(where_params)
- else:
- params = (tuple(accounts.ids),) + tuple(where_params)
- cr.execute(sql, params)
+ + WHERE + new_final_filter + ''' GROUP BY l.id, m.id, l.account_id, l.date, j.code, l.currency_id, l.amount_currency, l.ref, l.name, m.name, c.symbol, c.position, p.name ORDER BY l.date''' )
+
- for row in cr.dictfetchall():
- balance = 0
- for line in move_lines.get(row['account_id']):
- balance += round(line['debit'],2) - round(line['credit'],2)
- row['balance'] += round(balance,2)
- row['m_id'] = row['account_id']
- move_lines[row.pop('account_id')].append(row)
+ params = tuple(where_params)
+ cr.execute(sql, params)
+ account_ress = cr.dictfetchall()
+ i=0
# Calculate the debit, credit and balance for Accounts
account_res = []
for account in accounts:
@@ -387,34 +567,18 @@ class GeneralView(models.TransientModel):
res['code'] = account.code
res['name'] = account.name
res['id'] = account.id
- res['move_lines'] = move_lines[account.id]
- for line in res.get('move_lines'):
- res['debit'] += round(line['debit'],2)
- res['credit'] += round(line['credit'],2)
- res['balance'] = round(line['balance'],2)
- if display_account == 'all':
- account_res.append(res)
- if display_account == 'movement' and res.get('move_lines'):
- account_res.append(res)
- if display_account == 'not_zero' and not currency.is_zero(
- res['balance']):
- account_res.append(res)
+ res['move_lines'] = account_ress
- return account_res
+ account_res.append(res)
- @api.model
- def _get_currency(self):
- journal = self.env['account.journal'].browse(
- self.env.context.get('default_journal_id', False))
- if journal.currency_id:
- return journal.currency_id.id
- lang = self.env.user.lang
- if not lang:
- lang = 'en_US'
- lang = lang.replace("_", '-')
- currency_array = [self.env.company.currency_id.symbol,
- self.env.company.currency_id.position,lang]
- return currency_array
+
+ currency = self._get_currency()
+ return {
+
+ 'report_lines': account_res,
+
+ 'currency': currency,
+ }
def get_dynamic_xlsx_report(self, data, response ,report_data, dfr_data):
report_data_main = json.loads(report_data)
diff --git a/dynamic_accounts_report/wizard/partner_leadger.py b/dynamic_accounts_report/wizard/partner_leadger.py
index 9991996a0..ae497867f 100644
--- a/dynamic_accounts_report/wizard/partner_leadger.py
+++ b/dynamic_accounts_report/wizard/partner_leadger.py
@@ -311,7 +311,7 @@ class PartnerView(models.TransientModel):
LEFT JOIN res_partner p ON (l.partner_id=p.id)\
JOIN account_journal j ON (l.journal_id=j.id)\
JOIN account_account acc ON (l.account_id = acc.id) '''
- + WHERE + new_final_filter + ''' GROUP BY l.id, m.id, l.account_id, l.date, j.code, l.currency_id, l.amount_currency, l.ref, l.name, m.name, c.symbol, c.position, p.name''' )
+ + WHERE + new_final_filter + ''' GROUP BY l.id, m.id, l.account_id, l.date, j.code, l.currency_id, l.amount_currency, l.ref, l.name, m.name, c.symbol, c.position, p.name ORDER BY l.date''' )
if data.get('accounts'):
params = tuple(where_params)
else: