Browse Source

May 08: [FIX] Bug Fixed 'dynamic_accounts_report'

pull/320/head
RisvanaCybro 12 months ago
parent
commit
4d7e5f237a
  1. 2
      dynamic_accounts_report/__manifest__.py
  2. 5
      dynamic_accounts_report/doc/RELEASE_NOTES.md
  3. 72
      dynamic_accounts_report/wizard/general_ledger.py

2
dynamic_accounts_report/__manifest__.py

@ -22,7 +22,7 @@
{ {
'name': 'Dynamic Financial Reports V16', 'name': 'Dynamic Financial Reports V16',
'version': '16.0.1.0.10', 'version': '16.0.1.0.11',
'category': 'Accounting', 'category': 'Accounting',
'live_test_url': 'https://www.youtube.com/watch?v=gVQi9q9Rs-E&t=5s', 'live_test_url': 'https://www.youtube.com/watch?v=gVQi9q9Rs-E&t=5s',
'summary': "Odoo 17 Accounting Financial Reports,Dynamic Accounting Reports, Dynamic Financial Reports,Dynamic Report Odoo17, Odoo17,Financial Reports, Odoo17 Accounting,Accounting, Odoo Apps", 'summary': "Odoo 17 Accounting Financial Reports,Dynamic Accounting Reports, Dynamic Financial Reports,Dynamic Report Odoo17, Odoo17,Financial Reports, Odoo17 Accounting,Accounting, Odoo Apps",

5
dynamic_accounts_report/doc/RELEASE_NOTES.md

@ -40,3 +40,8 @@
### version 16.0.1.0.10, ### version 16.0.1.0.10,
### BUGFIX ### BUGFIX
- Profit And Loss: multiple lines of the same account in the financial reports. - Profit And Loss: multiple lines of the same account in the financial reports.
### 11.12.2023
### version 16.0.1.0.11,
### BUGFIX
- General Ledger: Fixed the Redundancy bug

72
dynamic_accounts_report/wizard/general_ledger.py

@ -331,7 +331,6 @@ class GeneralView(models.TransientModel):
return res return res
def _get_accounts(self, accounts, init_balance, display_account, data): def _get_accounts(self, accounts, init_balance, display_account, data):
cr = self.env.cr cr = self.env.cr
MoveLine = self.env['account.move.line'] MoveLine = self.env['account.move.line']
move_lines = {x: [] for x in accounts.ids} move_lines = {x: [] for x in accounts.ids}
@ -367,29 +366,39 @@ class GeneralView(models.TransientModel):
tuple(data.get('analytics').ids) + tuple([0])) tuple(data.get('analytics').ids) + tuple([0]))
if data['account_tags']: if data['account_tags']:
WHERE += ' AND tag IN %s' % str(data.get('account_tags')) WHERE += ' AND tag IN %s' % str(data.get('account_tags'))
sql = ('''SELECT l.account_id AS account_id, a.code AS code, sql = ('''SELECT
a.id AS id, a.name AS name, 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.debit),0),2) AS debit,
ROUND(COALESCE(SUM(l.credit),0),2) AS credit, ROUND(COALESCE(SUM(l.credit),0),2) AS credit,
ROUND(COALESCE(SUM(l.balance),0),2) AS balance, ROUND(COALESCE(SUM(l.balance),0),2) AS balance,
anl.keys, act.name as tag anl.keys,
FROM account_move_line l act.name AS tag
LEFT JOIN account_move m ON (l.move_id = m.id) FROM
LEFT JOIN res_currency c ON (l.currency_id = c.id) account_move_line l
LEFT JOIN res_partner p ON (l.partner_id = p.id) LEFT JOIN
JOIN account_journal j ON (l.journal_id = j.id) account_move m ON (l.move_id = m.id)
JOIN account_account a ON (l.account_id = a.id) LEFT JOIN
LEFT JOIN account_account_account_tag acct ON res_currency c ON (l.currency_id = c.id)
(acct.account_account_id = l.account_id) LEFT JOIN
LEFT JOIN account_account_tag act ON res_partner p ON (l.partner_id = p.id)
(act.id = acct.account_account_tag_id) JOIN
account_journal j ON (l.journal_id = j.id)
JOIN
account_account a ON (l.account_id = a.id)
LEFT JOIN
account_account_account_tag acct ON (acct.account_account_id = l.account_id)
LEFT JOIN
account_account_tag act ON (act.id = acct.account_account_tag_id)
LEFT JOIN LATERAL ( LEFT JOIN LATERAL (
SELECT jsonb_object_keys(l.analytic_distribution)::INT SELECT jsonb_array_elements_text(l.analytic_distribution->'ids')::INT AS keys
AS keys) anl ON true ) anl ON true
LEFT JOIN account_analytic_account an LEFT JOIN
ON (anl.keys = an.id)''' account_analytic_account an ON (anl.keys = an.id) '''+ WHERE + new_filter + '''
+ WHERE + new_filter + ''' GROUP BY l.account_id, GROUP BY
a.code,a.id,a.name,anl.keys, act.name''') l.account_id, a.code, a.id, a.name, anl.keys, act.name''')
if data.get('accounts'): if data.get('accounts'):
params = tuple(init_where_params) params = tuple(init_where_params)
@ -424,9 +433,10 @@ class GeneralView(models.TransientModel):
tuple(data.get('accounts').ids) + tuple([0])) tuple(data.get('accounts').ids) + tuple([0]))
else: else:
WHERE = "WHERE l.account_id IN %s" WHERE = "WHERE l.account_id IN %s"
if data.get('analytics'):
if self.analytic_ids:
WHERE += ' AND an.id IN %s' % str( WHERE += ' AND an.id IN %s' % str(
tuple(data.get('analytics').ids) + tuple([0])) tuple(self.analytic_ids.ids) + tuple([0]))
if data.get('account_tags'): if data.get('account_tags'):
WHERE += ' AND act.id IN %s' % str( WHERE += ' AND act.id IN %s' % str(
tuple(data.get('account_tags').ids) + tuple([0])) tuple(data.get('account_tags').ids) + tuple([0]))
@ -434,7 +444,7 @@ class GeneralView(models.TransientModel):
# Get move lines base on sql query and Calculate the total balance # Get move lines base on sql query and Calculate the total balance
# of move lines # of move lines
sql = ('''SELECT l.account_id AS account_id, a.code AS code, sql = ('''SELECT l.account_id AS account_id, a.code AS code,
a.id AS id, a.name AS name, a.id AS id, a.name AS name, l.id as line_id,
ROUND(COALESCE(SUM(l.debit),0),2) AS debit, ROUND(COALESCE(SUM(l.debit),0),2) AS debit,
ROUND(COALESCE(SUM(l.credit),0),2) AS credit, ROUND(COALESCE(SUM(l.credit),0),2) AS credit,
ROUND(COALESCE(SUM(l.balance),0),2) AS balance, ROUND(COALESCE(SUM(l.balance),0),2) AS balance,
@ -455,14 +465,21 @@ class GeneralView(models.TransientModel):
LEFT JOIN account_analytic_account an LEFT JOIN account_analytic_account an
ON (anl.keys = an.id)''' ON (anl.keys = an.id)'''
+ WHERE + new_final_filter + ''' GROUP BY l.account_id, + WHERE + new_final_filter + ''' GROUP BY l.account_id,
a.code,a.id,a.name,anl.keys, act.name''') a.code,a.id,a.name,anl.keys, act.name, l.id''')
if data.get('accounts'): if data.get('accounts'):
params = tuple(where_params) params = tuple(where_params)
else: else:
params = (tuple(accounts.ids),) + tuple(where_params) params = (tuple(accounts.ids),) + tuple(where_params)
cr.execute(sql, params) cr.execute(sql, params)
account_res = cr.dictfetchall() account_res = cr.dictfetchall()
return account_res unique_line_ids = set()
filtered_records = []
for record in account_res:
line_id = record['line_id']
if line_id not in unique_line_ids:
unique_line_ids.add(line_id)
filtered_records.append(record)
return filtered_records
@api.model @api.model
def _get_currency(self): def _get_currency(self):
@ -552,7 +569,8 @@ class GeneralView(models.TransientModel):
# Get move lines base on sql query and Calculate the total balance of # Get move lines base on sql query and Calculate the total balance of
# move lines # move lines
sql = ('''SELECT l.id AS lid,m.id AS move_id, l.account_id AS account_id, # print(new_final_filter)
sql = ('''SELECT DISTINCT ON (l.id) 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.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, 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, COALESCE(l.credit,0) AS credit, COALESCE(SUM(l.balance),0) AS balance,
@ -571,7 +589,9 @@ class GeneralView(models.TransientModel):
+ WHERE + new_final_filter + ''' GROUP BY l.id, m.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.account_id, l.date, j.code, l.currency_id, l.amount_currency,
l.ref, l.name, m.name, c.symbol, c.position, p.name, anl.keys''') l.ref, l.name, m.name, c.symbol, c.position, p.name, anl.keys''')
params = tuple(where_params) params = tuple(where_params)
# print('new_final_filter', sql, params)
cr.execute(sql, params) cr.execute(sql, params)
account_ress = cr.dictfetchall() account_ress = cr.dictfetchall()
i = 0 i = 0

Loading…
Cancel
Save