|
|
@ -120,6 +120,7 @@ class GeneralView(models.TransientModel): |
|
|
|
merged_data = {} |
|
|
|
for line in records['Accounts']: |
|
|
|
account_id = line['account_id'] |
|
|
|
print(line['balance'],'balance....') |
|
|
|
if account_id not in merged_data: |
|
|
|
merged_data[account_id] = line |
|
|
|
else: |
|
|
@ -284,7 +285,8 @@ class GeneralView(models.TransientModel): |
|
|
|
debit_total = 0 |
|
|
|
debit_total = sum(x['debit'] for x in account_res) |
|
|
|
credit_total = sum(x['credit'] for x in account_res) |
|
|
|
debit_balance = round(debit_total, 2) - round(credit_total, 2) |
|
|
|
decimal_places = self.env.company.currency_id.decimal_places |
|
|
|
debit_balance = round(debit_total, decimal_places) - round(credit_total, decimal_places) |
|
|
|
return { |
|
|
|
'doc_ids': self.ids, |
|
|
|
'debit_total': debit_total, |
|
|
@ -334,6 +336,7 @@ class GeneralView(models.TransientModel): |
|
|
|
cr = self.env.cr |
|
|
|
MoveLine = self.env['account.move.line'] |
|
|
|
move_lines = {x: [] for x in accounts.ids} |
|
|
|
decimal_places = self.env.company.currency_id.decimal_places |
|
|
|
# Prepare initial sql query and Get the initial move lines |
|
|
|
if init_balance and data.get('date_from'): |
|
|
|
init_tables, init_where_clause, init_where_params = MoveLine.with_context( |
|
|
@ -366,14 +369,14 @@ class GeneralView(models.TransientModel): |
|
|
|
tuple(data.get('analytics').ids) + tuple([0])) |
|
|
|
if data['account_tags']: |
|
|
|
WHERE += ' AND tag IN %s' % str(data.get('account_tags')) |
|
|
|
sql = ('''SELECT |
|
|
|
base_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, |
|
|
|
ROUND(COALESCE(SUM(l.debit),0),{}) AS debit, |
|
|
|
ROUND(COALESCE(SUM(l.credit),0),{}) AS credit, |
|
|
|
ROUND(COALESCE(SUM(l.balance),0),{}) AS balance, |
|
|
|
anl.keys, |
|
|
|
act.name AS tag |
|
|
|
FROM |
|
|
@ -396,15 +399,17 @@ class GeneralView(models.TransientModel): |
|
|
|
SELECT jsonb_array_elements_text(l.analytic_distribution->'ids')::INT AS keys |
|
|
|
) anl ON true |
|
|
|
LEFT JOIN |
|
|
|
account_analytic_account an ON (anl.keys = an.id) '''+ WHERE + new_filter + ''' |
|
|
|
account_analytic_account an ON (anl.keys = an.id) ''').format(decimal_places, decimal_places, decimal_places) |
|
|
|
sql = base_sql + WHERE + new_filter + ''' |
|
|
|
GROUP BY |
|
|
|
l.account_id, 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'): |
|
|
|
params = tuple(init_where_params) |
|
|
|
else: |
|
|
|
params = (tuple(accounts.ids),) + tuple(init_where_params) |
|
|
|
cr.execute(sql, params) |
|
|
|
print('1...............') |
|
|
|
for row in cr.dictfetchall(): |
|
|
|
row['m_id'] = row['account_id'] |
|
|
|
move_lines[row.pop('account_id')].append(row) |
|
|
@ -443,11 +448,11 @@ class GeneralView(models.TransientModel): |
|
|
|
|
|
|
|
# Get move lines base on sql query and Calculate the total balance |
|
|
|
# of move lines |
|
|
|
sql = ('''SELECT l.account_id AS account_id, a.code AS code, |
|
|
|
base_sql = ('''SELECT l.account_id AS account_id, a.code AS code, |
|
|
|
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.credit),0),2) AS credit, |
|
|
|
ROUND(COALESCE(SUM(l.balance),0),2) AS balance, |
|
|
|
ROUND(COALESCE(SUM(l.debit),0),{}) AS debit, |
|
|
|
ROUND(COALESCE(SUM(l.credit),0),{}) AS credit, |
|
|
|
ROUND(COALESCE(SUM(l.balance),0),{}) AS balance, |
|
|
|
anl.keys, act.name as tag |
|
|
|
FROM account_move_line l |
|
|
|
LEFT JOIN account_move m ON (l.move_id = m.id) |
|
|
@ -463,15 +468,17 @@ class GeneralView(models.TransientModel): |
|
|
|
SELECT jsonb_object_keys(l.analytic_distribution)::INT |
|
|
|
AS keys) anl ON true |
|
|
|
LEFT JOIN account_analytic_account an |
|
|
|
ON (anl.keys = an.id)''' |
|
|
|
+ WHERE + new_final_filter + ''' GROUP BY l.account_id, |
|
|
|
a.code,a.id,a.name,anl.keys, act.name, l.id''') |
|
|
|
ON (anl.keys = an.id)''').format(decimal_places, decimal_places, decimal_places) |
|
|
|
sql = base_sql+ WHERE + new_final_filter + ''' GROUP BY l.account_id, |
|
|
|
a.code,a.id,a.name,anl.keys, act.name, l.id''' |
|
|
|
if data.get('accounts'): |
|
|
|
params = tuple(where_params) |
|
|
|
else: |
|
|
|
params = (tuple(accounts.ids),) + tuple(where_params) |
|
|
|
cr.execute(sql, params) |
|
|
|
print('2.........') |
|
|
|
account_res = cr.dictfetchall() |
|
|
|
print(account_res,'account res....') |
|
|
|
unique_line_ids = set() |
|
|
|
filtered_records = [] |
|
|
|
for record in account_res: |
|
|
@ -492,7 +499,7 @@ class GeneralView(models.TransientModel): |
|
|
|
lang = 'en_US' |
|
|
|
lang = lang.replace("_", '-') |
|
|
|
currency_array = [self.env.company.currency_id.symbol, |
|
|
|
self.env.company.currency_id.position, lang] |
|
|
|
self.env.company.currency_id.position, lang,self.env.company.currency_id.decimal_places] |
|
|
|
return currency_array |
|
|
|
|
|
|
|
def get_accounts_line(self, account_id, title): |
|
|
|