def print_report(self, cr, uid, form, context=None): self.validate_parameters(cr, uid, form, context=context) form.add_marshalled_data('SQL_PARAMS', ar_cust_sql()) if len(form.customer_addr_ids) == 0: #TODO: Nothing sql_cust_ids = '' else: cust_list = form.get_customer_addr_ids(context=None) cust_addr_ids = ",".join(str(n) for n in cust_list) sql_cust_ids = ' AND id.address_id IN (%s)' % cust_addr_ids form.add_marshalled_data('CUSTOMER_ADDR_IDS', sql_cust_ids) receivable = self.get_receivable(cr, uid, form, context=context) receivable_table = list_to_pgTable(receivable, 'receivable_table', [('partner_id', 'INTEGER'), ('receivable', 'NUMERIC')]) form.add_marshalled_data('RECEIVABLE_TABLE', receivable_table) payable = self.get_payable(cr, uid, form, context=context) payable_table = list_to_pgTable(payable, 'payable_table', [('partner_id', 'INTEGER'), ('payable', 'NUMERIC')]) form.add_marshalled_data('PAYABLE_TABLE', payable_table) currency_company = self.get_currency_company(cr, uid, form, context=context) form.add_marshalled_data('CURRENCY_SYMBOL', currency_company)
def _get_tree_data(self, cr, uid, cid, from_date, to_date, context=None): # Get selected company ID and its descendant company IDs company = self.pool.get("res.company").browse(cr, uid, cid, context=context) cids = get_company_ids(company) # Get the periods of the selected company crit = [("date_stop", ">=", from_date), ("date_start", "<=", to_date), ("company_id", "=", cid)] period_ids = self.pool.get("account.period").search(cr, uid, crit, context=context) if not period_ids: return [] periods = self.pool.get("account.period").browse(cr, uid, period_ids, context=context) period_data = [] for period in periods: period_data.append((period.id, period.date_start, period.date_stop)) period_data_table = list_to_pgTable( period_data, "period", [("id", "INTEGER"), ("date_start", "DATE"), ("date_stop", "DATE")] ) acc_ids = self.pool.get("account.account").search(cr, uid, [("type", "=", "liquidity")], context=context) # Execute query query = cash_flow_realization_report_sql() % { "ROOT_COMPANY_PERIOD_ID_DATE_START_DATE_STOP_TABLE": period_data_table, "FISCAL_YEAR_DATE_START": periods[0].fiscalyear_id.date_start, "COMPANY_IDS": ", ".join(str(cid).replace("L", "") for cid in cids), "ACCOUNT_IDS": ", ".join("%d" % acc_id for acc_id in acc_ids), "DATE_START": from_date, "DATE_STOP": to_date, } cr.execute(query) return cr.dictfetchall()
def print_report(self, cr, uid, form, context=None): self.validate_parameters(cr, uid, form, context=context) _ails = self.get_ail(cr, uid, form, context=context) _ails_table = list_to_pgTable(_ails, _ARRAY_NAME, [('id', 'INTEGER')]) form.add_marshalled_data(_TABLE_NAME, _ails_table) form.add_marshalled_data('RPT_SQL', RPT_SQL) prec = self.pool.get('decimal.precision').precision_get(cr, uid, 'Product UoM') zero = '0' * prec form.add_marshalled_data('QTY_FORMAT', "#,##0.%s;-#,##0.%s" % (zero,zero))
def print_report(self, cr, uid, form, context=None): self.validate_parameters(cr, uid, form, context=context) sol_subtotal = self.get_sol_subtotal(cr, uid, form, context=context) sol_subtotal_table = list_to_pgTable(sol_subtotal, 'sol_subtotal', [('id', 'INTEGER'), ('subtotal', 'NUMERIC')]) form.add_marshalled_data('SOL_SUBTOTAL_TABLE', sol_subtotal_table) all_customers_credit_notes = self.get_credit_notes(cr, uid, form, context=context) form.add_marshalled_data('CREDIT_NOTES', all_customers_credit_notes) form.add_marshalled_data('REPORT_SQL', REPORT_SQL)
def _get_tree_data(self, cr, uid, cid, from_date, to_date, context=None): # Get selected company ID and its descendant company IDs company = self.pool.get('res.company').browse(cr, uid, cid, context=context) cids = get_company_ids(company) # Get the periods of the selected company crit = [('date_stop', '>=', from_date), ('date_start', '<=', to_date), ('company_id', '=', cid)] period_ids = self.pool.get('account.period').search(cr, uid, crit, context=context) if not period_ids: return [] periods = self.pool.get('account.period').browse(cr, uid, period_ids, context=context) period_data = [] for period in periods: period_data.append((period.id, period.date_start, period.date_stop)) period_data_table = list_to_pgTable(period_data, 'period', [('id', 'INTEGER'), ('date_start', 'DATE'), ('date_stop', 'DATE')]) acc_ids = self.pool.get('account.account').search(cr, uid, [('type', '=', 'liquidity')], context=context) # Execute query query = cash_flow_realization_report_sql() % { 'ROOT_COMPANY_PERIOD_ID_DATE_START_DATE_STOP_TABLE': period_data_table, 'FISCAL_YEAR_DATE_START': periods[0].fiscalyear_id.date_start, 'COMPANY_IDS': ', '.join(str(cid).replace('L', '') for cid in cids), 'ACCOUNT_IDS': ', '.join('%d' % acc_id for acc_id in acc_ids), 'DATE_START': from_date, 'DATE_STOP': to_date, } cr.execute(query) return cr.dictfetchall()
def generate_report(self, cr, uid, ids, context=None): # Prepare things if type(ids) != list: ids = [ids] form = self.read(cr, uid, ids, ['use_indentation', 'from_date', 'to_date', 'rpt_output', 'tree_id', 'company_id', 'rpt_name', 'no_zero'], context=context)[0] # Get tree data tree_data = self._get_tree_data(cr, uid, form['company_id'][0], form['from_date'], form['to_date'], context=context) if len(tree_data) == 0: raise osv.except_osv(_('Error !'), _('No data to print !')) # Now we can assume at least one company exists so that the crosstab # can be ensured to display all nodes in the reporting tree. # Get reporting tree tree = cash_flow_tree(cr, uid, form['tree_id'][0], context=context) # Fuse tree data and reporting tree form_obj = self.browse(cr, uid, ids, context=context)[0] (normalizer, rounder, is_zero) = get_currency_toolkit(cr, uid, form_obj.currency_id, context) tree.attach_data(tree_data, normalizer, rounder, is_zero) # Sum the tree up tree.sum_up(normalizer, rounder, is_zero) # Linearized and stringified the tree linearized_tree = tree.linearize(form['no_zero']) tree_table = list_to_pgTable(linearized_tree, 'core_data', [('row_id', 'INTEGER'), ('node_id', 'INTEGER'), ('period_id', 'INTEGER'), ('com_id', 'INTEGER'), ('amount', 'NUMERIC'), ('is_leaf', 'BOOLEAN'), ('is_total_node', 'BOOLEAN'), ('is_special_node', 'BOOLEAN')]) # Set report parameters report_parameters_left = [(1, 'Report Name', form['rpt_name']), (2, 'From (YYYY-MM-DD)', form['from_date']), (3, 'Company', form_obj.company_id.name), ] report_parameters_table_left = list_to_pgTable(report_parameters_left, 't', [('ord', 'INTEGER'), ('key', 'TEXT'), ('value', 'TEXT')]) report_parameters_right = [(1, 'Reporting Tree', form_obj.tree_id.name), (2, 'To (YYYY-MM-DD)', form['to_date']), ] report_parameters_table_right = list_to_pgTable(report_parameters_right, 't', [('ord', 'INTEGER'), ('key', 'TEXT'), ('value', 'TEXT')]) # Memorize the result for parser consumption self.write(cr, uid, ids, { 'tree_table': tree_table, 'report_parameters_table_left': report_parameters_table_left, 'report_parameters_table_right': report_parameters_table_right, }, context) # Redirecting to reporting service data = {} data['ids'] = context.get('active_ids', []) data['model'] = context.get('active_model', 'via.cash.flow.realization.report') data['form'] = form return {'type': 'ir.actions.report.xml', 'report_name': get_service_name(cr, data['form']['rpt_name'], data['form']['rpt_output'], context=context), 'datas': data}
def _get_data(self, cr, uid, root_account_id, rpt_name, display_checksum, display_move, cmp1_enabled, context): at = account_tree(display_checksum) if rpt_name in ('VIA Combined Balance Sheet', 'Balance Sheet'): ((pl_type, pl_account_id, shorter, shorter_end), tree, separator_nr) = at.report_balance_sheet(self.pool, cr, uid, root_account_id, context) if pl_type is None: if pl_account_id == 1: com_pool = self.pool.get('res.company') com_names = [x[1] for x in com_pool.name_get(cr, uid, tree, context=context)] raise osv.except_osv(_('Error !'), _("Companies '%s' do not have reserve account" % "', '".join(com_names))) elif pl_account_id == 2: acc_pool = self.pool.get('account.account') reserve_acc_names = [x[1] for x in acc_pool.name_get(cr, uid, tree, context=context)] raise osv.except_osv(_('Error !'), _("Reserve account(s) '%s' cannot be" " found in asset or liability branch." " The reserve account(s) may have not" " been mapped to the consolidating" " company or may have the wrong" " parent account(s)") % "', '".join(reserve_acc_names)) elif pl_account_id == 3: com_pool = self.pool.get('res.company') msgs = [] for (cid, missing_head_accs) in tree.iteritems(): com_name = com_pool.name_get(cr, uid, [cid], context=context)[0][1] msgs.append(_("company '%s' has not set its '%s' head" " account(s)") % (com_name, "', '".join(missing_head_accs))) raise osv.except_osv(_('Error !'), ", ".join(msgs)) elif pl_account_id == 4: acc_pool = self.pool.get('account.account') acc = acc_pool.browse(cr, uid, root_account_id, context=context) raise osv.except_osv(_('Error !'), ("Account '%s %s' is a descendant of root account '%s %s'," " but company '%s' is not a descendant of root company '%s'" % (tree.code, tree.name, acc.code, acc.name, tree.company_id.name, acc.company_id.name))) elif pl_account_id == 5: com_pool = self.pool.get('res.company') com_names = [x[1] for x in com_pool.name_get(cr, uid, tree, context=context)] raise osv.except_osv(_('Error !'), _("Companies '%s' do not have currency gain/loss account" % "', '".join(com_names))) elif pl_account_id == 6: acc_pool = self.pool.get('account.account') xgl_acc_names = [x[1] for x in acc_pool.name_get(cr, uid, tree, context=context)] raise osv.except_osv(_('Error !'), _("Currency gain/loss account(s) '%s' cannot be" " found in asset or liability branch." " The currency gain/loss account(s) may have not" " been mapped to the consolidating" " company or may have the wrong" " parent account(s)") % "', '".join(xgl_acc_names)) arg = ','.join([pl_type, str(pl_account_id), shorter, str(shorter_end)]) if rpt_name == 'Balance Sheet': type_cast = tree[0] linearized_tree = tree[1] prms_left = context['via_financial_reports.report_parameters_left'] prms_right = context['via_financial_reports.report_parameters_right'] if cmp1_enabled: context['via_financial_reports.cmp1_phase'] = True (unused, cmp1_tree, unused) = at.report_balance_sheet(self.pool, cr, uid, root_account_id, context) del context['via_financial_reports.cmp1_phase'] linearized_tree.extend(cmp1_tree[1]) prms_left.extend(context['via_financial_reports.report_parameters_left']) prms_right.extend(context['via_financial_reports.report_parameters_right']) tree = list_to_pgTable(linearized_tree, 't', type_cast) context['via_financial_reports.report_parameters_left'] = prms_left context['via_financial_reports.report_parameters_right'] = prms_right elif rpt_name in ('VIA Combined Profit/Loss', 'Profit/Loss'): (profit_loss_line, tree, separator_nr) = at.report_profit_loss(self.pool, cr, uid, root_account_id, context) if profit_loss_line is None: com_pool = self.pool.get('res.company') msgs = [] for (cid, missing_head_accs) in tree.iteritems(): com_name = com_pool.name_get(cr, uid, [cid], context=context)[0][1] msgs.append(_("company '%s' has not set its '%s' head" " account(s)") % (com_name, "', '".join(missing_head_accs))) raise osv.except_osv(_('Error !'), ", ".join(msgs)) if tree is None: acc_pool = self.pool.get('account.account') acc = acc_pool.browse(cr, uid, root_account_id, context=context) raise osv.except_osv(_('Error !'), ("Account '%s %s' is a descendant of root account '%s %s'," " but company '%s' is not a descendant of root company '%s'" % (separator_nr.code, separator_nr.name, acc.code, acc.name, separator_nr.company_id.name, acc.company_id.name))) arg = profit_loss_line if rpt_name == 'Profit/Loss': type_cast = tree[0] linearized_tree = tree[1] prms_left = context['via_financial_reports.report_parameters_left'] prms_right = context['via_financial_reports.report_parameters_right'] if cmp1_enabled: context['via_financial_reports.cmp1_phase'] = True (unused, cmp1_tree, unused) = at.report_profit_loss(self.pool, cr, uid, root_account_id, context) del context['via_financial_reports.cmp1_phase'] linearized_tree.extend(cmp1_tree[1]) prms_left.extend(context['via_financial_reports.report_parameters_left']) prms_right.extend(context['via_financial_reports.report_parameters_right']) tree = list_to_pgTable(linearized_tree, 't', type_cast) context['via_financial_reports.report_parameters_left'] = prms_left context['via_financial_reports.report_parameters_right'] = prms_right elif (rpt_name in ('Trial Balance', 'General Ledger', 'General Ledger/Trial Balance')): context['via_financial_reports.gl_new'] = (rpt_name in ('General Ledger', 'General Ledger/Trial Balance')) if context['via_financial_reports.gl_new']: context['via_financial_reports.gl_new_move_lines'] = {} if display_move or context['via_financial_reports.gl_new']: (move_lines, tree, separator_nr) = at.report_general_ledger_with_move(self.pool, cr, uid, root_account_id, context) arg = move_lines if rpt_name == 'General Ledger/Trial Balance': type_cast = tree[0] linearized_tree = tree[1] prms_left = context['via_financial_reports.report_parameters_left'] prms_right = context['via_financial_reports.report_parameters_right'] if cmp1_enabled: context['via_financial_reports.gl_new_move_lines'] = {} context['via_financial_reports.cmp1_phase'] = True (unused, cmp1_tree, unused) = at.report_general_ledger_with_move(self.pool, cr, uid, root_account_id, context) del context['via_financial_reports.cmp1_phase'] linearized_tree.extend(cmp1_tree[1]) prms_left.extend(context['via_financial_reports.report_parameters_left']) prms_right.extend(context['via_financial_reports.report_parameters_right']) tree = list_to_pgTable(linearized_tree, 't', type_cast) context['via_financial_reports.report_parameters_left'] = prms_left context['via_financial_reports.report_parameters_right'] = prms_right else: (unused, tree, separator_nr) = at.report_general_ledger(self.pool, cr, uid, root_account_id, context) arg = None if tree is None: acc_pool = self.pool.get('account.account') acc = acc_pool.browse(cr, uid, root_account_id, context=context) raise osv.except_osv(_('Error !'), ("Account '%s %s' is a descendant of root account '%s %s'," " but company '%s' is not a descendant of root company '%s'" % (separator_nr.code, separator_nr.name, acc.code, acc.name, separator_nr.company_id.name, acc.company_id.name))) else: raise osv.except_osv(_('Error !'), _('Unrecognized report name: %s' % rpt_name)) return (arg, tree, separator_nr)
def print_report(self, cr, uid, ids, context=None): if context is None: context = {} form = self.browse(cr, uid, ids[0], context=context) self._assert_within_fiscalyear(cr, uid, form.date_from, form.date_to, form.fiscalyear_id.id, context) context['via_financial_reports.form'] = form context['via_financial_reports.form.bs_as_of'] = form.bs_as_of root_account_id = form.chart_account_id and form.chart_account_id.id or 0 rpt_name = context['via_jasper_report_utils.rpt_name'] arg = None display_account = form.display_account if display_account == 'bal_all': display_checksum = form.display_checksum else: display_checksum = False # The use of the following filters destroy tree structure journal_ids = form.journal_ids account_ids = form.account_ids if display_account != 'bal_all' or journal_ids or account_ids: form.write({'use_indentation': False}, context=context) (arg, tree, separator_nr) = self._get_data(cr, uid, root_account_id, rpt_name, display_checksum, form.display_move, form.cmp1_enabled, context) del context['via_financial_reports.form'] report_parameters_left = list_to_pgTable(context.get('via_financial_reports.report_parameters_left', ''), 't', [('ord', 'INTEGER'), ('key', 'TEXT'), ('value', 'TEXT')]) report_parameters_right = list_to_pgTable(context.get('via_financial_reports.report_parameters_right', ''), 't', [('ord', 'INTEGER'), ('key', 'TEXT'), ('value', 'TEXT')]) form.write({'arg': arg, 'account_tree': tree, 'separator_nr': separator_nr, 'report_parameters_left': report_parameters_left, 'report_parameters_right': report_parameters_right,}, context=context) rpt_landscape = form.display_type rpt_format = form.display_format rpt_drcr = form.display_drcr if rpt_name in ('Trial Balance', 'General Ledger'): rpt_drcr = True if rpt_name in ('General Ledger', 'General Ledger/Trial Balance'): rpt_with_move = True else: rpt_with_move = form.display_move rpt_output = form.rpt_output service_names_filter_ctx = { 'via_financial_reports.rpt_output': rpt_output, 'via_financial_reports.rpt_landscape': rpt_landscape, 'via_financial_reports.rpt_drcr': rpt_drcr, 'via_financial_reports.rpt_with_move': rpt_with_move, 'via_financial_reports.rpt_format': rpt_format, } service_name = jasper_report.get_service_name(cr, uid, rpt_name, rpt_output, _service_names_filter, service_names_filter_ctx) data = { 'form': { 'id': form.id }, } return { 'type': 'ir.actions.report.xml', 'report_name': service_name, 'datas': data, }
def _get_data(self, cr, uid, root_account_id, rpt_name, display_checksum, display_move, cmp1_enabled, context): at = account_tree(display_checksum) if rpt_name in ('VIA Combined Balance Sheet', 'Balance Sheet'): ((pl_type, pl_account_id, shorter, shorter_end), tree, separator_nr) = at.report_balance_sheet(self.pool, cr, uid, root_account_id, context) if pl_type is None: if pl_account_id == 1: com_pool = self.pool.get('res.company') com_names = [ x[1] for x in com_pool.name_get( cr, uid, tree, context=context) ] raise osv.except_osv( _('Error !'), _("Companies '%s' do not have reserve account" % "', '".join(com_names))) elif pl_account_id == 2: acc_pool = self.pool.get('account.account') reserve_acc_names = [ x[1] for x in acc_pool.name_get( cr, uid, tree, context=context) ] raise osv.except_osv( _('Error !'), _("Reserve account(s) '%s' cannot be" " found in asset or liability branch." " The reserve account(s) may have not" " been mapped to the consolidating" " company or may have the wrong" " parent account(s)") % "', '".join(reserve_acc_names)) elif pl_account_id == 3: com_pool = self.pool.get('res.company') msgs = [] for (cid, missing_head_accs) in tree.iteritems(): com_name = com_pool.name_get(cr, uid, [cid], context=context)[0][1] msgs.append( _("company '%s' has not set its '%s' head" " account(s)") % (com_name, "', '".join(missing_head_accs))) raise osv.except_osv(_('Error !'), ", ".join(msgs)) elif pl_account_id == 4: acc_pool = self.pool.get('account.account') acc = acc_pool.browse(cr, uid, root_account_id, context=context) raise osv.except_osv(_('Error !'), ( "Account '%s %s' is a descendant of root account '%s %s'," " but company '%s' is not a descendant of root company '%s'" % (tree.code, tree.name, acc.code, acc.name, tree.company_id.name, acc.company_id.name))) elif pl_account_id == 5: com_pool = self.pool.get('res.company') com_names = [ x[1] for x in com_pool.name_get( cr, uid, tree, context=context) ] raise osv.except_osv( _('Error !'), _("Companies '%s' do not have currency gain/loss account" % "', '".join(com_names))) elif pl_account_id == 6: acc_pool = self.pool.get('account.account') xgl_acc_names = [ x[1] for x in acc_pool.name_get( cr, uid, tree, context=context) ] raise osv.except_osv( _('Error !'), _("Currency gain/loss account(s) '%s' cannot be" " found in asset or liability branch." " The currency gain/loss account(s) may have not" " been mapped to the consolidating" " company or may have the wrong" " parent account(s)") % "', '".join(xgl_acc_names)) arg = ','.join( [pl_type, str(pl_account_id), shorter, str(shorter_end)]) if rpt_name == 'Balance Sheet': type_cast = tree[0] linearized_tree = tree[1] prms_left = context[ 'via_financial_reports.report_parameters_left'] prms_right = context[ 'via_financial_reports.report_parameters_right'] if cmp1_enabled: context['via_financial_reports.cmp1_phase'] = True (unused, cmp1_tree, unused) = at.report_balance_sheet(self.pool, cr, uid, root_account_id, context) del context['via_financial_reports.cmp1_phase'] linearized_tree.extend(cmp1_tree[1]) prms_left.extend( context['via_financial_reports.report_parameters_left'] ) prms_right.extend(context[ 'via_financial_reports.report_parameters_right']) tree = list_to_pgTable(linearized_tree, 't', type_cast) context[ 'via_financial_reports.report_parameters_left'] = prms_left context[ 'via_financial_reports.report_parameters_right'] = prms_right elif rpt_name in ('VIA Combined Profit/Loss', 'Profit/Loss'): (profit_loss_line, tree, separator_nr) = at.report_profit_loss(self.pool, cr, uid, root_account_id, context) if profit_loss_line is None: com_pool = self.pool.get('res.company') msgs = [] for (cid, missing_head_accs) in tree.iteritems(): com_name = com_pool.name_get(cr, uid, [cid], context=context)[0][1] msgs.append( _("company '%s' has not set its '%s' head" " account(s)") % (com_name, "', '".join(missing_head_accs))) raise osv.except_osv(_('Error !'), ", ".join(msgs)) if tree is None: acc_pool = self.pool.get('account.account') acc = acc_pool.browse(cr, uid, root_account_id, context=context) raise osv.except_osv(_('Error !'), ( "Account '%s %s' is a descendant of root account '%s %s'," " but company '%s' is not a descendant of root company '%s'" % (separator_nr.code, separator_nr.name, acc.code, acc.name, separator_nr.company_id.name, acc.company_id.name))) arg = profit_loss_line if rpt_name == 'Profit/Loss': type_cast = tree[0] linearized_tree = tree[1] prms_left = context[ 'via_financial_reports.report_parameters_left'] prms_right = context[ 'via_financial_reports.report_parameters_right'] if cmp1_enabled: context['via_financial_reports.cmp1_phase'] = True (unused, cmp1_tree, unused) = at.report_profit_loss(self.pool, cr, uid, root_account_id, context) del context['via_financial_reports.cmp1_phase'] linearized_tree.extend(cmp1_tree[1]) prms_left.extend( context['via_financial_reports.report_parameters_left'] ) prms_right.extend(context[ 'via_financial_reports.report_parameters_right']) tree = list_to_pgTable(linearized_tree, 't', type_cast) context[ 'via_financial_reports.report_parameters_left'] = prms_left context[ 'via_financial_reports.report_parameters_right'] = prms_right elif (rpt_name in ('Trial Balance', 'General Ledger', 'General Ledger/Trial Balance')): context['via_financial_reports.gl_new'] = (rpt_name in ( 'General Ledger', 'General Ledger/Trial Balance')) if context['via_financial_reports.gl_new']: context['via_financial_reports.gl_new_move_lines'] = {} if display_move or context['via_financial_reports.gl_new']: (move_lines, tree, separator_nr) = at.report_general_ledger_with_move( self.pool, cr, uid, root_account_id, context) arg = move_lines if rpt_name == 'General Ledger/Trial Balance': type_cast = tree[0] linearized_tree = tree[1] prms_left = context[ 'via_financial_reports.report_parameters_left'] prms_right = context[ 'via_financial_reports.report_parameters_right'] if cmp1_enabled: context['via_financial_reports.gl_new_move_lines'] = {} context['via_financial_reports.cmp1_phase'] = True (unused, cmp1_tree, unused) = at.report_general_ledger_with_move( self.pool, cr, uid, root_account_id, context) del context['via_financial_reports.cmp1_phase'] linearized_tree.extend(cmp1_tree[1]) prms_left.extend(context[ 'via_financial_reports.report_parameters_left']) prms_right.extend(context[ 'via_financial_reports.report_parameters_right']) tree = list_to_pgTable(linearized_tree, 't', type_cast) context[ 'via_financial_reports.report_parameters_left'] = prms_left context[ 'via_financial_reports.report_parameters_right'] = prms_right else: (unused, tree, separator_nr) = at.report_general_ledger( self.pool, cr, uid, root_account_id, context) arg = None if tree is None: acc_pool = self.pool.get('account.account') acc = acc_pool.browse(cr, uid, root_account_id, context=context) raise osv.except_osv(_('Error !'), ( "Account '%s %s' is a descendant of root account '%s %s'," " but company '%s' is not a descendant of root company '%s'" % (separator_nr.code, separator_nr.name, acc.code, acc.name, separator_nr.company_id.name, acc.company_id.name))) else: raise osv.except_osv(_('Error !'), _('Unrecognized report name: %s' % rpt_name)) return (arg, tree, separator_nr)
def print_report(self, cr, uid, ids, context=None): if context is None: context = {} form = self.browse(cr, uid, ids[0], context=context) self._assert_within_fiscalyear(cr, uid, form.date_from, form.date_to, form.fiscalyear_id.id, context) context['via_financial_reports.form'] = form context['via_financial_reports.form.bs_as_of'] = form.bs_as_of root_account_id = form.chart_account_id and form.chart_account_id.id or 0 rpt_name = context['via_jasper_report_utils.rpt_name'] arg = None display_account = form.display_account if display_account == 'bal_all': display_checksum = form.display_checksum else: display_checksum = False # The use of the following filters destroy tree structure journal_ids = form.journal_ids account_ids = form.account_ids if display_account != 'bal_all' or journal_ids or account_ids: form.write({'use_indentation': False}, context=context) (arg, tree, separator_nr) = self._get_data(cr, uid, root_account_id, rpt_name, display_checksum, form.display_move, form.cmp1_enabled, context) del context['via_financial_reports.form'] report_parameters_left = list_to_pgTable( context.get('via_financial_reports.report_parameters_left', ''), 't', [('ord', 'INTEGER'), ('key', 'TEXT'), ('value', 'TEXT')]) report_parameters_right = list_to_pgTable( context.get('via_financial_reports.report_parameters_right', ''), 't', [('ord', 'INTEGER'), ('key', 'TEXT'), ('value', 'TEXT')]) form.write( { 'arg': arg, 'account_tree': tree, 'separator_nr': separator_nr, 'report_parameters_left': report_parameters_left, 'report_parameters_right': report_parameters_right, }, context=context) rpt_landscape = form.display_type rpt_format = form.display_format rpt_drcr = form.display_drcr if rpt_name in ('Trial Balance', 'General Ledger'): rpt_drcr = True if rpt_name in ('General Ledger', 'General Ledger/Trial Balance'): rpt_with_move = True else: rpt_with_move = form.display_move rpt_output = form.rpt_output service_names_filter_ctx = { 'via_financial_reports.rpt_output': rpt_output, 'via_financial_reports.rpt_landscape': rpt_landscape, 'via_financial_reports.rpt_drcr': rpt_drcr, 'via_financial_reports.rpt_with_move': rpt_with_move, 'via_financial_reports.rpt_format': rpt_format, } service_name = jasper_report.get_service_name( cr, uid, rpt_name, rpt_output, _service_names_filter, service_names_filter_ctx) data = { 'form': { 'id': form.id }, } return { 'type': 'ir.actions.report.xml', 'report_name': service_name, 'datas': data, }
def generate_report(self, cr, uid, ids, context=None): # Prepare things if type(ids) != list: ids = [ids] form = self.read( cr, uid, ids, ["use_indentation", "from_date", "to_date", "rpt_output", "tree_id", "company_id", "rpt_name", "no_zero"], context=context, )[0] # Get tree data tree_data = self._get_tree_data( cr, uid, form["company_id"][0], form["from_date"], form["to_date"], context=context ) if len(tree_data) == 0: raise osv.except_osv(_("Error !"), _("No data to print !")) # Now we can assume at least one company exists so that the crosstab # can be ensured to display all nodes in the reporting tree. # Get reporting tree tree = cash_flow_tree(cr, uid, form["tree_id"][0], context=context) # Fuse tree data and reporting tree form_obj = self.browse(cr, uid, ids, context=context)[0] (normalizer, rounder, is_zero) = get_currency_toolkit(cr, uid, form_obj.currency_id, context) tree.attach_data(tree_data, normalizer, rounder, is_zero) # Sum the tree up tree.sum_up(normalizer, rounder, is_zero) # Linearized and stringified the tree linearized_tree = tree.linearize(form["no_zero"]) tree_table = list_to_pgTable( linearized_tree, "core_data", [ ("row_id", "INTEGER"), ("node_id", "INTEGER"), ("period_id", "INTEGER"), ("com_id", "INTEGER"), ("amount", "NUMERIC"), ("is_leaf", "BOOLEAN"), ("is_total_node", "BOOLEAN"), ("is_special_node", "BOOLEAN"), ], ) # Set report parameters report_parameters_left = [ (1, "Report Name", form["rpt_name"]), (2, "From (YYYY-MM-DD)", form["from_date"]), (3, "Company", form_obj.company_id.name), ] report_parameters_table_left = list_to_pgTable( report_parameters_left, "t", [("ord", "INTEGER"), ("key", "TEXT"), ("value", "TEXT")] ) report_parameters_right = [ (1, "Reporting Tree", form_obj.tree_id.name), (2, "To (YYYY-MM-DD)", form["to_date"]), ] report_parameters_table_right = list_to_pgTable( report_parameters_right, "t", [("ord", "INTEGER"), ("key", "TEXT"), ("value", "TEXT")] ) # Memorize the result for parser consumption self.write( cr, uid, ids, { "tree_table": tree_table, "report_parameters_table_left": report_parameters_table_left, "report_parameters_table_right": report_parameters_table_right, }, context, ) # Redirecting to reporting service data = {} data["ids"] = context.get("active_ids", []) data["model"] = context.get("active_model", "via.cash.flow.realization.report") data["form"] = form return { "type": "ir.actions.report.xml", "report_name": get_service_name(cr, data["form"]["rpt_name"], data["form"]["rpt_output"], context=context), "datas": data, }