diff --git a/dynamic_accounts_report/controllers/controllers.py b/dynamic_accounts_report/controllers/controllers.py index b5bab0e9b..aa96f68c6 100644 --- a/dynamic_accounts_report/controllers/controllers.py +++ b/dynamic_accounts_report/controllers/controllers.py @@ -24,7 +24,9 @@ class TBXLSXReportController(http.Controller): ('Content-Disposition', content_disposition(report_name + '.xlsx')) ] ) + print('report data in controller: ', report_data) report_obj.get_dynamic_xlsx_report(options, response, report_data, dfr_data) + response.set_cookie('fileToken', token) return response except Exception as e: diff --git a/dynamic_accounts_report/models/move_line.py b/dynamic_accounts_report/models/move_line.py index 89709afc8..1c5b07ed7 100644 --- a/dynamic_accounts_report/models/move_line.py +++ b/dynamic_accounts_report/models/move_line.py @@ -55,8 +55,8 @@ class AccountMoveLine(models.Model): if context.get('account_ids'): domain += [('account_id', 'in', context['account_ids'].ids)] - if context.get('analytic_tag_ids'): - domain += [('analytic_tag_ids', 'in', context['analytic_tag_ids'].ids)] + # if context.get('analytic_tag_ids'): + # domain += [('analytic_tag_ids', 'in', context['analytic_tag_ids'].ids)] if context.get('analytic_account_ids'): domain += [('analytic_account_id', 'in', context['analytic_account_ids'].ids)] diff --git a/dynamic_accounts_report/report/general_ledger.py b/dynamic_accounts_report/report/general_ledger.py index 5d00d1bd3..25f21bc81 100644 --- a/dynamic_accounts_report/report/general_ledger.py +++ b/dynamic_accounts_report/report/general_ledger.py @@ -6,7 +6,7 @@ class GeneralLedger(models.AbstractModel): @api.model def _get_report_values(self, docids, data=None): - + print('data frm repot', data) if self.env.context.get('trial_pdf_report'): print(data.get('report_data')['report_lines'], "data") if data.get('report_data'): diff --git a/dynamic_accounts_report/report/general_ledger.xml b/dynamic_accounts_report/report/general_ledger.xml index 63f8b958c..465c50abf 100644 --- a/dynamic_accounts_report/report/general_ledger.xml +++ b/dynamic_accounts_report/report/general_ledger.xml @@ -8,19 +8,19 @@
-

: +

: +

- From: - + From: + - - To: - + To: + @@ -38,12 +38,12 @@

- Accounts: - -
  • - -
  • -
    + Accounts: + +
  • + +
  • +
    @@ -55,86 +55,106 @@
    -
    - Analytic Tag: - -
  • - -
  • -
    +
    + Analytic Tag: + +
  • + +
  • +
    Target move: -
  • - -
  • +
  • + +


  • - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    DateJRNLPartnerRefMoveEntry LabelDebitCreditBalanceCurrency
    - - - - - - - - - - + + + + + + + + + + + + + - - - - - - - - - - - - + + + + - - - - -
    DateJRNLPartnerRefMoveEntry LabelDebitCreditBalanceCurrency
    - - - - - - - - +
    + + +
    +
    + + + + + + +


    @@ -143,11 +163,11 @@ - Report - account.general.ledger - qweb-pdf - dynamic_accounts_report.general_ledger - dynamic_accounts_report.general_ledger + Report + account.general.ledger + qweb-pdf + dynamic_accounts_report.general_ledger + dynamic_accounts_report.general_ledger \ No newline at end of file diff --git a/dynamic_accounts_report/report/partner_ledger.xml b/dynamic_accounts_report/report/partner_ledger.xml index 0237eac20..eca0d762d 100644 --- a/dynamic_accounts_report/report/partner_ledger.xml +++ b/dynamic_accounts_report/report/partner_ledger.xml @@ -114,6 +114,7 @@ + diff --git a/dynamic_accounts_report/static/src/js/ageing.js b/dynamic_accounts_report/static/src/js/ageing.js index d8abb992a..9c92aad4c 100644 --- a/dynamic_accounts_report/static/src/js/ageing.js +++ b/dynamic_accounts_report/static/src/js/ageing.js @@ -125,7 +125,7 @@ odoo.define('dynamic_accounts_report.ageing', function (require) { } var child=[]; - + console.log(datas['report_lines'][0]) self.$('.table_view_tb').html(QWeb.render('Ageingtable', { report_lines : datas['report_lines'], diff --git a/dynamic_accounts_report/static/src/js/financial_reports.js b/dynamic_accounts_report/static/src/js/financial_reports.js index e048add0e..e88a06d90 100644 --- a/dynamic_accounts_report/static/src/js/financial_reports.js +++ b/dynamic_accounts_report/static/src/js/financial_reports.js @@ -87,7 +87,7 @@ odoo.define('dynamic_accounts_report.financial_reports', function (require) { }).then(function(datas) { - + console.log('Balance sheet values..........',datas) if (initial_render) { self.$('.filter_view_dfr').html(QWeb.render('DfrFilterView', { filter_data: datas['filters'], @@ -242,6 +242,7 @@ odoo.define('dynamic_accounts_report.financial_reports', function (require) { var account_ids = []; var account_text = []; var account_res = document.getElementById("acc_res") + console.log('account.value....',account_res.value) var account_list = $(".account").select2('data') for (var i = 0; i < account_list.length; i++) { if(account_list[i].element[0].selected === true){ diff --git a/dynamic_accounts_report/static/src/js/general_ledger.js b/dynamic_accounts_report/static/src/js/general_ledger.js index 425e6532d..bbb68b601 100644 --- a/dynamic_accounts_report/static/src/js/general_ledger.js +++ b/dynamic_accounts_report/static/src/js/general_ledger.js @@ -9,7 +9,7 @@ odoo.define('dynamic_accounts_report.general_ledger', function (require) { var QWeb = core.qweb; var _t = core._t; var trial = require('dynamic_accounts_report.trial_balance'); - + var framework = require('web.framework'); var datepicker = require('web.datepicker'); var time = require('web.time'); @@ -100,6 +100,7 @@ odoo.define('dynamic_accounts_report.general_ledger', function (require) { try{ var self = this; var action_title = self._title + console.log("action_title:",action_title) self._rpc({ model: 'account.general.ledger', method: 'view_report', @@ -209,10 +210,21 @@ odoo.define('dynamic_accounts_report.general_ledger', function (require) { }, }; // return self.do_action(action); - core.action_registry.map.t_b.prototype.downloadXlsx(action) +// core.action_registry.map.t_b.prototype.downloadXlsx(action) + self.downloadXlsx(action) }); }, + downloadXlsx: function (action){ + framework.blockUI(); + session.get_file({ + url: '/dynamic_xlsx_reports', + data: action.data, + complete: framework.unblockUI, + error: (error) => this.call('crash_manager', 'rpc_error', error), + }); + }, + @@ -294,6 +306,7 @@ odoo.define('dynamic_accounts_report.general_ledger', function (require) { if (account_id == data['report_lines'][i]['id'] ){ $(event.currentTarget).next('tr').find('td .gl-table-div').remove(); + $(event.currentTarget).next('tr').find('td ul').after( QWeb.render('SubSection', { account_data: data['report_lines'][i]['move_lines'], 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 cc1a4f4dd..046527366 100644 --- a/dynamic_accounts_report/static/src/xml/general_ledger_view.xml +++ b/dynamic_accounts_report/static/src/xml/general_ledger_view.xml @@ -27,7 +27,7 @@ diff --git a/dynamic_accounts_report/wizard/ageing.py b/dynamic_accounts_report/wizard/ageing.py index f545db609..fd4675cec 100644 --- a/dynamic_accounts_report/wizard/ageing.py +++ b/dynamic_accounts_report/wizard/ageing.py @@ -59,7 +59,7 @@ class AgeingView(models.TransientModel): records = self._get_report_values(data) currency = self._get_currency() - + print(records['Partners']) return { 'name': "Partner Ageing", 'type': 'ir.actions.client', diff --git a/dynamic_accounts_report/wizard/balance_sheet.py b/dynamic_accounts_report/wizard/balance_sheet.py index efd906b1e..038e673e8 100644 --- a/dynamic_accounts_report/wizard/balance_sheet.py +++ b/dynamic_accounts_report/wizard/balance_sheet.py @@ -68,7 +68,7 @@ class BalanceSheetView(models.TransientModel): company_domain.append(('id', 'in', r.account_ids.ids)) new_account_ids = self.env['account.account'].search(company_domain) - data.update({'accounts': new_account_ids,}) + data.update({'accounts': new_account_ids, }) filters = self.get_filter(option) records = self._get_report_values(data) @@ -83,14 +83,16 @@ class BalanceSheetView(models.TransientModel): new_records = list(filter(filter_code, records['Accounts'])) records['Accounts'] = new_records - trans_tag = self.env['ir.translation'].search([('value', '=', tag), ('module', '=', 'dynamic_accounts_report')], - limit=1).src + trans_tag = self.env['ir.translation'].search( + [('value', '=', tag), ('module', '=', 'dynamic_accounts_report')], + limit=1).src if trans_tag: tag_upd = trans_tag else: tag_upd = tag - account_report_id = self.env['account.financial.report'].with_context(lang='en_US').search([ + account_report_id = self.env['account.financial.report'].with_context( + lang='en_US').search([ ('name', 'ilike', tag_upd)]) new_data = {'id': self.id, 'date_from': False, @@ -109,8 +111,10 @@ class BalanceSheetView(models.TransientModel): 'lang': 'en_US'}} account_lines = self.get_account_lines(new_data) + print("account_lines",account_lines) report_lines = self.view_report_pdf(account_lines, new_data)[ 'report_lines'] + print("report_lines",report_lines) move_line_accounts = [] move_lines_dict = {} @@ -166,14 +170,12 @@ class BalanceSheetView(models.TransientModel): parent_list = list(set(parent_list)) final_report_lines = [] - for rec in report_lines_move: if rec['report_type'] != 'accounts': if rec['r_id'] in parent_list: final_report_lines.append(rec) else: final_report_lines.append(rec) - def filter_sum(obj): sum_list = {} for pl in parent_list: @@ -217,15 +219,16 @@ class BalanceSheetView(models.TransientModel): if position == "before": rec['m_debit'] = symbol + " " + "{:,.2f}".format(rec['debit']) - rec['m_credit'] = symbol + " " + "{:,.2f}".format(rec['credit']) + rec['m_credit'] = symbol + " " + "{:,.2f}".format( + rec['credit']) rec['m_balance'] = symbol + " " + "{:,.2f}".format( rec['balance']) else: rec['m_debit'] = "{:,.2f}".format(rec['debit']) + " " + symbol - rec['m_credit'] = "{:,.2f}".format(rec['credit']) + " " + symbol + rec['m_credit'] = "{:,.2f}".format( + rec['credit']) + " " + symbol rec['m_balance'] = "{:,.2f}".format( rec['balance']) + " " + symbol - return { 'name': tag, 'type': 'ir.actions.client', @@ -337,9 +340,6 @@ class BalanceSheetView(models.TransientModel): o_company = j.company_id accounts.append((j.id, j.name)) - - - filter_dict = { 'journal_ids': r.journal_ids.ids, 'account_ids': r.account_ids.ids, @@ -484,7 +484,6 @@ class BalanceSheetView(models.TransientModel): 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: @@ -534,7 +533,8 @@ class BalanceSheetView(models.TransientModel): self.env.company.currency_id.position] return currency_array - def get_dynamic_xlsx_report(self, options, response, report_data, dfr_data): + def get_dynamic_xlsx_report(self, options, response, report_data, + dfr_data): i_data = str(report_data) filters = json.loads(options) j_data = dfr_data @@ -638,4 +638,4 @@ class BalanceSheetView(models.TransientModel): workbook.close() output.seek(0) response.stream.write(output.read()) - output.close() \ No newline at end of file + output.close() diff --git a/dynamic_accounts_report/wizard/balance_sheet_config.py b/dynamic_accounts_report/wizard/balance_sheet_config.py index 60a8aded7..31e809656 100644 --- a/dynamic_accounts_report/wizard/balance_sheet_config.py +++ b/dynamic_accounts_report/wizard/balance_sheet_config.py @@ -92,9 +92,9 @@ class BalanceSheet(models.TransientModel): 'sum' : it's the sum of the children of this record (aka a 'view' record)""" - res = {} fields = ['credit', 'debit', 'balance'] + print("reportssssssss",reports) for report in reports: if report.id in res: continue @@ -128,13 +128,13 @@ class BalanceSheet(models.TransientModel): elif report.type == 'sum': # it's the sum of the children of this account.report res2 = self._compute_report_balance(report.children_ids) + print(fields,"ffff") for key, value in res2.items(): for field in fields: res[report.id][field] += value[field] return res def get_account_lines(self, data): - lines = [] account_report = data['account_report_id'] child_reports = account_report._get_children_by_order() @@ -196,7 +196,7 @@ class BalanceSheet(models.TransientModel): # used to display the details of the # financial report, so it's not needed here. continue - + print("get_account:",res[report.id]) if res[report.id].get('account'): sub_lines = [] for account_id, value \ @@ -226,7 +226,7 @@ class BalanceSheet(models.TransientModel): 'level': ( report.display_detail == 'detail_with_hierarchy' and 4), - 'account_type': account.internal_type, + # 'account_type': account.internal_type, } if data['debit_credit']: vals['debit'] = value['debit'] @@ -247,9 +247,9 @@ class BalanceSheet(models.TransientModel): flag = True if flag: sub_lines.append(vals) + print("sub_lines",sub_lines) lines += sorted(sub_lines, key=lambda sub_line: sub_line['name']) - return lines def find_journal_items(self, report_lines, form): @@ -296,9 +296,3 @@ class BalanceSheet(models.TransientModel): j['type'] = 'journal_item' journal_items.append(j) return journal_items - - - - - - diff --git a/dynamic_accounts_report/wizard/cash_flow.py b/dynamic_accounts_report/wizard/cash_flow.py index 155761575..91c262caa 100644 --- a/dynamic_accounts_report/wizard/cash_flow.py +++ b/dynamic_accounts_report/wizard/cash_flow.py @@ -263,18 +263,17 @@ class AccountCasgFlow(models.TransientModel): elif data.get('levels') == 'consolidated': state = """ AND am.state = 'posted' """ if data.get('target_move') == 'Posted' else '' state2 = ' AND aml.company_id IN %s' % str(tuple(self.env.companies.ids) + tuple([0])) - query2 = """SELECT aat.name, sum(aml.debit) AS total_debit, sum(aml.credit) AS total_credit, + query2 = """SELECT aml.account_type, sum(aml.debit) AS total_debit, sum(aml.credit) AS total_credit, sum(aml.balance) AS total_balance FROM ( SELECT am.id, am.state FROM account_move as am LEFT JOIN account_move_line aml ON aml.move_id = am.id LEFT JOIN account_account aa ON aa.id = aml.account_id - LEFT JOIN account_account_type aat ON aat.id = aa.user_type_id WHERE am.date BETWEEN '""" + str(data.get('date_from')) + """' and '""" + str( data.get('date_to')) + """' AND aat.id='""" + str( account_type_id) + """' """ + state + state2 + """) am LEFT JOIN account_move_line aml ON aml.move_id = am.id LEFT JOIN account_account aa ON aa.id = aml.account_id LEFT JOIN account_account_type aat ON aat.id = aa.user_type_id - GROUP BY aat.name""" + GROUP BY aml.account_type""" cr = self._cr cr.execute(query2) fetched_data = cr.dictfetchall() diff --git a/dynamic_accounts_report/wizard/general_ledger.py b/dynamic_accounts_report/wizard/general_ledger.py index 18782288a..1dbbf48fa 100644 --- a/dynamic_accounts_report/wizard/general_ledger.py +++ b/dynamic_accounts_report/wizard/general_ledger.py @@ -4,6 +4,7 @@ from odoo import fields, models, api, _ import io import json from odoo.exceptions import AccessError, UserError, AccessDenied + try: from odoo.tools.misc import xlsxwriter except ImportError: @@ -22,12 +23,14 @@ class GeneralView(models.TransientModel): "account.account", string="Accounts", ) - account_tag_ids = fields.Many2many("account.account.tag", string="Account Tags") + account_tag_ids = fields.Many2many("account.account.tag", + string="Account Tags") analytic_ids = fields.Many2many( "account.analytic.account", string="Analytic Accounts" ) - analytic_tag_ids = fields.Many2many("account.analytic.tag", string="Analytic Tags") + analytic_tag_ids = fields.Many2many("account.analytic.tag", + string="Analytic Tags") display_account = fields.Selection( [('all', 'All'), ('movement', 'With movements'), @@ -43,34 +46,42 @@ class GeneralView(models.TransientModel): @api.model def view_report(self, option, title): + print("view_report") 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 + trans_title = self.env['ir.translation'].search([('value', '=', title), + ('module', '=', + 'dynamic_accounts_report')], + limit=1).src company_id = self.env.companies.ids if r.journal_ids: journals = r.journal_ids else: - journals = self.env['account.journal'].search([('company_id', 'in', company_id)]) + journals = self.env['account.journal'].search( + [('company_id', 'in', company_id)]) if title == 'General Ledger' or trans_title == 'General Ledger': if r.journal_ids: journals = r.journal_ids else: - journals = self.env['account.journal'].search([('company_id', 'in', company_id)]) + journals = self.env['account.journal'].search( + [('company_id', 'in', company_id)]) new_title = title if title == 'Bank Book' or trans_title == 'Bank Book': - journals = self.env['account.journal'].search([('type', '=', 'bank'), ('company_id', 'in', company_id)]) + journals = self.env['account.journal'].search( + [('type', '=', 'bank'), ('company_id', 'in', company_id)]) new_title = title if title == 'Cash Book' or trans_title == 'Cash Book': - journals = self.env['account.journal'].search([('type', '=', 'cash'), ('company_id', 'in', company_id)]) + journals = self.env['account.journal'].search( + [('type', '=', 'cash'), ('company_id', 'in', company_id)]) new_title = title r.write({ 'titles': new_title, }) data = { 'display_account': r.display_account, - 'model':self, + 'model': self, 'journals': journals, 'target_move': r.target_move, 'accounts': r.account_ids, @@ -91,7 +102,7 @@ class GeneralView(models.TransientModel): filters = self.get_filter(option) records = self._get_report_values(data) currency = self._get_currency() - print(records, "records....") + print('last return') return { 'name': new_title, 'type': 'ir.actions.client', @@ -108,11 +119,13 @@ class GeneralView(models.TransientModel): data = self.get_filter_data(option) filters = {} if data.get('journal_ids'): - filters['journals'] = self.env['account.journal'].browse(data.get('journal_ids')).mapped('code') + filters['journals'] = self.env['account.journal'].browse( + data.get('journal_ids')).mapped('code') else: filters['journals'] = ['All'] if data.get('account_ids', []): - filters['accounts'] = self.env['account.account'].browse(data.get('account_ids', [])).mapped('code') + filters['accounts'] = self.env['account.account'].browse( + data.get('account_ids', [])).mapped('code') else: filters['accounts'] = ['All'] if data.get('account_tag_ids', []): @@ -155,14 +168,16 @@ class GeneralView(models.TransientModel): account_tags = r.account_tag_ids if r.account_tag_ids else self.env[ 'account.account.tag'].search([]) - analytics = r.analytic_ids if r.analytic_ids else self.env['account.analytic.account'].search( + analytics = r.analytic_ids if r.analytic_ids else self.env[ + 'account.analytic.account'].search( company_domain) analytic_tags = r.analytic_tag_ids if r.analytic_tag_ids else self.env[ 'account.analytic.tag'].search([]) - - journal_ids = r.journal_ids if r.journal_ids else self.env['account.journal'].search(company_domain, order="company_id, name") - accounts_ids = self.account_ids if self.account_ids else self.env['account.account'].search(company_domain, order="company_id, name") + journal_ids = r.journal_ids if r.journal_ids else self.env[ + 'account.journal'].search(company_domain, order="company_id, name") + accounts_ids = self.account_ids if self.account_ids else self.env[ + 'account.account'].search(company_domain, order="company_id, name") journals = [] o_company = False for j in journal_ids: @@ -180,8 +195,6 @@ class GeneralView(models.TransientModel): o_company = j.company_id accounts.append((j.id, j.name)) - - filter_dict = { 'journal_ids': r.journal_ids.ids, 'analytic_ids': r.analytic_ids.ids, @@ -198,7 +211,8 @@ class GeneralView(models.TransientModel): 'accounts_list': accounts, 'account_tag_list': [(a.id, a.name) for a in account_tags], 'analytic_list': [(anl.id, anl.name) for anl in analytics], - 'analytic_tag_list': [(anltag.id, anltag.name) for anltag in analytic_tags], + 'analytic_tag_list': [(anltag.id, anltag.name) for anltag in + analytic_tags], 'company_name': ', '.join(self.env.companies.mapped('name')), } filter_dict.update(default_filters) @@ -207,6 +221,7 @@ class GeneralView(models.TransientModel): def _get_report_values(self, data): docs = data['model'] + display_account = data['display_account'] init_balance = True journals = data['journals'] @@ -218,17 +233,17 @@ class GeneralView(models.TransientModel): accounts = self.env['account.account'].search(company_domain) if not accounts: raise UserError(_("No Accounts Found! Please Add One")) - account_res = self._get_accounts(accounts, init_balance, display_account, data) + account_res = self._get_accounts(accounts, init_balance, + display_account, data) 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) - print(account_res, ".................") + debit_balance = round(debit_total, 2) - round(credit_total, 2) return { 'doc_ids': self.ids, 'debit_total': debit_total, 'credit_total': credit_total, - 'debit_balance':debit_balance, + 'debit_balance': debit_balance, 'docs': docs, 'time': time, 'Accounts': account_res, @@ -248,32 +263,37 @@ class GeneralView(models.TransientModel): if vals.get('journal_ids') == []: vals.update({'journal_ids': [(5,)]}) if vals.get('account_ids'): - vals.update({'account_ids': [(4, j) for j in vals.get('account_ids')]}) + vals.update( + {'account_ids': [(4, j) for j in vals.get('account_ids')]}) if vals.get('account_ids') == []: vals.update({'account_ids': [(5,)]}) if vals.get('account_tag_ids'): - vals.update({'account_tag_ids': [(4, j) for j in vals.get('account_tag_ids')]}) + vals.update({'account_tag_ids': [(4, j) for j in + vals.get('account_tag_ids')]}) if vals.get('account_tag_ids') == []: vals.update({'account_tag_ids': [(5,)]}) if vals.get('analytic_ids'): - vals.update({'analytic_ids': [(4, j) for j in vals.get('analytic_ids')]}) + vals.update( + {'analytic_ids': [(4, j) for j in vals.get('analytic_ids')]}) if vals.get('analytic_ids') == []: vals.update({'analytic_ids': [(5,)]}) if vals.get('analytic_tag_ids') == []: - vals.update({'analytic_tag_ids': [(4, j) for j in vals.get('analytic_tag_ids')]}) + vals.update({'analytic_tag_ids': [(4, j) for j in + vals.get('analytic_tag_ids')]}) if vals.get('analytic_tag_ids') == []: vals.update({'analytic_tag_ids': [(5,)]}) res = super(GeneralView, self).write(vals) return res def _get_accounts(self, accounts, init_balance, display_account, data): - + print("function called..........") cr = self.env.cr MoveLine = self.env['account.move.line'] move_lines = {x: [] for x in accounts.ids} # Prepare initial sql query and Get the initial move lines if init_balance and data.get('date_from'): + print("function called..2") 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() @@ -292,18 +312,20 @@ class GeneralView(models.TransientModel): if data.get('date_from'): new_filter += " AND l.date < '%s'" % data.get('date_from') if data['journals']: - new_filter += ' AND j.id IN %s' % str(tuple(data['journals'].ids) + tuple([0])) + new_filter += ' AND j.id IN %s' % str( + tuple(data['journals'].ids) + tuple([0])) if data.get('accounts'): - WHERE = "WHERE l.account_id IN %s" % str(tuple(data.get('accounts').ids) + tuple([0])) + WHERE = "WHERE l.account_id IN %s" % str( + tuple(data.get('accounts').ids) + tuple([0])) else: WHERE = "WHERE l.account_id IN %s" if data.get('analytics'): - WHERE += ' AND anl.id IN %s' % str(tuple(data.get('analytics').ids) + tuple([0])) + WHERE += ' AND anl.id IN %s' % str( + tuple(data.get('analytics').ids) + tuple([0])) if data.get('analytic_tags'): WHERE += ' AND anltag.account_analytic_tag_id IN %s' % str( tuple(data.get('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,\ @@ -318,11 +340,12 @@ class GeneralView(models.TransientModel): 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') + + WHERE + new_filter + ' GROUP BY l.account_id') if data.get('accounts'): params = tuple(init_where_params) else: params = (tuple(accounts.ids),) + tuple(init_where_params) + # print("aaaaaaaaaaaaaaaaaaaaaaa", params) cr.execute(sql, params) for row in cr.dictfetchall(): row['m_id'] = row['account_id'] @@ -333,7 +356,8 @@ class GeneralView(models.TransientModel): 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( + final_filters = final_filters.replace('account_move_line__move_id', + 'm').replace( 'account_move_line', 'l') new_final_filter = final_filters if data['target_move'] == 'posted': @@ -346,13 +370,16 @@ class GeneralView(models.TransientModel): new_final_filter += " AND l.date <= '%s'" % data.get('date_to') if data['journals']: - new_final_filter += ' AND j.id IN %s' % str(tuple(data['journals'].ids) + tuple([0])) + new_final_filter += ' AND j.id IN %s' % str( + tuple(data['journals'].ids) + tuple([0])) if data.get('accounts'): - WHERE = "WHERE l.account_id IN %s" % str(tuple(data.get('accounts').ids) + tuple([0])) + WHERE = "WHERE l.account_id IN %s" % str( + tuple(data.get('accounts').ids) + tuple([0])) else: WHERE = "WHERE l.account_id IN %s" if data.get('analytics'): - WHERE += ' AND anl.id IN %s' % str(tuple(data.get('analytics').ids) + tuple([0])) + WHERE += ' AND anl.id IN %s' % str( + tuple(data.get('analytics').ids) + tuple([0])) if data.get('analytic_tags'): WHERE += ' AND anltag.account_analytic_tag_id IN %s' % str( @@ -375,6 +402,8 @@ class GeneralView(models.TransientModel): params = tuple(where_params) else: params = (tuple(accounts.ids),) + tuple(where_params) + # print("sql", sql) + # print("params", params) cr.execute(sql, params) account_res = cr.dictfetchall() @@ -422,29 +451,37 @@ 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] 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 + 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)]) + 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)]) + 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)]) + 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)]) + 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)]) + accounts = self.env['account.account'].search( + [('id', '=', account_id)]) else: company_id = self.env.companies company_domain = [('company_id', 'in', company_id.ids)] @@ -476,13 +513,16 @@ class GeneralView(models.TransientModel): 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])) + 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])) + 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])) + 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])) @@ -516,7 +556,8 @@ class GeneralView(models.TransientModel): 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( + 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': @@ -529,13 +570,16 @@ class GeneralView(models.TransientModel): 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])) + 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])) + 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])) + 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( @@ -553,14 +597,13 @@ 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 ORDER BY l.date''' ) - + + 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''') params = tuple(where_params) cr.execute(sql, params) account_ress = cr.dictfetchall() - i=0 + i = 0 # Calculate the debit, credit and balance for Accounts account_res = [] for account in accounts: @@ -573,7 +616,6 @@ class GeneralView(models.TransientModel): account_res.append(res) - currency = self._get_currency() return { @@ -582,8 +624,9 @@ class GeneralView(models.TransientModel): 'currency': currency, } - def get_dynamic_xlsx_report(self, data, response ,report_data, dfr_data): + def get_dynamic_xlsx_report(self, data, response, report_data, dfr_data): report_data_main = json.loads(report_data) + print('report data: ', report_data_main) output = io.BytesIO() name_data = json.loads(dfr_data) filters = json.loads(data) @@ -596,16 +639,21 @@ class GeneralView(models.TransientModel): 'border': 1, 'border_color': 'black'}) txt = workbook.add_format({'font_size': '10px', 'border': 1}) - txt_l = workbook.add_format({'font_size': '10px', 'border': 1, 'bold': True}) - sheet.merge_range('A2:J3', filters.get('company_name') + ':' + name_data.get('name'), head) + txt_l = workbook.add_format( + {'font_size': '10px', 'border': 1, 'bold': True}) + sheet.merge_range('A2:J3', + filters.get('company_name') + ':' + name_data.get( + 'name'), head) date_head = workbook.add_format({'align': 'center', 'bold': True, 'font_size': '10px'}) date_style = workbook.add_format({'align': 'center', 'font_size': '10px'}) if filters.get('date_from'): - sheet.merge_range('B4:C4', 'From: ' + filters.get('date_from'), date_head) + sheet.merge_range('B4:C4', 'From: ' + filters.get('date_from'), + date_head) if filters.get('date_to'): - sheet.merge_range('H4:I4', 'To: ' + filters.get('date_to'), date_head) + sheet.merge_range('H4:I4', 'To: ' + filters.get('date_to'), + date_head) # sheet.merge_range('A5:J6', 'Journals: ' + ', '.join( # [lt or '' for lt in filters['journals']]) + ' Target Moves: ' + filters.get('target_move'), date_head) @@ -617,10 +665,10 @@ class GeneralView(models.TransientModel): [lt or '' for lt in filters['analytic_tags']]) + ' Analytic: ' + ', '.join( [at or '' for at in - filters['analytics']]) + ' Target Moves : ' + filters.get('target_move'), + filters['analytics']]) + ' Target Moves : ' + filters.get( + 'target_move'), date_head) - sheet.write('A8', 'Code', sub_heading) sheet.write('B8', 'Amount', sub_heading) sheet.write('C8', 'Date', sub_heading) @@ -659,22 +707,24 @@ class GeneralView(models.TransientModel): sheet.write(row + 1, col + 7, rec_data['debit'], txt) sheet.write(row + 1, col + 8, rec_data['credit'], txt) sheet.write(row + 1, col + 9, rec_data['balance'], txt) - for line_data in rec_data['move_lines']: - row += 1 - sheet.write(row + 1, col, '', txt) - sheet.write(row + 1, col + 1, '', txt) - sheet.write(row + 1, col + 2, line_data.get('ldate'), txt) - sheet.write(row + 1, col + 3, line_data.get('lcode'), txt) - sheet.write(row + 1, col + 4, line_data.get('partner_name'), txt) - sheet.write(row + 1, col + 5, line_data.get('move_name'), txt) - sheet.write(row + 1, col + 6, line_data.get('lname'), txt) - sheet.write(row + 1, col + 7, line_data.get('debit'), txt) - sheet.write(row + 1, col + 8, line_data.get('credit'), txt) - sheet.write(row + 1, col + 9, line_data.get('balance'), txt) - - + if rec_data.get('move_lines'): + for line_data in rec_data['move_lines']: + row += 1 + sheet.write(row + 1, col, '', txt) + sheet.write(row + 1, col + 1, '', txt) + sheet.write(row + 1, col + 2, line_data.get('ldate'), txt) + sheet.write(row + 1, col + 3, line_data.get('lcode'), txt) + sheet.write(row + 1, col + 4, line_data.get('partner_name'), + txt) + sheet.write(row + 1, col + 5, line_data.get('move_name'), txt) + sheet.write(row + 1, col + 6, line_data.get('lname'), txt) + sheet.write(row + 1, col + 7, line_data.get('debit'), txt) + sheet.write(row + 1, col + 8, line_data.get('credit'), txt) + sheet.write(row + 1, col + 9, line_data.get('balance'), txt) + else: + print('///////////',rec_data) workbook.close() output.seek(0) response.stream.write(output.read()) - output.close() \ No newline at end of file + output.close()