Skip to Content
Menu
This question has been flagged
3 Replies
18532 Views

I have a print_excel method which is used to create an excel file for general ledger. I have generated all the data but there is some issue while passing data into the query. I couldn't fix the bug please someone helps me out.


account_report_general_ledger.py

def print_excel(self):

filename= 'GeneralLedger.xls'

ctx = self.env.context

data = self.get_data_for_xls()

sortby = data['form']['sortby']

init_balance = data['form']['initial_balance']

date_from = data['form']['date_from']

date_to = data['form']['date_to']

od_move_lines = self.get_move_line_ids()

od_move_lines = self.env['account.move.line'].browse(od_move_lines)

search_cond = ''' '''

if od_move_lines:

search_cond = search_cond + ''' and l.id in %s '''

if data['form'].get('journal_ids', False):

codes = [journal.code for journal in self.env['account.journal'].search([('id', 'in', data['form']['journal_ids'])])]

self.model = self.env.context.get('active_model')

accounts = self.env['account.account'].browse(ctx.get('active_id')) if self.model == 'account.account' else self.env['account.account'].search([])

display_account = data['form']['display_account']

ctx = {'dt_cont':{'date_from':date_from,'date_to':date_to}}

movelines = self.env['report.account.report_generalledger'].with_context(ctx)._get_account_move_entry( accounts, init_balance, sortby, display_account,od_move_lines,search_cond) ##ISSUE

account_general_ledger.py

def _get_account_move_entry(self, accounts, init_balance, sortby, display_account,od_move_lines,search_cond):

"""

:param:

accounts: the recordset of accounts

init_balance: boolean value of initial_balance

sortby: sorting by date or partner and journal

display_account: type of account(receivable, payable and both)

Returns a dictionary of accounts with following key and value {

'code': account code,

'name': account name,

'debit': sum of total debit amount,

'credit': sum of total credit amount,

'balance': total balance,

'amount_currency': sum of amount_currency,

'move_lines': list of move line

}

"""

cr = self.env.cr

context=self.env.context

MoveLine = self.env['account.move.line']

move_lines = dict(map(lambda x: (x, []), accounts.ids))

# Prepare initial sql query and Get the initial move lines

if init_balance:

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')

sql = ("""SELECT 0 AS lid, cc.name AS cost_center, l.account_id AS account_id, '' AS ldate, '' AS lcode, NULL 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 orchid_account_cost_center cc ON (l.orchid_cc_id=cc.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_invoice i ON (m.id =i.move_id)\

JOIN account_journal j ON (l.journal_id=j.id)\

WHERE l.account_id IN %s """ + search_cond + filters + ' GROUP BY l.account_id,l.partner_id,cc.name')

params = ()

print "where params>>>>>>>>>>>>>>>>>>>>>>>",init_where_params #####NO VALUES

if od_move_lines:

params = (tuple(accounts.ids),tuple(od_move_lines.ids),) + tuple(init_where_params)

else:

params = (tuple(accounts.ids),) + tuple(init_where_params)

cr.execute(sql, params)

for row in cr.dictfetchall():

if move_lines[row['account_id']]:

move_lines[row['account_id']][0]['credit'] = move_lines[row['account_id']][0]['credit'] + row['credit']

move_lines[row['account_id']][0]['debit'] = move_lines[row['account_id']][0]['debit'] + row['debit']

move_lines[row['account_id']][0]['balance'] = move_lines[row['account_id']][0]['balance'] + row['balance']

else:

move_lines[row.pop('account_id')].append(row)

sql_sort = 'l.date, l.move_id'

if sortby == 'sort_journal_partner':

sql_sort = 'j.code, p.name, l.move_id'


 

Avatar
Discard

I think it will be better if you can post the issue / error message along with the question

Author

There was no error and the issue was i am getting 2 different initial balance values in pdf and excel.

Best Answer

I don't know what you are looking for but try this may be its helpful to you.

return self.with_context({'signal':'call_from_desination', 'current_object':self})

Avatar
Discard
Related Posts Replies Views Activity
0
Mar 21
5199
2
Jan 19
5101
1
Dec 18
1842
1
Jul 18
6092
1
Apr 18
2544