def print_account_totals(self, _xs, xlwtlib, ws, row_start_account, row_position, current_account, _p): cell_format = _xs['bold'] + _xs['fill'] + \ _xs['borders_all'] + _xs['wrap'] + _xs['top'] cell_style = xlwtlib.easyxf(cell_format) cell_style_decimal = xlwtlib.easyxf( cell_format + _xs['right'], num_format_str=report_xls.decimal_format) c_specs = [ ('acc_title', 2, 0, 'text', current_account.name), ('code', 1, 0, 'text', current_account.code), ] for column in range(3, 7): # in case of one single comparison, the column 6 will contain # percentages if (_p.comparison_mode == 'single' and column == 6): total_diff = rowcol_to_cell(row_position, column - 1) total_balance = rowcol_to_cell(row_position, column - 2) account_formula = 'Round(' + total_diff + \ '/' + total_balance + '*100;0)' else: account_start = rowcol_to_cell(row_start_account, column) account_end = rowcol_to_cell(row_position - 1, column) account_formula = 'Round(SUM(' + \ account_start + ':' + account_end + ');2)' c_specs += [('total%s' % column, 1, 0, 'text', None, account_formula, None, cell_style_decimal)] row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs]) row_position = self.xls_write_row( ws, row_position, row_data, cell_style) return row_position + 1
def _print_totals(self, data, row_pos): init_pos = 5 end_pos = row_pos - 2 # Calculamos importes totales y coste total para calcular % rent total base, ld_base, ly_base = 0, 0, 0 cost, ld_cost, ly_cost = 0, 0, 0 for acc_name in data: val = data[acc_name] base += val['base'] if val['base'] else 0.0 ld_base += val['ld_base'] if val['ld_base'] else 0.0 ly_base += val['ly_base'] if val['ly_base'] else 0.0 cost += val['p_price'] if val['p_price'] else 0.0 ld_cost += val['ld_p_price'] if val['ld_p_price'] else 0.0 ly_cost += val['ly_p_price'] if val['ly_p_price'] else 0.0 margin = ((base - cost) * 100) / base if base else 0.0 ld_margin = ((ld_base - ld_cost) * 100) / ld_base if ld_base else 0.0 ly_margin = ((ly_base - ly_cost) * 100) / ly_base if ly_base else 0.0 # RENT val_margin = round(margin, 2) val_ld_margin = round(ld_margin, 2) val_ly_margin = round(ly_margin, 2) # EUROS - KILOS val_sum = {} for i in range(4, 14): cell_start = rowcol_to_cell(init_pos, i) cell_end = rowcol_to_cell(end_pos, i) val_sum[i] = 'SUM(' + cell_start + ':' + cell_end + ')' c_specs = [ ('a', 1, 0, 'text', _('TOTALES'), None, self.aml_cell_style_decimal), ('b', 1, 0, 'number', val_margin, None, self.aml_cell_style_decimal), ('c', 1, 0, 'number', val_ld_margin, None, self.aml_cell_style_decimal), ('d', 1, 0, 'number', val_ly_margin, None, self.aml_cell_style_decimal), ('e', 1, 0, 'number', None, val_sum[4], self.aml_cell_style_decimal), ('f', 1, 0, 'number', None, val_sum[5], self.aml_cell_style_decimal), ('g', 1, 0, 'number', None, val_sum[6], self.aml_cell_style_decimal), ('h', 1, 0, 'number', None, val_sum[7], self.aml_cell_style_decimal), ('i', 1, 0, 'number', None, val_sum[8], self.aml_cell_style_decimal), ('j', 1, 0, 'number', None, val_sum[9], self.aml_cell_style_decimal), ('k', 1, 0, 'number', None, val_sum[10], self.aml_cell_style_decimal), ('l', 1, 0, 'number', None, val_sum[11], self.aml_cell_style_decimal), ('m', 1, 0, 'number', None, val_sum[12], self.aml_cell_style_decimal), ('n', 1, 0, 'number', None, val_sum[13], self.aml_cell_style_decimal), ] row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs]) row_pos = self.xls_write_row(self.ws, row_pos, row_data) return row_pos
def print_cumul_partner(self, row_position, row_start_partner, account, _p, data): # the text "Cumulated Balance on Partner starts in column 4 when # selecting the option regroup by currency, 5 in the other case start_col = 5 debit_partner_start = rowcol_to_cell(row_start_partner, start_col + 3) debit_partner_end = rowcol_to_cell(row_position - 1, start_col + 3) debit_partner_total = 'SUM(' + debit_partner_start + \ ':' + debit_partner_end + ')' credit_partner_start = rowcol_to_cell(row_start_partner, start_col + 4) credit_partner_end = rowcol_to_cell(row_position - 1, start_col + 4) credit_partner_total = 'SUM(' + credit_partner_start + \ ':' + credit_partner_end + ')' bal_curr_start = rowcol_to_cell(row_start_partner, start_col + 6) bal_curr_end = rowcol_to_cell(row_position - 1, start_col + 6) cumul_balance_curr = 'SUM(' + bal_curr_start + ':' + bal_curr_end + ')' bal_partner_debit = rowcol_to_cell(row_position, start_col + 3) bal_partner_credit = rowcol_to_cell(row_position, start_col + 4) bal_partner_total = bal_partner_debit + '-' + bal_partner_credit c_specs = [('empty%s' % x, 1, 0, 'text', None) for x in range(start_col)] c_specs += [ ('init_bal', 1, 0, 'text', _('Cumulated Balance on Partner')), ('rec', 1, 0, 'text', None), ('empty5', 1, 0, 'text', None), ('debit', 1, 0, 'number', None, debit_partner_total, self.style_partner_cumul_decimal), ('credit', 1, 0, 'number', None, credit_partner_total, self.style_partner_cumul_decimal), ('cumul_bal', 1, 0, 'number', None, bal_partner_total, self.style_partner_cumul_decimal), ] if _p.amount_currency(data): if account.currency_id: c_specs += [('cumul_bal_curr', 1, 0, 'number', None, cumul_balance_curr, self.style_partner_cumul_decimal), ('curr_name', 1, 0, 'text', account.currency_id.name, None, self.style_partner_cumul_right), ] else: c_specs += [('cumul_bal_curr', 1, 0, 'text', '-', None, self.style_partner_cumul_right), ('curr_name', 1, 0, 'text', '', None, self.style_partner_cumul_right) ] row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs]) row_position = self.xls_write_row( self.ws, row_position, row_data, self.style_partner_cumul) return row_position + 1
def print_cumul_account(self, row_position, row_start_account, account, _p, data): #print by account the totals of the credit and debit + balance calculation #This procedure will create an Excel sumif function that will check in the column "label" for the "Cumulated Balance.." string and make a sum of the debit & credit data start_col = 5 #the text "Cumulated Balance on Partner starts in column 4 when selecting the option regroup by currency, 5 in the other case reference_start = rowcol_to_cell(row_start_account, start_col) #range in which we search for the text "Cumulated Balance on Partner" reference_stop = rowcol_to_cell(row_position -1 , start_col) range_debit_start = rowcol_to_cell(row_start_account, start_col + 3) #range in which we make the sum of all the cumulated balance lines (debit) range_debit_stop = rowcol_to_cell(row_position -1, start_col + 3) range_credit_start = rowcol_to_cell(row_start_account, start_col + 4) #range in which we make the sum of all the cumulated balance lines (crebit) range_credit_stop = rowcol_to_cell(row_position -1, start_col + 4) search_key = _('Cumulated Balance on Partner') total_debit_account = 'SUMIF(' + reference_start + ':' + reference_stop + ';"' + search_key + '";' + range_debit_start + ':' + range_debit_stop + ')' total_credit_account = 'SUMIF(' + reference_start + ':' + reference_stop + ';"' + search_key + '";' + range_credit_start + ':' + range_credit_stop + ')' bal_account_debit = rowcol_to_cell(row_position, start_col + 3) bal_account_credit = rowcol_to_cell(row_position, start_col + 4) bal_account_total = bal_account_debit + '-' + bal_account_credit bal_curr_start = rowcol_to_cell(row_start_account, start_col + 6) bal_curr_end = rowcol_to_cell(row_position-1, start_col + 6) cumul_balance_curr = 'SUMIF(' + reference_start + ':' + reference_stop + ';"' + search_key + '";' + bal_curr_start + ':' + bal_curr_end + ')' c_specs = [ ('acc_title', start_col, 0, 'text', ' - '.join([account.code, account.name])), ('init_bal', 2, 0, 'text', _('Cumulated Balance on Account')), ('empty2', 1, 0, 'text', None), ('debit', 1, 0, 'number', None, total_debit_account, style_account_title_decimal), ('credit', 1, 0, 'number', None, total_credit_account, style_account_title_decimal), ('balance', 1, 0, 'number', None, bal_account_total, style_account_title_decimal), ] if _p.amount_currency(data): if account.currency_id: c_specs += [('cumul_bal_curr', 1, 0, 'number', None, cumul_balance_curr), ('curr_name', 1, 0, 'text', account.currency_id.name, None, style_account_title_right), ] else: c_specs += [('cumul_bal_curr', 1, 0, 'text', "-", None, style_account_title_right), ('curr_name', 1, 0, 'text', "", None, style_account_title_right) ] row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs]) row_position = self.xls_write_row(ws, row_position, row_data, style_account_title) return row_position+1
def _journal_lines(self, o, ws, _p, row_pos, _xs): wanted_list = self.wanted_list debit_pos = self.debit_pos credit_pos = self.credit_pos # Column headers c_specs = map(lambda x: self.render( x, self.col_specs_lines_template, 'header', render_space={'_': _p._}), wanted_list) row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs]) row_pos = self.xls_write_row( ws, row_pos, row_data, row_style=self.rh_cell_style, set_column_size=True) ws.set_horz_split_pos(row_pos) # account move lines aml_start_pos = row_pos aml_cnt = len(_p.lines(o)) cnt = 0 for l in _p.lines(o): cnt += 1 debit_cell = rowcol_to_cell(row_pos, debit_pos) credit_cell = rowcol_to_cell(row_pos, credit_pos) bal_formula = debit_cell + '-' + credit_cell _logger.debug('dummy call - %s', bal_formula) c_specs = map( lambda x: self.render(x, self.col_specs_lines_template, 'lines'), wanted_list) row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs]) row_pos = self.xls_write_row( ws, row_pos, row_data, row_style=self.aml_cell_style) if l['draw_line'] and cnt != aml_cnt: row_pos += 1 # Totals debit_start = rowcol_to_cell(aml_start_pos, debit_pos) debit_stop = rowcol_to_cell(row_pos - 1, debit_pos) debit_formula = 'SUM(%s:%s)' % (debit_start, debit_stop) _logger.debug('dummy call - %s', debit_formula) credit_start = rowcol_to_cell(aml_start_pos, credit_pos) credit_stop = rowcol_to_cell(row_pos - 1, credit_pos) credit_formula = 'SUM(%s:%s)' % (credit_start, credit_stop) _logger.debug('dummy call - %s', credit_formula) debit_cell = rowcol_to_cell(row_pos, debit_pos) credit_cell = rowcol_to_cell(row_pos, credit_pos) bal_formula = debit_cell + '-' + credit_cell c_specs = map(lambda x: self.render( x, self.col_specs_lines_template, 'totals'), wanted_list) row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs]) row_pos = self.xls_write_row( ws, row_pos, row_data, row_style=self.rt_cell_style_right) return row_pos + 1
def print_group_cumul_partner(self,row_position, row_start_partner, account, _p, data): #print by partner the totals and cumulated balance (Excel formulas) when the option currency regroup is selected start_col = 4 #the text "Cumulated Balance on Partner starts in column 4 when selecting the option regroup by currency, 5 in the other case debit_partner_start = rowcol_to_cell(row_start_partner, start_col + 3) debit_partner_end = rowcol_to_cell(row_position-1, start_col + 3) debit_partner_total = 'SUM(' + debit_partner_start + ':' + debit_partner_end + ')' credit_partner_start = rowcol_to_cell(row_start_partner, start_col + 4) credit_partner_end = rowcol_to_cell(row_position-1, start_col + 4) credit_partner_total = 'SUM(' + credit_partner_start + ':' + credit_partner_end + ')' bal_curr_start = rowcol_to_cell(row_start_partner, start_col + 5) bal_curr_end = rowcol_to_cell(row_position-1, start_col + 5) cumul_balance_curr = 'SUM(' + bal_curr_start + ':' + bal_curr_end + ')' bal_partner_debit = rowcol_to_cell(row_position, start_col + 3) bal_partner_credit = rowcol_to_cell(row_position, start_col + 4) bal_partner_total = bal_partner_debit + '-' + bal_partner_credit c_specs = [('empty%s' %x, 1, 0, 'text', None) for x in range(start_col)] c_specs += [ ('init_bal', 1, 0, 'text', _('Cumulated Balance on Partner')), #, style_bold_italic), ('rec', 1, 0, 'text', None), ('empty5', 1, 0, 'text', None), ('debit', 1, 0, 'number', None, debit_partner_total, style_partner_cumul_decimal), ('credit', 1, 0, 'number', None, credit_partner_total, style_partner_cumul_decimal), ('cumul_bal', 1, 0, 'number', None, bal_partner_total, style_partner_cumul_decimal), ] if account.currency_id: c_specs += [ ('cumul_bal_curr', 1, 0, 'number', None, cumul_balance_curr, style_partner_cumul_decimal), ('curr_name', 1, 0, 'text', account.currency_id.name, None, style_partner_cumul_right), ] else: c_specs += [ ('cumul_bal_curr', 1, 0, 'text', "-", None, style_partner_cumul_right), ('curr_name', 1, 0, 'text', "", None, style_partner_cumul_right), ] row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs]) row_position = self.xls_write_row(ws, row_position, row_data, style_partner_cumul) return row_position+1
def generate_xls_report(self, _p, _xs, data, objects, wb): wl_overview = _p.wanted_list_overview wl_ar_details = _p.wanted_list_ar_details wl_ap_details = _p.wanted_list_ap_details self.col_specs_template_overview.update(_p.template_updates_overview) self.col_specs_template_details.update(_p.template_updates_details) _ = _p._ # TODO : adapt to allow rendering space extensions by inherited module # add objects to the render space for use in custom reports partner_obj = self.pool['res.partner'] # noqa: disable F841, report_xls namespace trick for i, wl in enumerate([wl_overview, wl_ar_details, wl_ap_details]): debit_pos = 'debit' in wl and wl.index('debit') credit_pos = 'credit' in wl and wl.index('credit') if not (credit_pos and debit_pos) and 'balance' in wl: raise orm.except_orm( _('Customisation Error!'), _("The 'Balance' field is a calculated XLS field " "requiring the presence of " "the 'Debit' and 'Credit' fields !")) if i == 0: debit_pos_o = debit_pos credit_pos_o = credit_pos elif i == 1: debit_pos_ar = debit_pos credit_pos_ar = credit_pos else: debit_pos_ap = debit_pos credit_pos_ap = credit_pos for r in _p.reports: title_short = r['title_short'].replace('/', '-') ws_o = wb.add_sheet(title_short) ws_d = wb.add_sheet((title_short + ' ' + _('Details'))[:31]) for ws in [ws_o, ws_d]: ws.panes_frozen = True ws.remove_splits = True ws.portrait = 0 # Landscape ws.fit_width_to_pages = 1 row_pos_o = 0 row_pos_d = 0 if r['type'] == 'receivable': wanted_list_details = wl_ar_details debit_pos_d = debit_pos_ar credit_pos_d = credit_pos_ar else: wanted_list_details = wl_ap_details debit_pos_d = debit_pos_ap credit_pos_d = credit_pos_ap # set print header/footer for ws in [ws_o, ws_d]: ws.header_str = self.xls_headers['standard'] ws.footer_str = self.xls_footers['standard'] # Title cell_style = xlwt.easyxf(_xs['xls_title']) report_name = ' - '.join( [_p.company.name, r['title'], _('Overview'), _p.report_info + ' - ' + _p.company.currency_id.name]) c_specs_o = [ ('report_name', 1, 0, 'text', report_name), ] row_data = self.xls_row_template(c_specs_o, ['report_name']) row_pos_o = self.xls_write_row( ws_o, row_pos_o, row_data, row_style=cell_style) row_pos_o += 1 report_name = ' - '.join( [_p.company.name, r['title'], _('Details'), _p.report_info + ' - ' + _p.company.currency_id.name]) c_specs_d = [ ('report_name', 1, 0, 'text', report_name), ] row_data = self.xls_row_template(c_specs_d, ['report_name']) row_pos_d = self.xls_write_row( ws_d, row_pos_d, row_data, row_style=cell_style) row_pos_d += 1 # Report Column Headers c_specs_o = map( lambda x: self.render( x, self.col_specs_template_overview, 'header', render_space={'_': _p._}), wl_overview) row_data = self.xls_row_template( c_specs_o, [x[0] for x in c_specs_o]) row_pos_o = self.xls_write_row( ws_o, row_pos_o, row_data, row_style=self.rh_cell_style, set_column_size=True) ws_o.set_horz_split_pos(row_pos_o) c_specs_d = map( lambda x: self.render( x, self.col_specs_template_details, 'header1', render_space={'_': _p._}), wanted_list_details) row_data = self.xls_row_template( c_specs_d, [x[0] for x in c_specs_d]) row_pos_d = self.xls_write_row( ws_d, row_pos_d, row_data, row_style=self.rh_cell_style, set_column_size=True) ws_d.set_horz_split_pos(row_pos_d) row_pos_d += 1 partner_debit_cells = [] partner_credit_cells = [] for p in r['partners']: debit_cell_o = rowcol_to_cell(row_pos_o, debit_pos_o) credit_cell_o = rowcol_to_cell(row_pos_o, credit_pos_o) bal_formula_o = debit_cell_o + '-' + credit_cell_o # noqa: disable F841, report_xls namespace trick c_specs_o = map( lambda x: self.render( x, self.col_specs_template_overview, 'lines'), wl_overview) row_data = self.xls_row_template( c_specs_o, [x[0] for x in c_specs_o]) row_pos_o = self.xls_write_row( ws_o, row_pos_o, row_data, row_style=self.pd_cell_style) row_pos_d += 1 debit_cell_d = rowcol_to_cell(row_pos_d, debit_pos_d) credit_cell_d = rowcol_to_cell(row_pos_d, credit_pos_d) partner_debit_cells.append(debit_cell_d) partner_credit_cells.append(credit_cell_d) bal_formula_d = debit_cell_d + '-' + credit_cell_d # noqa: disable F841, report_xls namespace trick line_cnt = len(p['lines']) debit_start = rowcol_to_cell(row_pos_d+1, debit_pos_d) debit_stop = rowcol_to_cell(row_pos_d+line_cnt, debit_pos_d) debit_formula = 'SUM(%s:%s)' % (debit_start, debit_stop) credit_start = rowcol_to_cell(row_pos_d+1, credit_pos_d) credit_stop = rowcol_to_cell(row_pos_d+line_cnt, credit_pos_d) credit_formula = 'SUM(%s:%s)' % (credit_start, credit_stop) c_specs_d = map( lambda x: self.render( x, self.col_specs_template_details, 'header2'), wanted_list_details) row_data = self.xls_row_template( c_specs_d, [x[0] for x in c_specs_d]) row_pos_d = self.xls_write_row( ws_d, row_pos_d, row_data, row_style=self.ph_cell_style) for l in p['lines']: debit_cell = rowcol_to_cell(row_pos_d, debit_pos_d) credit_cell = rowcol_to_cell(row_pos_d, credit_pos_d) bal_formula = debit_cell + '-' + credit_cell c_specs_d = map( lambda x: self.render( x, self.col_specs_template_details, 'lines'), wanted_list_details) row_data = self.xls_row_template( c_specs_d, [x[0] for x in c_specs_d]) row_pos_d = self.xls_write_row( ws_d, row_pos_d, row_data, row_style=self.pd_cell_style) # Totals p_cnt = len(r['partners']) debit_start = rowcol_to_cell(row_pos_o - p_cnt, debit_pos_o) debit_stop = rowcol_to_cell(row_pos_o - 1, debit_pos_o) debit_formula = 'SUM(%s:%s)' % (debit_start, debit_stop) credit_start = rowcol_to_cell(row_pos_o - p_cnt, credit_pos_o) credit_stop = rowcol_to_cell(row_pos_o - 1, credit_pos_o) credit_formula = 'SUM(%s:%s)' % (credit_start, credit_stop) debit_cell = rowcol_to_cell(row_pos_o, debit_pos_o) credit_cell = rowcol_to_cell(row_pos_o, credit_pos_o) bal_formula = debit_cell + '-' + credit_cell c_specs_o = map( lambda x: self.render( x, self.col_specs_template_overview, 'totals'), wl_overview) row_data = self.xls_row_template( c_specs_o, [x[0] for x in c_specs_o]) row_pos_o = self.xls_write_row( ws_o, row_pos_o, row_data, row_style=self.rt_cell_style_right) row_pos_d += 1 c_specs_d = map( lambda x: self.render( x, self.col_specs_template_details, 'totals1', render_space={'_': _p._}), wanted_list_details) row_data = self.xls_row_template( c_specs_d, [x[0] for x in c_specs_d]) row_pos_d = self.xls_write_row( ws_d, row_pos_d, row_data, row_style=self.rt_cell_style_right) debit_cell = rowcol_to_cell(row_pos_d, debit_pos_d) credit_cell = rowcol_to_cell(row_pos_d, credit_pos_d) bal_formula = debit_cell + '-' + credit_cell # noqa: disable F841, report_xls namespace trick debit_formula = '+'.join(partner_debit_cells) # noqa: disable F841, report_xls namespace trick credit_formula = '+'.join(partner_credit_cells) # noqa: disable F841, report_xls namespace trick c_specs_d = map( lambda x: self.render( x, self.col_specs_template_details, 'totals2'), wanted_list_details) row_data = self.xls_row_template( c_specs_d, [x[0] for x in c_specs_d]) row_pos_d = self.xls_write_row( ws_d, row_pos_d, row_data, row_style=self.rt_cell_style_right)
def print_lines(self, row_position, account, line, _p, data, line_number): label_elements = [line.get('lname') or ''] if line.get('invoice_number'): label_elements.append("(%s)" % (line['invoice_number'],)) label = ' '.join(label_elements) # Mako: <div class="act_as_row lines # ${line.get('is_from_previous_periods') and # 'open_invoice_previous_line' or ''} ${line.get('is_clearance_line') # and 'clearance_line' or ''}"> if line.get('is_from_previous_periods') \ or line.get('is_clearance_line'): style_line_default = self.style_default_italic style_line_right = self.style_right_italic style_line_date = self.style_date_italic style_line_decimal = self.style_decimal_italic else: style_line_default = self.style_default style_line_right = self.style_right style_line_date = self.style_date style_line_decimal = self.style_decimal if line.get('ldate'): c_specs = [('date', 1, 0, 'date', datetime.strptime( line['ldate'], '%Y-%m-%d'), None, style_line_date)] else: c_specs = [('date', 1, 0, 'text', None)] c_specs += [ ('period_code', 1, 0, 'text', line.get('period_code') or ''), ('entry', 1, 0, 'text', line.get('move_name') or ''), ('journal', 1, 0, 'text', line.get('jcode') or ''), ('partner', 1, 0, 'text', line.get('partner_name') or ''), ('label', 1, 0, 'text', label), ('rec', 1, 0, 'text', line.get('rec_name') or ''), ] if line.get('date_maturity'): c_specs += [('datedue', 1, 0, 'date', datetime.strptime(line['date_maturity'], '%Y-%m-%d'), None, style_line_date)] else: c_specs += [('datedue', 1, 0, 'text', None)] c_specs += [ ('debit', 1, 0, 'number', line.get('debit') or 0.0, None, style_line_decimal), ('credit', 1, 0, 'number', line.get('credit') or 0.0, None, style_line_decimal), ] # determine the formula of the cumulated balance debit_cell = rowcol_to_cell(row_position, 8) credit_cell = rowcol_to_cell(row_position, 9) previous_balance = rowcol_to_cell(row_position - 1, 10) # if it is the first line, the balance is only debit - credit if line_number == 1: cumul_balance = debit_cell + '-' + credit_cell # cumulate debit - credit and balance of previous line else: cumul_balance = debit_cell + '-' + \ credit_cell + '+' + previous_balance c_specs += [('cumul', 1, 0, 'number', None, cumul_balance, style_line_decimal)] if _p.amount_currency(data): if line.get('currency_code'): c_specs += [ ('curramount', 1, 0, 'number', line.get('amount_currency') or 0.0, None, style_line_decimal), ('currcode', 1, 0, 'text', line[ 'currency_code'], None, style_line_right), ] else: c_specs += [ ('curramount', 1, 0, 'text', '-', None, style_line_right), ('currcode', 1, 0, 'text', '', None, style_line_right), ] row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs]) row_position = self.xls_write_row( self.ws, row_position, row_data, style_line_default) return row_position
def generate_xls_report(self, _p, _xs, data, objects, wb): ws = wb.add_sheet(_p.report_name[:31]) ws.panes_frozen = True ws.remove_splits = True ws.portrait = 0 # Landscape ws.fit_width_to_pages = 1 row_pos = 0 # set print header/footer ws.header_str = self.xls_headers['standard'] ws.footer_str = self.xls_footers['standard'] # cf. account_report_general_ledger.mako initial_balance_text = { 'initial_balance': _('Computed'), 'opening_balance': _('Opening Entries'), False: _('No') } # Title cell_style = xlwt.easyxf(_xs['xls_title']) report_name = ' - '.join([ _p.report_name.upper(), _p.company.partner_id.name, _p.company.currency_id.name ]) c_specs = [ ('report_name', 1, 0, 'text', report_name), ] row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs]) row_pos = self.xls_write_row(ws, row_pos, row_data, row_style=cell_style) # write empty row to define column sizes c_sizes = [x[1] for x in _column_sizes] if not _p.amount_currency(data): c_sizes = [ x[1] for x in list( filter(lambda l: l[0] not in ('curr_bal', 'curr_code'), _column_sizes)) ] # -- c_specs = [('empty%s' % i, 1, c_sizes[i], 'text', None) for i in range(0, len(c_sizes))] row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs]) row_pos = self.xls_write_row(ws, row_pos, row_data, set_column_size=True) # Header Table cell_format = _xs['bold'] + _xs['fill_blue'] + _xs['borders_all'] cell_style = xlwt.easyxf(cell_format) cell_style_center = xlwt.easyxf(cell_format + _xs['center']) c_specs = [ ('coa', 2, 0, 'text', _('Chart of Account')), ('fy', 1, 0, 'text', _('Fiscal Year')), ('org', 1, 0, 'text', _('Org')), ('df', 3, 0, 'text', _p.filter_form(data) == 'filter_date' and _('Dates Filter') or _('Periods Filter')), ('af', 1, 0, 'text', _('Accounts Filter')), ('tm', 2, 0, 'text', _('Target Moves')), ('rec', 2, 0, 'text', _('Reconciled')), ('ib', 2, 0, 'text', _('Initial Balance')), ] row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs]) row_pos = self.xls_write_row(ws, row_pos, row_data, row_style=cell_style_center) cell_format = _xs['borders_all'] cell_style = xlwt.easyxf(cell_format) cell_style_center = xlwt.easyxf(cell_format + _xs['center']) #find dict org _org_name = self.pool.get('res.org').browse(_p["cr"], _p["uid"], _p.data["form"]["org_id"]) org_name = [] for record in _org_name: org_name.append(record.name_short) c_specs = [ ('coa', 2, 0, 'text', _p.chart_account.name), ('fy', 1, 0, 'text', _p.fiscalyear.name if _p.fiscalyear else '-'), ('org', 1, 0, 'text', ' '.join(org_name)), ] df = _('From') + ': ' if _p.filter_form(data) == 'filter_date': df += _p.start_date if _p.start_date else u'' else: df += _p.start_period.name if _p.start_period else u'' df += ' ' + _('To') + ': ' if _p.filter_form(data) == 'filter_date': df += _p.stop_date if _p.stop_date else u'' else: df += _p.stop_period.name if _p.stop_period else u'' c_specs += [ ('df', 3, 0, 'text', df), ('af', 1, 0, 'text', _p.accounts(data) and ', '.join([account.code for account in _p.accounts(data)]) or _('All')), ('tm', 2, 0, 'text', _p.display_target_move(data)), ('rec', 2, 0, 'text', _p.display_reconciled(data)), ('ib', 2, 0, 'text', initial_balance_text[_p.initial_balance_mode]), ] row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs]) row_pos = self.xls_write_row(ws, row_pos, row_data, row_style=cell_style_center) ws.set_horz_split_pos(row_pos) row_pos += 1 # Column Title Row cell_format = _xs['bold'] c_title_cell_style = xlwt.easyxf(cell_format) # Column Header Row cell_format = _xs['bold'] + _xs['fill'] + _xs['borders_all'] c_hdr_cell_style = xlwt.easyxf(cell_format) c_hdr_cell_style_right = xlwt.easyxf(cell_format + _xs['right']) c_hdr_cell_style_center = xlwt.easyxf(cell_format + _xs['center']) c_hdr_cell_style_decimal = xlwt.easyxf( cell_format + _xs['right'], num_format_str=report_xls.decimal_format) # Column Initial Balance Row cell_format = _xs['italic'] + _xs['borders_all'] c_init_cell_style = xlwt.easyxf(cell_format) c_init_cell_style_decimal = xlwt.easyxf( cell_format + _xs['right'], num_format_str=report_xls.decimal_format) c_specs = [ ('charge_type', 1, 0, 'text', _('Charge Type'), None, c_hdr_cell_style), ('document_date', 1, 0, 'text', _('Document Date'), None, c_hdr_cell_style), ('posting_date', 1, 0, 'text', _('Posting Date'), None, c_hdr_cell_style), ('due_date', 1, 0, 'text', _('Due Date'), None, c_hdr_cell_style), ('period', 1, 0, 'text', _('Period'), None, c_hdr_cell_style), ('fiscal_year', 1, 0, 'text', _('Fiscal Year'), None, c_hdr_cell_style), ('org_id', 1, 0, 'text', _('Org'), None, c_hdr_cell_style), ('budget', 1, 0, 'text', _('Budget'), None, c_hdr_cell_style), ('program', 1, 0, 'text', _('Program'), None, c_hdr_cell_style), ('section_program', 1, 0, 'text', _('Section Program'), None, c_hdr_cell_style), ('master_plan', 1, 0, 'text', _('Master Plan'), None, c_hdr_cell_style), ('mission', 1, 0, 'text', _('Mission'), None, c_hdr_cell_style), ('costcenter', 1, 0, 'text', _('Costcenter'), None, c_hdr_cell_style), ('fund', 1, 0, 'text', _('Fund'), None, c_hdr_cell_style), ('job_group', 1, 0, 'text', _('Job Order Group'), None, c_hdr_cell_style), ('job', 1, 0, 'text', _('Job Order'), None, c_hdr_cell_style), ('taxbranch', 1, 0, 'text', _('Tax Branch'), None, c_hdr_cell_style), ('move', 1, 0, 'text', _('Entry'), None, c_hdr_cell_style), ('item', 1, 0, 'text', _('Item'), None, c_hdr_cell_style), ('doctype', 1, 0, 'text', _('DocType'), None, c_hdr_cell_style), ('doc_journel', 1, 0, 'text', _('Doc Journal'), None, c_hdr_cell_style), ('activity_group', 1, 0, 'text', _('Activity Group'), None, c_hdr_cell_style), ('activity', 1, 0, 'text', _('Activity'), None, c_hdr_cell_style), ('account_code', 1, 0, 'text', ('Account'), None, c_hdr_cell_style), ('partner_code', 1, 0, 'text', ('Partner code'), None, c_hdr_cell_style), ('partner', 1, 0, 'text', _('Partner'), None, c_hdr_cell_style), ('reference', 1, 0, 'text', _('Reference'), None, c_hdr_cell_style), ('source_document', 1, 0, 'text', _('Source Doc.'), None, c_hdr_cell_style), ('line_description', 1, 0, 'text', _('Line Description'), None, c_hdr_cell_style), ('header_description', 1, 0, 'text', _('Header Description'), None, c_hdr_cell_style), ('counterpart', 1, 0, 'text', _('Counterpart'), None, c_hdr_cell_style), ('debit', 1, 0, 'text', _('Debit'), None, c_hdr_cell_style_right), ('credit', 1, 0, 'text', _('Credit'), None, c_hdr_cell_style_right), ('cumul_bal', 1, 0, 'text', _('Cumul. Bal.'), None, c_hdr_cell_style_right), ] if _p.amount_currency(data): c_specs += [ ('curr_bal', 1, 0, 'text', _('Curr. Bal.'), None, c_hdr_cell_style_right), ('curr_code', 1, 0, 'text', _('Curr.'), None, c_hdr_cell_style_center), ] c_specs += [ # PABI2 ('posted_by', 1, 0, 'text', _('Posted By'), None, c_hdr_cell_style ), ('reconcile_id', 1, 0, 'text', _('Rec.ID'), None, c_hdr_cell_style), ('partial_id', 1, 0, 'text', _('Part.ID'), None, c_hdr_cell_style), # -- ] c_hdr_data = self.xls_row_template(c_specs, [x[0] for x in c_specs]) # cell styles for ledger lines ll_cell_format = _xs['borders_all'] ll_cell_style = xlwt.easyxf(ll_cell_format) ll_cell_style_center = xlwt.easyxf(ll_cell_format + _xs['center']) ll_cell_style_date = xlwt.easyxf(ll_cell_format + _xs['left'], num_format_str=report_xls.date_format) ll_cell_style_decimal = xlwt.easyxf( ll_cell_format + _xs['right'], num_format_str=report_xls.decimal_format) cnt = 0 for account in objects: display_initial_balance = _p['init_balance'][account.id] and \ (_p['init_balance'][account.id].get( 'debit', 0.0) != 0.0 or _p['init_balance'][account.id].get('credit', 0.0) != 0.0) display_ledger_lines = _p['ledger_lines'][account.id] if _p.display_account_raw(data) == 'all' or \ (display_ledger_lines or display_initial_balance): # TO DO : replace cumul amounts by xls formulas cnt += 1 cumul_debit = 0.0 cumul_credit = 0.0 cumul_balance = 0.0 cumul_balance_curr = 0.0 c_specs = [ ('acc_title', 11, 0, 'text', ' - '.join([account.code, account.name])), ] row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs]) row_pos = self.xls_write_row(ws, row_pos, row_data, c_title_cell_style) row_pos = self.xls_write_row(ws, row_pos, c_hdr_data) row_start = row_pos if display_initial_balance: init_balance = _p['init_balance'][account.id] cumul_debit = init_balance.get('debit') or 0.0 cumul_credit = init_balance.get('credit') or 0.0 cumul_balance = init_balance.get('init_balance') or 0.0 cumul_balance_curr = init_balance.get( 'init_balance_currency') or 0.0 c_specs = [('empty%s' % x, 1, 0, 'text', None) for x in range(29)] c_specs += [ ('init_bal', 1, 0, 'text', _('Initial Balance')), ('counterpart', 1, 0, 'text', None), ('debit', 1, 0, 'number', cumul_debit, None, c_init_cell_style_decimal), ('credit', 1, 0, 'number', cumul_credit, None, c_init_cell_style_decimal), ('cumul_bal', 1, 0, 'number', cumul_balance, None, c_init_cell_style_decimal), ] if _p.amount_currency(data): c_specs += [ ('curr_bal', 1, 0, 'number', cumul_balance_curr, None, c_init_cell_style_decimal), ('curr_code', 1, 0, 'text', None), ] row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs]) row_pos = self.xls_write_row(ws, row_pos, row_data, c_init_cell_style) for line in _p['ledger_lines'][account.id]: if (line.get('debit', 0.0)): cumul_debit += line.get('debit', 0.0) if (line.get('credit', 0.0)): cumul_credit += line.get('credit', 0.0) if (line.get('amount_currency', 0.0)): cumul_balance_curr += line.get('amount_currency', 0.0) if (line.get('balance', 0.0)): cumul_balance += line.get('balance', 0.0) label_elements = [line.get('lname', '')] if line.get('invoice_number'): label_elements.append("(%s)" % (line['invoice_number'], )) label = ' '.join(label_elements) _charge_type = dict( self.pool.get("account.move.line"). _columns["charge_type"].selection) # Start write data c_specs = [ ('charge_type', 1, 0, 'text', _charge_type.get(line.get('charge_type', False), False)) ] if line.get('document_date'): c_specs += [ ('document_date', 1, 0, 'date', datetime.strptime(line['document_date'], '%Y-%m-%d'), None, ll_cell_style_date), ] else: c_specs += [ ('document_date', 1, 0, 'text', None), ] if line.get('ldate'): c_specs += [ ('posting_date', 1, 0, 'date', datetime.strptime(line['ldate'], '%Y-%m-%d'), None, ll_cell_style_date), ] else: c_specs += [ ('posting_date', 1, 0, 'text', None), ] c_specs += [ ('due_date', 1, 0, 'text', line.get('due_date', '')), ('period', 1, 0, 'text', line.get('period_code', '')), ('fiscal_year', 1, 0, 'text', line.get('fiscalyear', '')), ('org_id', 1, 0, 'text', line.get('org_id', '')), #PABI2 ('budget', 1, 0, 'text', line.get('budget_name', '')), ('program', 1, 0, 'text', line.get('program', '')), ('section_program', 1, 0, 'text', line.get('section_program', '')), ('master_plan', 1, 0, 'text', line.get('master_plan', '')), ('mission', 1, 0, 'text', line.get('mission', '')), ('costcenter', 1, 0, 'text', line.get('costcenter_name', '')), ('fund', 1, 0, 'text', line.get('fund_name', '')), ('job_group', 1, 0, 'text', line.get('job_order_group', '')), ('job', 1, 0, 'text', line.get('job_order', '')), ('taxbranch', 1, 0, 'text', line.get('taxbranch_name', '')), ('move', 1, 0, 'text', line.get('move_name', '')), ('item', 1, 0, 'number', line.get('item', '')), ('doctype', 1, 0, 'text', line.get('doctype', '')), ('doc_journel', 1, 0, 'text', line.get('journal', '')), ('activity_group', 1, 0, 'text', line.get('activity_group', '')), ('activity', 1, 0, 'text', line.get('activity', '')), ('account_code', 1, 0, 'text', account.code), ('partner_code', 1, 0, 'text', line.get('partner_code', '')), ('partner', 1, 0, 'text', line.get('partner_name', '')), ('reference', 1, 0, 'text', line.get('lref', '')), ('source_document', 1, 0, 'text', line.get('source_document', '')), ('description', 1, 0, 'text', label), ('header_description', 1, 0, 'text', line.get('hname', '')), ('counterpart', 1, 0, 'text', line.get('counterparts', '')), ('debit', 1, 0, 'number', line.get('debit', 0.0), None, ll_cell_style_decimal), ('credit', 1, 0, 'number', line.get('credit', 0.0), None, ll_cell_style_decimal), ('cumul_bal', 1, 0, 'number', cumul_balance, None, ll_cell_style_decimal), ] if _p.amount_currency(data): c_specs += [ ('curr_bal', 1, 0, 'number', line.get('amount_currency') or 0.0, None, ll_cell_style_decimal), ('curr_code', 1, 0, 'text', line.get('currency_code') or '', None, ll_cell_style_center), ] #if _p.display_reconciled(data) == 'Open Items': # rec = None #else: # rec = line.get('reconcile_id', '') rec = line.get('reconcile_id', '') c_specs += [ # PABI2 ('posted_by', 1, 0, 'text', line.get('posted_by', '')), ('reconcile_id', 1, 0, 'text', rec), ('partial_id', 1, 0, 'text', line.get('partial_id', '')), # -- ] row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs]) row_pos = self.xls_write_row(ws, row_pos, row_data, ll_cell_style) debit_start = rowcol_to_cell(row_start, 31) debit_end = rowcol_to_cell(row_pos - 1, 31) debit_formula = 'SUM(' + debit_start + ':' + debit_end + ')' credit_start = rowcol_to_cell(row_start, 32) credit_end = rowcol_to_cell(row_pos - 1, 32) credit_formula = 'SUM(' + credit_start + ':' + credit_end + ')' balance_debit = rowcol_to_cell(row_pos, 31) balance_credit = rowcol_to_cell(row_pos, 32) balance_formula = balance_debit + '-' + balance_credit c_specs = [ ('acc_title', 30, 0, 'text', ' - '.join([account.code, account.name])), ('cum_bal', 1, 0, 'text', _('Cumulated Balance on Account'), None, c_hdr_cell_style_right), ('debit', 1, 0, 'number', None, debit_formula, c_hdr_cell_style_decimal), ('credit', 1, 0, 'number', None, credit_formula, c_hdr_cell_style_decimal), ('balance', 1, 0, 'number', None, balance_formula, c_hdr_cell_style_decimal), ] if _p.amount_currency(data): if account.currency_id: c_specs += [ ('curr_bal', 1, 0, 'number', cumul_balance_curr, None, c_hdr_cell_style_decimal) ] else: c_specs += [('curr_bal', 1, 0, 'text', None)] c_specs += [('curr_code', 1, 0, 'text', None)] c_specs += [ ('posted_by', 1, 0, 'text', None), ('reconcile_id', 1, 0, 'text', None), ('partial_id', 1, 0, 'text', None), ] row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs]) row_pos = self.xls_write_row(ws, row_pos, row_data, c_hdr_cell_style) row_pos += 1
def _active_report(self, _p, _xs, data, objects, wb): cr = self.cr uid = self.uid context = self.context fy = self.fiscalyear wl_act = _p.wanted_list_active template = self.active_template asset_obj = self.pool.get("account.asset.asset") title = self._get_title("active", "normal") title_short = self._get_title("active", "short") sheet_name = title_short[:31].replace("/", "-") ws = wb.add_sheet(sheet_name) ws.panes_frozen = True ws.remove_splits = True ws.portrait = 0 # Landscape ws.fit_width_to_pages = 1 row_pos = 0 ws.header_str = self.xls_headers["standard"] ws.footer_str = self.xls_footers["standard"] row_pos = self._report_title(ws, _p, row_pos, _xs, title) cr.execute( "SELECT id FROM account_asset_asset " "WHERE date_start <= %s" "AND ((date_remove IS NULL) OR " "(date_remove >= %s AND date_remove <= %s)) " "AND id IN %s AND type = 'normal' " "ORDER BY date_start ASC", (fy.date_stop, fy.date_start, fy.date_stop, tuple(self.asset_ids)), ) act_ids = [x[0] for x in cr.fetchall()] if not act_ids: return self._empty_report(ws, _p, row_pos, _xs, "active") c_specs = map(lambda x: self.render(x, template, "header", render_space={"_": _p._}), wl_act) row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs]) row_pos = self.xls_write_row(ws, row_pos, row_data, row_style=self.rh_cell_style, set_column_size=True) ws.set_horz_split_pos(row_pos) row_pos_start = row_pos if "account" not in wl_act: raise orm.except_orm( _("Customization Error"), _("The 'account' field is a mandatory entry of the " "'_xls_active_fields' list !"), ) asset_value_pos = "asset_value" in wl_act and wl_act.index("asset_value") salvage_value_pos = "salvage_value" in wl_act and wl_act.index("salvage_value") fy_start_value_pos = "fy_start_value" in wl_act and wl_act.index("fy_start_value") fy_end_value_pos = "fy_end_value" in wl_act and wl_act.index("fy_end_value") acts = filter(lambda x: x[0] in act_ids, self.assets) acts_and_parents = [] for act in acts: self._view_add(act, acts_and_parents) entries = [] for asset_i, data in enumerate(acts_and_parents): entry = {} asset = asset_obj.browse(cr, uid, data[0], context=context) if data[1] == "view": cp_i = asset_i + 1 cp = [] for a in acts_and_parents[cp_i:]: if a[2] == data[0]: cp.append(cp_i) cp_i += 1 entry["child_pos"] = cp else: # fy_start_value cr.execute( "SELECT depreciated_value " "FROM account_asset_depreciation_line " "WHERE line_date >= %s" "AND asset_id = %s AND type = 'depreciate' " "ORDER BY line_date ASC LIMIT 1", (fy.date_start, data[0]), ) res = cr.fetchone() if res: value_depreciated = res[0] elif asset.state in ["close", "removed"]: value_depreciated = asset.value_depreciated elif not asset.method_number: value_depreciated = 0.0 else: error_name = asset.name if asset.code: error_name += " (" + asset.code + ")" or "" if asset.state in ["open"]: cr.execute( "SELECT line_date " "FROM account_asset_depreciation_line " "WHERE asset_id = %s AND type = 'depreciate' " "AND init_entry=FALSE AND move_check=FALSE " "AND line_date < %s" "ORDER BY line_date ASC LIMIT 1", (data[0], fy.date_start), ) res = cr.fetchone() if res: raise orm.except_orm( _("Data Error"), _( "You can not report on a Fiscal Year " "with unposted entries in prior years. " "Please post depreciation table entry " "dd. '%s' of asset '%s' !" ) % (res[0], error_name), ) else: raise orm.except_orm( _("Data Error"), _("Depreciation Table error for asset %s !") % error_name ) else: raise orm.except_orm(_("Data Error"), _("Depreciation Table error for asset %s !") % error_name) asset.fy_start_value = asset.asset_value - value_depreciated # fy_end_value cr.execute( "SELECT depreciated_value " "FROM account_asset_depreciation_line " "WHERE line_date > %s" "AND asset_id = %s AND type = 'depreciate' " "ORDER BY line_date ASC LIMIT 1", (fy.date_stop, data[0]), ) res = cr.fetchone() if res: value_depreciated = res[0] elif not asset.method_number: value_depreciated = 0.0 else: value_depreciated = asset.asset_value asset.fy_end_value = asset.asset_value - value_depreciated entry["asset"] = asset entries.append(entry) for entry in entries: asset = entry["asset"] fy_start_value_cell = rowcol_to_cell(row_pos, fy_start_value_pos) fy_end_value_cell = rowcol_to_cell(row_pos, fy_end_value_pos) asset_value_cell = rowcol_to_cell(row_pos, asset_value_pos) fy_diff_formula = fy_start_value_cell + "-" + fy_end_value_cell total_depr_formula = asset_value_cell + "-" + fy_end_value_cell if asset.type == "view": asset_value_cells = [rowcol_to_cell(row_pos_start + x, asset_value_pos) for x in entry["child_pos"]] asset_formula = "+".join(asset_value_cells) # noqa: disable F841, report_xls namespace trick salvage_value_cells = [rowcol_to_cell(row_pos_start + x, salvage_value_pos) for x in entry["child_pos"]] salvage_formula = "+".join(salvage_value_cells) # noqa: disable F841, report_xls namespace trick fy_start_value_cells = [ rowcol_to_cell(row_pos_start + x, fy_start_value_pos) for x in entry["child_pos"] ] fy_start_formula = "+".join(fy_start_value_cells) # noqa: disable F841, report_xls namespace trick fy_end_value_cells = [rowcol_to_cell(row_pos_start + x, fy_end_value_pos) for x in entry["child_pos"]] fy_end_formula = "+".join(fy_end_value_cells) # noqa: disable F841, report_xls namespace trick c_specs = map(lambda x: self.render(x, template, "asset_view"), wl_act) row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs]) row_pos = self.xls_write_row(ws, row_pos, row_data, row_style=self.av_cell_style) else: c_specs = map(lambda x: self.render(x, template, "asset"), wl_act) row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs]) row_pos = self.xls_write_row(ws, row_pos, row_data, row_style=self.an_cell_style) asset_total_formula = rowcol_to_cell( row_pos_start, asset_value_pos ) # noqa: disable F841, report_xls namespace trick salvage_total_formula = rowcol_to_cell( row_pos_start, salvage_value_pos # noqa: disable F841, report_xls namespace trick ) fy_start_total_formula = rowcol_to_cell( row_pos_start, fy_start_value_pos # noqa: disable F841, report_xls namespace trick ) fy_end_total_formula = rowcol_to_cell( row_pos_start, fy_end_value_pos ) # noqa: disable F841, report_xls namespace trick fy_start_value_cell = rowcol_to_cell(row_pos, fy_start_value_pos) fy_end_value_cell = rowcol_to_cell(row_pos, fy_end_value_pos) asset_value_cell = rowcol_to_cell(row_pos, asset_value_pos) fy_diff_formula = ( fy_start_value_cell + "-" + fy_end_value_cell ) # noqa: disable F841, report_xls namespace trick total_depr_formula = ( asset_value_cell + "-" + fy_end_value_cell ) # noqa: disable F841, report_xls namespace trick c_specs = map(lambda x: self.render(x, template, "totals"), wl_act) row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs]) row_pos = self.xls_write_row(ws, row_pos, row_data, row_style=self.rt_cell_style_right)
def print_group_cumul_account(self, row_position, row_start_account, account): # This procedure will create an Excel sumif function that will check # in the column "label" for the "Cumulated Balance.." string and make a # sum of the debit & credit data # the text "Cumulated Balance on Partner starts in column 4 when # selecting the option regroup by currency, 5 in the other case start_col = 4 # range in which we search for the text "Cumulated Balance on Partner" reference_start = rowcol_to_cell(row_start_account, start_col) reference_stop = rowcol_to_cell(row_position - 1, start_col) # range in which we make the sum of all the cumulated balance lines # (debit) range_debit_start = rowcol_to_cell(row_start_account, start_col + 3) range_debit_stop = rowcol_to_cell(row_position - 1, start_col + 3) # range in which we make the sum of all the cumulated balance lines # (crebit) range_credit_start = rowcol_to_cell(row_start_account, start_col + 4) range_credit_stop = rowcol_to_cell(row_position - 1, start_col + 4) search_key = _('Cumulated Balance on Partner') total_debit_account = 'SUMIF(' + reference_start + ':' + \ reference_stop + ';"' + search_key + '";' + range_debit_start + \ ':' + range_debit_stop + ')' total_credit_account = 'SUMIF(' + reference_start + ':' + \ reference_stop + ';"' + search_key + '";' + range_credit_start + \ ':' + range_credit_stop + ')' bal_account_debit = rowcol_to_cell(row_position, start_col + 3) bal_account_credit = rowcol_to_cell(row_position, start_col + 4) bal_account_total = bal_account_debit + '-' + bal_account_credit bal_curr_start = rowcol_to_cell(row_start_account, start_col + 6) bal_curr_end = rowcol_to_cell(row_position - 1, start_col + 6) cumul_balance_curr = 'SUMIF(' + reference_start + ':' + \ reference_stop + ';"' + search_key + '";' + \ bal_curr_start + ':' + bal_curr_end + ')' c_specs = [ ('acc_title', start_col, 0, 'text', ' - '.join([account.code, account.name])), ('init_bal', 2, 0, 'text', _('Cumulated Balance on Account')), ('empty2', 1, 0, 'text', None), ('debit', 1, 0, 'number', None, total_debit_account, self.style_account_title_decimal), ('credit', 1, 0, 'number', None, total_credit_account, self.style_account_title_decimal), ('balance', 1, 0, 'number', None, bal_account_total, self.style_account_title_decimal), ] if account.currency_id: c_specs += [ ('cumul_bal_curr', 1, 0, 'number', None, cumul_balance_curr, self.style_account_title_decimal), ('curr_name', 1, 0, 'text', account.currency_id.name, None, self.style_account_title_decimal), ] else: c_specs += [('cumul_bal_curr', 1, 0, 'text', "-", None, self.style_account_title_right), ('curr_name', 1, 0, 'text', "", None, self.style_account_title_right)] row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs]) row_position = self.xls_write_row(self.ws, row_position, row_data, self.style_account_title) return row_position + 1
def generate_xls_report(self, _p, _xs, data, objects, wb): ws = wb.add_sheet(_('Stato Patrimoniale')) # _p.report_name[:31]) ws.panes_frozen = True ws.remove_splits = True ws.portrait = 0 # Landscape ws.fit_width_to_pages = 1 row_pos = 0 # set print header/footer ws.header_str = self.xls_headers['standard'] ws.footer_str = self.xls_footers['standard'] # Title cell_style = xlwt.easyxf(_xs['xls_title']) report_name = ' - '.join( [_('Stato Patrimoniale').upper(), _p.company.partner_id.name]) c_specs = [ ('report_name', 1, 0, 'text', report_name), ] row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs]) row_pos = self.xls_write_row(ws, row_pos, row_data, row_style=cell_style) # write empty row to define column sizes c_sizes = self.column_sizes c_specs = [('empty%s' % i, 1, c_sizes[i], 'text', None) for i in range(0, len(c_sizes))] row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs]) row_pos = self.xls_write_row(ws, row_pos, row_data, set_column_size=True) # Header Table cell_format = _xs['bold'] + _xs['fill_blue'] + _xs['borders_all'] cell_style = xlwt.easyxf(cell_format) cell_style_center = xlwt.easyxf(cell_format + _xs['center']) c_specs = [ ('fy', 1, 0, 'text', _('Anno Fiscale')), ('df', 2, 0, 'text', _('Filtro')), # data['form'].get('filter', False) == 'filter_date' and _('Dates Filter') # or data['form'].get('filter', False) == 'filter_period' and _('Periods Filter') # or u''), # ('ib', 1, 0, 'text', _('Initial Balance'), None, cell_style_center), # ('coa', 1, 0, 'text', _('Chart of Account'), None, cell_style_center), ] row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs]) row_pos = self.xls_write_row(ws, row_pos, row_data, row_style=cell_style) cell_format = _xs['borders_all'] + _xs['wrap'] + _xs['top'] cell_style = xlwt.easyxf(cell_format) cell_style_center = xlwt.easyxf(cell_format + _xs['center']) c_specs = [ ('fy', 1, 0, 'text', _p.get_fiscalyear(data) if _p.get_fiscalyear(data) else '-'), # ('af', 2, 0, 'text', _p.accounts(data) and ', '.join([account.code for account in _p.accounts(data)]) or _('All')), ] df = _('Da') + ': ' dt = _('A') + ': ' if data['form'].get('filter', False) == 'filter_date': df += _p.get_start_date(data) if _p.get_start_date(data) else u'' dt += _p.get_end_date(data) if _p.get_end_date(data) else u'' elif data['form'].get('filter', False) == 'filter_period': df += _p.get_start_period(data) if _p.get_start_period( data) else u'' dt += _p.get_end_period(data) if _p.get_end_period(data) else u'' else: df += u'' dt += u'' c_specs += [ ('df', 1, 0, 'text', df), ('dt', 1, 0, 'text', dt), # ('tm', 2, 0, 'text', _p.display_target_move(data), None, cell_style_center), _ # ('ib', 1, 0, 'text', initial_balance_text[_p.initial_balance_mode], None, cell_style_center), # ('coa', 1, 0, 'text', p.get_chart_account(data), None, cell_style_center), ] row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs]) row_pos = self.xls_write_row(ws, row_pos, row_data, row_style=cell_style) # Column Header Row cell_format = _xs['bold'] + _xs['fill_blue'] + _xs[ 'borders_all'] + _xs['wrap'] + _xs['top'] cell_style = xlwt.easyxf(cell_format) cell_style_right = xlwt.easyxf(cell_format + _xs['right']) cell_style_center = xlwt.easyxf(cell_format + _xs['center']) account_span = 3 c_specs = [ ('d_code', 1, 0, 'text', _('Codice')), ('d_account', account_span, 0, 'text', _('Conto')), ('total_debit', 1, 0, 'text', _('Totale Attività'), None, cell_style_right), ('debit', 1, 0, 'text', _('Attività'), None, cell_style_right), ('c_code', 1, 0, 'text', _('Codice')), ('c_account', account_span, 0, 'text', _('Conto')), ('total_credit', 1, 0, 'text', _('Totale Passività'), None, cell_style_right), ('credit', 1, 0, 'text', _('Passività'), None, cell_style_right) ] row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs]) row_pos = self.xls_write_row(ws, row_pos, row_data, row_style=cell_style) ws.set_horz_split_pos(row_pos) # cell styles for account data view_cell_format = _xs['bold'] + _xs['fill'] + _xs['borders_all'] view_cell_style = xlwt.easyxf(view_cell_format) view_cell_style_center = xlwt.easyxf(view_cell_format + _xs['center']) view_cell_style_decimal = xlwt.easyxf( view_cell_format + _xs['right'], num_format_str=report_xls.decimal_format) view_cell_style_pct = xlwt.easyxf(view_cell_format + _xs['center'], num_format_str='0') regular_cell_format = _xs['borders_all'] regular_cell_style = xlwt.easyxf(regular_cell_format) regular_cell_style_center = xlwt.easyxf(regular_cell_format + _xs['center']) regular_cell_style_decimal = xlwt.easyxf( regular_cell_format + _xs['right'], num_format_str=report_xls.decimal_format) regular_cell_style_pct = xlwt.easyxf(regular_cell_format + _xs['center'], num_format_str='0') account_id = data['form'].get('chart_account_id', False) if account_id: account_id = account_id[0] chart_id = 'chart_template_id' in data['form'] \ and data['form']['chart_template_id'] \ and [data['form']['chart_template_id'][0]] or [] chart = self.pool['account.chart.template'].browse( self.cr, self.uid, chart_id) partners = [ chart.property_account_payable.code, chart.property_account_receivable.code, ] result = objects.pop() for row in objects: if row: # debit if row['type1'] == 'view' and not row['code1'] in partners: c_specs = [ ('d_code', 1, 0, 'text', row['code1'], None, view_cell_style), ('d_account', account_span, 0, 'text', row['name1'], None, view_cell_style), ('total_debit', 1, 0, 'number', row['balance1'], None, view_cell_style_decimal), ('debit', 1, 0, 'text', None, None, view_cell_style), ] else: c_specs = [ ('d_code', 1, 0, 'text', row['code1'], None, regular_cell_style), ('d_account', account_span, 0, 'text', row['name1'], None, regular_cell_style), ('total_debit', 1, 0, 'text', None, None, regular_cell_style), ('debit', 1, 0, 'number', row['balance1'], None, regular_cell_style_decimal), ] # credit if row['type'] == 'view' and not row['code'] in partners: c_specs += [ ('c_code', 1, 0, 'text', row['code'], None, view_cell_style), ('c_account', account_span, 0, 'text', row['name'], None, view_cell_style), ('total_credit', 1, 0, 'number', row['balance'], None, view_cell_style_decimal), ('credit', 1, 0, 'text', None, None, view_cell_style), ] else: c_specs += [ ('c_code', 1, 0, 'text', row['code'], None, regular_cell_style), ('c_account', account_span, 0, 'text', row['name'], None, regular_cell_style), ('total_credit', 1, 0, 'text', None, None, regular_cell_style), ('credit', 1, 0, 'number', row['balance'], None, regular_cell_style_decimal), ] row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs]) row_pos = self.xls_write_row(ws, row_pos, row_data) # print totals and result d_tot_formula = 'sum(' + rowcol_to_cell(5, 5) + ':' + rowcol_to_cell( row_pos - 1, 5) + ')' c_tot_formula = 'sum(' + rowcol_to_cell(5, 11) + ':' + rowcol_to_cell( row_pos - 1, 11) + ')' c_specs = [('d_code', 1, 0, 'text', None, None, view_cell_style), ('d_account', account_span, 0, 'text', _('Totale'), None, view_cell_style), ('total_debit', 1, 0, 'text', None, None, view_cell_style), ('debit', 1, 0, 'number', None, d_tot_formula, view_cell_style_decimal), ('c_code', 1, 0, 'text', None, None, view_cell_style), ('c_account', account_span, 0, 'text', _('Totale'), None, view_cell_style), ('total_credit', 1, 0, 'text', None, None, view_cell_style), ('credit', 1, 0, 'number', None, c_tot_formula, view_cell_style_decimal)] row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs]) row_pos = self.xls_write_row(ws, row_pos, row_data, row_style=cell_style) res = result['result'][0] profit = False if res.get('type', False) == 'Utile': profit = True c_specs = [ ('d_code', 1, 0, 'text', None, None, view_cell_style), ('d_account', account_span, 0, 'text', not profit and res.get('type', False) or None, None, view_cell_style), ('total_debit', 1, 0, 'text', None, None, view_cell_style), ('debit', 1, 0, 'number', not profit and res.get('balance', False) or None, None, view_cell_style_decimal), ('c_code', 1, 0, 'text', None, None, view_cell_style), ('c_account', account_span, 0, 'text', profit and res.get('type', False) or None, None, view_cell_style), ('total_credit', 1, 0, 'text', None, None, view_cell_style), ('credit', 1, 0, 'number', profit and res.get('balance', False) or None, None, view_cell_style_decimal), ] row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs]) row_pos = self.xls_write_row(ws, row_pos, row_data, row_style=cell_style) d_tot_formula = 'sum(' + rowcol_to_cell( row_pos - 2, 5) + ':' + rowcol_to_cell(row_pos - 1, 5) + ')' c_tot_formula = 'sum(' + rowcol_to_cell( row_pos - 2, 5) + ':' + rowcol_to_cell(row_pos - 1, 5) + ')' c_specs = [('d_code', 1, 0, 'text', None, None, view_cell_style), ('d_account', account_span, 0, 'text', _('Totale Attività'), None, view_cell_style), ('total_debit', 1, 0, 'text', None, None, view_cell_style), ('debit', 1, 0, 'number', None, d_tot_formula, view_cell_style_decimal), ('c_code', 1, 0, 'text', None, None, view_cell_style), ('c_account', account_span, 0, 'text', _('Totale Passività'), None, view_cell_style), ('total_credit', 1, 0, 'text', None, None, view_cell_style), ('credit', 1, 0, 'number', None, c_tot_formula, view_cell_style_decimal)] row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs]) row_pos = self.xls_write_row(ws, row_pos, row_data, row_style=cell_style)
def generate_xls_report(self, _p, _xs, data, objects, wb): ws = wb.add_sheet(_p.report_name[:31]) ws.panes_frozen = True ws.remove_splits = True ws.portrait = 0 # Landscape ws.fit_width_to_pages = 1 row_pos = 0 # set print header/footer ws.header_str = self.xls_headers['standard'] ws.footer_str = self.xls_footers['standard'] # cf. account_report_general_ledger.mako initial_balance_text = {'initial_balance': _('Computed'), 'opening_balance': _('Opening Entries'), False: _('No')} # Title cell_style = xlwt.easyxf(_xs['xls_title']) report_name = ' - '.join([_p.report_name.upper(), _p.company.partner_id.name, _p.company.currency_id.name]) c_specs = [ ('report_name', 1, 0, 'text', report_name), ] row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs]) row_pos = self.xls_write_row( ws, row_pos, row_data, row_style=cell_style) # write empty row to define column sizes c_sizes = self.column_sizes c_specs = [('empty%s' % i, 1, c_sizes[i], 'text', None) for i in range(0, len(c_sizes))] row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs]) row_pos = self.xls_write_row( ws, row_pos, row_data, set_column_size=True) # Header Table cell_format = _xs['bold'] + _xs['fill_blue'] + _xs['borders_all'] cell_style = xlwt.easyxf(cell_format) cell_style_center = xlwt.easyxf(cell_format + _xs['center']) c_specs = [ ('coa', 2, 0, 'text', _('Chart of Account')), ('fy', 1, 0, 'text', _('Fiscal Year')), ('df', 3, 0, 'text', _p.filter_form(data) == 'filter_date' and _('Dates Filter') or _('Periods Filter')), ('af', 1, 0, 'text', _('Accounts Filter')), ('tm', 2, 0, 'text', _('Target Moves')), ('ib', 2, 0, 'text', _('Initial Balance')), ] row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs]) row_pos = self.xls_write_row( ws, row_pos, row_data, row_style=cell_style_center) cell_format = _xs['borders_all'] cell_style = xlwt.easyxf(cell_format) cell_style_center = xlwt.easyxf(cell_format + _xs['center']) c_specs = [ ('coa', 2, 0, 'text', _p.chart_account.name), ('fy', 1, 0, 'text', _p.fiscalyear.name if _p.fiscalyear else '-'), ] df = _('From') + ': ' if _p.filter_form(data) == 'filter_date': df += _p.start_date if _p.start_date else u'' else: df += _p.start_period.name if _p.start_period else u'' df += ' ' + _('To') + ': ' if _p.filter_form(data) == 'filter_date': df += _p.stop_date if _p.stop_date else u'' else: df += _p.stop_period.name if _p.stop_period else u'' c_specs += [ ('df', 3, 0, 'text', df), ('af', 1, 0, 'text', _p.accounts(data) and ', '.join( [account.code for account in _p.accounts(data)]) or _('All')), ('tm', 2, 0, 'text', _p.display_target_move(data)), ('ib', 2, 0, 'text', initial_balance_text[ _p.initial_balance_mode]), ] row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs]) row_pos = self.xls_write_row( ws, row_pos, row_data, row_style=cell_style_center) ws.set_horz_split_pos(row_pos) row_pos += 1 # Column Title Row cell_format = _xs['bold'] c_title_cell_style = xlwt.easyxf(cell_format) # Column Header Row cell_format = _xs['bold'] + _xs['fill'] + _xs['borders_all'] c_hdr_cell_style = xlwt.easyxf(cell_format) c_hdr_cell_style_right = xlwt.easyxf(cell_format + _xs['right']) c_hdr_cell_style_center = xlwt.easyxf(cell_format + _xs['center']) c_hdr_cell_style_decimal = xlwt.easyxf( cell_format + _xs['right'], num_format_str=report_xls.decimal_format) # Column Initial Balance Row cell_format = _xs['italic'] + _xs['borders_all'] c_init_cell_style = xlwt.easyxf(cell_format) c_init_cell_style_decimal = xlwt.easyxf( cell_format + _xs['right'], num_format_str=report_xls.decimal_format) c_specs = [ ('date', 1, 0, 'text', _('Date'), None, c_hdr_cell_style), ('period', 1, 0, 'text', _('Period'), None, c_hdr_cell_style), ('move', 1, 0, 'text', _('Entry'), None, c_hdr_cell_style), ('journal', 1, 0, 'text', _('Journal'), None, c_hdr_cell_style), ('account_code', 1, 0, 'text', _('Account'), None, c_hdr_cell_style), ('partner', 1, 0, 'text', _('Partner'), None, c_hdr_cell_style), ('ref', 1, 0, 'text', _('Reference'), None, c_hdr_cell_style), ('label', 1, 0, 'text', _('Label'), None, c_hdr_cell_style), ('counterpart', 1, 0, 'text', _('Counterpart'), None, c_hdr_cell_style), ('debit', 1, 0, 'text', _('Debit'), None, c_hdr_cell_style_right), ('credit', 1, 0, 'text', _('Credit'), None, c_hdr_cell_style_right), ('cumul_bal', 1, 0, 'text', _('Cumul. Bal.'), None, c_hdr_cell_style_right), ] if _p.amount_currency(data): c_specs += [ ('curr_bal', 1, 0, 'text', _('Curr. Bal.'), None, c_hdr_cell_style_right), ('curr_code', 1, 0, 'text', _('Curr.'), None, c_hdr_cell_style_center), ] c_hdr_data = self.xls_row_template(c_specs, [x[0] for x in c_specs]) # cell styles for ledger lines ll_cell_format = _xs['borders_all'] ll_cell_style = xlwt.easyxf(ll_cell_format) ll_cell_style_center = xlwt.easyxf(ll_cell_format + _xs['center']) ll_cell_style_date = xlwt.easyxf( ll_cell_format + _xs['left'], num_format_str=report_xls.date_format) ll_cell_style_decimal = xlwt.easyxf( ll_cell_format + _xs['right'], num_format_str=report_xls.decimal_format) cnt = 0 for account in objects: display_initial_balance = _p['init_balance'][account.id] and \ (_p['init_balance'][account.id].get( 'debit', 0.0) != 0.0 or _p['init_balance'][account.id].get('credit', 0.0) != 0.0) display_ledger_lines = _p['ledger_lines'][account.id] if _p.display_account_raw(data) == 'all' or \ (display_ledger_lines or display_initial_balance): # TO DO : replace cumul amounts by xls formulas cnt += 1 cumul_debit = 0.0 cumul_credit = 0.0 cumul_balance = 0.0 cumul_balance_curr = 0.0 c_specs = [ ('acc_title', 11, 0, 'text', ' - '.join([account.code, account.name])), ] row_data = self.xls_row_template( c_specs, [x[0] for x in c_specs]) row_pos = self.xls_write_row( ws, row_pos, row_data, c_title_cell_style) row_pos = self.xls_write_row(ws, row_pos, c_hdr_data) row_start = row_pos if display_initial_balance: init_balance = _p['init_balance'][account.id] cumul_debit = init_balance.get('debit') or 0.0 cumul_credit = init_balance.get('credit') or 0.0 cumul_balance = init_balance.get('init_balance') or 0.0 cumul_balance_curr = init_balance.get( 'init_balance_currency') or 0.0 c_specs = [('empty%s' % x, 1, 0, 'text', None) for x in range(6)] c_specs += [ ('init_bal', 1, 0, 'text', _('Initial Balance')), ('counterpart', 1, 0, 'text', None), ('debit', 1, 0, 'number', cumul_debit, None, c_init_cell_style_decimal), ('credit', 1, 0, 'number', cumul_credit, None, c_init_cell_style_decimal), ('cumul_bal', 1, 0, 'number', cumul_balance, None, c_init_cell_style_decimal), ] if _p.amount_currency(data): c_specs += [ ('curr_bal', 1, 0, 'number', cumul_balance_curr, None, c_init_cell_style_decimal), ('curr_code', 1, 0, 'text', None), ] row_data = self.xls_row_template( c_specs, [x[0] for x in c_specs]) row_pos = self.xls_write_row( ws, row_pos, row_data, c_init_cell_style) for line in _p['ledger_lines'][account.id]: cumul_debit += line.get('debit') or 0.0 cumul_credit += line.get('credit') or 0.0 cumul_balance_curr += line.get('amount_currency') or 0.0 cumul_balance += line.get('balance') or 0.0 label_elements = [line.get('lname') or ''] if line.get('invoice_number'): label_elements.append( "(%s)" % (line['invoice_number'],)) label = ' '.join(label_elements) if line.get('ldate'): c_specs = [ ('ldate', 1, 0, 'date', datetime.strptime( line['ldate'], '%Y-%m-%d'), None, ll_cell_style_date), ] else: c_specs = [ ('ldate', 1, 0, 'text', None), ] c_specs += [ ('period', 1, 0, 'text', line.get('period_code') or ''), ('move', 1, 0, 'text', line.get('move_name') or ''), ('journal', 1, 0, 'text', line.get('jcode') or ''), ('account_code', 1, 0, 'text', account.code), ('partner', 1, 0, 'text', line.get('partner_name') or ''), ('ref', 1, 0, 'text', line.get('lref')), ('label', 1, 0, 'text', label), ('counterpart', 1, 0, 'text', line.get('counterparts') or ''), ('debit', 1, 0, 'number', line.get('debit', 0.0), None, ll_cell_style_decimal), ('credit', 1, 0, 'number', line.get('credit', 0.0), None, ll_cell_style_decimal), ('cumul_bal', 1, 0, 'number', cumul_balance, None, ll_cell_style_decimal), ] if _p.amount_currency(data): c_specs += [ ('curr_bal', 1, 0, 'number', line.get( 'amount_currency') or 0.0, None, ll_cell_style_decimal), ('curr_code', 1, 0, 'text', line.get( 'currency_code') or '', None, ll_cell_style_center), ] row_data = self.xls_row_template( c_specs, [x[0] for x in c_specs]) row_pos = self.xls_write_row( ws, row_pos, row_data, ll_cell_style) debit_start = rowcol_to_cell(row_start, 9) debit_end = rowcol_to_cell(row_pos - 1, 9) debit_formula = 'SUM(' + debit_start + ':' + debit_end + ')' credit_start = rowcol_to_cell(row_start, 10) credit_end = rowcol_to_cell(row_pos - 1, 10) credit_formula = 'SUM(' + credit_start + ':' + credit_end + ')' balance_debit = rowcol_to_cell(row_pos, 9) balance_credit = rowcol_to_cell(row_pos, 10) balance_formula = balance_debit + '-' + balance_credit c_specs = [ ('acc_title', 8, 0, 'text', ' - '.join([account.code, account.name])), ('cum_bal', 1, 0, 'text', _('Cumulated Balance on Account'), None, c_hdr_cell_style_right), ('debit', 1, 0, 'number', None, debit_formula, c_hdr_cell_style_decimal), ('credit', 1, 0, 'number', None, credit_formula, c_hdr_cell_style_decimal), ('balance', 1, 0, 'number', None, balance_formula, c_hdr_cell_style_decimal), ] if _p.amount_currency(data): if account.currency_id: c_specs += [('curr_bal', 1, 0, 'number', cumul_balance_curr, None, c_hdr_cell_style_decimal)] else: c_specs += [('curr_bal', 1, 0, 'text', None)] c_specs += [('curr_code', 1, 0, 'text', None)] row_data = self.xls_row_template( c_specs, [x[0] for x in c_specs]) row_pos = self.xls_write_row( ws, row_pos, row_data, c_hdr_cell_style) row_pos += 1
def _active_report(self, _p, _xs, data, objects, wb): cr = self.cr uid = self.uid context = self.context fy = self.fiscalyear wl_act = _p.wanted_list_active template = self.active_template asset_obj = self.pool.get('account.asset.asset') title = self._get_title('active', 'normal') title_short = self._get_title('active', 'short') sheet_name = title_short[:31].replace('/', '-') ws = wb.add_sheet(sheet_name) ws.panes_frozen = True ws.remove_splits = True ws.portrait = 0 # Landscape ws.fit_width_to_pages = 1 row_pos = 0 ws.header_str = self.xls_headers['standard'] ws.footer_str = self.xls_footers['standard'] row_pos = self._report_title(ws, _p, row_pos, _xs, title) cr.execute( "SELECT id FROM account_asset_asset " "WHERE date_start <= %s" "AND ((date_remove IS NULL) OR " "(date_remove >= %s AND date_remove <= %s)) " "AND id IN %s AND type = 'normal' " "ORDER BY date_start ASC", (fy.date_stop, fy.date_start, fy.date_stop, tuple(self.asset_ids)) ) act_ids = [x[0] for x in cr.fetchall()] if not act_ids: return self._empty_report(ws, _p, row_pos, _xs, 'active') c_specs = map( lambda x: self.render( x, template, 'header', render_space={'_': _p._}), wl_act) row_data = self.xls_row_template( c_specs, [x[0] for x in c_specs]) row_pos = self.xls_write_row( ws, row_pos, row_data, row_style=self.rh_cell_style, set_column_size=True) ws.set_horz_split_pos(row_pos) row_pos_start = row_pos if 'account' not in wl_act: raise orm.except_orm(_('Customization Error'), _( "The 'account' field is a mandatory entry of the " "'_xls_active_fields' list !")) asset_value_pos = 'asset_value' in wl_act and \ wl_act.index('asset_value') salvage_value_pos = 'salvage_value' in wl_act and \ wl_act.index('salvage_value') fy_start_value_pos = 'fy_start_value' in wl_act and \ wl_act.index('fy_start_value') fy_end_value_pos = 'fy_end_value' in wl_act and \ wl_act.index('fy_end_value') acts = filter(lambda x: x[0] in act_ids, self.assets) acts_and_parents = [] for act in acts: self._view_add(act, acts_and_parents) entries = [] for asset_i, data in enumerate(acts_and_parents): entry = {} asset = asset_obj.browse(cr, uid, data[0], context=context) if data[1] == 'view': cp_i = asset_i + 1 cp = [] for a in acts_and_parents[cp_i:]: if a[2] == data[0]: cp.append(cp_i) cp_i += 1 entry['child_pos'] = cp else: # fy_start_value cr.execute( "SELECT depreciated_value " "FROM account_asset_depreciation_line " "WHERE line_date >= %s" "AND asset_id = %s AND type = 'depreciate' " "ORDER BY line_date ASC LIMIT 1", (fy.date_start, data[0])) res = cr.fetchone() if res: value_depreciated = res[0] elif asset.state in ['close', 'removed']: value_depreciated = asset.value_depreciated elif not asset.method_number: value_depreciated = 0.0 else: error_name = asset.name if asset.code: error_name += ' (' + asset.code + ')' or '' if asset.state in ['open']: cr.execute( "SELECT line_date " "FROM account_asset_depreciation_line " "WHERE asset_id = %s AND type = 'depreciate' " "AND init_entry=FALSE AND move_check=FALSE " "AND line_date < %s" "ORDER BY line_date ASC LIMIT 1", (data[0], fy.date_start)) res = cr.fetchone() if res: raise orm.except_orm( _('Data Error'), _("You can not report on a Fiscal Year " "with unposted entries in prior years. " "Please post depreciation table entry " "dd. '%s' of asset '%s' !") % (res[0], error_name)) else: raise orm.except_orm( _('Data Error'), _("Depreciation Table error for asset %s !") % error_name) else: raise orm.except_orm( _('Data Error'), _("Depreciation Table error for asset %s !") % error_name) asset.fy_start_value = asset.asset_value - value_depreciated # fy_end_value cr.execute( "SELECT depreciated_value " "FROM account_asset_depreciation_line " "WHERE line_date > %s" "AND asset_id = %s AND type = 'depreciate' " "ORDER BY line_date ASC LIMIT 1", (fy.date_stop, data[0])) res = cr.fetchone() if res: value_depreciated = res[0] elif not asset.method_number: value_depreciated = 0.0 else: value_depreciated = asset.asset_value asset.fy_end_value = asset.asset_value - value_depreciated entry['asset'] = asset entries.append(entry) for entry in entries: asset = entry['asset'] fy_start_value_cell = rowcol_to_cell(row_pos, fy_start_value_pos) fy_end_value_cell = rowcol_to_cell(row_pos, fy_end_value_pos) asset_value_cell = rowcol_to_cell(row_pos, asset_value_pos) fy_diff_formula = fy_start_value_cell + '-' + fy_end_value_cell total_depr_formula = asset_value_cell + '-' + fy_end_value_cell if asset.type == 'view': asset_value_cells = [ rowcol_to_cell(row_pos_start + x, asset_value_pos) for x in entry['child_pos']] asset_formula = '+'.join(asset_value_cells) # noqa: disable F841, report_xls namespace trick salvage_value_cells = [ rowcol_to_cell(row_pos_start + x, salvage_value_pos) for x in entry['child_pos']] salvage_formula = '+'.join(salvage_value_cells) # noqa: disable F841, report_xls namespace trick fy_start_value_cells = [ rowcol_to_cell(row_pos_start + x, fy_start_value_pos) for x in entry['child_pos']] fy_start_formula = '+'.join(fy_start_value_cells) # noqa: disable F841, report_xls namespace trick fy_end_value_cells = [ rowcol_to_cell(row_pos_start + x, fy_end_value_pos) for x in entry['child_pos']] fy_end_formula = '+'.join(fy_end_value_cells) # noqa: disable F841, report_xls namespace trick c_specs = map( lambda x: self.render( x, template, 'asset_view'), wl_act) row_data = self.xls_row_template( c_specs, [x[0] for x in c_specs]) row_pos = self.xls_write_row( ws, row_pos, row_data, row_style=self.av_cell_style) else: c_specs = map( lambda x: self.render( x, template, 'asset'), wl_act) row_data = self.xls_row_template( c_specs, [x[0] for x in c_specs]) row_pos = self.xls_write_row( ws, row_pos, row_data, row_style=self.an_cell_style) asset_total_formula = rowcol_to_cell(row_pos_start, asset_value_pos) # noqa: disable F841, report_xls namespace trick salvage_total_formula = rowcol_to_cell(row_pos_start, # noqa: disable F841, report_xls namespace trick salvage_value_pos) fy_start_total_formula = rowcol_to_cell(row_pos_start, # noqa: disable F841, report_xls namespace trick fy_start_value_pos) fy_end_total_formula = rowcol_to_cell(row_pos_start, fy_end_value_pos) # noqa: disable F841, report_xls namespace trick fy_start_value_cell = rowcol_to_cell(row_pos, fy_start_value_pos) fy_end_value_cell = rowcol_to_cell(row_pos, fy_end_value_pos) asset_value_cell = rowcol_to_cell(row_pos, asset_value_pos) fy_diff_formula = fy_start_value_cell + '-' + fy_end_value_cell # noqa: disable F841, report_xls namespace trick total_depr_formula = asset_value_cell + '-' + fy_end_value_cell # noqa: disable F841, report_xls namespace trick c_specs = map( lambda x: self.render( x, template, 'totals'), wl_act) row_data = self.xls_row_template( c_specs, [x[0] for x in c_specs]) row_pos = self.xls_write_row( ws, row_pos, row_data, row_style=self.rt_cell_style_right)
def _removal_report(self, _p, _xs, data, objects, wb): cr = self.cr uid = self.uid context = self.context fy = self.fiscalyear wl_dsp = _p.wanted_list_removal template = self.removal_template asset_obj = self.pool.get('account.asset.asset') title = self._get_title('removal', 'normal') title_short = self._get_title('removal', 'short') sheet_name = title_short[:31].replace('/', '-') ws = wb.add_sheet(sheet_name) ws.panes_frozen = True ws.remove_splits = True ws.portrait = 0 # Landscape ws.fit_width_to_pages = 1 row_pos = 0 ws.header_str = self.xls_headers['standard'] ws.footer_str = self.xls_footers['standard'] row_pos = self._report_title(ws, _p, row_pos, _xs, title) cr.execute( "SELECT id FROM account_asset_asset " "WHERE date_remove >= %s AND date_remove <= %s" "AND id IN %s AND type = 'normal' " "ORDER BY date_remove ASC", (fy.date_start, fy.date_stop, tuple(self.asset_ids))) dsp_ids = [x[0] for x in cr.fetchall()] if not dsp_ids: return self._empty_report(ws, _p, row_pos, _xs, 'removal') c_specs = map( lambda x: self.render( x, template, 'header', render_space={'_': _p._}), wl_dsp) row_data = self.xls_row_template( c_specs, [x[0] for x in c_specs]) row_pos = self.xls_write_row( ws, row_pos, row_data, row_style=self.rh_cell_style, set_column_size=True) ws.set_horz_split_pos(row_pos) row_pos_start = row_pos if 'account' not in wl_dsp: raise orm.except_orm(_('Customization Error'), _( "The 'account' field is a mandatory entry of the " "'_xls_removal_fields' list !")) asset_value_pos = 'asset_value' in wl_dsp and \ wl_dsp.index('asset_value') salvage_value_pos = 'salvage_value' in wl_dsp and \ wl_dsp.index('salvage_value') dsps = filter(lambda x: x[0] in dsp_ids, self.assets) dsps_and_parents = [] for dsp in dsps: self._view_add(dsp, dsps_and_parents) entries = [] for asset_i, data in enumerate(dsps_and_parents): entry = {} asset = asset_obj.browse(cr, uid, data[0], context=context) if data[1] == 'view': cp_i = asset_i + 1 cp = [] for a in dsps_and_parents[cp_i:]: if a[2] == data[0]: cp.append(cp_i) cp_i += 1 entry['child_pos'] = cp entry['asset'] = asset entries.append(entry) for entry in entries: asset = entry['asset'] if asset.type == 'view': asset_value_cells = [ rowcol_to_cell(row_pos_start + x, asset_value_pos) for x in entry['child_pos']] asset_formula = '+'.join(asset_value_cells) # noqa: disable F841, report_xls namespace trick salvage_value_cells = [ rowcol_to_cell(row_pos_start + x, salvage_value_pos) for x in entry['child_pos']] salvage_formula = '+'.join(salvage_value_cells) # noqa: disable F841, report_xls namespace trick c_specs = map( lambda x: self.render( x, template, 'asset_view'), wl_dsp) row_data = self.xls_row_template( c_specs, [x[0] for x in c_specs]) row_pos = self.xls_write_row( ws, row_pos, row_data, row_style=self.av_cell_style) else: c_specs = map( lambda x: self.render( x, template, 'asset'), wl_dsp) row_data = self.xls_row_template( c_specs, [x[0] for x in c_specs]) row_pos = self.xls_write_row( ws, row_pos, row_data, row_style=self.an_cell_style) asset_total_formula = rowcol_to_cell(row_pos_start, asset_value_pos) # noqa: disable F841, report_xls namespace trick salvage_total_formula = rowcol_to_cell(row_pos_start, # noqa: disable F841, report_xls namespace trick salvage_value_pos) c_specs = map( lambda x: self.render( x, template, 'totals'), wl_dsp) row_data = self.xls_row_template( c_specs, [x[0] for x in c_specs]) row_pos = self.xls_write_row( ws, row_pos, row_data, row_style=self.rt_cell_style_right)
def generate_xls_report(self, _p, _xs, data, objects, wb): wanted_list = _p.wanted_list self.col_specs_template.update(_p.template_changes) _ = _p._ subtotal_pos = 'price_subtotal' in wanted_list \ and wanted_list.index('price_subtotal') report_name = _("Invoice Lines") ws = wb.add_sheet(report_name[:31]) ws.panes_frozen = True ws.remove_splits = True ws.portrait = 0 # Landscape ws.fit_width_to_pages = 1 row_pos = 0 # set print header/footer ws.header_str = self.xls_headers['standard'] ws.footer_str = self.xls_footers['standard'] # Title cell_style = xlwt.easyxf(_xs['xls_title']) c_specs = [ ('report_name', 1, 0, 'text', report_name), ] row_data = self.xls_row_template(c_specs, ['report_name']) row_pos = self.xls_write_row( ws, row_pos, row_data, row_style=cell_style) row_pos += 1 # Column headers c_specs = map( lambda x: self.render( x, self.col_specs_template, 'header', render_space={'_': _p._}), wanted_list) row_data = self.xls_row_template( c_specs, [x[0] for x in c_specs]) row_pos = self.xls_write_row( ws, row_pos, row_data, row_style=self.rh_cell_style, set_column_size=True) ws.set_horz_split_pos(row_pos) ws.set_vert_split_pos(1) # invoice lines for line in objects: c_specs = map( lambda x: self.render( x, self.col_specs_template, 'lines'), wanted_list) row_data = self.xls_row_template( c_specs, [x[0] for x in c_specs]) row_pos = self.xls_write_row( ws, row_pos, row_data, row_style=self.ail_cell_style) # Totals ail_cnt = len(objects) if subtotal_pos: subtotal_start = rowcol_to_cell(row_pos - ail_cnt, subtotal_pos) subtotal_stop = rowcol_to_cell(row_pos - 1, subtotal_pos) subtotal_formula = 'SUM(%s:%s)' % (subtotal_start, subtotal_stop) # noqa: disable F841, report_xls namespace trick c_specs = map( lambda x: self.render( x, self.col_specs_template, 'totals'), wanted_list) row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs]) row_pos = self.xls_write_row( ws, row_pos, row_data, row_style=self.rt_cell_style_right)
def generate_xls_report(self, _p, _xs, data, objects, wb): ws = wb.add_sheet(_p.report_name[:31]) ws.panes_frozen = True ws.remove_splits = True ws.portrait = 0 # Landscape ws.fit_width_to_pages = 1 row_pos = 0 # set print header/footer ws.header_str = self.xls_headers["standard"] ws.footer_str = self.xls_footers["standard"] # cf. account_report_general_ledger.mako initial_balance_text = { "initial_balance": _("Computed"), "opening_balance": _("Opening Entries"), False: _("No"), } # Title cell_style = xlwt.easyxf(_xs["xls_title"]) report_name = " - ".join([_p.report_name.upper(), _p.company.partner_id.name, _p.company.currency_id.name]) c_specs = [("report_name", 1, 0, "text", report_name)] row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs]) row_pos = self.xls_write_row(ws, row_pos, row_data, row_style=cell_style) # write empty row to define column sizes c_sizes = self.column_sizes c_specs = [("empty%s" % i, 1, c_sizes[i], "text", None) for i in range(0, len(c_sizes))] row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs]) row_pos = self.xls_write_row(ws, row_pos, row_data, set_column_size=True) # Header Table cell_format = _xs["bold"] + _xs["fill_blue"] + _xs["borders_all"] cell_style = xlwt.easyxf(cell_format) cell_style_center = xlwt.easyxf(cell_format + _xs["center"]) c_specs = [ ("coa", 2, 0, "text", _("Chart of Account")), ("fy", 1, 0, "text", _("Fiscal Year")), ("df", 3, 0, "text", _p.filter_form(data) == "filter_date" and _("Dates Filter") or _("Periods Filter")), ("af", 1, 0, "text", _("Accounts Filter")), ("tm", 2, 0, "text", _("Target Moves")), ("ib", 2, 0, "text", _("Initial Balance")), ] row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs]) row_pos = self.xls_write_row(ws, row_pos, row_data, row_style=cell_style_center) cell_format = _xs["borders_all"] cell_style = xlwt.easyxf(cell_format) cell_style_center = xlwt.easyxf(cell_format + _xs["center"]) c_specs = [ ("coa", 2, 0, "text", _p.chart_account.name), ("fy", 1, 0, "text", _p.fiscalyear.name if _p.fiscalyear else "-"), ] df = _("From") + ": " if _p.filter_form(data) == "filter_date": df += _p.start_date if _p.start_date else u"" else: df += _p.start_period.name if _p.start_period else u"" df += " " + _("To") + ": " if _p.filter_form(data) == "filter_date": df += _p.stop_date if _p.stop_date else u"" else: df += _p.stop_period.name if _p.stop_period else u"" c_specs += [ ("df", 3, 0, "text", df), ( "af", 1, 0, "text", _p.accounts(data) and ", ".join([account.code for account in _p.accounts(data)]) or _("All"), ), ("tm", 2, 0, "text", _p.display_target_move(data)), ("ib", 2, 0, "text", initial_balance_text[_p.initial_balance_mode]), ] row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs]) row_pos = self.xls_write_row(ws, row_pos, row_data, row_style=cell_style_center) ws.set_horz_split_pos(row_pos) row_pos += 1 # Column Title Row cell_format = _xs["bold"] c_title_cell_style = xlwt.easyxf(cell_format) # Column Header Row cell_format = _xs["bold"] + _xs["fill"] + _xs["borders_all"] c_hdr_cell_style = xlwt.easyxf(cell_format) c_hdr_cell_style_right = xlwt.easyxf(cell_format + _xs["right"]) c_hdr_cell_style_center = xlwt.easyxf(cell_format + _xs["center"]) c_hdr_cell_style_decimal = xlwt.easyxf(cell_format + _xs["right"], num_format_str=report_xls.decimal_format) # Column Initial Balance Row cell_format = _xs["italic"] + _xs["borders_all"] c_init_cell_style = xlwt.easyxf(cell_format) c_init_cell_style_right = xlwt.easyxf(cell_format + _xs["right"]) c_init_cell_style_center = xlwt.easyxf(cell_format + _xs["center"]) c_init_cell_style_decimal = xlwt.easyxf(cell_format + _xs["right"], num_format_str=report_xls.decimal_format) c_specs = [ ("date", 1, 0, "text", _("Date"), None, c_hdr_cell_style), ("period", 1, 0, "text", _("Period"), None, c_hdr_cell_style), ("move", 1, 0, "text", _("Entry"), None, c_hdr_cell_style), ("journal", 1, 0, "text", _("Journal"), None, c_hdr_cell_style), ("account_code", 1, 0, "text", _("Account"), None, c_hdr_cell_style), ("partner", 1, 0, "text", _("Partner"), None, c_hdr_cell_style), ("label", 1, 0, "text", _("Label"), None, c_hdr_cell_style), ("counterpart", 1, 0, "text", _("Counterpart"), None, c_hdr_cell_style), ("debit", 1, 0, "text", _("Debit"), None, c_hdr_cell_style_right), ("credit", 1, 0, "text", _("Credit"), None, c_hdr_cell_style_right), ("cumul_bal", 1, 0, "text", _("Cumul. Bal."), None, c_hdr_cell_style_right), ] if _p.amount_currency(data): c_specs += [ ("curr_bal", 1, 0, "text", _("Curr. Bal."), None, c_hdr_cell_style_right), ("curr_code", 1, 0, "text", _("Curr."), None, c_hdr_cell_style_center), ] c_hdr_data = self.xls_row_template(c_specs, [x[0] for x in c_specs]) # cell styles for ledger lines ll_cell_format = _xs["borders_all"] ll_cell_style = xlwt.easyxf(ll_cell_format) ll_cell_style_right = xlwt.easyxf(ll_cell_format + _xs["right"]) ll_cell_style_center = xlwt.easyxf(ll_cell_format + _xs["center"]) ll_cell_style_date = xlwt.easyxf(ll_cell_format + _xs["left"], num_format_str=report_xls.date_format) ll_cell_style_decimal = xlwt.easyxf(ll_cell_format + _xs["right"], num_format_str=report_xls.decimal_format) cnt = 0 for account in objects: display_initial_balance = account.init_balance and ( account.init_balance.get("debit", 0.0) != 0.0 or account.init_balance.get("credit", 0.0) != 0.0 ) display_ledger_lines = account.ledger_lines if _p.display_account_raw(data) == "all" or (display_ledger_lines or display_initial_balance): # TO DO : replace cumul amounts by xls formulas cnt += 1 cumul_debit = 0.0 cumul_credit = 0.0 cumul_balance = 0.0 cumul_balance_curr = 0.0 c_specs = [("acc_title", 11, 0, "text", " - ".join([account.code, account.name]))] row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs]) row_pos = self.xls_write_row(ws, row_pos, row_data, c_title_cell_style) row_pos = self.xls_write_row(ws, row_pos, c_hdr_data) row_start = row_pos if display_initial_balance: cumul_debit = account.init_balance.get("debit") or 0.0 cumul_credit = account.init_balance.get("credit") or 0.0 cumul_balance = account.init_balance.get("init_balance") or 0.0 cumul_balance_curr = account.init_balance.get("init_balance_currency") or 0.0 debit_cell = rowcol_to_cell(row_pos, 8) credit_cell = rowcol_to_cell(row_pos, 9) bal_formula = debit_cell + "-" + credit_cell c_specs = [("empty%s" % x, 1, 0, "text", None) for x in range(6)] c_specs += [ ("init_bal", 1, 0, "text", _("Initial Balance")), ("counterpart", 1, 0, "text", None), ("debit", 1, 0, "number", cumul_debit, None, c_init_cell_style_decimal), ("credit", 1, 0, "number", cumul_credit, None, c_init_cell_style_decimal), ("cumul_bal", 1, 0, "number", cumul_balance, None, c_init_cell_style_decimal), ] if _p.amount_currency(data): c_specs += [ ("curr_bal", 1, 0, "number", cumul_balance_curr, None, c_init_cell_style_decimal), ("curr_code", 1, 0, "text", None), ] row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs]) row_pos = self.xls_write_row(ws, row_pos, row_data, c_init_cell_style) for line in account.ledger_lines: cumul_debit += line.get("debit") or 0.0 cumul_credit += line.get("credit") or 0.0 cumul_balance_curr += line.get("amount_currency") or 0.0 cumul_balance += line.get("balance") or 0.0 label_elements = [line.get("lname") or ""] if line.get("invoice_number"): label_elements.append("(%s)" % (line["invoice_number"],)) label = " ".join(label_elements) if line.get("ldate"): c_specs = [ ( "ldate", 1, 0, "date", datetime.strptime(line["ldate"], "%Y-%m-%d"), None, ll_cell_style_date, ) ] else: c_specs = [("ldate", 1, 0, "text", None)] c_specs += [ ("period", 1, 0, "text", line.get("period_code") or ""), ("move", 1, 0, "text", line.get("move_name") or ""), ("journal", 1, 0, "text", line.get("jcode") or ""), ("account_code", 1, 0, "text", account.code), ("partner", 1, 0, "text", line.get("partner_name") or ""), ("label", 1, 0, "text", label), ("counterpart", 1, 0, "text", line.get("counterparts") or ""), ("debit", 1, 0, "number", line.get("debit", 0.0), None, ll_cell_style_decimal), ("credit", 1, 0, "number", line.get("credit", 0.0), None, ll_cell_style_decimal), ("cumul_bal", 1, 0, "number", cumul_balance, None, ll_cell_style_decimal), ] if _p.amount_currency(data): c_specs += [ ( "curr_bal", 1, 0, "number", line.get("amount_currency") or 0.0, None, ll_cell_style_decimal, ), ("curr_code", 1, 0, "text", line.get("currency_code") or "", None, ll_cell_style_center), ] row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs]) row_pos = self.xls_write_row(ws, row_pos, row_data, ll_cell_style) debit_start = rowcol_to_cell(row_start, 8) debit_end = rowcol_to_cell(row_pos - 1, 8) debit_formula = "SUM(" + debit_start + ":" + debit_end + ")" credit_start = rowcol_to_cell(row_start, 9) credit_end = rowcol_to_cell(row_pos - 1, 9) credit_formula = "SUM(" + credit_start + ":" + credit_end + ")" balance_debit = rowcol_to_cell(row_pos, 8) balance_credit = rowcol_to_cell(row_pos, 9) balance_formula = balance_debit + "-" + balance_credit c_specs = [ ("acc_title", 7, 0, "text", " - ".join([account.code, account.name])), ("cum_bal", 1, 0, "text", _("Cumulated Balance on Account"), None, c_hdr_cell_style_right), ("debit", 1, 0, "number", None, debit_formula, c_hdr_cell_style_decimal), ("credit", 1, 0, "number", None, credit_formula, c_hdr_cell_style_decimal), ("balance", 1, 0, "number", None, balance_formula, c_hdr_cell_style_decimal), ] if _p.amount_currency(data): if account.currency_id: c_specs += [("curr_bal", 1, 0, "number", cumul_balance_curr, None, c_hdr_cell_style_decimal)] else: c_specs += [("curr_bal", 1, 0, "text", None)] c_specs += [("curr_code", 1, 0, "text", None)] row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs]) row_pos = self.xls_write_row(ws, row_pos, row_data, c_hdr_cell_style) row_pos += 1
def _print_totals(self, row_pos): init_pos = 4 end_pos = row_pos - 2 # VALQUIN TOTALS sale_start = rowcol_to_cell(init_pos, 1) sale_end = rowcol_to_cell(end_pos, 1) val_sales = 'SUM(' + sale_start + ':' + sale_end + ')' cost_start = rowcol_to_cell(init_pos, 2) cost_end = rowcol_to_cell(end_pos, 2) val_cost = 'SUM(' + cost_start + ':' + cost_end + ')' total_sale = rowcol_to_cell(row_pos, 1) total_cost = rowcol_to_cell(row_pos, 2) val_benefit = total_sale + '-' + total_cost total_benefit = rowcol_to_cell(row_pos, 3) val_benefit_per = total_benefit + '*' + '100' + '/' + total_sale # VALQUIN INDIRECT TOTALS sale_start = rowcol_to_cell(init_pos, 5) sale_end = rowcol_to_cell(end_pos, 5) in_val_sales = 'SUM(' + sale_start + ':' + sale_end + ')' # QUIVAL TOTALS sale_start = rowcol_to_cell(init_pos, 9) sale_end = rowcol_to_cell(end_pos, 9) qui_sales = 'SUM(' + sale_start + ':' + sale_end + ')' cost_start = rowcol_to_cell(init_pos, 10) cost_end = rowcol_to_cell(end_pos, 10) qui_cost = 'SUM(' + cost_start + ':' + cost_end + ')' total_sale = rowcol_to_cell(row_pos, 9) total_cost = rowcol_to_cell(row_pos, 10) qui_benefit = total_sale + '-' + total_cost total_benefit = rowcol_to_cell(row_pos, 11) qui_benefit_per = total_benefit + '*' + '100' + '/' + total_sale # TOTAL SALES sale_start = rowcol_to_cell(init_pos, 13) sale_end = rowcol_to_cell(end_pos, 13) total_toal_sales = 'SUM(' + sale_start + ':' + sale_end + ')' c_specs = [ ('a', 1, 0, 'text', _('TOTALES'), None, None), ('b', 1, 0, 'number', None, val_sales, None), ('c', 1, 0, 'number', None, val_cost, None), ('d', 1, 0, 'number', None, val_benefit, None), ('e', 1, 0, 'number', None, val_benefit_per, None), ('f', 1, 0, 'number', None, in_val_sales, None), ('g', 1, 0, 'number', None, None, None), ('h', 1, 0, 'number', None, None, None), ('i', 1, 0, 'number', None, None, None), ('j', 1, 0, 'number', None, qui_sales, None), ('k', 1, 0, 'number', None, qui_cost, None), ('l', 1, 0, 'number', None, qui_benefit, None), ('m', 1, 0, 'number', None, qui_benefit_per, None), ('n', 1, 0, 'number', None, total_toal_sales, None), ] row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs]) row_pos = self.xls_write_row(self.ws, row_pos, row_data) return row_pos
def generate_xls_report(self, _p, _xs, data, objects, wb): context = {'lang': (_p.get('lang') or 'en_US')} ws = wb.add_sheet(_p.report_name[:31]) ws.panes_frozen = True ws.remove_splits = True ws.portrait = 0 # Landscape ws.fit_width_to_pages = 1 row_pos = 0 # set print header/footer ws.header_str = self.xls_headers['standard'] ws.footer_str = self.xls_footers['standard'] # cf. account_report_trial_balance.mako initial_balance_text = {'initial_balance': _('Computed'), 'opening_balance': _('Opening Entries'), False: _('No')} # Title cell_style = xlwt.easyxf(_xs['xls_title']) report_name = ' - '.join([_p.report_name.upper(), _p.company.partner_id.name, _p.company.currency_id.name]) c_specs = [ ('report_name', 1, 0, 'text', report_name), ] row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs]) row_pos = self.xls_write_row( ws, row_pos, row_data, row_style=cell_style) # write empty row to define column sizes c_sizes = self.column_sizes c_specs = [('empty%s' % i, 1, c_sizes[i], 'text', None) for i in range(0, len(c_sizes))] row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs]) row_pos = self.xls_write_row( ws, row_pos, row_data, set_column_size=True) # Alternative Currency base_currency_id = _p.company.currency_id.id currency_obj = self.pool.get('res.currency') alt_curr_ids = currency_obj.search(self.cr, self.uid, [('alt_currency','=',True)]) alt_curr_id = alt_curr_ids and alt_curr_ids[0] or False display_curr_columns = data.get('form',{}).get('display_curr_columns', False) and \ (alt_curr_id and base_currency_id != alt_curr_id or False) or False ## Alternative currency rate options context.update({ 'curr_rate_option': data.get('form',{}).get('curr_rate_option', False), 'curr_rate_date': data.get('form',{}).get('curr_rate_date', False), 'curr_rate': data.get('form',{}).get('curr_rate', False), }) # Header Table cell_format = _xs['bold'] + _xs['fill_blue'] + _xs['borders_all'] cell_style = xlwt.easyxf(cell_format) cell_style_center = xlwt.easyxf(cell_format + _xs['center']) c_specs = [ ('fy', 1, 0, 'text', _('Fiscal Year')), ('af', 1, 0, 'text', _('Accounts Filter')), ('df', 1, 0, 'text', _p.filter_form(data) == 'filter_date' and _('Dates Filter') or _('Periods Filter')), ('tm', 2, 0, 'text', _('Target Moves'), None, cell_style_center), ('ib', 1, 0, 'text', _('Initial Balance'), None, cell_style_center), ('coa', 1, 0, 'text', _('Chart of Account'), None, cell_style_center), ] if display_curr_columns: c_specs += [('altc', 1, 0, 'text', _('Alt. Currency'))] c_specs += [('altcro', 2, 0, 'text', _('Alt. Curr. Rate Option'))] row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs]) row_pos = self.xls_write_row( ws, row_pos, row_data, row_style=cell_style) cell_format = _xs['borders_all'] + _xs['wrap'] + _xs['top'] cell_style = xlwt.easyxf(cell_format) cell_style_center = xlwt.easyxf(cell_format + _xs['center']) disp_acc = "" if data.get('form',{}).get('display_accounts', False)=='movement': disp_acc = _("[With movements] ") if data.get('form',{}).get('display_accounts', False)=='not_zero': disp_acc = _("[With balance not equal to 0] ") c_specs = [ ('fy', 1, 0, 'text', _p.fiscalyear.name if _p.fiscalyear else '-'), ('af', 1, 0, 'text', disp_acc + (_p.accounts(data) and ', '.join( [account.code for account in _p.accounts(data)]) or _('All'))), ] df = _('From') + ': ' if _p.filter_form(data) == 'filter_date': df += _p.start_date if _p.start_date else u'' else: df += _p.start_period.name if _p.start_period else u'' df += ' ' + _('\nTo') + ': ' if _p.filter_form(data) == 'filter_date': df += _p.stop_date if _p.stop_date else u'' else: df += _p.stop_period.name if _p.stop_period else u'' c_specs += [ ('df', 1, 0, 'text', df), ('tm', 2, 0, 'text', _p.display_target_move( data), None, cell_style_center), ('ib', 1, 0, 'text', initial_balance_text[ _p.initial_balance_mode], None, cell_style_center), ('coa', 1, 0, 'text', _p.chart_account.name, None, cell_style_center), ] if display_curr_columns: c_specs += [('altc', 1, 0, 'text', currency_obj.read(self.cr, self.uid, alt_curr_id, ['name'])['name'] )] rate_option = _("Transaction Date") if data.get('form',{}).get('curr_rate_option', False)=='set_date': rate_option = _("Custom Date: ") + data.get('form',{}).get('curr_rate_date', '') elif data.get('form',{}).get('curr_rate_option', False)=='set_curr_rate': rate_option = _("Currency Rate: ") + str(data.get('form',{}).get('curr_rate', 0.0)) c_specs += [('altcro', 2, 0, 'text', rate_option )] row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs]) row_pos = self.xls_write_row( ws, row_pos, row_data, row_style=cell_style) # comparison header table if _p.comparison_mode in ('single', 'multiple'): row_pos += 1 cell_format_ct = _xs['bold'] + \ _xs['fill_blue'] + _xs['borders_all'] cell_style_ct = xlwt.easyxf(cell_format_ct) c_specs = [('ct', 8, 0, 'text', _('Comparisons'))] row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs]) row_pos = self.xls_write_row( ws, row_pos, row_data, row_style=cell_style_ct) cell_style_center = xlwt.easyxf(cell_format) for index, params in enumerate(_p.comp_params): c_specs = [ ('c', 3, 0, 'text', _('Comparison') + str(index + 1) + ' (C' + str(index + 1) + ')')] if params['comparison_filter'] == 'filter_date': c_specs += [('f', 3, 0, 'text', _('Dates Filter') + ': ' + _p.formatLang( params['start'], date=True) + ' - ' + _p.formatLang(params['stop'], date=True))] elif params['comparison_filter'] == 'filter_period': c_specs += [('f', 3, 0, 'text', _('Periods Filter') + ': ' + params['start'].name + ' - ' + params['stop'].name)] else: c_specs += [('f', 3, 0, 'text', _('Fiscal Year') + ': ' + params['fiscalyear'].name)] c_specs += [('ib', 2, 0, 'text', _('Initial Balance') + ': ' + initial_balance_text[ params['initial_balance_mode']])] row_data = self.xls_row_template( c_specs, [x[0] for x in c_specs]) row_pos = self.xls_write_row( ws, row_pos, row_data, row_style=cell_style_center) row_pos += 1 # Column Header Row cell_format = _xs['bold'] + _xs['fill_blue'] + \ _xs['borders_all'] + _xs['wrap'] + _xs['top'] cell_style = xlwt.easyxf(cell_format) cell_style_right = xlwt.easyxf(cell_format + _xs['right']) cell_style_center = xlwt.easyxf(cell_format + _xs['center']) if len(_p.comp_params) == 2: account_span = 3 else: account_span = _p.initial_balance_mode and 2 or 3 c_specs = [ ('code', 1, 0, 'text', _('Code')), ('account', 1, 0, 'text', _('Account')), ] if _p.comparison_mode == 'no_comparison': if _p.initial_balance_mode: c_specs += [('init_bal', 1, 0, 'text', _('Initial Balance'), None, cell_style_right)] c_specs += [ ('debit', 1, 0, 'text', _('Debit'), None, cell_style_right), ('credit', 1, 0, 'text', _('Credit'), None, cell_style_right), ] if _p.comparison_mode == 'no_comparison' or not _p.fiscalyear: c_specs += [('balance', 1, 0, 'text', _('Balance'), None, cell_style_right)] if display_curr_columns: if _p.comparison_mode == 'no_comparison': if _p.initial_balance_mode: c_specs += [('curr_init_bal', 1, 0, 'text', _('Curr. Initial Balance'), None, cell_style_right)] c_specs += [ ('curr_debit', 1, 0, 'text', _('Curr. Debit'), None, cell_style_right), ('curr_credit', 1, 0, 'text', _('Curr. Credit'), None, cell_style_right), ] c_specs += [('curr_balance', 1, 0, 'text', _('Curr. Balance'), None, cell_style_right)] else: c_specs += [('balance_fy', 1, 0, 'text', _('Balance %s') % _p.fiscalyear.name, None, cell_style_right)] if display_curr_columns: if _p.comparison_mode == 'no_comparison': if _p.initial_balance_mode: c_specs += [('curr_init_bal', 1, 0, 'text', _('Curr. Initial Balance'), None, cell_style_right)] c_specs += [ ('curr_debit', 1, 0, 'text', _('Curr. Debit'), None, cell_style_right), ('curr_credit', 1, 0, 'text', _('Curr. Credit'), None, cell_style_right), ] c_specs += [('curr_balance_fy', 1, 0, 'text', _('Curr. Balance %s') % _p.fiscalyear.name, None, cell_style_right)] if _p.comparison_mode in ('single', 'multiple'): for index in range(_p.nb_comparison): if _p.comp_params[index]['comparison_filter'] == 'filter_year' \ and _p.comp_params[index].get('fiscalyear', False): c_specs += [('balance_%s' % index, 1, 0, 'text', _('Balance %s') % _p.comp_params[index]['fiscalyear'].name, None, cell_style_right)] else: c_specs += [('balance_%s' % index, 1, 0, 'text', _('Balance C%s') % (index + 1), None, cell_style_right)] if _p.comparison_mode == 'single': c_specs += [ ('diff', 1, 0, 'text', _('Difference'), None, cell_style_right), ('diff_percent', 1, 0, 'text', _('% Difference'), None, cell_style_center), ] if display_curr_columns: for index in range(_p.nb_comparison): if _p.comp_params[index]['comparison_filter'] == 'filter_year' \ and _p.comp_params[index].get('fiscalyear', False): c_specs += [('curr_balance_%s' % index, 1, 0, 'text', _('Curr. Balance %s') % _p.comp_params[index]['fiscalyear'].name, None, cell_style_right)] else: c_specs += [('curr_balance_%s' % index, 1, 0, 'text', _('Curr. Balance C%s') % (index + 1), None, cell_style_right)] if _p.comparison_mode == 'single': c_specs += [ ('curr_diff', 1, 0, 'text', _('Curr. Difference'), None, cell_style_right), ('curr_diff_percent', 1, 0, 'text', _('Curr. % Difference'), None, cell_style_center), ] c_specs += [('type', 1, 0, 'text', _('Type'), None, cell_style_center)] row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs]) row_pos = self.xls_write_row( ws, row_pos, row_data, row_style=cell_style) ws.set_horz_split_pos(row_pos) last_child_consol_ids = [] # cell styles for account data view_cell_format = _xs['bold'] + _xs['fill'] + _xs['borders_all'] view_cell_style = xlwt.easyxf(view_cell_format) view_cell_style_center = xlwt.easyxf(view_cell_format + _xs['center']) view_cell_style_decimal = xlwt.easyxf( view_cell_format + _xs['right'], num_format_str=report_xls.decimal_format) view_cell_style_pct = xlwt.easyxf( view_cell_format + _xs['center'], num_format_str='0') regular_cell_format = _xs['borders_all'] regular_cell_style = xlwt.easyxf(regular_cell_format) regular_cell_style_center = xlwt.easyxf( regular_cell_format + _xs['center']) regular_cell_style_decimal = xlwt.easyxf( regular_cell_format + _xs['right'], num_format_str=report_xls.decimal_format) regular_cell_style_pct = xlwt.easyxf( regular_cell_format + _xs['center'], num_format_str='0') for current_account in objects: if not _p['to_display_accounts'][current_account.id]: continue if current_account.type == 'view': cell_style = view_cell_style cell_style_center = view_cell_style_center cell_style_decimal = view_cell_style_decimal cell_style_pct = view_cell_style_pct else: cell_style = regular_cell_style cell_style_center = regular_cell_style_center cell_style_decimal = regular_cell_style_decimal cell_style_pct = regular_cell_style_pct comparisons = _p['comparisons_accounts'][current_account.id] if current_account.id not in last_child_consol_ids: # current account is a not a consolidation child: use its own # level last_child_consol_ids = [ child_consol_id.id for child_consol_id in current_account.child_consol_ids] c_specs = [ ('code', 1, 0, 'text', current_account.code), ('account', 1, 0, 'text', current_account.name), ] if _p.comparison_mode == 'no_comparison': debit_cell = rowcol_to_cell(row_pos, 4 - (account_span-1)) credit_cell = rowcol_to_cell(row_pos, 5 - (account_span-1)) bal_formula = debit_cell + '-' + credit_cell if _p.initial_balance_mode: init_cell = rowcol_to_cell(row_pos, 3 - (account_span-1)) debit_cell = rowcol_to_cell(row_pos, 4 - (account_span-1)) credit_cell = rowcol_to_cell(row_pos, 5 - (account_span-1)) bal_formula = init_cell + '+' + \ debit_cell + '-' + credit_cell c_specs += [('init_bal', 1, 0, 'number', _p['init_balance_' 'accounts'][current_account.id], None, cell_style_decimal)] c_specs += [ ('debit', 1, 0, 'number', _p['debit_accounts'][current_account.id], None, cell_style_decimal), ('credit', 1, 0, 'number', _p['credit_accounts'][current_account.id], None, cell_style_decimal), ] c_specs += [('balance', 1, 0, 'number', None, bal_formula, cell_style_decimal)] if display_curr_columns: curr_debit_cell = rowcol_to_cell(row_pos, 7 - (account_span-1)) curr_credit_cell = rowcol_to_cell(row_pos, 8 - (account_span-1)) curr_bal_formula = curr_debit_cell + '-' + curr_credit_cell if _p.initial_balance_mode: curr_init_cell = rowcol_to_cell(row_pos, 7 - (account_span-1)) curr_debit_cell = rowcol_to_cell(row_pos, 8 - (account_span-1)) curr_credit_cell = rowcol_to_cell(row_pos, 9 - (account_span-1)) curr_bal_formula = curr_init_cell + '+' + curr_debit_cell + '-' + curr_credit_cell c_specs += [('curr_init_bal', 1, 0, 'number', compute_amounts_in_currency(self, self.cr, self.uid, _p['init_balance_accounts'][current_account.id], base_currency_id, alt_curr_id, context=context), None, cell_style_decimal)] if _p['lines_accounts'][current_account.id]: cumul_curr_debit = 0.0 cumul_curr_credit = 0.0 for line in _p['lines_accounts'][current_account.id]: cumul_curr_debit += (line.get('debit', 0.0) and line.get('currency_id', False)==alt_curr_id) and (line.get('amount_currency') < 0 and -line.get('amount_currency') or (line.get('amount_currency') or 0.0)) or \ compute_amounts_in_currency(self, self.cr, self.uid, line.get('debit', 0.0), base_currency_id, alt_curr_id, date=line.get('ldate', False), context=context) cumul_curr_credit += (line.get('credit', 0.0) and line.get('currency_id', False)==alt_curr_id) and (line.get('amount_currency') < 0 and -line.get('amount_currency') or (line.get('amount_currency') or 0.0)) or \ compute_amounts_in_currency(self, self.cr, self.uid, line.get('credit', 0.0), base_currency_id, alt_curr_id, date=line.get('ldate', False), context=context) else: cumul_curr_debit = compute_amounts_in_currency(self, self.cr, self.uid, _p['debit_accounts'][current_account.id], base_currency_id, alt_curr_id, context=context) cumul_curr_credit = compute_amounts_in_currency(self, self.cr, self.uid, _p['credit_accounts'][current_account.id], base_currency_id, alt_curr_id, context=context) c_specs += [ ('curr_debit', 1, 0, 'number', cumul_curr_debit, None, cell_style_decimal), ('curr_credit', 1, 0, 'number', cumul_curr_credit, None, cell_style_decimal), ] c_specs += [('curr_balance', 1, 0, 'number', None, curr_bal_formula, cell_style_decimal)] else: c_specs += [('balance', 1, 0, 'number', _p['balance_accounts'][current_account.id], None, cell_style_decimal)] if display_curr_columns: c_specs += [('curr_balance', 1, 0, 'number', compute_amounts_in_currency(self, self.cr, self.uid, _p['balance_accounts'][current_account.id], base_currency_id, alt_curr_id, context=context), None, cell_style_decimal)] if _p.comparison_mode in ('single', 'multiple'): c = 1 for comp_account in comparisons: c_specs += [('balance_%s' % c, 1, 0, 'number', comp_account['balance'], None, cell_style_decimal)] c += 1 if _p.comparison_mode == 'single': c_specs += [ ('diff', 1, 0, 'number', comp_account[ 'diff'], None, cell_style_decimal), ('diff_percent', 1, 0, 'number', comp_account[ 'percent_diff'] and comp_account['percent_diff'] or 0, None, cell_style_pct), ] if display_curr_columns: c = 1 for comp_account in comparisons: c_specs += [('curr_balance_%s' % c, 1, 0, 'number', compute_amounts_in_currency(self, self.cr, self.uid, comp_account['balance'], base_currency_id, alt_curr_id, context=context), None, cell_style_decimal)] c += 1 if _p.comparison_mode == 'single': c_specs += [ ('curr_diff', 1, 0, 'number', compute_amounts_in_currency(self, self.cr, self.uid, comp_account['diff'], base_currency_id, alt_curr_id, context=context), None, cell_style_decimal), ('curr_diff_percent', 1, 0, 'number', compute_amounts_in_currency(self, self.cr, self.uid, comp_account['percent_diff'] and comp_account['percent_diff'] or 0, base_currency_id, alt_curr_id, context=context), None, cell_style_pct), ] c_specs += [('type', 1, 0, 'text', current_account.type, None, cell_style_center)] row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs]) row_pos = self.xls_write_row( ws, row_pos, row_data, row_style=cell_style)
def generate_xls_report(self, _p, _xs, data, objects, wb): ws = wb.add_sheet(_p.report_name[:31]) ws.panes_frozen = True ws.remove_splits = True ws.portrait = 0 # Landscape ws.fit_width_to_pages = 1 row_pos = 0 # set print header/footer ws.header_str = self.xls_headers['standard'] ws.footer_str = self.xls_footers['standard'] # Header cell_style = xlwt.easyxf(_xs['bold']) c_specs = [ ('organization', 1, 0, 'text', _('NSTDA')), ] row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs]) row_pos = self.xls_write_row( ws, row_pos, row_data, row_style=cell_style) c_specs = [ ('report_name', 1, 0, 'text', _p.report_name), ] row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs]) row_pos = self.xls_write_row( ws, row_pos, row_data, row_style=cell_style) c_specs = [ ('fiscalyear_title', 1, 0, 'text', _('Fiscal Year'), None, cell_style), ('fiscalyear_value', 1, 0, 'text', _p.fiscalyear.name) ] row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs]) row_pos = self.xls_write_row(ws, row_pos, row_data) date_start = datetime.datetime.strptime(_p.fiscalyear.date_start, "%Y-%m-%d") date_stop = datetime.datetime.strptime(_p.fiscalyear.date_stop, "%Y-%m-%d") c_specs = [ ('duration', 1, 0, 'text', _('From ') + date_start.strftime('%d %B %Y') + _(' to ') + date_stop.strftime('%d %B %Y') + _(' (') + str(relativedelta.relativedelta(date_stop, date_start).months) + _(' Months)')) ] row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs]) row_pos = self.xls_write_row(ws, row_pos, row_data) c_sizes = self.column_sizes c_specs = [('empty%s' % i, 1, c_sizes[i], 'text', None) for i in range(0, len(c_sizes))] row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs]) row_pos = self.xls_write_row( ws, row_pos, row_data, set_column_size=True) # Column Header cell_style = xlwt.easyxf(_xs['bold'] + _xs['center'] + _xs['fill'] + _xs['borders_all']) c_specs = [ ('budget_structure', 1, 0, 'text', _('Budget Structure'), None, cell_style), ('budget_plan', 1, 0, 'text', _('Budget Plan'), None, cell_style), ('budget_policy', 1, 0, 'text', _('Budget Policy'), None, cell_style), ('release_budget', 1, 0, 'text', _('Release Budget'), None, cell_style), ('pr_commitment', 1, 0, 'text', _('PR Commitment'), None, cell_style), ('po_commitment', 1, 0, 'text', _('PO Commitment'), None, cell_style), ('ex_commitment', 1, 0, 'text', _('EX Commitment'), None, cell_style), ('actual', 1, 0, 'text', _('Actual'), None, cell_style), ('residual_budget', 1, 0, 'text', _('Residual Budget (Released)'), None, cell_style), ('percent_actual', 1, 0, 'text', _('% Actual'), None, cell_style), ('percent_commitment', 1, 0, 'text', _('% Commitment'), None, cell_style), ('total_commitment', 1, 0, 'text', _('Total Commitment'), None, cell_style) ] row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs]) row_pos = self.xls_write_row(ws, row_pos, row_data) row_start = row_pos # Column Detail cell_format = _xs['right'] + _xs['borders_all'] cell_style_right = xlwt.easyxf(cell_format) cell_style_decimal = xlwt.easyxf( cell_format, num_format_str=report_xls.decimal_format) for report in _p.report: chart_view = CHART_VIEW.get(report.chart_view, False) c_specs = [ ('budget_structure', 1, 0, 'text', chart_view), ('budget_plan', 1, 0, 'number', report.plan, None, cell_style_decimal), ('budget_policy', 1, 0, 'number', report.policy, None, cell_style_decimal), ('release_budget', 1, 0, 'number', report.released, None, cell_style_decimal), ('pr_commitment', 1, 0, 'number', report.pr_commit, None, cell_style_decimal), ('po_commitment', 1, 0, 'number', report.po_commit, None, cell_style_decimal), ('ex_commitment', 1, 0, 'number', report.exp_commit, None, cell_style_decimal), ('actual', 1, 0, 'number', report.actual_total, None, cell_style_decimal), ('residual_budget', 1, 0, 'number', report.balance, None, cell_style_decimal), ('percent_actual', 1, 0, 'text', '{:,.2f}'.format(report.actual_percent) + '%', None, cell_style_right), ('percent_commitment', 1, 0, 'text', '{:,.2f}'.format(report.commit_percent) + '%', None, cell_style_right), ('total_commitment', 1, 0, 'number', report.commit_total, None, cell_style_decimal) ] row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs]) row_pos = self.xls_write_row(ws, row_pos, row_data) # Column Footer cell_format = _xs['fill'] + _xs['borders_all'] + _xs['bold'] cell_style_right = xlwt.easyxf(cell_format + _xs['right']) cell_style_center = xlwt.easyxf(cell_format + _xs['center']) cell_style_decimal = xlwt.easyxf( cell_format + _xs['right'], num_format_str=report_xls.decimal_format) cell_style_percent = xlwt.easyxf( cell_format + _xs['right'], num_format_str='0.00%') plan_start = rowcol_to_cell(row_start, 1) plan_end = rowcol_to_cell(row_pos - 1, 1) plan_formula = 'SUM(' + plan_start + ':' + plan_end + ')' policy_start = rowcol_to_cell(row_start, 2) policy_end = rowcol_to_cell(row_pos - 1, 2) policy_formula = 'SUM(' + policy_start + ':' + policy_end + ')' released_start = rowcol_to_cell(row_start, 3) released_end = rowcol_to_cell(row_pos - 1, 3) released_formula = 'SUM(' + released_start + ':' + released_end + ')' pr_commit_start = rowcol_to_cell(row_start, 4) pr_commit_end = rowcol_to_cell(row_pos - 1, 4) pr_commit_formula = \ 'SUM(' + pr_commit_start + ':' + pr_commit_end + ')' po_commit_start = rowcol_to_cell(row_start, 5) po_commit_end = rowcol_to_cell(row_pos - 1, 5) po_commit_formula = \ 'SUM(' + po_commit_start + ':' + po_commit_end + ')' exp_commit_start = rowcol_to_cell(row_start, 6) exp_commit_end = rowcol_to_cell(row_pos - 1, 6) exp_commit_formula = \ 'SUM(' + exp_commit_start + ':' + exp_commit_end + ')' actual_total_start = rowcol_to_cell(row_start, 7) actual_total_end = rowcol_to_cell(row_pos - 1, 7) actual_total_formula = \ 'SUM(' + actual_total_start + ':' + actual_total_end + ')' balance_start = rowcol_to_cell(row_start, 8) balance_end = rowcol_to_cell(row_pos - 1, 8) balance_formula = 'SUM(' + balance_start + ':' + balance_end + ')' actual_percent_formula = \ rowcol_to_cell(row_pos, 7) + '/' + rowcol_to_cell(row_pos, 2) commit_percent_formula = \ rowcol_to_cell(row_pos, 11) + '/' + rowcol_to_cell(row_pos, 2) commit_total_start = rowcol_to_cell(row_start, 11) commit_total_end = rowcol_to_cell(row_pos - 1, 11) commit_total_formula = \ 'SUM(' + commit_total_start + ':' + commit_total_end + ')' c_specs = [ ('budget_structure', 1, 0, 'text', _('Total'), None, cell_style_center), ('budget_plan', 1, 0, 'number', None, plan_formula, cell_style_decimal), ('budget_policy', 1, 0, 'number', None, policy_formula, cell_style_decimal), ('release_budget', 1, 0, 'number', None, released_formula, cell_style_decimal), ('pr_commitment', 1, 0, 'number', None, pr_commit_formula, cell_style_decimal), ('po_commitment', 1, 0, 'number', None, po_commit_formula, cell_style_decimal), ('ex_commitment', 1, 0, 'number', None, exp_commit_formula, cell_style_decimal), ('actual', 1, 0, 'number', None, actual_total_formula, cell_style_decimal), ('residual_budget', 1, 0, 'number', None, balance_formula, cell_style_decimal), ('percent_actual', 1, 0, 'number', None, actual_percent_formula, cell_style_percent), ('percent_commitment', 1, 0, 'number', None, commit_percent_formula, cell_style_percent), ('total_commitment', 1, 0, 'number', None, commit_total_formula, cell_style_decimal) ] row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs]) row_pos = self.xls_write_row(ws, row_pos, row_data) c_specs = [('empty%s' % i, 1, c_sizes[i], 'text', None) for i in range(0, len(c_sizes))] row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs]) row_pos = self.xls_write_row( ws, row_pos, row_data, set_column_size=True) # Footer cell_format = _xs['borders_all'] + _xs['right'] cell_style = xlwt.easyxf(_xs['borders_all']) cell_style_decimal = xlwt.easyxf( cell_format, num_format_str=report_xls.decimal_format) cell_style_percent = xlwt.easyxf(cell_format, num_format_str='0.00%') actual_formula = rowcol_to_cell(row_pos - 2, 7) actual_percent_formula = rowcol_to_cell(row_pos, 1) + '/' + \ rowcol_to_cell(row_pos + 2, 1) budget_policy_formula = rowcol_to_cell(row_pos - 2, 2) c_specs = [ ('actual_title', 1, 0, 'text', _('Actual'), None, cell_style), ('actual_value', 1, 0, 'number', None, actual_formula, cell_style_decimal), ('actual_percent', 1, 0, 'number', None, actual_percent_formula, cell_style_percent), ('space_1', 1, 0, 'text', None), ('space_2', 1, 0, 'text', None), ('space_3', 1, 0, 'text', None), ('space_4', 1, 0, 'text', None), ('budget_policy_title', 1, 0, 'text', _('Budget Policy'), None, cell_style), ('budget_policy_value', 1, 0, 'number', None, budget_policy_formula, cell_style_decimal), ('budget_policy_percent', 1, 0, 'number', 1, None, cell_style_percent) ] row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs]) row_pos = self.xls_write_row(ws, row_pos, row_data) total_commitment_formula = rowcol_to_cell(row_pos - 3, 11) total_commitment_percent_formula = \ rowcol_to_cell(row_pos, 1) + '/' + rowcol_to_cell(row_pos + 1, 1) actual_formula = rowcol_to_cell(row_pos - 1, 1) actual_percent_formula = \ rowcol_to_cell(row_pos, 8) + '/' + rowcol_to_cell(row_pos - 1, 8) c_specs = [ ('total_commitment_title', 1, 0, 'text', _('Total Commitment'), None, cell_style), ('total_commitment_value', 1, 0, 'number', None, total_commitment_formula, cell_style_decimal), ('total_commitment_percent', 1, 0, 'text', None, total_commitment_percent_formula, cell_style_percent), ('space_1', 1, 0, 'text', None), ('space_2', 1, 0, 'text', None), ('space_3', 1, 0, 'text', None), ('space_4', 1, 0, 'text', None), ('actual_title', 1, 0, 'text', _('Actual'), None, cell_style), ('actual_value', 1, 0, 'text', None, actual_formula, cell_style_decimal), ('actual_percent', 1, 0, 'text', None, actual_percent_formula, cell_style_percent) ] row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs]) row_pos = self.xls_write_row(ws, row_pos, row_data) total_actual_commitment_formula_1 = \ 'SUM(' + rowcol_to_cell(row_pos - 2, 1) + ':' + \ rowcol_to_cell(row_pos - 1, 1) + ')' total_actual_commitment_percent_formula_1 = \ rowcol_to_cell(row_pos, 1) + '/' + rowcol_to_cell(row_pos, 1) total_actual_commitment_formula_2 = rowcol_to_cell(row_pos, 1) total_actual_commitment_percent_formula_2 = \ rowcol_to_cell(row_pos, 8) + '/' + rowcol_to_cell(row_pos - 2, 8) c_specs = [ ('total_actual_commitment_title_1', 1, 0, 'text', _('Total Actual + Commitment'), None, cell_style), ('total_actual_commitment_value_1', 1, 0, 'number', None, total_actual_commitment_formula_1, cell_style_decimal), ('total_actual_commitment_percent_1', 1, 0, 'number', None, total_actual_commitment_percent_formula_1, cell_style_percent), ('space_1', 1, 0, 'text', None), ('space_2', 1, 0, 'text', None), ('space_3', 1, 0, 'text', None), ('space_4', 1, 0, 'text', None), ('total_actual_commitment_title_2', 1, 0, 'text', _('Total Actual + Commitment'), None, cell_style), ('total_actual_commitment_value_2', 1, 0, 'number', None, total_actual_commitment_formula_2, cell_style_decimal), ('total_actual_commitment_percent_2', 1, 0, 'number', None, total_actual_commitment_percent_formula_2, cell_style_percent), ] row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs]) row_pos = self.xls_write_row(ws, row_pos, row_data) budget_balance_formula = \ rowcol_to_cell(row_pos - 3, 8) + '-' + \ rowcol_to_cell(row_pos - 1, 8) budget_balance_percent_formula = \ rowcol_to_cell(row_pos, 8) + '/' + rowcol_to_cell(row_pos - 3, 8) c_specs = [ ('space_1', 1, 0, 'text', None), ('space_2', 1, 0, 'text', None), ('space_3', 1, 0, 'text', None), ('space_4', 1, 0, 'text', None), ('space_5', 1, 0, 'text', None), ('space_6', 1, 0, 'text', None), ('space_7', 1, 0, 'text', None), ('budget_balance_title', 1, 0, 'text', _('Budget Balance (Policy)'), None, cell_style), ('budget_balance_value', 1, 0, 'number', None, budget_balance_formula, cell_style_decimal), ('budget_balance_percent', 1, 0, 'number', None, budget_balance_percent_formula, cell_style_percent) ] row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs]) row_pos = self.xls_write_row(ws, row_pos, row_data)
def generate_xls_report(self, _p, _xs, data, objects, wb): ws, row_pos = self._new_ws_with_header(_p, _xs, data, wb) # cell styles for account data regular_cell_format = _xs['borders_all'] regular_cell_style = xlwt.easyxf(regular_cell_format) regular_cell_style_decimal = xlwt.easyxf( regular_cell_format + _xs['right'], num_format_str=report_xls.decimal_format) # row_pos += 1 for current_account in objects: ws, row_pos = self._get_ws_row_pos(_p, _xs, data, wb, ws, row_pos) partners_order = _p['partners_order_accounts']\ .get(current_account.id, False) # do not display accounts without partners if not partners_order: continue comparisons = _p['comparisons_accounts']\ .get(current_account.id, False) # in multiple columns mode, we do not want to print accounts # without any rows if _p.comparison_mode in ('single', 'multiple'): all_comparison_lines = [comp['partners_amounts'][partner_id[1]] for partner_id in partners_order for comp in comparisons] if not display_line(all_comparison_lines): continue current_partner_amounts = _p['partners_amounts_accounts']\ .get(current_account.id, False) if _p.comparison_mode in ('single', 'multiple'): comparison_total = {} for i, comp in enumerate(comparisons): comparison_total[i] = {'balance': 0.0} # print row: Code - Account name row_pos = self.print_row_code_account( ws, current_account, row_pos, _xs, xlwt) row_account_start = row_pos # Print row: Titles "Account/Partner Name-Code/ref-Initial # Balance-Debit-Credit-Balance" or "Account/Partner # Name-Code/ref-Balance Year-Balance Year2-Balance C2-Balance C3" row_pos = self.print_account_header(ws, _p, _xs, xlwt, row_pos) for (partner_code_name, partner_id, partner_ref, partner_name) \ in partners_order: ws, row_pos = self._get_ws_row_pos( _p, _xs, data, wb, ws, row_pos) partner = current_partner_amounts.get(partner_id, {}) # in single mode, we have to display all the partners even if # their balance is 0.0 because the initial balance should match # with the previous year closings # in multiple columns mode, we do not want to print partners # which have a balance at 0.0 in each comparison column if _p.comparison_mode in ('single', 'multiple'): all_comparison_lines = [comp['partners_amounts'] [partner_id] for comp in comparisons if comp['partners_amounts']. get(partner_id)] if not display_line(all_comparison_lines): continue # display data row if len(_p.comp_params) == 2: account_span = 3 else: account_span = _p.initial_balance_mode and 2 or 3 c_specs = [('acc_title', account_span, 0, 'text', partner_name if partner_name else _('Unallocated'))] c_specs += [('partner_ref', 1, 0, 'text', partner_ref if partner_ref else '')] if _p.comparison_mode == 'no_comparison': bal_formula = '' if _p.initial_balance_mode: init_bal_cell = rowcol_to_cell(row_pos, 3) bal_formula = init_bal_cell + '+' debit_col = 4 c_specs += [ ('init_bal', 1, 0, 'number', partner.get( 'init_balance', 0.0), None, regular_cell_style_decimal), ] else: debit_col = 3 c_specs += [ ('debit', 1, 0, 'number', partner.get('debit', 0.0), None, regular_cell_style_decimal), ('credit', 1, 0, 'number', partner.get('credit', 0.0), None, regular_cell_style_decimal), ] debit_cell = rowcol_to_cell(row_pos, debit_col) credit_cell = rowcol_to_cell(row_pos, debit_col + 1) bal_formula += debit_cell + '-' + credit_cell c_specs += [('bal', 1, 0, 'number', None, bal_formula, regular_cell_style_decimal), ] else: c_specs += [('bal', 1, 0, 'number', partner.get('balance', 0.0), None, regular_cell_style_decimal), ] if _p.comparison_mode in ('single', 'multiple'): for i, comp in enumerate(comparisons): comp_partners = comp['partners_amounts'] balance = diff = percent_diff = 0 if comp_partners.get(partner_id): balance = comp_partners[partner_id]['balance'] diff = comp_partners[partner_id]['diff'] percent_diff = comp_partners[ partner_id]['percent_diff'] comparison_total[i]['balance'] += balance c_specs += [('balance_%s' % i, 1, 0, 'number', balance, None, regular_cell_style_decimal), ] # no diff in multiple comparisons because it shows too much # data if _p.comparison_mode == 'single': c_specs += [('balance_diff', 1, 0, 'number', diff, None, regular_cell_style_decimal), ] if percent_diff is False: c_specs += [('balance', 1, 0, 'number', diff, None, regular_cell_style_decimal), ] else: c_specs += [('perc_diff', 1, 0, 'number', int(round(percent_diff))), ] row_data = self.xls_row_template( c_specs, [x[0] for x in c_specs]) row_pos = self.xls_write_row( ws, row_pos, row_data, regular_cell_style) row_pos = self.print_account_totals( _xs, xlwt, ws, row_account_start, row_pos, current_account, _p)
def print_group_lines(self, row_position, account, line, _p, line_number): label_elements = [line.get('lname') or ''] if line.get('invoice_number'): label_elements.append("(%s)" % (line['invoice_number'],)) label = ' '.join(label_elements) # Mako: <div class="act_as_row lines # ${line.get('is_from_previous_periods') and # 'open_invoice_previous_line' or ''} ${line.get('is_clearance_line') # and 'clearance_line' or ''}"> if line.get('is_from_previous_periods') or \ line.get('is_clearance_line'): style_line_default = self.style_default_italic style_line_right = self.style_right_italic style_line_date = self.style_date_italic style_line_decimal = self.style_decimal_italic else: style_line_default = self.style_default style_line_right = self.style_right style_line_date = self.style_date style_line_decimal = self.style_decimal debit_cell = rowcol_to_cell(row_position, 7) credit_cell = rowcol_to_cell(row_position, 8) previous_balance = rowcol_to_cell(row_position - 1, 9) # if it is the first line, the balance is only debit - credit if line_number == 1: cumul_balance = debit_cell + '-' + credit_cell # cumulate debit - credit and balance of previous line else: cumul_balance = debit_cell + '-' + \ credit_cell + '+' + previous_balance if line.get('ldate'): c_specs = [('date', 1, 0, 'date', datetime.strptime( line['ldate'], '%Y-%m-%d'), None, style_line_date)] else: c_specs = [('date', 1, 0, 'text', None)] c_specs += [ ('period_code', 1, 0, 'text', line.get('period_code') or ''), ('entry', 1, 0, 'text', line.get('move_name') or ''), ('journal', 1, 0, 'text', line.get('jcode') or ''), ('label', 1, 0, 'text', label), ('rec', 1, 0, 'text', line.get('rec_name') or ''), ] if line.get('date_maturity'): c_specs += [('datedue', 1, 0, 'date', datetime.strptime(line['date_maturity'], '%Y-%m-%d'), None, style_line_date)] else: c_specs += [('datedue', 1, 0, 'text', None)] c_specs += [ ('debit', 1, 0, 'number', line.get('debit') or 0.0, None, style_line_decimal), ('credit', 1, 0, 'number', line.get('credit') or 0.0, None, style_line_decimal), ('cumul', 1, 0, 'number', None, cumul_balance, style_line_decimal), ] if self.display_curr_columns(_p): curr_debit = (line.get('debit', 0.0) and line.get('currency_id', False)==self.alt_curr_id) and (abs(line.get('amount_currency') or 0.0)) or \ compute_amounts_in_currency(self, self.cr, self.uid, line.get('debit', 0.0), self.base_currency_id, self.alt_curr_id, date=line.get('ldate', False), context=self.alt_curr_context) curr_credit = (line.get('credit', 0.0) and line.get('currency_id', False)==self.alt_curr_id) and (abs(line.get('amount_currency') or 0.0)) or \ compute_amounts_in_currency(self, self.cr, self.uid, line.get('credit', 0.0), self.base_currency_id, self.alt_curr_id, date=line.get('ldate', False), context=self.alt_curr_context) # determine the formula of the cumulated balance curr_debit_cell = rowcol_to_cell(row_position, 10) curr_credit_cell = rowcol_to_cell(row_position, 11) curr_previous_balance = rowcol_to_cell(row_position - 1, 12) if line_number == 1: curr_cumul_balance = curr_debit_cell + '-' + curr_credit_cell else: curr_cumul_balance = curr_debit_cell + '-' + \ curr_credit_cell + '+' + curr_previous_balance c_specs += [ ('curr_debit', 1, 0, 'number', curr_debit, None, style_line_decimal), ('curr_credit', 1, 0, 'number', curr_credit, None, style_line_decimal), ('curr_cumul', 1, 0, 'number', None, curr_cumul_balance, style_line_decimal), ] #if account.currency_id: # By irabaza # We want to show lines paid in another currency even # if account has no secundary currency c_specs += [ ('curramount', 1, 0, 'number', line.get('amount_currency') or 0.0, None, style_line_decimal), ('currcode', 1, 0, 'text', line.get('currency_code') or '', None, style_line_right), ] #else: # c_specs += [ # ('curramount', 1, 0, 'text', '-', None, style_line_right), # ('currcode', 1, 0, 'text', '', None, style_line_right), # ] row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs]) row_position = self.xls_write_row( self.ws, row_position, row_data, style_line_default) return (row_position, cumul_balance)
def _voucher_reposition_unincluded_section(self, wizard, ws, _p, row_pos, _xs, _combination): voucher_reposition_type = { 'account_invoice_fr': u'Facturas de fondo rotatorio', 'account_invoice_refund_fr': u'Nota de Crédito fondo rotatorio', 'hr_expense_anticipo': u'Rendición de anticipo', 'hr_expense': u'Rendición de viático', 'hr_expense_v': u'Vales', 'bank_statement': u'Líneas de Registros de caja', 'caja_chica': u'Líneas de Caja efectivo', 'hr_expense_a': u'Abonos' } c_specs = [ ('report_name', 7, 2, 'text', _('Comprobantes no incluidos en reposición')), ] row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs]) row_pos = self.xls_write_row(ws, row_pos, row_data, row_style=self.subtitle_style) data = self.get_voucher_reposition_unincluded( _p['user'].id, _combination['operating_unit'], _combination['fondo_rotatorio_siif']) for tipo_documento, tipo_documento_data in data.items(): c_specs = [ ('title', 2, 2, 'text', _(u'Tipo de documento')), ('doct_type', 2, 2, 'text', voucher_reposition_type.get(tipo_documento)), ] row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs]) row_pos = self.xls_write_row(ws, row_pos, row_data, row_style=self.bold_left_style) c_specs = [ ('partner', 3, 2, 'text', _(u'Proveedor')), ('date', 1, 2, 'text', _(u'Fecha')), ('nro_doc', 1, 2, 'text', _(u'N° documento')), ('total', 1, 2, 'text', _(u'Total')), ] row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs]) row_pos = self.xls_write_row(ws, row_pos, row_data, row_style=self.bold_left_style) row_start = row_pos for data in tipo_documento_data: c_specs = [ ('partner', 3, 2, 'text', data.proveedor), ('date', 1, 2, 'text', data.fecha_factura), ('nro_doc', 1, 2, 'text', data.n_documento), ('total', 1, 2, 'number', data.total, None, self.normal_number_style), ] row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs]) row_pos = self.xls_write_row(ws, row_pos, row_data) stotal_summary = 'SUM(' + rowcol_to_cell( row_start, 5) + ':' + rowcol_to_cell(row_pos - 1, 5) + ')' c_specs = [ ('partner', 3, 2, 'text', ''), ('date', 1, 2, 'text', ''), ('nro_doc', 1, 2, 'text', ''), ('total', 1, 2, 'number', None, stotal_summary, self.bold_number_style), ] row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs]) row_pos = self.xls_write_row(ws, row_pos, row_data) return row_pos
def print_group_cumul_partner(self, row_position, row_start_partner, account, _p, data): # the text "Cumulated Balance on Partner starts in column 4 when # selecting the option regroup by currency, 5 in the other case start_col = 4 debit_partner_start = rowcol_to_cell(row_start_partner, start_col + 3) debit_partner_end = rowcol_to_cell(row_position - 1, start_col + 3) debit_partner_total = 'SUM(' + debit_partner_start + \ ':' + debit_partner_end + ')' credit_partner_start = rowcol_to_cell(row_start_partner, start_col + 4) credit_partner_end = rowcol_to_cell(row_position - 1, start_col + 4) credit_partner_total = 'SUM(' + credit_partner_start + \ ':' + credit_partner_end + ')' bal_curr_start = rowcol_to_cell(row_start_partner, start_col + 5) bal_curr_end = rowcol_to_cell(row_position - 1, start_col + 5) cumul_balance_curr = 'SUM(' + bal_curr_start + ':' + bal_curr_end + ')' bal_partner_debit = rowcol_to_cell(row_position, start_col + 3) bal_partner_credit = rowcol_to_cell(row_position, start_col + 4) bal_partner_total = bal_partner_debit + '-' + bal_partner_credit c_specs = [('empty%s' % x, 1, 0, 'text', None) for x in range(start_col)] c_specs += [ # , style_bold_italic), ('init_bal', 1, 0, 'text', _('Cumulated Balance on Partner')), ('rec', 1, 0, 'text', None), ('empty5', 1, 0, 'text', None), ('debit', 1, 0, 'number', None, debit_partner_total, self.style_partner_cumul_decimal), ('credit', 1, 0, 'number', None, credit_partner_total, self.style_partner_cumul_decimal), ('cumul_bal', 1, 0, 'number', None, bal_partner_total, self.style_partner_cumul_decimal), ] if self.display_curr_columns(_p, data): curr_debit_partner_start = rowcol_to_cell(row_start_partner, start_col + 6) curr_debit_partner_end = rowcol_to_cell(row_position - 1, start_col + 6) curr_debit_partner_total = 'SUM(' + curr_debit_partner_start + \ ':' + curr_debit_partner_end + ')' curr_credit_partner_start = rowcol_to_cell(row_start_partner, start_col + 7) curr_credit_partner_end = rowcol_to_cell(row_position - 1, start_col + 7) curr_credit_partner_total = 'SUM(' + curr_credit_partner_start + \ ':' + curr_credit_partner_end + ')' curr_bal_partner_debit = rowcol_to_cell(row_position, start_col + 6) curr_bal_partner_credit = rowcol_to_cell(row_position, start_col + 7) curr_bal_partner_total = curr_bal_partner_debit + '-' + curr_bal_partner_credit c_specs += [ ('curr_debit', 1, 0, 'number', None, curr_debit_partner_total, self.style_partner_cumul_decimal), ('curr_credit', 1, 0, 'number', None, curr_credit_partner_total, self.style_partner_cumul_decimal), ('curr_cumul_bal', 1, 0, 'number', None, curr_bal_partner_total, self.style_partner_cumul_decimal), ] if account.currency_id: c_specs += [ ('cumul_bal_curr', 1, 0, 'number', None, cumul_balance_curr, self.style_partner_cumul_decimal), ('curr_name', 1, 0, 'text', account.currency_id.name, None, self.style_partner_cumul_right), ] else: c_specs += [ ('cumul_bal_curr', 1, 0, 'text', "-", None, self.style_partner_cumul_right), ('curr_name', 1, 0, 'text', "", None, self.style_partner_cumul_right), ] row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs]) row_position = self.xls_write_row( self.ws, row_position, row_data, self.style_partner_cumul) return row_position + 1
def print_group_lines(self, row_position, account, line, _p, line_number): label_elements = [line.get('lname') or ''] if line.get('invoice_number'): label_elements.append("(%s)" % (line['invoice_number'], )) label = ' '.join(label_elements) # Mako: <div class="act_as_row lines # ${line.get('is_from_previous_periods') and # 'open_invoice_previous_line' or ''} ${line.get('is_clearance_line') # and 'clearance_line' or ''}"> if line.get('is_from_previous_periods') or \ line.get('is_clearance_line'): style_line_default = self.style_default_italic style_line_right = self.style_right_italic style_line_date = self.style_date_italic style_line_decimal = self.style_decimal_italic else: style_line_default = self.style_default style_line_right = self.style_right style_line_date = self.style_date style_line_decimal = self.style_decimal debit_cell = rowcol_to_cell(row_position, 7) credit_cell = rowcol_to_cell(row_position, 8) previous_balance = rowcol_to_cell(row_position - 1, 9) # if it is the first line, the balance is only debit - credit if line_number == 1: cumul_balance = debit_cell + '-' + credit_cell # cumulate devit - credit and balance of previous line else: cumul_balance = debit_cell + '-' + \ credit_cell + '+' + previous_balance if line.get('ldate'): c_specs = [('date', 1, 0, 'date', datetime.strptime(line['ldate'], '%Y-%m-%d'), None, style_line_date)] else: c_specs = [('date', 1, 0, 'text', None)] c_specs += [ ('period_code', 1, 0, 'text', line.get('period_code') or ''), ('entry', 1, 0, 'text', line.get('move_name') or ''), ('journal', 1, 0, 'text', line.get('jcode') or ''), ('label', 1, 0, 'text', label), ('rec', 1, 0, 'text', line.get('rec_name') or ''), ] if line.get('date_maturity'): c_specs += [('datedue', 1, 0, 'date', datetime.strptime(line['date_maturity'], '%Y-%m-%d'), None, style_line_date)] else: c_specs += [('datedue', 1, 0, 'text', None)] c_specs += [ ('debit', 1, 0, 'number', line.get('debit') or 0.0, None, style_line_decimal), ('credit', 1, 0, 'number', line.get('credit') or 0.0, None, style_line_decimal), ('cumul', 1, 0, 'number', None, cumul_balance, style_line_decimal), ] if account.currency_id: c_specs += [ ('curramount', 1, 0, 'number', line.get('amount_currency') or 0.0, None, style_line_decimal), ('currcode', 1, 0, 'text', line.get('currency_code') or '', None, style_line_right), ] else: c_specs += [ ('curramount', 1, 0, 'text', '-', None, style_line_right), ('currcode', 1, 0, 'text', '', None, style_line_right), ] row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs]) row_position = self.xls_write_row(self.ws, row_position, row_data, style_line_default) return (row_position, cumul_balance)
def _journal_lines(self, o, ws, _p, row_pos, _xs): if _p.space_extra: locals().update(_p.space_extra) wanted_list = self.wanted_list debit_pos = self.debit_pos credit_pos = self.credit_pos # Column headers c_specs = map( lambda x: self.render(x, self.col_specs_lines_template, 'header', render_space={'_': _p._}), wanted_list) row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs]) row_pos = self.xls_write_row(ws, row_pos, row_data, row_style=self.rh_cell_style, set_column_size=True) ws.set_horz_split_pos(row_pos) # account move lines aml_start_pos = row_pos aml_cnt = len(_p.lines(o)) cnt = 0 for l in _p.lines(o): cnt += 1 debit_cell = rowcol_to_cell(row_pos, debit_pos) credit_cell = rowcol_to_cell(row_pos, credit_pos) bal_formula = debit_cell + '-' + credit_cell _logger.debug('dummy call - %s', bal_formula) c_specs = map( lambda x: self.render(x, self.col_specs_lines_template, 'lines' ), wanted_list) row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs]) row_pos = self.xls_write_row(ws, row_pos, row_data, row_style=self.aml_cell_style) if l['draw_line'] and cnt != aml_cnt: row_pos += 1 # Totals debit_start = rowcol_to_cell(aml_start_pos, debit_pos) debit_stop = rowcol_to_cell(row_pos - 1, debit_pos) debit_formula = 'SUM(%s:%s)' % (debit_start, debit_stop) _logger.debug('dummy call - %s', debit_formula) credit_start = rowcol_to_cell(aml_start_pos, credit_pos) credit_stop = rowcol_to_cell(row_pos - 1, credit_pos) credit_formula = 'SUM(%s:%s)' % (credit_start, credit_stop) _logger.debug('dummy call - %s', credit_formula) debit_cell = rowcol_to_cell(row_pos, debit_pos) credit_cell = rowcol_to_cell(row_pos, credit_pos) bal_formula = debit_cell + '-' + credit_cell c_specs = map( lambda x: self.render(x, self.col_specs_lines_template, 'totals'), wanted_list) row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs]) row_pos = self.xls_write_row(ws, row_pos, row_data, row_style=self.rt_cell_style_right) return row_pos + 1
def generate_xls_report(self, _p, _xs, data, objects, wb): ws = wb.add_sheet(_p.report_name[:31]) ws.panes_frozen = True ws.remove_splits = True ws.portrait = 0 # Landscape ws.fit_width_to_pages = 1 row_pos = 0 # set print header/footer ws.header_str = self.xls_headers['standard'] ws.footer_str = self.xls_footers['standard'] # cf. account_report_trial_balance.mako initial_balance_text = {'initial_balance': _('Computed'), 'opening_balance': _('Opening Entries'), False: _('No')} # Title cell_style = xlwt.easyxf(_xs['xls_title']) report_name = ' - '.join([_p.report_name.upper(), _p.company.partner_id.name, _p.company.currency_id.name]) c_specs = [ ('report_name', 1, 0, 'text', report_name), ] row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs]) row_pos = self.xls_write_row( ws, row_pos, row_data, row_style=cell_style) # write empty row to define column sizes c_sizes = self.column_sizes c_specs = [('empty%s' % i, 1, c_sizes[i], 'text', None) for i in range(0, len(c_sizes))] row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs]) row_pos = self.xls_write_row( ws, row_pos, row_data, set_column_size=True) # Header Table cell_format = _xs['bold'] + _xs['fill_blue'] + _xs['borders_all'] cell_style = xlwt.easyxf(cell_format) cell_style_center = xlwt.easyxf(cell_format + _xs['center']) c_specs = [ ('fy', 1, 0, 'text', _('Fiscal Year')), ('af', 2, 0, 'text', _('Accounts Filter')), ('df', 1, 0, 'text', _p.filter_form(data) == 'filter_date' and _('Dates Filter') or _('Periods Filter')), ('tm', 2, 0, 'text', _('Target Moves'), None, cell_style_center), ('ib', 1, 0, 'text', _('Initial Balance'), None, cell_style_center), ('coa', 1, 0, 'text', _('Chart of Account'), None, cell_style_center), ] row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs]) row_pos = self.xls_write_row( ws, row_pos, row_data, row_style=cell_style) cell_format = _xs['borders_all'] + _xs['wrap'] + _xs['top'] cell_style = xlwt.easyxf(cell_format) cell_style_center = xlwt.easyxf(cell_format + _xs['center']) c_specs = [ ('fy', 1, 0, 'text', _p.fiscalyear.name if _p.fiscalyear else '-'), ('af', 2, 0, 'text', _p.accounts(data) and ', '.join( [account.code for account in _p.accounts(data)]) or _('All')), ] df = _('From') + ': ' if _p.filter_form(data) == 'filter_date': df += _p.start_date if _p.start_date else u'' else: df += _p.start_period.name if _p.start_period else u'' df += ' ' + _('\nTo') + ': ' if _p.filter_form(data) == 'filter_date': df += _p.stop_date if _p.stop_date else u'' else: df += _p.stop_period.name if _p.stop_period else u'' c_specs += [ ('df', 1, 0, 'text', df), ('tm', 2, 0, 'text', _p.display_target_move( data), None, cell_style_center), ('ib', 1, 0, 'text', initial_balance_text[ _p.initial_balance_mode], None, cell_style_center), ('coa', 1, 0, 'text', _p.chart_account.name, None, cell_style_center), ] row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs]) row_pos = self.xls_write_row( ws, row_pos, row_data, row_style=cell_style) # comparison header table if _p.comparison_mode in ('single', 'multiple'): row_pos += 1 cell_format_ct = _xs['bold'] + \ _xs['fill_blue'] + _xs['borders_all'] cell_style_ct = xlwt.easyxf(cell_format_ct) c_specs = [('ct', 8, 0, 'text', _('Comparisons'))] row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs]) row_pos = self.xls_write_row( ws, row_pos, row_data, row_style=cell_style_ct) cell_style_center = xlwt.easyxf(cell_format) for index, params in enumerate(_p.comp_params): c_specs = [ ('c', 3, 0, 'text', _('Comparison') + str(index + 1) + ' (C' + str(index + 1) + ')')] if params['comparison_filter'] == 'filter_date': c_specs += [('f', 3, 0, 'text', _('Dates Filter') + ': ' + _p.formatLang( params['start'], date=True) + ' - ' + _p.formatLang(params['stop'], date=True))] elif params['comparison_filter'] == 'filter_period': c_specs += [('f', 3, 0, 'text', _('Periods Filter') + ': ' + params['start'].name + ' - ' + params['stop'].name)] else: c_specs += [('f', 3, 0, 'text', _('Fiscal Year') + ': ' + params['fiscalyear'].name)] c_specs += [('ib', 2, 0, 'text', _('Initial Balance') + ': ' + initial_balance_text[ params['initial_balance_mode']])] row_data = self.xls_row_template( c_specs, [x[0] for x in c_specs]) row_pos = self.xls_write_row( ws, row_pos, row_data, row_style=cell_style_center) row_pos += 1 # Column Header Row cell_format = _xs['bold'] + _xs['fill_blue'] + \ _xs['borders_all'] + _xs['wrap'] + _xs['top'] cell_style = xlwt.easyxf(cell_format) cell_style_right = xlwt.easyxf(cell_format + _xs['right']) cell_style_center = xlwt.easyxf(cell_format + _xs['center']) if len(_p.comp_params) == 2: account_span = 3 else: account_span = _p.initial_balance_mode and 2 or 3 c_specs = [ ('code', 1, 0, 'text', _('Code')), ('account', account_span, 0, 'text', _('Account')), ] if _p.comparison_mode == 'no_comparison': if _p.initial_balance_mode: c_specs += [('init_bal', 1, 0, 'text', _('Initial Balance'), None, cell_style_right)] c_specs += [ ('debit', 1, 0, 'text', _('Debit'), None, cell_style_right), ('credit', 1, 0, 'text', _('Credit'), None, cell_style_right), ] if _p.comparison_mode == 'no_comparison' or not _p.fiscalyear: c_specs += [('balance', 1, 0, 'text', _('Balance'), None, cell_style_right)] else: c_specs += [('balance_fy', 1, 0, 'text', _('Balance %s') % _p.fiscalyear.name, None, cell_style_right)] if _p.comparison_mode in ('single', 'multiple'): for index in range(_p.nb_comparison): if _p.comp_params[index][ 'comparison_filter'] == 'filter_year' \ and _p.comp_params[index].get('fiscalyear', False): c_specs += [('balance_%s' % index, 1, 0, 'text', _('Balance %s') % _p.comp_params[index]['fiscalyear'].name, None, cell_style_right)] else: c_specs += [('balance_%s' % index, 1, 0, 'text', _('Balance C%s') % (index + 1), None, cell_style_right)] if _p.comparison_mode == 'single': c_specs += [ ('diff', 1, 0, 'text', _('Difference'), None, cell_style_right), ('diff_percent', 1, 0, 'text', _('% Difference'), None, cell_style_center), ] c_specs += [('type', 1, 0, 'text', _('Type'), None, cell_style_center)] row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs]) row_pos = self.xls_write_row( ws, row_pos, row_data, row_style=cell_style) ws.set_horz_split_pos(row_pos) last_child_consol_ids = [] # cell styles for account data view_cell_format = _xs['bold'] + _xs['fill'] + _xs['borders_all'] view_cell_style = xlwt.easyxf(view_cell_format) view_cell_style_center = xlwt.easyxf(view_cell_format + _xs['center']) view_cell_style_decimal = xlwt.easyxf( view_cell_format + _xs['right'], num_format_str=report_xls.decimal_format) view_cell_style_pct = xlwt.easyxf( view_cell_format + _xs['center'], num_format_str='0') regular_cell_format = _xs['borders_all'] regular_cell_style = xlwt.easyxf(regular_cell_format) regular_cell_style_center = xlwt.easyxf( regular_cell_format + _xs['center']) regular_cell_style_decimal = xlwt.easyxf( regular_cell_format + _xs['right'], num_format_str=report_xls.decimal_format) regular_cell_style_pct = xlwt.easyxf( regular_cell_format + _xs['center'], num_format_str='0') for current_account in objects: if not current_account.to_display: continue if current_account.type == 'view': cell_style = view_cell_style cell_style_center = view_cell_style_center cell_style_decimal = view_cell_style_decimal cell_style_pct = view_cell_style_pct else: cell_style = regular_cell_style cell_style_center = regular_cell_style_center cell_style_decimal = regular_cell_style_decimal cell_style_pct = regular_cell_style_pct comparisons = current_account.comparisons if current_account.id not in last_child_consol_ids: # current account is a not a consolidation child: use its own # level last_child_consol_ids = [ child_consol_id.id for child_consol_id in current_account.child_consol_ids] c_specs = [ ('code', 1, 0, 'text', current_account.code), ('account', account_span, 0, 'text', current_account.name), ] if _p.comparison_mode == 'no_comparison': debit_cell = rowcol_to_cell(row_pos, 4) credit_cell = rowcol_to_cell(row_pos, 5) bal_formula = debit_cell + '-' + credit_cell if _p.initial_balance_mode: init_cell = rowcol_to_cell(row_pos, 3) debit_cell = rowcol_to_cell(row_pos, 4) credit_cell = rowcol_to_cell(row_pos, 5) bal_formula = init_cell + '+' + \ debit_cell + '-' + credit_cell c_specs += [('init_bal', 1, 0, 'number', current_account.init_balance, None, cell_style_decimal)] c_specs += [ ('debit', 1, 0, 'number', current_account.debit, None, cell_style_decimal), ('credit', 1, 0, 'number', current_account.credit, None, cell_style_decimal), ] c_specs += [('balance', 1, 0, 'number', None, bal_formula, cell_style_decimal)] else: c_specs += [('balance', 1, 0, 'number', current_account.balance, None, cell_style_decimal)] if _p.comparison_mode in ('single', 'multiple'): c = 1 for comp_account in comparisons: c_specs += [('balance_%s' % c, 1, 0, 'number', comp_account['balance'], None, cell_style_decimal)] c += 1 if _p.comparison_mode == 'single': c_specs += [ ('diff', 1, 0, 'number', comp_account[ 'diff'], None, cell_style_decimal), ('diff_percent', 1, 0, 'number', comp_account[ 'percent_diff'] and comp_account['percent_diff'] or 0, None, cell_style_pct), ] c_specs += [('type', 1, 0, 'text', current_account.type, None, cell_style_center)] row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs]) row_pos = self.xls_write_row( ws, row_pos, row_data, row_style=cell_style)
def generate_xls_report(self, _p, _xs, data, objects, wb): for account in objects: ws = wb.add_sheet(account.code) ws.panes_frozen = True ws.remove_splits = True ws.portrait = 0 # Landscape ws.fit_width_to_pages = 1 row_pos = 0 # set print header/footer ws.header_str = self.xls_headers['standard'] ws.footer_str = self.xls_footers['standard'] # Title cell_style = xlwt.easyxf(_xs['xls_title']) c_specs = [ ('report_name', 1, 0, 'text', account.name), ] row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs]) row_pos = self.xls_write_row(ws, row_pos, row_data, row_style=cell_style) # write empty row to define column sizes c_sizes = self.column_sizes c_specs = [('empty%s' % i, 1, c_sizes[i], 'text', None) for i in range(0, len(c_sizes))] row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs]) row_pos = self.xls_write_row(ws, row_pos, row_data, set_column_size=True) # # Header Table # cell_format = _xs['bold'] + _xs['fill_blue'] + _xs['borders_all'] # cell_style = xlwt.easyxf(cell_format) # cell_style_center = xlwt.easyxf(cell_format + _xs['center']) # c_specs = [ # ('fy', 2, 0, 'text', _('Fiscal Year')), # ('af', 2, 0, 'text', _('Accounts Filter')), # ('df', 1, 0, 'text', _p.filter_form(data) == # 'filter_date' and _('Dates Filter') or _('Periods Filter')), # ('tm', 2, 0, 'text', _('Target Moves'), None, cell_style_center), # ('ib', 1, 0, 'text', _('Initial Balance'), # None, cell_style_center), # ('coa', 1, 0, 'text', _('Chart of Account'), # None, cell_style_center), # ] # row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs]) # row_pos = self.xls_write_row(ws, row_pos, row_data, row_style=cell_style) # cell_format = _xs['borders_all'] + _xs['wrap'] + _xs['top'] # cell_style = xlwt.easyxf(cell_format) # cell_style_center = xlwt.easyxf(cell_format + _xs['center']) # c_specs = [ # ('fy', 2, 0, 'text', _p.fiscalyear.name if _p.fiscalyear else '-'), # ('af', 2, 0, 'text', _p.accounts(data) and ', '.join( # [account.code for account in _p.accounts(data)]) or _('All')), # ] # df = _('From') + ': ' # if _p.filter_form(data) == 'filter_date': # df += _p.start_date if _p.start_date else u'' # else: # df += _p.start_period.name if _p.start_period else u'' # df += ' ' + _('\nTo') + ': ' # if _p.filter_form(data) == 'filter_date': # df += _p.stop_date if _p.stop_date else u'' # else: # df += _p.stop_period.name if _p.stop_period else u'' # c_specs += [ # ('df', 1, 0, 'text', df), # ('tm', 2, 0, 'text', _p.display_target_move( # data), None, cell_style_center), # ('ib', 1, 0, 'text', initial_balance_text[ # _p.initial_balance_mode], None, cell_style_center), # ('coa', 1, 0, 'text', _p.chart_account.name, # None, cell_style_center), # ] # row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs]) # row_pos = self.xls_write_row( # ws, row_pos, row_data, row_style=cell_style) row_pos += 1 # Column Header Row cell_format = _xs['bold'] + _xs['fill_blue'] + \ _xs['borders_all'] + _xs['wrap'] + _xs['top'] cell_style = xlwt.easyxf(cell_format) cell_style_right = xlwt.easyxf(cell_format + _xs['right']) cell_style_center = xlwt.easyxf(cell_format + _xs['center']) ws.write_merge(row_pos, row_pos + 1, 0, 0, "Code", cell_style_center) ws.write_merge(row_pos, row_pos + 1, 1, 1, "Old Code", cell_style_center) ws.write_merge(row_pos, row_pos + 1, 2, 2, "Account", cell_style_center) ws.write_merge(row_pos, row_pos, 3, 4, "Bank", cell_style_center) ws.write(row_pos + 1, 3, "Debit", cell_style_center) ws.write(row_pos + 1, 4, "Credit", cell_style_center) ws.write_merge(row_pos, row_pos + 1, 5, 5, "CCY\nAmount", cell_style_center) ws.write_merge(row_pos, row_pos, 6, 7, "General Journal", cell_style_center) ws.write(row_pos + 1, 6, "Debit", cell_style_center) ws.write(row_pos + 1, 7, "Credit", cell_style_center) ws.write_merge(row_pos, row_pos + 1, 8, 8, "CCY\nAmount", cell_style_center) ws.set_horz_split_pos(row_pos) row_pos += 2 # cell styles for account data view_cell_format = _xs['bold'] + _xs['fill'] + _xs['borders_all'] view_cell_style = xlwt.easyxf(view_cell_format) view_cell_style_center = xlwt.easyxf(view_cell_format + _xs['center']) view_cell_style_decimal = xlwt.easyxf( view_cell_format + _xs['right'], num_format_str=report_xls.decimal_format) view_cell_style_pct = xlwt.easyxf(view_cell_format + _xs['center'], num_format_str='0') regular_cell_format = _xs['borders_all'] regular_cell_style = xlwt.easyxf(regular_cell_format) regular_cell_style_center = xlwt.easyxf(regular_cell_format + _xs['center']) regular_cell_style_decimal = xlwt.easyxf( regular_cell_format + _xs['right'], num_format_str=report_xls.decimal_format) regular_cell_style_pct = xlwt.easyxf(regular_cell_format + _xs['center'], num_format_str='0') total_debit = 0.0 total_credit = 0.0 total_ccy = 0.0 debit_cells = [] credit_cells = [] ccy_cells = [] for counterpart in _p['detail_counterpart_accounts'][account.id]: # if current_account.type == 'view': # cell_style = view_cell_style # cell_style_center = view_cell_style_center # cell_style_decimal = view_cell_style_decimal # cell_style_pct = view_cell_style_pct # else: # cell_style = regular_cell_style # cell_style_center = regular_cell_style_center # cell_style_decimal = regular_cell_style_decimal # cell_style_pct = regular_cell_style_pct c_specs = [ ('code', 1, 0, 'text', counterpart['account'].code, None, regular_cell_style), ('code2', 1, 0, 'text', counterpart['account'].code2, None, regular_cell_style), ('account', 1, 0, 'text', counterpart['account'].name, None, regular_cell_style), ('debit1', 1, 0, 'number', counterpart['debit'], None, regular_cell_style_decimal), ('credit1', 1, 0, 'number', counterpart['credit'], None, regular_cell_style_decimal), ('ccy1', 1, 0, 'number', counterpart['amount_currency'], None, regular_cell_style_decimal), ('debit2', 1, 0, 'number', None, None, regular_cell_style_decimal), ('credit2', 1, 0, 'number', None, None, regular_cell_style_decimal), ('ccy2', 1, 0, 'number', None, None, regular_cell_style_decimal), ] row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs]) row_pos = self.xls_write_row(ws, row_pos, row_data, row_style=regular_cell_style) debit_cells.append(rowcol_to_cell(row_pos, 4)) credit_cells.append(rowcol_to_cell(row_pos, 5)) ccy_cells.append(rowcol_to_cell(row_pos, 6)) total_debit += counterpart['debit'] total_credit += counterpart['credit'] total_ccy += counterpart['amount_currency'] c_specs = [ ('code', 1, 0, 'text', 'Total', None, view_cell_style), ('code2', 1, 0, 'text', '', None, view_cell_style), ('account', 1, 0, 'text', '', None, view_cell_style), ('debit1', 1, 0, 'number', total_debit, None, view_cell_style_decimal), ('credit1', 1, 0, 'number', total_credit, None, view_cell_style_decimal), ('ccy1', 1, 0, 'number', total_ccy, None, view_cell_style_decimal), ('debit2', 1, 0, 'number', None, None, view_cell_style_decimal), ('credit2', 1, 0, 'number', None, None, view_cell_style_decimal), ('ccy2', 1, 0, 'number', None, None, view_cell_style_decimal), ] row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs]) row_pos_total = self.xls_write_row(ws, row_pos, row_data, row_style=view_cell_style) c_specs = [ ('code', 1, 0, 'text', 'Initial Balance', None, view_cell_style), ('code2', 1, 0, 'text', '', None, view_cell_style), ('account', 1, 0, 'text', '', None, view_cell_style), ('debit1', 1, 0, 'number', _p['init_balance_accounts'][account.id], None, view_cell_style_decimal), ('credit1', 1, 0, 'number', None, None, view_cell_style_decimal), ('ccy1', 1, 0, 'number', None, None, view_cell_style_decimal), ('debit2', 1, 0, 'number', None, None, view_cell_style_decimal), ('credit2', 1, 0, 'number', None, None, view_cell_style_decimal), ('ccy2', 1, 0, 'number', None, None, view_cell_style_decimal), ] row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs]) row_pos_init = self.xls_write_row(ws, row_pos_total, row_data, row_style=view_cell_style) init_cell = rowcol_to_cell(row_pos_init, 4) debit_cell = rowcol_to_cell(row_pos_total, 4) credit_cell = rowcol_to_cell(row_pos_total, 5) # bal_formula = init_cell + '+' + debit_cell + '-' + credit_cell c_specs = [ ('code', 1, 0, 'text', 'Closing Balance', None, view_cell_style), ('code2', 1, 0, 'text', '', None, view_cell_style), ('account', 1, 0, 'text', '', None, view_cell_style), ('debit1', 1, 0, 'number', _p['init_balance_accounts'][account.id] + total_debit - total_credit, None, view_cell_style_decimal), ('credit1', 1, 0, 'number', None, None, view_cell_style_decimal), ('ccy1', 1, 0, 'number', None, None, view_cell_style_decimal), ('debit2', 1, 0, 'number', None, None, view_cell_style_decimal), ('credit2', 1, 0, 'number', None, None, view_cell_style_decimal), ('ccy2', 1, 0, 'number', None, None, view_cell_style_decimal), ] row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs]) row_pos = self.xls_write_row(ws, row_pos_init, row_data, row_style=view_cell_style)
def _removal_report(self, _p, _xs, data, objects, wb): cr = self.cr uid = self.uid context = self.context fy = self.fiscalyear wl_dsp = _p.wanted_list_removal template = self.removal_template asset_obj = self.pool.get("account.asset.asset") title = self._get_title("removal", "normal") title_short = self._get_title("removal", "short") sheet_name = title_short[:31].replace("/", "-") ws = wb.add_sheet(sheet_name) ws.panes_frozen = True ws.remove_splits = True ws.portrait = 0 # Landscape ws.fit_width_to_pages = 1 row_pos = 0 ws.header_str = self.xls_headers["standard"] ws.footer_str = self.xls_footers["standard"] row_pos = self._report_title(ws, _p, row_pos, _xs, title) cr.execute( "SELECT id FROM account_asset_asset " "WHERE date_remove >= %s AND date_remove <= %s" "AND id IN %s AND type = 'normal' " "ORDER BY date_remove ASC", (fy.date_start, fy.date_stop, tuple(self.asset_ids)), ) dsp_ids = [x[0] for x in cr.fetchall()] if not dsp_ids: return self._empty_report(ws, _p, row_pos, _xs, "removal") c_specs = map(lambda x: self.render(x, template, "header", render_space={"_": _p._}), wl_dsp) row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs]) row_pos = self.xls_write_row(ws, row_pos, row_data, row_style=self.rh_cell_style, set_column_size=True) ws.set_horz_split_pos(row_pos) row_pos_start = row_pos if "account" not in wl_dsp: raise orm.except_orm( _("Customization Error"), _("The 'account' field is a mandatory entry of the " "'_xls_removal_fields' list !"), ) asset_value_pos = "asset_value" in wl_dsp and wl_dsp.index("asset_value") salvage_value_pos = "salvage_value" in wl_dsp and wl_dsp.index("salvage_value") dsps = filter(lambda x: x[0] in dsp_ids, self.assets) dsps_and_parents = [] for dsp in dsps: self._view_add(dsp, dsps_and_parents) entries = [] for asset_i, data in enumerate(dsps_and_parents): entry = {} asset = asset_obj.browse(cr, uid, data[0], context=context) if data[1] == "view": cp_i = asset_i + 1 cp = [] for a in dsps_and_parents[cp_i:]: if a[2] == data[0]: cp.append(cp_i) cp_i += 1 entry["child_pos"] = cp entry["asset"] = asset entries.append(entry) for entry in entries: asset = entry["asset"] if asset.type == "view": asset_value_cells = [rowcol_to_cell(row_pos_start + x, asset_value_pos) for x in entry["child_pos"]] asset_formula = "+".join(asset_value_cells) # noqa: disable F841, report_xls namespace trick salvage_value_cells = [rowcol_to_cell(row_pos_start + x, salvage_value_pos) for x in entry["child_pos"]] salvage_formula = "+".join(salvage_value_cells) # noqa: disable F841, report_xls namespace trick c_specs = map(lambda x: self.render(x, template, "asset_view"), wl_dsp) row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs]) row_pos = self.xls_write_row(ws, row_pos, row_data, row_style=self.av_cell_style) else: c_specs = map(lambda x: self.render(x, template, "asset"), wl_dsp) row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs]) row_pos = self.xls_write_row(ws, row_pos, row_data, row_style=self.an_cell_style) asset_total_formula = rowcol_to_cell( row_pos_start, asset_value_pos ) # noqa: disable F841, report_xls namespace trick salvage_total_formula = rowcol_to_cell( row_pos_start, salvage_value_pos # noqa: disable F841, report_xls namespace trick ) c_specs = map(lambda x: self.render(x, template, "totals"), wl_dsp) row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs]) row_pos = self.xls_write_row(ws, row_pos, row_data, row_style=self.rt_cell_style_right)
def generate_xls_report(self, _p, _xs, data, objects, wb): ws = wb.add_sheet(_p.report_name[:31]) ws.panes_frozen = True ws.remove_splits = True ws.portrait = 0 # Landscape ws.fit_width_to_pages = 1 row_pos = 0 # set print header/footer ws.header_str = self.xls_headers['standard'] ws.footer_str = self.xls_footers['standard'] initial_balance_text = {'initial_balance': _('Computed'), 'opening_balance': _('Opening Entries'), False: _('No')} # Title cell_style = xlwt.easyxf(_xs['xls_title']) report_name = ' - '.join([_p.report_name.upper(), _p.company.partner_id.name, _p.company.currency_id.name]) c_specs = [ ('report_name', 1, 0, 'text', report_name), ] row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs]) row_pos = self.xls_write_row( ws, row_pos, row_data, row_style=cell_style) # write empty row to define column sizes c_sizes = self.column_sizes c_specs = [('empty%s' % i, 1, c_sizes[i], 'text', None) for i in range(0, len(c_sizes))] row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs]) row_pos = self.xls_write_row( ws, row_pos, row_data, set_column_size=True) # Header Table nbr_columns = 16 cell_format = _xs['bold'] + _xs['fill_blue'] + _xs['borders_all'] cell_style_center = xlwt.easyxf(cell_format + _xs['center']) c_specs = [ ('coa', 2, 0, 'text', _('Chart of Account')), ('fy', 2, 0, 'text', _('Fiscal Year')), ('df', 3, 0, 'text', _p.filter_form(data) == 'filter_date' and _('Dates Filter') or _('Periods Filter')), ('af', 3, 0, 'text', _('Accounts Filter')), ('tm', 2, 0, 'text', _('Target Moves')), ('ib', nbr_columns - 12, 0, 'text', _('Initial Balance')), ] row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs]) row_pos = self.xls_write_row( ws, row_pos, row_data, row_style=cell_style_center) cell_format = _xs['borders_all'] cell_style_center = xlwt.easyxf(cell_format + _xs['center']) c_specs = [ ('coa', 2, 0, 'text', _p.chart_account.name), ('fy', 2, 0, 'text', _p.fiscalyear.name if _p.fiscalyear else '-'), ] df = _('From') + ': ' if _p.filter_form(data) == 'filter_date': df += _p.start_date if _p.start_date else u'' else: df += _p.start_period.name if _p.start_period else u'' df += ' ' + _('To') + ': ' if _p.filter_form(data) == 'filter_date': df += _p.stop_date if _p.stop_date else u'' else: df += _p.stop_period.name if _p.stop_period else u'' c_specs += [ ('df', 3, 0, 'text', df), ('af', 3, 0, 'text', _('Custom Filter') if _p.partner_ids else _p.display_partner_account(data)), ('tm', 2, 0, 'text', _p.display_target_move(data)), ('ib', nbr_columns - 12, 0, 'text', initial_balance_text[_p.initial_balance_mode]), ] row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs]) row_pos = self.xls_write_row( ws, row_pos, row_data, row_style=cell_style_center) ws.set_horz_split_pos(row_pos) row_pos += 1 # Account Title Row cell_format = _xs['xls_title'] + _xs['bold'] + \ _xs['fill'] + _xs['borders_all'] account_cell_style = xlwt.easyxf(cell_format) account_cell_style_decimal = xlwt.easyxf( cell_format + _xs['right'], num_format_str=report_xls.decimal_format) # Column Title Row cell_format = _xs['bold'] c_title_cell_style = xlwt.easyxf(cell_format) # Column Header Row cell_format = _xs['bold'] + _xs['fill'] + _xs['borders_all'] c_hdr_cell_style = xlwt.easyxf(cell_format) # Column Initial Balance Row cell_format = _xs['italic'] + _xs['borders_all'] c_init_cell_style = xlwt.easyxf(cell_format) c_init_cell_style_decimal = xlwt.easyxf( cell_format + _xs['right'], num_format_str=report_xls.decimal_format) # Column Cumulated balance Row cell_format = _xs['bold'] + _xs['fill'] + _xs['borders_all'] c_cumul_cell_style = xlwt.easyxf(cell_format) c_cumul_cell_style_decimal = xlwt.easyxf( cell_format + _xs['right'], num_format_str=report_xls.decimal_format) # Column Partner Row cell_format = _xs['bold'] c_part_cell_style = xlwt.easyxf(cell_format) c_specs = [ ('period', 1, 0, 'text', _('Period'), None, c_hdr_cell_style), ('date', 1, 0, 'text', _('Date'), None, c_hdr_cell_style), ('ref', 1, 0, 'text', _('Reference'), None, c_hdr_cell_style), ('payment_ref', 1, 0, 'text', _('Payment Reference'), None, c_hdr_cell_style), ('curr_code', 1, 0, 'text', _('Cur'), None, c_hdr_cell_style), ('curr_rate', 1, 0, 'text', _('FX Rate'), None, c_hdr_cell_style), ('curr_amt', 1, 0, 'text', _('Amount in Currency'), None, c_hdr_cell_style), ('debit', 1, 0, 'text', _('Debit'), None, c_hdr_cell_style), ('credit', 1, 0, 'text', _('Credit'), None, c_hdr_cell_style), ('cumul_bal', 1, 0, 'text', _('Balance'), None, c_hdr_cell_style), ('move', 1, 0, 'text', _('Notes 1'), None, c_hdr_cell_style), ('note', 1, 0, 'text', _('Notes 2'), None, c_hdr_cell_style), ('rec', 1, 0, 'text', _('Rec.'), None, c_hdr_cell_style), ('payment_amt', 1, 0, 'text', _('Payment Amount'), None, c_hdr_cell_style), ('payment_curr', 1, 0, 'text', _('Payment Currency'), None, c_hdr_cell_style), ('int_note', 1, 0, 'text', _('Internal Notes'), None, c_hdr_cell_style), ] c_hdr_data = self.xls_row_template(c_specs, [x[0] for x in c_specs]) # Set light-grey background color light_green = 'pattern: pattern solid, fore_color 42;' # cell styles for statement lines ll_cell_format = _xs['borders_all'] ll_cell_style = xlwt.easyxf(ll_cell_format) ll_cell_style_grey = xlwt.easyxf(light_green + _xs['borders_all']) ll_cell_style_date = xlwt.easyxf( ll_cell_format + _xs['left'], num_format_str=report_xls.date_format) ll_cell_style_date_grey = xlwt.easyxf( ll_cell_format + _xs['left'] + light_green, num_format_str=report_xls.date_format) ll_cell_style_decimal = xlwt.easyxf( ll_cell_format + _xs['right'], num_format_str=report_xls.decimal_format) ll_cell_style_decimal_grey = xlwt.easyxf( ll_cell_format + _xs['right'] + light_green, num_format_str=report_xls.decimal_format) ll_cell_style_currency = xlwt.easyxf( ll_cell_format + _xs['right'], num_format_str='0.000000') ll_cell_style_currency_grey = xlwt.easyxf( ll_cell_format + _xs['right'] + light_green, num_format_str='0.000000') cnt = 0 partner_account_summary = {} for account in objects: if _p['statement_lines'].get(account.id, False) or \ _p['init_balance'].get(account.id, False): if not _p['partners_order'].get(account.id, False): continue cnt += 1 account_total_debit = 0.0 account_total_credit = 0.0 account_balance_cumul = 0.0 account_balance_cumul_curr = 0.0 c_specs = [ ('acc_title', nbr_columns, 0, 'text', ' - '.join([account.code, account.name]), None, account_cell_style), ] row_data = self.xls_row_template( c_specs, [x[0] for x in c_specs]) row_pos = self.xls_write_row( ws, row_pos, row_data, c_title_cell_style) row_pos += 1 for partner_name, p_id, p_ref, p_name in \ _p['partners_order'][account.id]: total_debit = 0.0 total_credit = 0.0 cumul_balance = 0.0 cumul_balance_curr = 0.0 part_cumul_balance = 0.0 part_cumul_balance_curr = 0.0 rec_code = False cell_style = ll_cell_style cell_style_date = ll_cell_style_date cell_style_decimal = ll_cell_style_decimal cell_style_currency = ll_cell_style_currency c_specs = [ ('partner_title', nbr_columns, 0, 'text', partner_name or _('No Partner'), None, c_part_cell_style), ] row_data = self.xls_row_template( c_specs, [x[0] for x in c_specs]) row_pos = self.xls_write_row( ws, row_pos, row_data, c_title_cell_style) row_pos = self.xls_write_row(ws, row_pos, c_hdr_data) row_start_partner = row_pos total_debit = _p['init_balance'][account.id].get( p_id, {}).get('debit') or 0.0 total_credit = _p['init_balance'][account.id].get( p_id, {}).get('credit') or 0.0 init_deposit = _p['init_deposit'][account.id].get( p_id, {}).get('balance') or 0.0 end_deposit = _p['end_deposit'][account.id].get( p_id, {}).get('balance') or 0.0 init_line = False if _p.initial_balance_mode and \ (total_debit or total_credit): init_line = True part_cumul_balance = \ _p['init_balance'][account.id].get( p_id, {}).get('init_balance') or 0.0 part_cumul_balance_curr = \ _p['init_balance'][account.id].get( p_id, {}).get('init_balance_currency') or 0.0 cumul_balance += part_cumul_balance cumul_balance_curr += part_cumul_balance_curr debit_cell = rowcol_to_cell(row_pos, 7) credit_cell = rowcol_to_cell(row_pos, 8) init_bal_formula = debit_cell + '-' + credit_cell # Print row 'Initial Balance' by partner c_specs = [('empty%s' % x, 1, 0, 'text', None) for x in range(6)] c_specs += [ ('init_bal', 1, 0, 'text', _('Initial Balance')), ('debit', 1, 0, 'number', total_debit, None, c_init_cell_style_decimal), ('credit', 1, 0, 'number', total_credit, None, c_init_cell_style_decimal), ('cumul_bal', 1, 0, 'number', None, init_bal_formula, c_init_cell_style_decimal), ('depo_bal_t', 1, 0, 'text', _('Deposit Balance')), ('depo_bal', 1, 0, 'number', init_deposit, None, c_init_cell_style_decimal), ] row_data = self.xls_row_template( c_specs, [x[0] for x in c_specs]) row_pos = self.xls_write_row( ws, row_pos, row_data, c_init_cell_style) curr_amt = 0.0 curr_rate = 0.0 for line in _p['statement_lines'][account.id].get(p_id, []): total_debit += line.get('debit') or 0.0 total_credit += line.get('credit') or 0.0 label_elements = [line.get('lname') or ''] if line.get('invoice_number'): label_elements.append( "(%s)" % (line['invoice_number'],)) label = ' '.join(label_elements) cumul_balance += line.get('balance') or 0.0 if init_line or row_pos > row_start_partner: cumbal_formula = rowcol_to_cell( row_pos - 1, 9) + '+' else: cumbal_formula = '' debit_cell = rowcol_to_cell(row_pos, 7) credit_cell = rowcol_to_cell(row_pos, 8) cumbal_formula += debit_cell + '-' + credit_cell # Currency Information if not line.get('amount_currency'): curr_rate = 1.000000 curr_amt = line.get('debit') + line.get('credit') else: curr_rate = abs(line.get('amount_currency') / (line.get('debit') + line.get('credit'))) curr_amt = abs(line.get('amount_currency')) # Handle Payment if line.get('payment_amt') and line.get( 'payment_amt') <> 0 and line.get( 'payment_amt') <> curr_amt: payment_amt = line.get('payment_amt') payment_curr = line.get('payment_curr') else: payment_amt = False payment_curr = False # Define reference and note2 (for payments) reference = '' note = '' if line.get('payment_type'): if line.get('payment_type') == "payment": reference = line.get('supplier_invoice_number') if line.get('payment_type') == "receipt": reference = line.get('order_ref') note = line.get('invoice_ref') # Define reference and note2 (for invoices) if line.get('invoice_type'): if line.get('invoice_type') == "in_invoice": reference = line.get('supplier_invoice_number') else: reference = line.get('quotation_number') note = line.get('invoice_number') if (not note or note == '') and line.get( 'reconcile_item_ref'): note = line.get('reconcile_item_ref') # Staggered color for different reconcile number if rec_code: if rec_code <> line.get('rec_name'): rec_code = line.get('rec_name') if cell_style == ll_cell_style_grey: cell_style = ll_cell_style cell_style_date = ll_cell_style_date cell_style_decimal = ll_cell_style_decimal cell_style_currency = \ ll_cell_style_currency else: cell_style = ll_cell_style_grey cell_style_date = ll_cell_style_date_grey cell_style_decimal = \ ll_cell_style_decimal_grey cell_style_currency = \ ll_cell_style_currency_grey else: rec_code = line.get('rec_name') # Print row statement line data # c_specs = [ ('period', 1, 0, 'text', line.get('period_code') or '') ] if line.get('ldate'): c_specs += [ ('ldate', 1, 0, 'date', datetime.strptime( line['ldate'], '%Y-%m-%d'), None, cell_style_date), ] else: c_specs += [ ('ldate', 1, 0, 'text', None), ] c_specs += [ ('ref', 1, 0, 'text', reference, None), ('payment_ref', 1, 0, 'text', line.get( 'payment_ref')), ('curr_code', 1, 0, 'text', line.get( 'currency_code') or _p.company.currency_id.name, None), ('curr_rate', 1, 0, 'number', curr_rate, None, cell_style_currency), ('curr_bal', 1, 0, 'number', curr_amt, None, cell_style_decimal), ('debit', 1, 0, 'number', line.get('debit'), None, cell_style_decimal), ('credit', 1, 0, 'number', line.get('credit'), None, cell_style_decimal), ('cumul_bal', 1, 0, 'number', None, cumbal_formula, cell_style_decimal), ('move', 1, 0, 'text', line.get('move_name') or ''), ('note', 1, 0, 'text', note, None), ('rec_name', 1, 0, 'text', line.get('rec_name') or ''), ] if payment_amt: c_specs += [ ('payment_amt', 1, 0, 'number', payment_amt, None, cell_style_decimal), ] else: c_specs += [ ('payment_amt', 1, 0, 'text', None), ] c_specs += [ ('payment_curr', 1, 0, 'text', payment_curr or '', None), ('int_note', 1, 0, 'text', line.get( 'int_note')), ] row_data = self.xls_row_template( c_specs, [x[0] for x in c_specs]) row_pos = self.xls_write_row( ws, row_pos, row_data, cell_style) # end for line # Print row Cumulated Balance by partner # debit_partner_start = rowcol_to_cell(row_start_partner, 7) debit_partner_end = rowcol_to_cell(row_pos - 1, 7) debit_partner_total = 'SUM(' + debit_partner_start + \ ':' + debit_partner_end + ')' credit_partner_start = rowcol_to_cell(row_start_partner, 8) credit_partner_end = rowcol_to_cell(row_pos - 1, 8) credit_partner_total = 'SUM(' + credit_partner_start + \ ':' + credit_partner_end + ')' bal_partner_debit = rowcol_to_cell(row_pos, 7) bal_partner_credit = rowcol_to_cell(row_pos, 8) bal_partner_total = bal_partner_debit + \ '-' + bal_partner_credit c_specs = [('empty%s' % x, 1, 0, 'text', None) for x in range(5)] c_specs += [ ('init_bal', 2, 0, 'text', _('Cumulated balance on Partner')), ('debit', 1, 0, 'number', None, debit_partner_total, c_cumul_cell_style_decimal), ('credit', 1, 0, 'number', None, credit_partner_total, c_cumul_cell_style_decimal), ('cumul_bal', 1, 0, 'number', None, bal_partner_total, c_cumul_cell_style_decimal), ('depo_bal_t', 1, 0, 'text', _('Deposit Balance')), ('depo_bal', 1, 0, 'number', end_deposit, None, c_cumul_cell_style_decimal), ('empty%5', 4, 0, 'text', None), ] row_data = self.xls_row_template( c_specs, [x[0] for x in c_specs]) row_pos = self.xls_write_row( ws, row_pos, row_data, c_cumul_cell_style) row_pos += 1 account_total_debit += total_debit account_total_credit += total_credit account_balance_cumul += cumul_balance account_balance_cumul_curr += cumul_balance_curr # Add the balance to the partner_account_summary if partner_account_summary.get(p_id) and \ partner_account_summary[p_id].get(account.type): partner_account_summary[p_id][account.type]['debit'] \ += total_debit partner_account_summary[p_id][account.type]['credit'] \ += total_credit partner_account_summary[p_id][account.type]['deposit'] \ += end_deposit else: if not partner_account_summary.get(p_id): partner_account_summary[p_id] = { account.type: { 'debit': total_debit or 0.0, 'credit': total_credit or 0.0, 'deposit': end_deposit or 0.0 } } partner_account_summary[p_id]['partner_name'] = \ partner_name else: partner_account_summary[p_id].update({ account.type: { 'debit': total_debit or 0.0, 'credit': total_credit or 0.0, 'deposit': end_deposit or 0.0 } }) # Print row Cumulated Balance by account # c_specs = [ ('acc_title', 5, 0, 'text', ' - '. join([account.code, account.name])), ] c_specs += [ ('label', 2, 0, 'text', _('Cumulated balance on Account')), ('debit', 1, 0, 'number', account_total_debit, None, account_cell_style_decimal), ('credit', 1, 0, 'number', account_total_credit, None, account_cell_style_decimal), ('cumul_bal', 1, 0, 'number', account_balance_cumul, None, account_cell_style_decimal), ('empty', 6, 0, 'text', None) ] row_data = self.xls_row_template( c_specs, [x[0] for x in c_specs]) row_pos = self.xls_write_row( ws, row_pos, row_data, account_cell_style) row_pos += 2 self.generate_summary_sheet(_p, _xs, wb, partner_account_summary)
def generate_xls_report(self, _p, _xs, data, objects, wb): wanted_list = _p.wanted_list self.col_specs_template.update(_p.template_changes) _ = _p._ debit_pos = 'debit' in wanted_list and wanted_list.index('debit') credit_pos = 'credit' in wanted_list and wanted_list.index('credit') if not (credit_pos and debit_pos) and 'balance' in wanted_list: raise orm.except_orm( _('Customisation Error!'), _("The 'Balance' field is a calculated XLS field requiring \ the presence of the 'Debit' and 'Credit' fields !")) # report_name = objects[0]._description or objects[0]._name report_name = _("Journal Items") ws = wb.add_sheet(report_name[:31]) ws.panes_frozen = True ws.remove_splits = True ws.portrait = 0 # Landscape ws.fit_width_to_pages = 1 row_pos = 0 # set print header/footer ws.header_str = self.xls_headers['standard'] ws.footer_str = self.xls_footers['standard'] # Title cell_style = xlwt.easyxf(_xs['xls_title']) c_specs = [ ('report_name', 1, 0, 'text', report_name), ] row_data = self.xls_row_template(c_specs, ['report_name']) row_pos = self.xls_write_row( ws, row_pos, row_data, row_style=cell_style) row_pos += 1 # Column headers c_specs = map(lambda x: self.render( x, self.col_specs_template, 'header', render_space={'_': _p._}), wanted_list) row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs]) row_pos = self.xls_write_row( ws, row_pos, row_data, row_style=self.rh_cell_style, set_column_size=True) ws.set_horz_split_pos(row_pos) # account move lines for line in objects: debit_cell = rowcol_to_cell(row_pos, debit_pos) credit_cell = rowcol_to_cell(row_pos, credit_pos) bal_formula = debit_cell + '-' + credit_cell _logger.debug('dummy call - %s', bal_formula) c_specs = map( lambda x: self.render(x, self.col_specs_template, 'lines'), wanted_list) row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs]) row_pos = self.xls_write_row( ws, row_pos, row_data, row_style=self.aml_cell_style) # Totals aml_cnt = len(objects) debit_start = rowcol_to_cell(row_pos - aml_cnt, debit_pos) debit_stop = rowcol_to_cell(row_pos - 1, debit_pos) debit_formula = 'SUM(%s:%s)' % (debit_start, debit_stop) _logger.debug('dummy call - %s', debit_formula) credit_start = rowcol_to_cell(row_pos - aml_cnt, credit_pos) credit_stop = rowcol_to_cell(row_pos - 1, credit_pos) credit_formula = 'SUM(%s:%s)' % (credit_start, credit_stop) _logger.debug('dummy call - %s', credit_formula) debit_cell = rowcol_to_cell(row_pos, debit_pos) credit_cell = rowcol_to_cell(row_pos, credit_pos) bal_formula = debit_cell + '-' + credit_cell _logger.debug('dummy call - %s', bal_formula) c_specs = map( lambda x: self.render(x, self.col_specs_template, 'totals'), wanted_list) row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs]) row_pos = self.xls_write_row( ws, row_pos, row_data, row_style=self.rt_cell_style_right)
def generate_xls_report(self, _p, _xs, data, objects, wb): # Initialisations ws = wb.add_sheet(_p.report_name[:31]) ws.panes_frozen = True ws.remove_splits = True ws.portrait = 0 # Landscape ws.fit_width_to_pages = 1 row_pos = 0 ws.header_str = self.xls_headers['standard'] ws.footer_str = self.xls_footers['standard'] # Print Title row_pos = self.print_title(ws, _p, row_pos, xlwt, _xs) # Print empty row to define column sizes row_pos = self.print_empty_row(ws, row_pos) # Print Header Table titles (Fiscal Year - Accounts Filter - Periods # Filter...) row_pos = self.print_header_titles(ws, _p, data, row_pos, xlwt, _xs) initial_balance_text = { 'initial_balance': _('Computed'), 'opening_balance': _('Opening Entries'), False: _('No')} # cf. account_report_partner_balance.mako # Print Header Table data row_pos = self.print_header_data( ws, _p, data, row_pos, xlwt, _xs, initial_balance_text) # Print comparison header table if _p.comparison_mode in ('single', 'multiple'): row_pos += 1 row_pos = self.print_comparison_header( _xs, xlwt, row_pos, _p, ws, initial_balance_text) # Freeze the line ws.set_horz_split_pos(row_pos) # cell styles for account data regular_cell_format = _xs['borders_all'] regular_cell_style = xlwt.easyxf(regular_cell_format) regular_cell_style_decimal = xlwt.easyxf( regular_cell_format + _xs['right'], num_format_str=report_xls.decimal_format) row_pos += 1 for current_account in objects: partners_order = current_account.partners_order # do not display accounts without partners if not partners_order: continue comparisons = current_account.comparisons # in multiple columns mode, we do not want to print accounts # without any rows if _p.comparison_mode in ('single', 'multiple'): all_comparison_lines = [comp['partners_amounts'][partner_id[1]] for partner_id in partners_order for comp in comparisons] if not display_line(all_comparison_lines): continue current_partner_amounts = current_account.partners_amounts if _p.comparison_mode in ('single', 'multiple'): comparison_total = {} for i, comp in enumerate(comparisons): comparison_total[i] = {'balance': 0.0} # print row: Code - Account name row_pos = self.print_row_code_account( ws, current_account, row_pos, _xs, xlwt) row_account_start = row_pos # Print row: Titles "Account/Partner Name-Code/ref-Initial # Balance-Debit-Credit-Balance" or "Account/Partner # Name-Code/ref-Balance Year-Balance Year2-Balance C2-Balance C3" row_pos = self.print_account_header(ws, _p, _xs, xlwt, row_pos) for (partner_code_name, partner_id, partner_ref, partner_name) \ in partners_order: partner = current_partner_amounts.get(partner_id, {}) if _p.exclude_partner_zero and not partner.get('balance', 0.0): continue # in single mode, we have to display all the partners even if # their balance is 0.0 because the initial balance should match # with the previous year closings # in multiple columns mode, we do not want to print partners # which have a balance at 0.0 in each comparison column if _p.comparison_mode in ('single', 'multiple'): all_comparison_lines = [comp['partners_amounts'] [partner_id] for comp in comparisons if comp['partners_amounts']. get(partner_id)] if not display_line(all_comparison_lines): continue # display data row if len(_p.comp_params) == 2: account_span = 3 else: account_span = _p.initial_balance_mode and 2 or 3 c_specs = [('acc_title', account_span, 0, 'text', partner_name if partner_name else _('Unallocated'))] c_specs += [('partner_ref', 1, 0, 'text', partner_ref if partner_ref else '')] if _p.comparison_mode == 'no_comparison': bal_formula = '' if _p.initial_balance_mode: init_bal_cell = rowcol_to_cell(row_pos, 3) bal_formula = init_bal_cell + '+' debit_col = 4 c_specs += [ ('init_bal', 1, 0, 'number', partner.get( 'init_balance', 0.0), None, regular_cell_style_decimal), ] else: debit_col = 3 c_specs += [ ('debit', 1, 0, 'number', partner.get('debit', 0.0), None, regular_cell_style_decimal), ('credit', 1, 0, 'number', partner.get('credit', 0.0), None, regular_cell_style_decimal), ] debit_cell = rowcol_to_cell(row_pos, debit_col) credit_cell = rowcol_to_cell(row_pos, debit_col + 1) bal_formula += debit_cell + '-' + credit_cell c_specs += [('bal', 1, 0, 'number', None, bal_formula, regular_cell_style_decimal), ] else: c_specs += [('bal', 1, 0, 'number', partner.get('balance', 0.0), None, regular_cell_style_decimal), ] if _p.comparison_mode in ('single', 'multiple'): for i, comp in enumerate(comparisons): comp_partners = comp['partners_amounts'] balance = diff = percent_diff = 0 if comp_partners.get(partner_id): balance = comp_partners[partner_id]['balance'] diff = comp_partners[partner_id]['diff'] percent_diff = comp_partners[ partner_id]['percent_diff'] comparison_total[i]['balance'] += balance c_specs += [('balance_%s' % i, 1, 0, 'number', balance, None, regular_cell_style_decimal), ] # no diff in multiple comparisons because it shows too much # data if _p.comparison_mode == 'single': c_specs += [('balance_diff', 1, 0, 'number', diff, None, regular_cell_style_decimal), ] if percent_diff is False: c_specs += [('balance', 1, 0, 'number', diff, None, regular_cell_style_decimal), ] else: c_specs += [('perc_diff', 1, 0, 'number', int(round(percent_diff))), ] row_data = self.xls_row_template( c_specs, [x[0] for x in c_specs]) row_pos = self.xls_write_row( ws, row_pos, row_data, regular_cell_style) row_pos = self.print_account_totals( _xs, xlwt, ws, row_account_start, row_pos, current_account, _p)
def generate_xls_report(self, _p, _xs, data, objects, wb): # Initialisations ws = wb.add_sheet(_p.report_name[:31]) ws.panes_frozen = True ws.remove_splits = True ws.portrait = 0 # Landscape ws.fit_width_to_pages = 1 row_pos = 0 ws.header_str = self.xls_headers['standard'] ws.footer_str = self.xls_footers['standard'] # Print Title row_pos = self.print_title(ws, _p, row_pos, xlwt, _xs) # Print empty row to define column sizes row_pos = self.print_empty_row(ws, row_pos) # Print Header Table titles (Fiscal Year - Accounts Filter - Periods # Filter...) row_pos = self.print_header_titles(ws, _p, data, row_pos, xlwt, _xs) initial_balance_text = { 'initial_balance': _('Computed'), 'opening_balance': _('Opening Entries'), False: _('No') } # cf. account_report_partner_balance.mako # Print Header Table data row_pos = self.print_header_data(ws, _p, data, row_pos, xlwt, _xs, initial_balance_text) # Print comparison header table if _p.comparison_mode in ('single', 'multiple'): row_pos += 1 row_pos = self.print_comparison_header(_xs, xlwt, row_pos, _p, ws, initial_balance_text) # Freeze the line ws.set_horz_split_pos(row_pos) # cell styles for account data regular_cell_format = _xs['borders_all'] regular_cell_style = xlwt.easyxf(regular_cell_format) regular_cell_style_decimal = xlwt.easyxf( regular_cell_format + _xs['right'], num_format_str=report_xls.decimal_format) row_pos += 1 for current_account in objects: partners_order = _p['partners_order_accounts']\ .get(current_account.id, False) # do not display accounts without partners if not partners_order: continue comparisons = _p['comparisons_accounts']\ .get(current_account.id, False) # in multiple columns mode, we do not want to print accounts # without any rows if _p.comparison_mode in ('single', 'multiple'): all_comparison_lines = [ comp['partners_amounts'][partner_id[1]] for partner_id in partners_order for comp in comparisons ] if not display_line(all_comparison_lines): continue current_partner_amounts = _p['partners_amounts_accounts']\ .get(current_account.id, False) if _p.comparison_mode in ('single', 'multiple'): comparison_total = {} for i, comp in enumerate(comparisons): comparison_total[i] = {'balance': 0.0} # print row: Code - Account name row_pos = self.print_row_code_account(ws, current_account, row_pos, _xs, xlwt) row_account_start = row_pos # Print row: Titles "Account/Partner Name-Code/ref-Initial # Balance-Debit-Credit-Balance" or "Account/Partner # Name-Code/ref-Balance Year-Balance Year2-Balance C2-Balance C3" row_pos = self.print_account_header(ws, _p, _xs, xlwt, row_pos) for (partner_code_name, partner_id, partner_ref, partner_name) \ in partners_order: partner = current_partner_amounts.get(partner_id, {}) # in single mode, we have to display all the partners even if # their balance is 0.0 because the initial balance should match # with the previous year closings # in multiple columns mode, we do not want to print partners # which have a balance at 0.0 in each comparison column if _p.comparison_mode in ('single', 'multiple'): all_comparison_lines = [ comp['partners_amounts'][partner_id] for comp in comparisons if comp['partners_amounts'].get(partner_id) ] if not display_line(all_comparison_lines): continue # display data row if len(_p.comp_params) == 2: account_span = 3 else: account_span = _p.initial_balance_mode and 2 or 3 c_specs = [('acc_title', account_span, 0, 'text', partner_name if partner_name else _('Unallocated')) ] c_specs += [('partner_ref', 1, 0, 'text', partner_ref if partner_ref else '')] if _p.comparison_mode == 'no_comparison': bal_formula = '' if _p.initial_balance_mode: init_bal_cell = rowcol_to_cell(row_pos, 3) bal_formula = init_bal_cell + '+' debit_col = 4 c_specs += [ ('init_bal', 1, 0, 'number', partner.get('init_balance', 0.0), None, regular_cell_style_decimal), ] else: debit_col = 3 c_specs += [ ('debit', 1, 0, 'number', partner.get('debit', 0.0), None, regular_cell_style_decimal), ('credit', 1, 0, 'number', partner.get('credit', 0.0), None, regular_cell_style_decimal), ] debit_cell = rowcol_to_cell(row_pos, debit_col) credit_cell = rowcol_to_cell(row_pos, debit_col + 1) bal_formula += debit_cell + '-' + credit_cell c_specs += [ ('bal', 1, 0, 'number', None, bal_formula, regular_cell_style_decimal), ] else: c_specs += [ ('bal', 1, 0, 'number', partner.get('balance', 0.0), None, regular_cell_style_decimal), ] if _p.comparison_mode in ('single', 'multiple'): for i, comp in enumerate(comparisons): comp_partners = comp['partners_amounts'] balance = diff = percent_diff = 0 if comp_partners.get(partner_id): balance = comp_partners[partner_id]['balance'] diff = comp_partners[partner_id]['diff'] percent_diff = comp_partners[partner_id][ 'percent_diff'] comparison_total[i]['balance'] += balance c_specs += [ ('balance_%s' % i, 1, 0, 'number', balance, None, regular_cell_style_decimal), ] # no diff in multiple comparisons because it shows too much # data if _p.comparison_mode == 'single': c_specs += [ ('balance_diff', 1, 0, 'number', diff, None, regular_cell_style_decimal), ] if percent_diff is False: c_specs += [ ('balance', 1, 0, 'number', diff, None, regular_cell_style_decimal), ] else: c_specs += [ ('perc_diff', 1, 0, 'number', int(round(percent_diff))), ] row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs]) row_pos = self.xls_write_row(ws, row_pos, row_data, regular_cell_style) row_pos = self.print_account_totals(_xs, xlwt, ws, row_account_start, row_pos, current_account, _p)
def generate_xls_report(self, _p, _xs, data, objects, wb): ws, row_pos = self._new_ws_with_header(_p, _xs, data, wb) nbr_columns = 10 if _p.amount_currency(data): nbr_columns = 12 # Account Title Row cell_format = _xs['xls_title'] + _xs['bold'] + \ _xs['fill'] + _xs['borders_all'] account_cell_style = xlwt.easyxf(cell_format) account_cell_style_right = xlwt.easyxf(cell_format + _xs['right']) account_cell_style_decimal = xlwt.easyxf( cell_format + _xs['right'], num_format_str=report_xls.decimal_format) # Column Title Row cell_format = _xs['bold'] c_title_cell_style = xlwt.easyxf(cell_format) # Column Header Row cell_format = _xs['bold'] + _xs['fill'] + _xs['borders_all'] c_hdr_cell_style = xlwt.easyxf(cell_format) c_hdr_cell_style_right = xlwt.easyxf(cell_format + _xs['right']) c_hdr_cell_style_center = xlwt.easyxf(cell_format + _xs['center']) # Column Initial Balance Row cell_format = _xs['italic'] + _xs['borders_all'] c_init_cell_style = xlwt.easyxf(cell_format) c_init_cell_style_decimal = xlwt.easyxf( cell_format + _xs['right'], num_format_str=report_xls.decimal_format) # Column Cumulated balance Row cell_format = _xs['bold'] + _xs['fill'] + _xs['borders_all'] c_cumul_cell_style = xlwt.easyxf(cell_format) c_cumul_cell_style_right = xlwt.easyxf(cell_format + _xs['right']) c_cumul_cell_style_center = xlwt.easyxf(cell_format + _xs['center']) c_cumul_cell_style_decimal = xlwt.easyxf( cell_format + _xs['right'], num_format_str=report_xls.decimal_format) # Column Partner Row cell_format = _xs['bold'] c_part_cell_style = xlwt.easyxf(cell_format) c_specs = [ ('date', 1, 0, 'text', _('Date'), None, c_hdr_cell_style), ('period', 1, 0, 'text', _('Period'), None, c_hdr_cell_style), ('move', 1, 0, 'text', _('Entry'), None, c_hdr_cell_style), ('journal', 1, 0, 'text', _('Journal'), None, c_hdr_cell_style), ('partner', 1, 0, 'text', _('Partner'), None, c_hdr_cell_style), ('label', 1, 0, 'text', _('Label'), None, c_hdr_cell_style), ('rec', 1, 0, 'text', _('Rec.'), None, c_hdr_cell_style), ('debit', 1, 0, 'text', _('Debit'), None, c_hdr_cell_style_right), ('credit', 1, 0, 'text', _('Credit'), None, c_hdr_cell_style_right), ('cumul_bal', 1, 0, 'text', _('Balance'), None, c_hdr_cell_style_right), ] if _p.amount_currency(data): c_specs += [ ('curr_bal', 1, 0, 'text', _('Curr. Bal.'), None, c_hdr_cell_style_right), ('curr_code', 1, 0, 'text', _('Curr.'), None, c_hdr_cell_style_center), ] c_hdr_data = self.xls_row_template(c_specs, [x[0] for x in c_specs]) # cell styles for ledger lines ll_cell_format = _xs['borders_all'] ll_cell_style = xlwt.easyxf(ll_cell_format) ll_cell_style_center = xlwt.easyxf(ll_cell_format + _xs['center']) ll_cell_style_date = xlwt.easyxf( ll_cell_format + _xs['left'], num_format_str=report_xls.date_format) ll_cell_style_decimal = xlwt.easyxf( ll_cell_format + _xs['right'], num_format_str=report_xls.decimal_format) cnt = 0 for account in objects: ws, row_pos = self._get_ws_row_pos(_p, _xs, data, wb, ws, row_pos) if _p['ledger_lines'].get(account.id, False) or \ _p['init_balance'].get(account.id, False): if not _p['partners_order'].get(account.id, False): continue cnt += 1 account_total_debit = 0.0 account_total_credit = 0.0 account_balance_cumul = 0.0 account_balance_cumul_curr = 0.0 c_specs = [ ('acc_title', nbr_columns, 0, 'text', ' - '.join([account.code, account.name]), None, account_cell_style), ] row_data = self.xls_row_template( c_specs, [x[0] for x in c_specs]) row_pos = self.xls_write_row( ws, row_pos, row_data, c_title_cell_style) row_pos += 1 for partner_name, p_id, p_ref, p_name in \ _p['partners_order'][account.id]: ws, row_pos = self._get_ws_row_pos( _p, _xs, data, wb, ws, row_pos) total_debit = 0.0 total_credit = 0.0 cumul_balance = 0.0 cumul_balance_curr = 0.0 part_cumul_balance = 0.0 part_cumul_balance_curr = 0.0 c_specs = [ ('partner_title', nbr_columns, 0, 'text', partner_name or _('No Partner'), None, c_part_cell_style), ] row_data = self.xls_row_template( c_specs, [x[0] for x in c_specs]) row_pos = self.xls_write_row( ws, row_pos, row_data, c_title_cell_style) row_pos = self.xls_write_row(ws, row_pos, c_hdr_data) row_start_partner = row_pos total_debit = _p['init_balance'][account.id].get( p_id, {}).get('debit') or 0.0 total_credit = _p['init_balance'][account.id].get( p_id, {}).get('credit') or 0.0 init_line = False if _p.initial_balance_mode and \ (total_debit or total_credit): init_line = True part_cumul_balance = \ _p['init_balance'][account.id].get( p_id, {}).get('init_balance') or 0.0 part_cumul_balance_curr = \ _p['init_balance'][account.id].get( p_id, {}).get('init_balance_currency') or 0.0 balance_forward_currency = \ _p['init_balance'][account.id].get( p_id, {}).get('currency_name') or '' cumul_balance += part_cumul_balance cumul_balance_curr += part_cumul_balance_curr debit_cell = rowcol_to_cell(row_pos, 7) credit_cell = rowcol_to_cell(row_pos, 8) init_bal_formula = debit_cell + '-' + credit_cell # Print row 'Initial Balance' by partn c_specs = [('empty%s' % x, 1, 0, 'text', None) for x in range(5)] c_specs += [ ('init_bal', 1, 0, 'text', _('Initial Balance')), ('rec', 1, 0, 'text', None), ('debit', 1, 0, 'number', total_debit, None, c_init_cell_style_decimal), ('credit', 1, 0, 'number', total_credit, None, c_init_cell_style_decimal), ('cumul_bal', 1, 0, 'number', None, init_bal_formula, c_init_cell_style_decimal), ] if _p.amount_currency(data): c_specs += [ ('curr_bal', 1, 0, 'number', part_cumul_balance_curr, None, c_init_cell_style_decimal), ('curr_code', 1, 0, 'text', balance_forward_currency), ] row_data = self.xls_row_template( c_specs, [x[0] for x in c_specs]) row_pos = self.xls_write_row( ws, row_pos, row_data, c_init_cell_style) for line in _p['ledger_lines'][account.id].get(p_id, []): ws, row_pos = self._get_ws_row_pos( _p, _xs, data, wb, ws, row_pos) total_debit += line.get('debit') or 0.0 total_credit += line.get('credit') or 0.0 label_elements = [line.get('lname') or ''] if line.get('invoice_number'): label_elements.append( "(%s)" % (line['invoice_number'],)) label = ' '.join(label_elements) cumul_balance += line.get('balance') or 0.0 if init_line or row_pos > row_start_partner: cumbal_formula = rowcol_to_cell( row_pos - 1, 9) + '+' else: cumbal_formula = '' debit_cell = rowcol_to_cell(row_pos, 7) credit_cell = rowcol_to_cell(row_pos, 8) cumbal_formula += debit_cell + '-' + credit_cell # Print row ledger line data # if line.get('ldate'): c_specs = [ ('ldate', 1, 0, 'date', datetime.strptime( line['ldate'], '%Y-%m-%d'), None, ll_cell_style_date), ] else: c_specs = [ ('ldate', 1, 0, 'text', None), ] c_specs += [ ('period', 1, 0, 'text', line.get('period_code') or ''), ('move', 1, 0, 'text', line.get('move_name') or ''), ('journal', 1, 0, 'text', line.get('jcode') or ''), ('partner', 1, 0, 'text', line.get('partner_name') or ''), ('label', 1, 0, 'text', label), ('rec_name', 1, 0, 'text', line.get('rec_name') or ''), ('debit', 1, 0, 'number', line.get('debit'), None, ll_cell_style_decimal), ('credit', 1, 0, 'number', line.get('credit'), None, ll_cell_style_decimal), ('cumul_bal', 1, 0, 'number', None, cumbal_formula, ll_cell_style_decimal), ] if _p.amount_currency(data): c_specs += [ ('curr_bal', 1, 0, 'number', line.get( 'amount_currency') or 0.0, None, ll_cell_style_decimal), ('curr_code', 1, 0, 'text', line.get( 'currency_code') or '', None, ll_cell_style_center), ] row_data = self.xls_row_template( c_specs, [x[0] for x in c_specs]) row_pos = self.xls_write_row( ws, row_pos, row_data, ll_cell_style) # end for line # Print row Cumulated Balance by partner # debit_partner_start = rowcol_to_cell(row_start_partner, 7) debit_partner_end = rowcol_to_cell(row_pos - 1, 7) debit_partner_total = 'SUM(' + debit_partner_start + \ ':' + debit_partner_end + ')' credit_partner_start = rowcol_to_cell(row_start_partner, 8) credit_partner_end = rowcol_to_cell(row_pos - 1, 8) credit_partner_total = 'SUM(' + credit_partner_start + \ ':' + credit_partner_end + ')' bal_partner_debit = rowcol_to_cell(row_pos, 7) bal_partner_credit = rowcol_to_cell(row_pos, 8) bal_partner_total = bal_partner_debit + \ '-' + bal_partner_credit c_specs = [('empty%s' % x, 1, 0, 'text', None) for x in range(5)] c_specs += [ ('init_bal', 1, 0, 'text', _('Ending balance on Partner')), ('rec', 1, 0, 'text', None), ('debit', 1, 0, 'number', None, debit_partner_total, c_cumul_cell_style_decimal), ('credit', 1, 0, 'number', None, credit_partner_total, c_cumul_cell_style_decimal), ('cumul_bal', 1, 0, 'number', None, bal_partner_total, c_cumul_cell_style_decimal), ] if _p.amount_currency(data): if account.currency_id: c_specs += [('curr_bal', 1, 0, 'number', cumul_balance_curr or 0.0, None, c_cumul_cell_style_decimal)] else: c_specs += [('curr_bal', 1, 0, 'text', '-', None, c_cumul_cell_style_right)] c_specs += [('curr_code', 1, 0, 'text', account.currency_id.name if account.currency_id else u'', None, c_cumul_cell_style_center)] row_data = self.xls_row_template( c_specs, [x[0] for x in c_specs]) row_pos = self.xls_write_row( ws, row_pos, row_data, c_cumul_cell_style) row_pos += 1 account_total_debit += total_debit account_total_credit += total_credit account_balance_cumul += cumul_balance account_balance_cumul_curr += cumul_balance_curr # Print row Cumulated Balance by account # c_specs = [ ('acc_title', 5, 0, 'text', ' - '. join([account.code, account.name])), ] c_specs += [ ('label', 1, 0, 'text', _('Ending balance on Account')), ('rec', 1, 0, 'text', None), ('debit', 1, 0, 'number', account_total_debit, None, account_cell_style_decimal), ('credit', 1, 0, 'number', account_total_credit, None, account_cell_style_decimal), ('cumul_bal', 1, 0, 'number', account_balance_cumul, None, account_cell_style_decimal), ] if _p.amount_currency(data): if account.currency_id: c_specs += [('curr_bal', 1, 0, 'number', account_balance_cumul_curr or 0.0, None, account_cell_style_decimal)] else: c_specs += [('curr_bal', 1, 0, 'text', '-', None, account_cell_style_right)] c_specs += [('curr_code', 1, 0, 'text', account.currency_id.name if account.currency_id else u'', None, account_cell_style)] row_data = self.xls_row_template( c_specs, [x[0] for x in c_specs]) row_pos = self.xls_write_row( ws, row_pos, row_data, account_cell_style) row_pos += 2
def generate_xls_report(self, _p, _xs, data, objects, wb): ws = wb.add_sheet(_p.report_name[:31]) ws.panes_frozen = True ws.remove_splits = True ws.portrait = 0 # Landscape ws.fit_width_to_pages = 1 row_pos = 0 # set print header/footer ws.header_str = self.xls_headers['standard'] ws.footer_str = self.xls_footers['standard'] # cf. account_report_partner_ledger.mako initial_balance_text = {'initial_balance': _('Computed'), 'opening_balance': _('Opening Entries'), False: _('No')} # Title cell_style = xlwt.easyxf(_xs['xls_title']) report_name = ' - '.join([_p.report_name.upper(), _p.company.partner_id.name, _p.company.currency_id.name]) c_specs = [ ('report_name', 1, 0, 'text', report_name), ] row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs]) row_pos = self.xls_write_row(ws, row_pos, row_data, row_style=cell_style) # write empty row to define column sizes c_sizes = self.column_sizes c_specs = [('empty%s'%i, 1, c_sizes[i], 'text', None) for i in range(0,len(c_sizes))] row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs]) row_pos = self.xls_write_row(ws, row_pos, row_data, set_column_size=True) # Header Table nbr_columns = 10 if _p.amount_currency(data): nbr_columns = 12 cell_format = _xs['bold'] + _xs['fill_blue'] + _xs['borders_all'] cell_style = xlwt.easyxf(cell_format) cell_style_center = xlwt.easyxf(cell_format + _xs['center']) c_specs = [ ('coa', 2, 0, 'text', _('Chart of Account')), ('fy', 1, 0, 'text', _('Fiscal Year')), ('df', 2, 0, 'text', _p.filter_form(data) == 'filter_date' and _('Dates Filter') or _('Periods Filter')), ('af', 1, 0, 'text', _('Accounts Filter')), ('tm', 2, 0, 'text', _('Target Moves')), ('ib', nbr_columns-8, 0, 'text', _('Initial Balance')), ] row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs]) row_pos = self.xls_write_row(ws, row_pos, row_data, row_style=cell_style_center) cell_format = _xs['borders_all'] cell_style = xlwt.easyxf(cell_format) cell_style_center = xlwt.easyxf(cell_format + _xs['center']) c_specs = [ ('coa', 2, 0, 'text', _p.chart_account.name), ('fy', 1, 0, 'text', _p.fiscalyear.name if _p.fiscalyear else '-'), ] df = _('From') + ': ' if _p.filter_form(data) == 'filter_date': df += _p.start_date if _p.start_date else u'' else: df += _p.start_period.name if _p.start_period else u'' df += ' ' + _('To') + ': ' if _p.filter_form(data) == 'filter_date': df += _p.stop_date if _p.stop_date else u'' else: df += _p.stop_period.name if _p.stop_period else u'' c_specs += [ ('df', 2, 0, 'text', df), ('af', 1, 0, 'text', _('Custom Filter') if _p.partner_ids else _p.display_partner_account(data)), ('tm', 2, 0, 'text', _p.display_target_move(data)), ('ib', nbr_columns-8, 0, 'text', initial_balance_text[_p.initial_balance_mode]), ] row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs]) row_pos = self.xls_write_row(ws, row_pos, row_data, row_style=cell_style_center) ws.set_horz_split_pos(row_pos) row_pos += 1 # Account Title Row cell_format = _xs['xls_title'] + _xs['bold'] + _xs['fill'] + _xs['borders_all'] account_cell_style = xlwt.easyxf(cell_format) account_cell_style_right = xlwt.easyxf(cell_format + _xs['right']) account_cell_style_decimal = xlwt.easyxf(cell_format + _xs['right'], num_format_str = report_xls.decimal_format) # Column Title Row cell_format = _xs['bold'] c_title_cell_style = xlwt.easyxf(cell_format) # Column Header Row cell_format = _xs['bold'] + _xs['fill'] + _xs['borders_all'] c_hdr_cell_style = xlwt.easyxf(cell_format) c_hdr_cell_style_right = xlwt.easyxf(cell_format + _xs['right']) c_hdr_cell_style_center = xlwt.easyxf(cell_format + _xs['center']) c_hdr_cell_style_decimal = xlwt.easyxf(cell_format + _xs['right'], num_format_str = report_xls.decimal_format) # Column Initial Balance Row cell_format = _xs['italic'] + _xs['borders_all'] c_init_cell_style = xlwt.easyxf(cell_format) c_init_cell_style_right = xlwt.easyxf(cell_format + _xs['right']) c_init_cell_style_center = xlwt.easyxf(cell_format + _xs['center']) c_init_cell_style_decimal = xlwt.easyxf(cell_format + _xs['right'], num_format_str = report_xls.decimal_format) # Column Cumulated balance Row cell_format = _xs['bold'] + _xs['fill'] + _xs['borders_all'] c_cumul_cell_style = xlwt.easyxf(cell_format) c_cumul_cell_style_right = xlwt.easyxf(cell_format + _xs['right']) c_cumul_cell_style_center = xlwt.easyxf(cell_format + _xs['center']) c_cumul_cell_style_decimal = xlwt.easyxf(cell_format + _xs['right'], num_format_str = report_xls.decimal_format) # Column Partner Row cell_format = _xs['bold'] c_part_cell_style = xlwt.easyxf(cell_format) c_specs = [ ('date', 1, 0, 'text', _('Date'), None, c_hdr_cell_style), ('period', 1, 0, 'text', _('Period'), None, c_hdr_cell_style), ('move', 1, 0, 'text', _('Entry'), None, c_hdr_cell_style), ('journal', 1, 0, 'text', _('Journal'), None, c_hdr_cell_style), ('partner', 1, 0, 'text', _('Partner'), None, c_hdr_cell_style), ('label', 1, 0, 'text', _('Label'), None, c_hdr_cell_style), ('rec', 1, 0, 'text', _('Rec.'), None, c_hdr_cell_style), ('debit', 1, 0, 'text', _('Debit'), None, c_hdr_cell_style_right), ('credit', 1, 0, 'text', _('Credit'), None, c_hdr_cell_style_right), ('cumul_bal', 1, 0, 'text', _('Cumul. Bal.'), None, c_hdr_cell_style_right), ] if _p.amount_currency(data): c_specs += [ ('curr_bal', 1, 0, 'text', _('Curr. Bal.'), None, c_hdr_cell_style_right), ('curr_code', 1, 0, 'text', _('Curr.'), None, c_hdr_cell_style_center), ] c_hdr_data = self.xls_row_template(c_specs, [x[0] for x in c_specs]) # cell styles for ledger lines ll_cell_format = _xs['borders_all'] ll_cell_style = xlwt.easyxf(ll_cell_format) ll_cell_style_right = xlwt.easyxf(ll_cell_format + _xs['right']) ll_cell_style_center = xlwt.easyxf(ll_cell_format + _xs['center']) ll_cell_style_date = xlwt.easyxf(ll_cell_format + _xs['left'], num_format_str = report_xls.date_format) ll_cell_style_decimal = xlwt.easyxf(ll_cell_format + _xs['right'], num_format_str = report_xls.decimal_format) cnt = 0 for account in objects: if account.ledger_lines or account.init_balance: if not account.partners_order: continue cnt += 1 account_total_debit = 0.0 account_total_credit = 0.0 account_balance_cumul = 0.0 account_balance_cumul_curr = 0.0 c_specs = [ ('acc_title', nbr_columns, 0, 'text', ' - '.join([account.code, account.name]), None, account_cell_style), ] row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs]) row_pos = self.xls_write_row(ws, row_pos, row_data, c_title_cell_style) row_pos += 1 row_start_account = row_pos for partner_name, p_id, p_ref, p_name in account.partners_order: total_debit = 0.0 total_credit = 0.0 cumul_balance = 0.0 cumul_balance_curr = 0.0 part_cumul_balance = 0.0 part_cumul_balance_curr = 0.0 c_specs = [ ('partner_title', nbr_columns, 0, 'text', partner_name or _('No Partner'), None, c_part_cell_style), ] row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs]) row_pos = self.xls_write_row(ws, row_pos, row_data, c_title_cell_style) row_pos = self.xls_write_row(ws, row_pos, c_hdr_data) row_start_partner = row_pos total_debit = account.init_balance.get(p_id, {}).get('debit') or 0.0 total_credit = account.init_balance.get(p_id, {}).get('credit') or 0.0 init_line = False if _p.initial_balance_mode and (total_debit or total_credit): init_line = True part_cumul_balance = account.init_balance.get(p_id, {}).get('init_balance') or 0.0 part_cumul_balance_curr = account.init_balance.get(p_id, {}).get('init_balance_currency') or 0.0 balance_forward_currency = account.init_balance.get(p_id, {}).get('currency_name') or '' cumul_balance += part_cumul_balance cumul_balance_curr += part_cumul_balance_curr debit_cell = rowcol_to_cell(row_pos, 7) credit_cell = rowcol_to_cell(row_pos, 8) init_bal_formula = debit_cell + '-' + credit_cell ################## Print row 'Initial Balance' by partner ################# c_specs = [('empty%s' %x, 1, 0, 'text', None) for x in range(5)] c_specs += [ ('init_bal', 1, 0, 'text', _('Initial Balance')), ('rec', 1, 0, 'text', None), ('debit', 1, 0, 'number', total_debit, None, c_init_cell_style_decimal), ('credit', 1, 0, 'number', total_credit, None, c_init_cell_style_decimal), ('cumul_bal', 1, 0, 'number', None, init_bal_formula, c_init_cell_style_decimal), ] if _p.amount_currency(data): c_specs += [ ('curr_bal', 1, 0, 'number', part_cumul_balance_curr, None, c_init_cell_style_decimal), ('curr_code', 1, 0, 'text', balance_forward_currency), ] row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs]) row_pos = self.xls_write_row(ws, row_pos, row_data, c_init_cell_style) for line in account.ledger_lines.get(p_id, []): total_debit += line.get('debit') or 0.0 total_credit += line.get('credit') or 0.0 label_elements = [line.get('lname') or ''] if line.get('invoice_number'): label_elements.append("(%s)" % (line['invoice_number'],)) label = ' '.join(label_elements) cumul_balance += line.get('balance') or 0.0 if init_line or row_pos > row_start_partner: cumbal_formula = rowcol_to_cell(row_pos-1, 9) + '+' else: cumbal_formula = '' debit_cell = rowcol_to_cell(row_pos, 7) credit_cell = rowcol_to_cell(row_pos, 8) cumbal_formula += debit_cell + '-' + credit_cell ################## Print row ledger line data ################# if line.get('ldate'): c_specs = [ ('ldate', 1, 0, 'date', datetime.strptime(line['ldate'],'%Y-%m-%d'), None, ll_cell_style_date), ] else: c_specs = [ ('ldate', 1, 0, 'text', None), ] c_specs += [ ('period', 1, 0, 'text', line.get('period_code') or ''), ('move', 1, 0, 'text', line.get('move_name') or ''), ('journal', 1, 0, 'text', line.get('jcode') or ''), ('partner', 1, 0, 'text', line.get('partner_name') or ''), ('label', 1, 0, 'text', label), ('rec_name', 1, 0, 'text', line.get('rec_name') or ''), ('debit', 1, 0, 'number', line.get('debit'), None, ll_cell_style_decimal), ('credit', 1, 0, 'number', line.get('credit'), None, ll_cell_style_decimal), ('cumul_bal', 1, 0, 'number', None, cumbal_formula, ll_cell_style_decimal), ] if _p.amount_currency(data): c_specs += [ ('curr_bal', 1, 0, 'number', line.get('amount_currency') or 0.0, None, ll_cell_style_decimal), ('curr_code', 1, 0, 'text', line.get('currency_code') or '', None, ll_cell_style_center), ] row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs]) row_pos = self.xls_write_row(ws, row_pos, row_data, ll_cell_style) #end for line ################## Print row Cumulated Balance by partner ################# debit_partner_start = rowcol_to_cell(row_start_partner, 7) debit_partner_end = rowcol_to_cell(row_pos-1, 7) debit_partner_total = 'SUM(' + debit_partner_start + ':' + debit_partner_end + ')' credit_partner_start = rowcol_to_cell(row_start_partner, 8) credit_partner_end = rowcol_to_cell(row_pos-1, 8) credit_partner_total = 'SUM(' + credit_partner_start + ':' + credit_partner_end + ')' bal_partner_debit = rowcol_to_cell(row_pos, 7) bal_partner_credit = rowcol_to_cell(row_pos, 8) bal_partner_total = bal_partner_debit + '-' + bal_partner_credit c_specs = [('empty%s' %x, 1, 0, 'text', None) for x in range(5)] c_specs += [ ('init_bal', 1, 0, 'text', _('Cumulated balance on Partner')), ('rec', 1, 0, 'text', None), ('debit', 1, 0, 'number', None, debit_partner_total, c_cumul_cell_style_decimal), ('credit', 1, 0, 'number', None, credit_partner_total, c_cumul_cell_style_decimal), ('cumul_bal', 1, 0, 'number', None, bal_partner_total, c_cumul_cell_style_decimal), ] if _p.amount_currency(data): if account.currency_id: c_specs += [('curr_bal', 1, 0, 'number', cumul_balance_curr or 0.0, None, c_cumul_cell_style_decimal)] else: c_specs += [('curr_bal', 1, 0, 'text', '-', None, c_cumul_cell_style_right)] c_specs += [('curr_code', 1, 0, 'text', account.currency_id.name if account.currency_id else u'', None, c_cumul_cell_style_center)] row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs]) row_pos = self.xls_write_row(ws, row_pos, row_data, c_cumul_cell_style) row_pos += 1 account_total_debit += total_debit account_total_credit += total_credit account_balance_cumul += cumul_balance account_balance_cumul_curr += cumul_balance_curr ################## Print row Cumulated Balance by account ################# c_specs = [('acc_title', 5, 0, 'text', ' - '.join([account.code, account.name])), ] c_specs += [ ('label', 1, 0, 'text', _('Cumulated balance on Account')), ('rec', 1, 0, 'text', None), ('debit', 1, 0, 'number', account_total_debit, None, account_cell_style_decimal), ('credit', 1, 0, 'number', account_total_credit, None, account_cell_style_decimal), ('cumul_bal', 1, 0, 'number', account_balance_cumul, None, account_cell_style_decimal), ] if _p.amount_currency(data): if account.currency_id: c_specs += [('curr_bal', 1, 0, 'number', account_balance_cumul_curr or 0.0, None, account_cell_style_decimal)] else: c_specs += [('curr_bal', 1, 0, 'text', '-', None, account_cell_style_right)] c_specs += [('curr_code', 1, 0, 'text', account.currency_id.name if account.currency_id else u'', None, account_cell_style)] row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs]) row_pos = self.xls_write_row(ws, row_pos, row_data, account_cell_style) row_pos += 2
def generate_xls_report(self, _p, _xs, data, objects, wb): ws = wb.add_sheet(_p.report_name[:31]) ws.panes_frozen = True ws.remove_splits = True ws.portrait = 0 # Landscape ws.fit_width_to_pages = 1 row_pos = 0 # set print header/footer ws.header_str = self.xls_headers['standard'] ws.footer_str = self.xls_footers['standard'] # Header cell_style = xlwt.easyxf(_xs['bold']) c_specs = [ ('report_name', 1, 0, 'text', '%s %s' % (_p.report_name, CHART_VIEW.get(_p.chart_view, ''))), ] row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs]) row_pos = self.xls_write_row(ws, row_pos, row_data, row_style=cell_style) c_specs = [ ('period_end_title', 1, 0, 'text', _('For the period ended'), None, cell_style), ('period_end_value', 1, 0, 'text', _p.period.name), ] row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs]) row_pos = self.xls_write_row(ws, row_pos, row_data) c_specs = [ ('costcenter_title', 1, 0, 'text', _('Cost Center'), None, cell_style), ('costcenter_code', 1, 0, 'text', _p.costcenter.code), ('costcenter_name', 1, 0, 'text', _p.costcenter.name), ] row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs]) row_pos = self.xls_write_row(ws, row_pos, row_data) c_sizes = self.column_sizes c_specs = [('empty%s' % i, 1, c_sizes[i], 'text', None) for i in range(0, len(c_sizes))] row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs]) row_pos = self.xls_write_row(ws, row_pos, row_data, set_column_size=True) # Column Header cell_style = xlwt.easyxf(_xs['bold'] + _xs['center'] + _xs['fill'] + _xs['borders_all']) c_specs = [ ('budget_structure', 1, 0, 'text', _('Budget Structure'), None, cell_style), ('budget_code', 1, 0, 'text', _('Budget Code'), None, cell_style), ('activity', 1, 0, 'text', _('Activity Group / Activity'), None, cell_style), ('budget_control', 1, 0, 'text', _('Budget Control'), None, cell_style), ('budget_release', 1, 0, 'text', _('Budget Release'), None, cell_style), ('expense_commitment', 1, 0, 'text', _('EX'), None, cell_style), ('pr_commitment', 1, 0, 'text', _('PR'), None, cell_style), ('po_commitment', 1, 0, 'text', _('PO'), None, cell_style), ('total_commitment', 1, 0, 'text', _('Total Commitment'), None, cell_style), ('actual', 1, 0, 'text', _('Actual'), None, cell_style), ('consumed_budget', 1, 0, 'text', _('Consumed Budget'), None, cell_style), ('residual_budget', 1, 0, 'text', _('Residual Budget'), None, cell_style), ('percent_consumed_budget', 1, 0, 'text', _('% Consumed Budget'), None, cell_style), ] row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs]) row_pos = self.xls_write_row(ws, row_pos, row_data) # Column Detail row_pos_subtotal_list = [] cell_format = _xs['bold'] + _xs['borders_all'] cell_style_subtotal = xlwt.easyxf(cell_format) cell_style_subtotal_decimal = xlwt.easyxf( cell_format + _xs['right'], num_format_str=report_xls.decimal_format) cell_style_subtotal_percent = xlwt.easyxf(cell_format + _xs['right'], num_format_str='0.00%') cell_format = _xs['right'] + _xs['borders_all'] cell_style = xlwt.easyxf(_xs['borders_all']) cell_style_decimal = xlwt.easyxf( cell_format, num_format_str=report_xls.decimal_format) cell_style_percent = xlwt.easyxf(cell_format, num_format_str='0.00%') for budget in _p.report.mapped('budget_id'): report = _p.report.filtered(lambda l: l.budget_id.id == budget.id) for activity_group in report.mapped('activity_group_id'): budget_report = report.filtered( lambda l: l.activity_group_id.id == activity_group.id) budget_count = len(budget_report) budget_control_start = rowcol_to_cell(row_pos + 1, 3) budget_control_end = rowcol_to_cell(row_pos + budget_count, 3) budget_control_formula = \ 'SUM(' + budget_control_start + ':' + \ budget_control_end + ')' budget_release_start = rowcol_to_cell(row_pos + 1, 4) budget_release_end = rowcol_to_cell(row_pos + budget_count, 4) budget_release_formula = \ 'SUM(' + budget_release_start + ':' + \ budget_release_end + ')' expense_commitment_start = rowcol_to_cell(row_pos + 1, 5) expense_commitment_end = \ rowcol_to_cell(row_pos + budget_count, 5) expense_commitment_formula = \ 'SUM(' + expense_commitment_start + ':' + \ expense_commitment_end + ')' pr_commitment_start = rowcol_to_cell(row_pos + 1, 6) pr_commitment_end = rowcol_to_cell(row_pos + budget_count, 6) pr_commitment_formula = \ 'SUM(' + pr_commitment_start + ':' + \ pr_commitment_end + ')' po_commitment_start = rowcol_to_cell(row_pos + 1, 7) po_commitment_end = rowcol_to_cell(row_pos + budget_count, 7) po_commitment_formula = \ 'SUM(' + po_commitment_start + ':' + \ po_commitment_end + ')' total_commitment_start = rowcol_to_cell(row_pos, 5) total_commitment_end = rowcol_to_cell(row_pos, 7) total_commitment_formula = \ 'SUM(' + total_commitment_start + ':' + \ total_commitment_end + ')' actual_start = rowcol_to_cell(row_pos + 1, 9) actual_end = rowcol_to_cell(row_pos + budget_count, 9) actual_formula = 'SUM(' + actual_start + ':' + actual_end + ')' consumed_budget_start = rowcol_to_cell(row_pos, 8) consumed_budget_end = rowcol_to_cell(row_pos, 9) consumed_budget_formula = \ 'SUM(' + consumed_budget_start + ':' + \ consumed_budget_end + ')' residual_budget_formula = \ rowcol_to_cell(row_pos, 4) + '-' + \ rowcol_to_cell(row_pos, 10) percent_consumed_budget_formula = \ rowcol_to_cell(row_pos, 10) + '/' + \ rowcol_to_cell(row_pos, 4) c_specs = [ ('budget_structure', 1, 0, 'text', CHART_VIEW.get(_p.chart_view, None), None, cell_style_subtotal), ('budget_code', 1, 0, 'text', budget.code, None, cell_style_subtotal), ('activity', 1, 0, 'text', activity_group.name, None, cell_style_subtotal), ('budget_control', 1, 0, 'number', None, budget_control_formula, cell_style_subtotal_decimal), ('budget_release', 1, 0, 'number', None, budget_release_formula, cell_style_subtotal_decimal), ('expense_commitment', 1, 0, 'number', None, expense_commitment_formula, cell_style_subtotal_decimal), ('pr_commitment', 1, 0, 'number', None, pr_commitment_formula, cell_style_subtotal_decimal), ('po_commitment', 1, 0, 'number', None, po_commitment_formula, cell_style_subtotal_decimal), ('total_commitment', 1, 0, 'number', None, total_commitment_formula, cell_style_subtotal_decimal), ('actual', 1, 0, 'number', None, actual_formula, cell_style_subtotal_decimal), ('consumed_budget', 1, 0, 'number', None, consumed_budget_formula, cell_style_subtotal_decimal), ('residual_budget', 1, 0, 'number', None, residual_budget_formula, cell_style_subtotal_decimal), ('percent_consumed_budget', 1, 0, 'number', None, percent_consumed_budget_formula, cell_style_subtotal_percent), ] row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs]) row_pos = self.xls_write_row(ws, row_pos, row_data) row_pos_subtotal_list.append(row_pos) for budget_report in budget_report: total_commitment_start = rowcol_to_cell(row_pos, 5) total_commitment_end = rowcol_to_cell(row_pos, 7) total_commitment_formula = \ 'SUM(' + total_commitment_start + ':' + \ total_commitment_end + ')' consumed_budget_start = rowcol_to_cell(row_pos, 8) consumed_budget_end = rowcol_to_cell(row_pos, 9) consumed_budget_formula = \ 'SUM(' + consumed_budget_start + ':' + \ consumed_budget_end + ')' residual_budget_formula = \ rowcol_to_cell(row_pos, 4) + '-' + \ rowcol_to_cell(row_pos, 10) percent_consumed_formula = \ rowcol_to_cell(row_pos, 10) + '/' + \ rowcol_to_cell(row_pos, 4) c_specs = [ ('budget_structure', 1, 0, 'text', CHART_VIEW.get(_p.chart_view, None), None, cell_style), ('budget_code', 1, 0, 'text', budget_report.budget_id.code, None, cell_style), ('activity', 1, 0, 'text', budget_report.activity_id.name, None, cell_style), ('budget_control', 1, 0, 'number', budget_report.planned_amount, None, cell_style_decimal), ('budget_release', 1, 0, 'number', budget_report.released_amount, None, cell_style_decimal), ('expense_commitment', 1, 0, 'number', budget_report.amount_exp_commit, None, cell_style_decimal), ('pr_commitment', 1, 0, 'number', budget_report.amount_pr_commit, None, cell_style_decimal), ('po_commitment', 1, 0, 'number', budget_report.amount_po_commit, None, cell_style_decimal), ('total_commitment', 1, 0, 'number', None, total_commitment_formula, cell_style_decimal), ('actual', 1, 0, 'number', budget_report.amount_actual, None, cell_style_decimal), ('consumed_budget', 1, 0, 'number', None, consumed_budget_formula, cell_style_decimal), ('residual_budget', 1, 0, 'number', None, residual_budget_formula, cell_style_decimal), ('percent_consumed_budget', 1, 0, 'number', None, percent_consumed_formula, cell_style_percent) ] row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs]) row_pos = self.xls_write_row(ws, row_pos, row_data) # Column Footer cell_format = _xs['bold'] + _xs['fill'] + _xs['borders_all'] cell_style = xlwt.easyxf(cell_format) cell_style_decimal = xlwt.easyxf( cell_format + _xs['right'], num_format_str=report_xls.decimal_format) cell_style_percent = xlwt.easyxf(cell_format + _xs['right'], num_format_str='0.00%') budget_control_formula_list = [] budget_release_formula_list = [] expense_commitment_formula_list = [] pr_commitment_formula_list = [] po_commitment_formula_list = [] actual_formula_list = [] for row_pos_subtotal in row_pos_subtotal_list: budget_control_formula_list.append( rowcol_to_cell(row_pos_subtotal - 1, 3)) budget_release_formula_list.append( rowcol_to_cell(row_pos_subtotal - 1, 4)) expense_commitment_formula_list.append( rowcol_to_cell(row_pos_subtotal - 1, 5)) pr_commitment_formula_list.append( rowcol_to_cell(row_pos_subtotal - 1, 6)) po_commitment_formula_list.append( rowcol_to_cell(row_pos_subtotal - 1, 7)) actual_formula_list.append(rowcol_to_cell(row_pos_subtotal - 1, 9)) if row_pos_subtotal_list: budget_control_formula = '+'.join(budget_control_formula_list) budget_release_formula = '+'.join(budget_release_formula_list) expense_commitment_formula = \ '+'.join(expense_commitment_formula_list) pr_commitment_formula = '+'.join(pr_commitment_formula_list) po_commitment_formula = '+'.join(po_commitment_formula_list) actual_formula = '+'.join(actual_formula_list) else: budget_control_formula = '0' budget_release_formula = '0' expense_commitment_formula = '0' pr_commitment_formula = '0' po_commitment_formula = '0' actual_formula = '0' total_commitment_start = rowcol_to_cell(row_pos, 5) total_commitment_end = rowcol_to_cell(row_pos, 7) total_commitment_formula = \ 'SUM(' + total_commitment_start + ':' + total_commitment_end + ')' consumed_budget_start = rowcol_to_cell(row_pos, 8) consumed_budget_end = rowcol_to_cell(row_pos, 9) consumed_budget_formula = \ 'SUM(' + consumed_budget_start + ':' + consumed_budget_end + ')' residual_budget_formula = \ rowcol_to_cell(row_pos, 4) + '-' + rowcol_to_cell(row_pos, 10) percent_consumed_budget_formula = \ rowcol_to_cell(row_pos, 10) + '/' + rowcol_to_cell(row_pos, 4) c_specs = [('budget_structure', 1, 0, 'text', _('Grand Total'), None, cell_style), ('budget_code', 1, 0, 'text', None, None, cell_style), ('activity', 1, 0, 'text', None, None, cell_style), ('budget_control', 1, 0, 'number', None, budget_control_formula, cell_style_decimal), ('budget_release', 1, 0, 'number', None, budget_release_formula, cell_style_decimal), ('expense_commitment', 1, 0, 'number', None, expense_commitment_formula, cell_style_decimal), ('pr_commitment', 1, 0, 'number', None, pr_commitment_formula, cell_style_decimal), ('po_commitment', 1, 0, 'number', None, po_commitment_formula, cell_style_decimal), ('total_commitment', 1, 0, 'number', None, total_commitment_formula, cell_style_decimal), ('actual', 1, 0, 'number', None, actual_formula, cell_style_decimal), ('consumed_budget', 1, 0, 'number', None, consumed_budget_formula, cell_style_decimal), ('residual_budget', 1, 0, 'number', None, residual_budget_formula, cell_style_decimal), ('percent_consumed_budget', 1, 0, 'number', None, percent_consumed_budget_formula, cell_style_percent)] row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs]) row_pos = self.xls_write_row(ws, row_pos, row_data)
def generate_xls_report(self, _p, _xs, data, objects, wb): ws, row_pos = self._new_ws_with_header(_p, _xs, data, wb) # Column Title Row cell_format = _xs['bold'] c_title_cell_style = xlwt.easyxf(cell_format) # Column Header Row cell_format = _xs['bold'] + _xs['fill'] + _xs['borders_all'] c_hdr_cell_style = xlwt.easyxf(cell_format) c_hdr_cell_style_right = xlwt.easyxf(cell_format + _xs['right']) c_hdr_cell_style_center = xlwt.easyxf(cell_format + _xs['center']) c_hdr_cell_style_decimal = xlwt.easyxf( cell_format + _xs['right'], num_format_str=report_xls.decimal_format) # Column Initial Balance Row cell_format = _xs['italic'] + _xs['borders_all'] c_init_cell_style = xlwt.easyxf(cell_format) c_init_cell_style_decimal = xlwt.easyxf( cell_format + _xs['right'], num_format_str=report_xls.decimal_format) c_specs = [ ('date', 1, 0, 'text', _('Date'), None, c_hdr_cell_style), ('period', 1, 0, 'text', _('Period'), None, c_hdr_cell_style), ('move', 1, 0, 'text', _('Entry'), None, c_hdr_cell_style), ('journal', 1, 0, 'text', _('Journal'), None, c_hdr_cell_style), ('account_code', 1, 0, 'text', _('Account'), None, c_hdr_cell_style), ('partner', 1, 0, 'text', _('Partner'), None, c_hdr_cell_style), ('label', 1, 0, 'text', _('Label'), None, c_hdr_cell_style), ('counterpart', 1, 0, 'text', _('Counterpart'), None, c_hdr_cell_style), ('debit', 1, 0, 'text', _('Debit'), None, c_hdr_cell_style_right), ('credit', 1, 0, 'text', _('Credit'), None, c_hdr_cell_style_right), ('cumul_bal', 1, 0, 'text', _('Balance'), None, c_hdr_cell_style_right), ] if _p.amount_currency(data): c_specs += [ ('curr_bal', 1, 0, 'text', _('Curr. Bal.'), None, c_hdr_cell_style_right), ('curr_code', 1, 0, 'text', _('Curr.'), None, c_hdr_cell_style_center), ] c_hdr_data = self.xls_row_template(c_specs, [x[0] for x in c_specs]) # cell styles for ledger lines ll_cell_format = _xs['borders_all'] ll_cell_style = xlwt.easyxf(ll_cell_format) ll_cell_style_center = xlwt.easyxf(ll_cell_format + _xs['center']) ll_cell_style_date = xlwt.easyxf(ll_cell_format + _xs['left'], num_format_str=report_xls.date_format) ll_cell_style_decimal = xlwt.easyxf( ll_cell_format + _xs['right'], num_format_str=report_xls.decimal_format) cnt = 0 for account in objects: ws, row_pos = self._get_ws_row_pos(_p, _xs, data, wb, ws, row_pos) display_initial_balance = _p['init_balance'][account.id] and \ (_p['init_balance'][account.id].get( 'debit', 0.0) != 0.0 or _p['init_balance'][account.id].get('credit', 0.0) != 0.0) display_ledger_lines = _p['ledger_lines'][account.id] if _p.display_account_raw(data) == 'all' or \ (display_ledger_lines or display_initial_balance): # TO DO : replace cumul amounts by xls formulas cnt += 1 cumul_debit = 0.0 cumul_credit = 0.0 cumul_balance = 0.0 cumul_balance_curr = 0.0 c_specs = [ ('acc_title', 11, 0, 'text', ' - '.join([account.code, account.name])), ] row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs]) row_pos = self.xls_write_row(ws, row_pos, row_data, c_title_cell_style) row_pos = self.xls_write_row(ws, row_pos, c_hdr_data) row_start = row_pos if display_initial_balance: init_balance = _p['init_balance'][account.id] cumul_debit = init_balance.get('debit') or 0.0 cumul_credit = init_balance.get('credit') or 0.0 cumul_balance = init_balance.get('init_balance') or 0.0 cumul_balance_curr = init_balance.get( 'init_balance_currency') or 0.0 c_specs = [('empty%s' % x, 1, 0, 'text', None) for x in range(6)] c_specs += [ ('init_bal', 1, 0, 'text', _('Initial Balance')), ('counterpart', 1, 0, 'text', None), ('debit', 1, 0, 'number', cumul_debit, None, c_init_cell_style_decimal), ('credit', 1, 0, 'number', cumul_credit, None, c_init_cell_style_decimal), ('cumul_bal', 1, 0, 'number', cumul_balance, None, c_init_cell_style_decimal), ] if _p.amount_currency(data): c_specs += [ ('curr_bal', 1, 0, 'number', cumul_balance_curr, None, c_init_cell_style_decimal), ('curr_code', 1, 0, 'text', None), ] row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs]) row_pos = self.xls_write_row(ws, row_pos, row_data, c_init_cell_style) for line in _p['ledger_lines'][account.id]: cumul_debit += line.get('debit') or 0.0 cumul_credit += line.get('credit') or 0.0 cumul_balance_curr += line.get('amount_currency') or 0.0 cumul_balance += line.get('balance') or 0.0 label_elements = [line.get('lname') or ''] if line.get('invoice_number'): label_elements.append("(%s)" % (line['invoice_number'], )) label = ' '.join(label_elements) if line.get('ldate'): c_specs = [ ('ldate', 1, 0, 'date', datetime.strptime(line['ldate'], '%Y-%m-%d'), None, ll_cell_style_date), ] else: c_specs = [ ('ldate', 1, 0, 'text', None), ] c_specs += [ ('period', 1, 0, 'text', line.get('period_code') or ''), ('move', 1, 0, 'text', line.get('move_name') or ''), ('journal', 1, 0, 'text', line.get('jcode') or ''), ('account_code', 1, 0, 'text', account.code), ('partner', 1, 0, 'text', line.get('partner_name') or ''), ('label', 1, 0, 'text', label), ('counterpart', 1, 0, 'text', line.get('counterparts') or ''), ('debit', 1, 0, 'number', line.get('debit', 0.0), None, ll_cell_style_decimal), ('credit', 1, 0, 'number', line.get('credit', 0.0), None, ll_cell_style_decimal), ('cumul_bal', 1, 0, 'number', cumul_balance, None, ll_cell_style_decimal), ] if _p.amount_currency(data): c_specs += [ ('curr_bal', 1, 0, 'number', line.get('amount_currency') or 0.0, None, ll_cell_style_decimal), ('curr_code', 1, 0, 'text', line.get('currency_code') or '', None, ll_cell_style_center), ] row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs]) row_pos = self.xls_write_row(ws, row_pos, row_data, ll_cell_style) debit_start = rowcol_to_cell(row_start, 8) debit_end = rowcol_to_cell(row_pos - 1, 8) debit_formula = 'SUM(' + debit_start + ':' + debit_end + ')' credit_start = rowcol_to_cell(row_start, 9) credit_end = rowcol_to_cell(row_pos - 1, 9) credit_formula = 'SUM(' + credit_start + ':' + credit_end + ')' balance_debit = rowcol_to_cell(row_pos, 8) balance_credit = rowcol_to_cell(row_pos, 9) balance_formula = balance_debit + '-' + balance_credit c_specs = [ ('acc_title', 7, 0, 'text', ' - '.join([account.code, account.name])), ('cum_bal', 1, 0, 'text', _('Ending Balance on Account'), None, c_hdr_cell_style_right), ('debit', 1, 0, 'number', None, debit_formula, c_hdr_cell_style_decimal), ('credit', 1, 0, 'number', None, credit_formula, c_hdr_cell_style_decimal), ('balance', 1, 0, 'number', None, balance_formula, c_hdr_cell_style_decimal), ] if _p.amount_currency(data): if account.currency_id: c_specs += [ ('curr_bal', 1, 0, 'number', cumul_balance_curr, None, c_hdr_cell_style_decimal) ] else: c_specs += [('curr_bal', 1, 0, 'text', None)] c_specs += [('curr_code', 1, 0, 'text', None)] row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs]) row_pos = self.xls_write_row(ws, row_pos, row_data, c_hdr_cell_style) row_pos += 1
def generate_xls_report(self, _p, _xs, data, objects, wb): initial_bal = data['form']['initial_balance'] ws = wb.add_sheet(_p.report_name[:31]) ws.panes_frozen = True ws.remove_splits = True ws.portrait = 0 # Landscape ws.fit_width_to_pages = 1 row_pos = 0 # set print header/footer ws.header_str = self.xls_headers['standard'] ws.footer_str = self.xls_footers['standard'] # cf. account_report_trial_balance.mako initial_balance_text = { 'initial_balance': _('Computed'), 'opening_balance': _('Opening Entries'), False: _('No') } # Title cell_style = xlwt.easyxf(_xs['xls_title']) report_name = ' - '.join([ _p.report_name.upper(), _p.company.partner_id.name, _p.company.currency_id.name ]) c_specs = [ ('report_name', 1, 0, 'text', report_name), ] row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs]) row_pos = self.xls_write_row(ws, row_pos, row_data, row_style=cell_style) # write empty row to define column sizes c_sizes = self.column_sizes c_specs = [('empty%s' % i, 1, c_sizes[i], 'text', None) for i in range(0, len(c_sizes))] row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs]) row_pos = self.xls_write_row(ws, row_pos, row_data, set_column_size=True) # Header Table cell_format = _xs['bold'] + _xs['fill_blue'] + _xs['borders_all'] cell_style = xlwt.easyxf(cell_format) cell_style_center = xlwt.easyxf(cell_format + _xs['center']) c_specs = [ ('fy', 1, 0, 'text', _('Fiscal Year')), ('af', 2, 0, 'text', _('Accounts Filter')), ('df', 1, 0, 'text', _p.filter_form(data) == 'filter_date' and _('Dates Filter') or _('Periods Filter')), ('tm', 2, 0, 'text', _('Target Moves'), None, cell_style_center), ('ib', 1, 0, 'text', _('Initial Balance'), None, cell_style_center), ('coa', 1, 0, 'text', _('Chart of Account'), None, cell_style_center), ] row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs]) row_pos = self.xls_write_row(ws, row_pos, row_data, row_style=cell_style) cell_format = _xs['borders_all'] + _xs['wrap'] + _xs['top'] cell_style = xlwt.easyxf(cell_format) cell_style_center = xlwt.easyxf(cell_format + _xs['center']) c_specs = [ ('fy', 1, 0, 'text', _p.fiscalyear.name if _p.fiscalyear else '-'), ('af', 2, 0, 'text', _p.accounts(data) and ', '.join([account.code for account in _p.accounts(data)]) or _('All')), ] df = _('From') + ': ' if _p.filter_form(data) == 'filter_date': df += _p.start_date if _p.start_date else u'' else: df += _p.start_period.name if _p.start_period else u'' df += ' ' + _('\nTo') + ': ' if _p.filter_form(data) == 'filter_date': df += _p.stop_date if _p.stop_date else u'' else: df += _p.stop_period.name if _p.stop_period else u'' c_specs += [ ('df', 1, 0, 'text', df), ('tm', 2, 0, 'text', _p.display_target_move(data), None, cell_style_center), ('ib', 1, 0, 'text', initial_balance_text[_p.initial_balance_mode], None, cell_style_center), ('coa', 1, 0, 'text', _p.chart_account.name, None, cell_style_center), ] row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs]) row_pos = self.xls_write_row(ws, row_pos, row_data, row_style=cell_style) # comparison header table if _p.comparison_mode in ('single', 'multiple'): row_pos += 1 cell_format_ct = _xs['bold'] + \ _xs['fill_blue'] + _xs['borders_all'] cell_style_ct = xlwt.easyxf(cell_format_ct) c_specs = [('ct', 8, 0, 'text', _('Comparisons'))] row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs]) row_pos = self.xls_write_row(ws, row_pos, row_data, row_style=cell_style_ct) cell_style_center = xlwt.easyxf(cell_format) for index, params in enumerate(_p.comp_params): c_specs = [('c', 3, 0, 'text', _('Comparison') + str(index + 1) + ' (C' + str(index + 1) + ')')] if params['comparison_filter'] == 'filter_date': c_specs += [ ('f', 3, 0, 'text', _('Dates Filter') + ': ' + _p.formatLang(params['start'], date=True) + ' - ' + _p.formatLang(params['stop'], date=True)) ] elif params['comparison_filter'] == 'filter_period': c_specs += [ ('f', 3, 0, 'text', _('Periods Filter') + ': ' + params['start'].name + ' - ' + params['stop'].name) ] else: c_specs += [ ('f', 3, 0, 'text', _('Fiscal Year') + ': ' + params['fiscalyear'].name) ] c_specs += [ ('ib', 2, 0, 'text', _('Initial Balance') + ': ' + initial_balance_text[params['initial_balance_mode']]) ] row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs]) row_pos = self.xls_write_row(ws, row_pos, row_data, row_style=cell_style_center) row_pos += 1 # Column Header Row cell_format = _xs['bold'] + _xs['fill_blue'] + \ _xs['borders_all'] + _xs['wrap'] + _xs['top'] cell_style = xlwt.easyxf(cell_format) cell_style_right = xlwt.easyxf(cell_format + _xs['right']) cell_style_center = xlwt.easyxf(cell_format + _xs['center']) if len(_p.comp_params) == 2: account_span = 3 else: account_span = _p.initial_balance_mode and 2 or 3 c_specs = [ ('code', 1, 0, 'text', _('Code')), ('account', account_span, 0, 'text', _('Account')), ] if _p.comparison_mode == 'no_comparison': if _p.initial_balance_mode: c_specs += [('init_bal', 1, 0, 'text', _('Initial Balance'), None, cell_style_right)] c_specs += [ ('debit', 1, 0, 'text', _('Debit'), None, cell_style_right), ('credit', 1, 0, 'text', _('Credit'), None, cell_style_right), ] if _p.comparison_mode == 'no_comparison' or not _p.fiscalyear: c_specs += [('balance', 1, 0, 'text', _('Balance'), None, cell_style_right)] else: c_specs += [ ('balance_fy', 1, 0, 'text', _('Balance %s') % _p.fiscalyear.name, None, cell_style_right) ] if _p.comparison_mode in ('single', 'multiple'): for index in range(_p.nb_comparison): if _p.comp_params[index][ 'comparison_filter'] == 'filter_year' \ and _p.comp_params[index].get('fiscalyear', False): c_specs += [('balance_%s' % index, 1, 0, 'text', _('Balance %s') % _p.comp_params[index]['fiscalyear'].name, None, cell_style_right)] else: c_specs += [('balance_%s' % index, 1, 0, 'text', _('Balance C%s') % (index + 1), None, cell_style_right)] if _p.comparison_mode == 'single': c_specs += [ ('diff', 1, 0, 'text', _('Difference'), None, cell_style_right), ('diff_percent', 1, 0, 'text', _('% Difference'), None, cell_style_center), ] c_specs += [('type', 1, 0, 'text', _('Type'), None, cell_style_center)] row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs]) row_pos = self.xls_write_row(ws, row_pos, row_data, row_style=cell_style) ws.set_horz_split_pos(row_pos) last_child_consol_ids = [] # cell styles for account data view_cell_format = _xs['bold'] + _xs['fill'] + _xs['borders_all'] view_cell_style = xlwt.easyxf(view_cell_format) view_cell_style_center = xlwt.easyxf(view_cell_format + _xs['center']) view_cell_style_decimal = xlwt.easyxf( view_cell_format + _xs['right'], num_format_str=report_xls.decimal_format) view_cell_style_pct = xlwt.easyxf(view_cell_format + _xs['center'], num_format_str='0') regular_cell_format = _xs['borders_all'] regular_cell_style = xlwt.easyxf(regular_cell_format) regular_cell_style_center = xlwt.easyxf(regular_cell_format + _xs['center']) regular_cell_style_decimal = xlwt.easyxf( regular_cell_format + _xs['right'], num_format_str=report_xls.decimal_format) regular_cell_style_pct = xlwt.easyxf(regular_cell_format + _xs['center'], num_format_str='0') for current_account in objects: if initial_bal: start_date = self.number_of_fiscal_years(_p.fiscalyear.id) end_date = datetime.strptime(_p.start_date, '%Y-%m-%d') end_date = end_date - relativedelta(days=1) end_date = str(end_date).split(' ') end_date = end_date[0] results = self.cal_ini_bal(start_date, end_date, current_account.id) if not _p['to_display_accounts'][current_account.id]: continue if current_account.type == 'views': cell_style = view_cell_style cell_style_center = view_cell_style_center cell_style_decimal = view_cell_style_decimal cell_style_pct = view_cell_style_pct else: cell_style = regular_cell_style cell_style_center = regular_cell_style_center cell_style_decimal = regular_cell_style_decimal cell_style_pct = regular_cell_style_pct comparisons = _p['comparisons_accounts'][current_account.id] if current_account.id not in last_child_consol_ids: # current account is a not a consolidation child: use its own # level last_child_consol_ids = [ child_consol_id.id for child_consol_id in current_account.child_consol_ids ] c_specs = [ ('code', 1, 0, 'text', current_account.code), ('account', account_span, 0, 'text', current_account.name), ] if _p.comparison_mode == 'no_comparison': debit_cell = rowcol_to_cell(row_pos, 4) credit_cell = rowcol_to_cell(row_pos, 5) bal_formula = debit_cell + '-' + credit_cell if _p.initial_balance_mode: init_cell = rowcol_to_cell(row_pos, 3) debit_cell = rowcol_to_cell(row_pos, 4) credit_cell = rowcol_to_cell(row_pos, 5) bal_formula = init_cell + '+' + \ debit_cell + '-' + credit_cell c_specs += [('init_bal', 1, 0, 'number', _p['init_balance_' 'accounts'][current_account.id], None, cell_style_decimal)] c_specs += [ ('debit', 1, 0, 'number', _p['debit_accounts'][current_account.id] + ((results['balance'] or 0.0) if initial_bal else 0.0), None, cell_style_decimal), ('credit', 1, 0, 'number', _p['credit_accounts'][current_account.id], None, cell_style_decimal), ] c_specs += [('balance', 1, 0, 'number', None, bal_formula, cell_style_decimal)] else: c_specs += [('balance', 1, 0, 'number', _p['balance_accounts'][current_account.id], None, cell_style_decimal)] if _p.comparison_mode in ('single', 'multiple'): c = 1 for comp_account in comparisons: c_specs += [ ('balance_%s' % c, 1, 0, 'number', comp_account['balance'], None, cell_style_decimal) ] c += 1 if _p.comparison_mode == 'single': c_specs += [ ('diff', 1, 0, 'number', comp_account['diff'], None, cell_style_decimal), ('diff_percent', 1, 0, 'number', comp_account['percent_diff'] and comp_account['percent_diff'] or 0, None, cell_style_pct), ] c_specs += [('type', 1, 0, 'text', current_account.type, None, cell_style_center)] row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs]) row_pos = self.xls_write_row(ws, row_pos, row_data, row_style=cell_style)
def generate_xls_report(self, _p, _xs, data, objects, wb): wanted_list = _p.wanted_list self.col_specs_template.update(_p.template_changes) _ = _p._ subtotal_pos = 'price_subtotal' in wanted_list \ and wanted_list.index('price_subtotal') report_name = _("Invoice Lines") ws = wb.add_sheet(report_name[:31]) ws.panes_frozen = True ws.remove_splits = True ws.portrait = 0 # Landscape ws.fit_width_to_pages = 1 row_pos = 0 # set print header/footer ws.header_str = self.xls_headers['standard'] ws.footer_str = self.xls_footers['standard'] # Title cell_style = xlwt.easyxf(_xs['xls_title']) c_specs = [ ('report_name', 1, 0, 'text', report_name), ] row_data = self.xls_row_template(c_specs, ['report_name']) row_pos = self.xls_write_row(ws, row_pos, row_data, row_style=cell_style) row_pos += 1 # Column headers c_specs = map( lambda x: self.render( x, self.col_specs_template, 'header', render_space={'_': _p._} ), wanted_list) row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs]) row_pos = self.xls_write_row(ws, row_pos, row_data, row_style=self.rh_cell_style, set_column_size=True) ws.set_horz_split_pos(row_pos) ws.set_vert_split_pos(1) # invoice lines for line in objects: c_specs = map( lambda x: self.render(x, self.col_specs_template, 'lines'), wanted_list) row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs]) row_pos = self.xls_write_row(ws, row_pos, row_data, row_style=self.ail_cell_style) # Totals ail_cnt = len(objects) if subtotal_pos: subtotal_start = rowcol_to_cell(row_pos - ail_cnt, subtotal_pos) subtotal_stop = rowcol_to_cell(row_pos - 1, subtotal_pos) subtotal_formula = 'SUM(%s:%s)' % ( subtotal_start, subtotal_stop ) # noqa: disable F841, report_xls namespace trick c_specs = map( lambda x: self.render(x, self.col_specs_template, 'totals'), wanted_list) row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs]) row_pos = self.xls_write_row(ws, row_pos, row_data, row_style=self.rt_cell_style_right)
def generate_xls_report(self, _p, _xs, data, objects, wb): ws = wb.add_sheet(_p.report_name[:31]) ws.panes_frozen = True ws.remove_splits = True ws.portrait = 0 # Landscape ws.fit_width_to_pages = 1 row_pos = 0 # set print header/footer ws.header_str = self.xls_headers['standard'] ws.footer_str = self.xls_footers['standard'] # cf. account_report_general_ledger.mako initial_balance_text = {'initial_balance': _('Computed'), 'opening_balance': _('Opening Entries'), False: _('No')} # Title cell_style = xlwt.easyxf(_xs['xls_title']) report_name = ' - '.join([_p.report_name.upper(), _p.company.partner_id.name, _p.company.currency_id.name]) c_specs = [ ('report_name', 1, 0, 'text', report_name), ] row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs]) row_pos = self.xls_write_row( ws, row_pos, row_data, row_style=cell_style) # write empty row to define column sizes c_sizes = self.column_sizes c_specs = [('empty%s' % i, 1, c_sizes[i], 'text', None) for i in range(0, len(c_sizes))] row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs]) row_pos = self.xls_write_row( ws, row_pos, row_data, set_column_size=True) # Header Table cell_format = _xs['bold'] + _xs['fill_blue'] + _xs['borders_all'] cell_style = xlwt.easyxf(cell_format) cell_style_center = xlwt.easyxf(cell_format + _xs['center']) c_specs = [ ('coa', 2, 0, 'text', _('Chart of Account')), ('fy', 1, 0, 'text', _('Fiscal Year')), ('df', 3, 0, 'text', _p.filter_form(data) == 'filter_date' and _('Dates Filter') or _('Periods Filter')), ('af', 1, 0, 'text', _('Accounts Filter')), ('tm', 2, 0, 'text', _('Target Moves')), ('ib', 2, 0, 'text', _('Initial Balance')), ] row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs]) row_pos = self.xls_write_row( ws, row_pos, row_data, row_style=cell_style_center) cell_format = _xs['borders_all'] cell_style = xlwt.easyxf(cell_format) cell_style_center = xlwt.easyxf(cell_format + _xs['center']) c_specs = [ ('coa', 2, 0, 'text', _p.chart_account.name), ('fy', 1, 0, 'text', _p.fiscalyear.name if _p.fiscalyear else '-'), ] df = _('From') + ': ' if _p.filter_form(data) == 'filter_date': df += _p.start_date if _p.start_date else u'' else: df += _p.start_period.name if _p.start_period else u'' df += ' ' + _('To') + ': ' if _p.filter_form(data) == 'filter_date': df += _p.stop_date if _p.stop_date else u'' else: df += _p.stop_period.name if _p.stop_period else u'' c_specs += [ ('df', 3, 0, 'text', df), ('af', 1, 0, 'text', _p.accounts(data) and ', '.join( [account.code for account in _p.accounts(data)]) or _('All')), ('tm', 2, 0, 'text', _p.display_target_move(data)), ('ib', 2, 0, 'text', initial_balance_text[ _p.initial_balance_mode]), ] row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs]) row_pos = self.xls_write_row( ws, row_pos, row_data, row_style=cell_style_center) ws.set_horz_split_pos(row_pos) row_pos += 1 # Column Title Row cell_format = _xs['bold'] c_title_cell_style = xlwt.easyxf(cell_format) # Column Header Row cell_format = _xs['bold'] + _xs['fill'] + _xs['borders_all'] c_hdr_cell_style = xlwt.easyxf(cell_format) c_hdr_cell_style_right = xlwt.easyxf(cell_format + _xs['right']) c_hdr_cell_style_center = xlwt.easyxf(cell_format + _xs['center']) c_hdr_cell_style_decimal = xlwt.easyxf( cell_format + _xs['right'], num_format_str=report_xls.decimal_format) # Column Initial Balance Row cell_format = _xs['italic'] + _xs['borders_all'] c_init_cell_style = xlwt.easyxf(cell_format) c_init_cell_style_decimal = xlwt.easyxf( cell_format + _xs['right'], num_format_str=report_xls.decimal_format) c_specs = [ ('document_date', 1, 0, 'text', _('Document Date'), None, c_hdr_cell_style), ('posting_date', 1, 0, 'text', _('Posting Date'), None, c_hdr_cell_style), ('period', 1, 0, 'text', _('Period'), None, c_hdr_cell_style), ('budget', 1, 0, 'text', _('Budget'), None, c_hdr_cell_style), ('fund', 1, 0, 'text', _('Fund'), None, c_hdr_cell_style), ('costcenter', 1, 0, 'text', _('Costcenter'), None, c_hdr_cell_style), ('taxbranch', 1, 0, 'text', _('Tax Branch'), None, c_hdr_cell_style), ('move', 1, 0, 'text', _('Entry'), None, c_hdr_cell_style), ('doctype', 1, 0, 'text', _('DocType'), None, c_hdr_cell_style), ('activity_group', 1, 0, 'text', _('Activity Group'), None, c_hdr_cell_style), ('activity', 1, 0, 'text', _('Activity'), None, c_hdr_cell_style), ('account_code', 1, 0, 'text', _('Account'), None, c_hdr_cell_style), ('partner', 1, 0, 'text', _('Partner'), None, c_hdr_cell_style), ('reference', 1, 0, 'text', _('Reference'), None, c_hdr_cell_style), ('description', 1, 0, 'text', _('Description'), None, c_hdr_cell_style), ('counterpart', 1, 0, 'text', _('Counterpart'), None, c_hdr_cell_style), ('debit', 1, 0, 'text', _('Debit'), None, c_hdr_cell_style_right), ('credit', 1, 0, 'text', _('Credit'), None, c_hdr_cell_style_right), ('cumul_bal', 1, 0, 'text', _('Cumul. Bal.'), None, c_hdr_cell_style_right), ] if _p.amount_currency(data): c_specs += [ ('curr_bal', 1, 0, 'text', _('Curr. Bal.'), None, c_hdr_cell_style_right), ('curr_code', 1, 0, 'text', _('Curr.'), None, c_hdr_cell_style_center), ] c_specs += [ ('created_by', 1, 0, 'text', _('Created by'), None, c_hdr_cell_style), ] c_hdr_data = self.xls_row_template(c_specs, [x[0] for x in c_specs]) # cell styles for ledger lines ll_cell_format = _xs['borders_all'] ll_cell_style = xlwt.easyxf(ll_cell_format) ll_cell_style_center = xlwt.easyxf(ll_cell_format + _xs['center']) ll_cell_style_date = xlwt.easyxf( ll_cell_format + _xs['left'], num_format_str=report_xls.date_format) ll_cell_style_decimal = xlwt.easyxf( ll_cell_format + _xs['right'], num_format_str=report_xls.decimal_format) cnt = 0 for account in objects: display_initial_balance = _p['init_balance'][account.id] and \ (_p['init_balance'][account.id].get( 'debit', 0.0) != 0.0 or _p['init_balance'][account.id].get('credit', 0.0) != 0.0) display_ledger_lines = _p['ledger_lines'][account.id] if _p.display_account_raw(data) == 'all' or \ (display_ledger_lines or display_initial_balance): # TO DO : replace cumul amounts by xls formulas cnt += 1 cumul_debit = 0.0 cumul_credit = 0.0 cumul_balance = 0.0 cumul_balance_curr = 0.0 c_specs = [ ('acc_title', 11, 0, 'text', ' - '.join([account.code, account.name])), ] row_data = self.xls_row_template( c_specs, [x[0] for x in c_specs]) row_pos = self.xls_write_row( ws, row_pos, row_data, c_title_cell_style) row_pos = self.xls_write_row(ws, row_pos, c_hdr_data) row_start = row_pos if display_initial_balance: init_balance = _p['init_balance'][account.id] cumul_debit = init_balance.get('debit') or 0.0 cumul_credit = init_balance.get('credit') or 0.0 cumul_balance = init_balance.get('init_balance') or 0.0 cumul_balance_curr = init_balance.get( 'init_balance_currency') or 0.0 c_specs = [('empty%s' % x, 1, 0, 'text', None) for x in range(14)] c_specs += [ ('init_bal', 1, 0, 'text', _('Initial Balance')), ('counterpart', 1, 0, 'text', None), ('debit', 1, 0, 'number', cumul_debit, None, c_init_cell_style_decimal), ('credit', 1, 0, 'number', cumul_credit, None, c_init_cell_style_decimal), ('cumul_bal', 1, 0, 'number', cumul_balance, None, c_init_cell_style_decimal), ] if _p.amount_currency(data): c_specs += [ ('curr_bal', 1, 0, 'number', cumul_balance_curr, None, c_init_cell_style_decimal), ('curr_code', 1, 0, 'text', None), ] row_data = self.xls_row_template( c_specs, [x[0] for x in c_specs]) row_pos = self.xls_write_row( ws, row_pos, row_data, c_init_cell_style) for line in _p['ledger_lines'][account.id]: cumul_debit += line.get('debit') or 0.0 cumul_credit += line.get('credit') or 0.0 cumul_balance_curr += line.get('amount_currency') or 0.0 cumul_balance += line.get('balance') or 0.0 label_elements = [line.get('lname') or ''] if line.get('invoice_number'): label_elements.append( "(%s)" % (line['invoice_number'],)) label = ' '.join(label_elements) if line.get('document_date'): c_specs = [ ('document_date', 1, 0, 'date', datetime.strptime( line['document_date'], '%Y-%m-%d'), None, ll_cell_style_date), ] else: c_specs = [ ('document_date', 1, 0, 'text', None), ] if line.get('ldate'): c_specs += [ ('posting_date', 1, 0, 'date', datetime.strptime( line['ldate'], '%Y-%m-%d'), None, ll_cell_style_date), ] else: c_specs += [ ('posting_date', 1, 0, 'text', None), ] c_specs += [ ('period', 1, 0, 'text', line.get('period_code') or ''), ('budget', 1, 0, 'text', line.get('budget_name') or ''), ('fund', 1, 0, 'text', line.get('fund_name') or ''), ('costcenter', 1, 0, 'text', line.get('costcenter_name') or ''), ('taxbranch', 1, 0, 'text', line.get('taxbranch_name') or ''), ('move', 1, 0, 'text', line.get('move_name') or ''), ('doctype', 1, 0, 'text', line.get('doctype') or ''), ('activity_group', 1, 0, 'text', line.get('activity_group_name') or ''), ('activity', 1, 0, 'text', line.get('activity_name') or ''), ('account_code', 1, 0, 'text', account.code), ('partner', 1, 0, 'text', line.get('partner_name') or ''), ('reference', 1, 0, 'text', line.get('lref') or ''), ('description', 1, 0, 'text', label), ('counterpart', 1, 0, 'text', line.get('counterparts') or ''), ('debit', 1, 0, 'number', line.get('debit', 0.0), None, ll_cell_style_decimal), ('credit', 1, 0, 'number', line.get('credit', 0.0), None, ll_cell_style_decimal), ('cumul_bal', 1, 0, 'number', cumul_balance, None, ll_cell_style_decimal), ] if _p.amount_currency(data): c_specs += [ ('curr_bal', 1, 0, 'number', line.get( 'amount_currency') or 0.0, None, ll_cell_style_decimal), ('curr_code', 1, 0, 'text', line.get( 'currency_code') or '', None, ll_cell_style_center), ] c_specs += [ ('created_by', 1, 0, 'text', line.get('created_name') or ''), ] row_data = self.xls_row_template( c_specs, [x[0] for x in c_specs]) row_pos = self.xls_write_row( ws, row_pos, row_data, ll_cell_style) debit_start = rowcol_to_cell(row_start, 16) debit_end = rowcol_to_cell(row_pos - 1, 16) debit_formula = 'SUM(' + debit_start + ':' + debit_end + ')' credit_start = rowcol_to_cell(row_start, 17) credit_end = rowcol_to_cell(row_pos - 1, 17) credit_formula = 'SUM(' + credit_start + ':' + credit_end + ')' balance_debit = rowcol_to_cell(row_pos, 16) balance_credit = rowcol_to_cell(row_pos, 17) balance_formula = balance_debit + '-' + balance_credit c_specs = [ ('acc_title', 15, 0, 'text', ' - '.join([account.code, account.name])), ('cum_bal', 1, 0, 'text', _('Cumulated Balance on Account'), None, c_hdr_cell_style_right), ('debit', 1, 0, 'number', None, debit_formula, c_hdr_cell_style_decimal), ('credit', 1, 0, 'number', None, credit_formula, c_hdr_cell_style_decimal), ('balance', 1, 0, 'number', None, balance_formula, c_hdr_cell_style_decimal), ] if _p.amount_currency(data): if account.currency_id: c_specs += [('curr_bal', 1, 0, 'number', cumul_balance_curr, None, c_hdr_cell_style_decimal)] else: c_specs += [('curr_bal', 1, 0, 'text', None)] c_specs += [('curr_code', 1, 0, 'text', None)] c_specs += [ ('created_by', 1, 0, 'text', None), ] row_data = self.xls_row_template( c_specs, [x[0] for x in c_specs]) row_pos = self.xls_write_row( ws, row_pos, row_data, c_hdr_cell_style) row_pos += 1
def _tb_account_data(self, ws, _p, row_pos, _xs, entry): account = entry['account'] av_style = account.type == 'view' and True or False if av_style: code_cell_style = self.av_code_cell_style account_cell_style = self.av_account_cell_style debit_cell_style = self.av_debit_cell_style credit_cell_style = self.av_credit_cell_style balance_cell_style = self.av_balance_cell_style type_cell_style = entry.get('last') and \ self.av_type_cell_style_last or self.av_type_cell_style level_cell_style = entry.get('last') and \ self.av_level_cell_style_last or self.av_level_cell_style else: code_cell_style = self.ar_code_cell_style account_cell_style = self.ar_account_cell_style debit_cell_style = self.ar_debit_cell_style credit_cell_style = self.ar_credit_cell_style balance_cell_style = self.ar_balance_cell_style type_cell_style = entry.get('last') and \ self.ar_type_cell_style_last or self.ar_type_cell_style level_cell_style = entry.get('last') and \ self.ar_level_cell_style_last or self.ar_level_cell_style if entry.get('child_row_pos'): child_row_pos = [row_pos + p for p in entry['child_row_pos']] c_specs = [ ('code', 1, 0, 'text', account.code, None, code_cell_style), ('account', 1, 0, 'text', account.name, None, account_cell_style), ] for i, vals in enumerate(entry['periods_data']): debit_pos = 2 + i * 3 credit_pos = debit_pos + 1 debit_cell = rowcol_to_cell(row_pos, debit_pos) credit_cell = rowcol_to_cell(row_pos, credit_pos) bal_formula = debit_cell + '-' + credit_cell if i == 0: debit_total_formula = debit_cell credit_total_formula = credit_cell else: debit_total_formula += '+' + debit_cell credit_total_formula += '+' + credit_cell child_debit_cells = [ rowcol_to_cell(p, debit_pos) for p in child_row_pos] debit_formula = '+'.join(child_debit_cells) child_credit_cells = [ rowcol_to_cell(p, credit_pos) for p in child_row_pos] credit_formula = '+'.join(child_credit_cells) c_specs += [ ('debit%s' % i, 1, 0, 'number', None, debit_formula, debit_cell_style), ('credit%s' % i, 1, 0, 'number', None, credit_formula, credit_cell_style), ('balance%s' % i, 1, 0, 'number', None, bal_formula, balance_cell_style), ] debit_pos += 3 credit_pos = debit_pos + 1 debit_cell = rowcol_to_cell(row_pos, debit_pos) credit_cell = rowcol_to_cell(row_pos, credit_pos) bal_formula = debit_cell + '-' + credit_cell c_specs += [ ('total_debit%s' % i, 1, 0, 'number', None, debit_total_formula, debit_cell_style), ('total_credit%s' % i, 1, 0, 'number', None, credit_total_formula, credit_cell_style), ('total_balance%s' % i, 1, 0, 'number', None, bal_formula, balance_cell_style), ] c_specs += [ ('type', 1, 0, 'text', entry['account_type'], None, type_cell_style), ('level', 1, 0, 'number', account.level, None, level_cell_style), ] else: c_specs = [ ('code', 1, 0, 'text', account.code, None, code_cell_style), ('account', 1, 0, 'text', account.name, None, account_cell_style), ] for i, vals in enumerate(entry['periods_data']): debit_pos = 2 + i * 3 credit_pos = debit_pos + 1 debit_cell = rowcol_to_cell(row_pos, debit_pos) credit_cell = rowcol_to_cell(row_pos, credit_pos) bal_formula = debit_cell + '-' + credit_cell if i == 0: debit_total_formula = debit_cell credit_total_formula = credit_cell else: debit_total_formula += '+' + debit_cell credit_total_formula += '+' + credit_cell c_specs += [ ('debit%s' % i, 1, 0, 'number', vals['debit'], None, debit_cell_style), ('credit%s' % i, 1, 0, 'number', vals['credit'], None, credit_cell_style), ('balance%s' % i, 1, 0, 'number', None, bal_formula, balance_cell_style), ] debit_pos += 3 credit_pos = debit_pos + 1 debit_cell = rowcol_to_cell(row_pos, debit_pos) credit_cell = rowcol_to_cell(row_pos, credit_pos) bal_formula = debit_cell + '-' + credit_cell c_specs += [ ('total_debit%s' % i, 1, 0, 'number', None, debit_total_formula, debit_cell_style), ('total_credit%s' % i, 1, 0, 'number', None, credit_total_formula, credit_cell_style), ('total_balance%s' % i, 1, 0, 'number', None, bal_formula, balance_cell_style), ] c_specs += [ ('type', 1, 0, 'text', entry['account_type'], None, type_cell_style), ('level', 1, 0, 'number', account.level, None, level_cell_style), ] row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs]) row_pos = self.xls_write_row(ws, row_pos, row_data) return row_pos
def print_group_lines(self, row_position, account, line,_p, line_number): # Fill in rows of invoice line when the option currency regroup is selected label_elements = [line.get('lname') or ''] if line.get('invoice_number'): label_elements.append("(%s)" % (line['invoice_number'],)) label = ' '.join(label_elements) # Mako: <div class="act_as_row lines ${line.get('is_from_previous_periods') and 'open_invoice_previous_line' or ''} ${line.get('is_clearance_line') and 'clearance_line' or ''}"> if line.get('is_from_previous_periods') or line.get('is_clearance_line'): style_line_default = style_default_italic style_line_right = style_right_italic style_line_date = style_date_italic style_line_decimal = style_decimal_italic else: style_line_default = style_default style_line_right = style_right style_line_date = style_date style_line_decimal = style_decimal debit_cell = rowcol_to_cell(row_position, 7) credit_cell = rowcol_to_cell(row_position, 8) previous_balance = rowcol_to_cell(row_position - 1, 9) if line_number == 1: #if it is the first line, the balance is only debit - credit cumul_balance = debit_cell + '-' + credit_cell else: # cumulate devit - credit and balance of previous line cumul_balance = debit_cell + '-' + credit_cell + '+' + previous_balance if line.get('ldate'): c_specs = [('date', 1, 0, 'date', datetime.strptime(line['ldate'],'%Y-%m-%d'), None, style_line_date)] else: c_specs = [('date', 1, 0, 'text', None)] c_specs += [ ('period_code', 1, 0, 'text', line.get('period_code') or '' ), ('entry', 1, 0, 'text', line.get('move_name') or '' ), ('journal', 1, 0, 'text', line.get('jcode') or '' ), ('label', 1, 0, 'text', label), ('rec', 1, 0, 'text', line.get('rec_name') or '' ), ] if line.get('date_maturity'): c_specs += [('datedue', 1, 0, 'date', datetime.strptime(line['date_maturity'],'%Y-%m-%d'), None, style_line_date)] else: c_specs += [('datedue', 1, 0, 'text', None)] c_specs += [ ('debit', 1, 0, 'number', line.get('debit') or 0.0, None, style_line_decimal), ('credit', 1, 0, 'number', line.get('credit') or 0.0, None, style_line_decimal), ('cumul', 1, 0, 'number', None, cumul_balance, style_line_decimal), ] if account.currency_id: c_specs += [ ('curramount', 1, 0, 'number', line.get('amount_currency') or 0.0, None, style_line_decimal), ('currcode', 1, 0, 'text', line.get('currency_code') or '', None, style_line_right), ] else: c_specs += [ ('curramount', 1, 0, 'text', '-', None, style_line_right), ('currcode', 1, 0, 'text', '', None, style_line_right), ] row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs]) row_position = self.xls_write_row(ws, row_position, row_data, style_line_default) return (row_position, cumul_balance)
def generate_xls_report(self, _p, _xs, data, objects, wb): ws = wb.add_sheet(_p.report_name[:31]) ws.panes_frozen = True ws.remove_splits = True ws.portrait = 0 # Landscape ws.fit_width_to_pages = 1 row_pos = 0 # set print header/footer ws.header_str = self.xls_headers['standard'] ws.footer_str = self.xls_footers['standard'] # Header cell_format = _xs['bold'] + _xs['borders_all'] cell_style_title = xlwt.easyxf( cell_format + "pattern: pattern solid, fore_color ice_blue;") cell_style_value = xlwt.easyxf(cell_format + _xs['center'] + _xs['fill_blue']) c_specs = [ ('financial_year_title', 1, 0, 'text', _('Financial Year'), None, cell_style_title), ('financial_year_value', 1, 0, 'text', _p.fiscalyear.name, None, cell_style_value), ] row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs]) row_pos = self.xls_write_row(ws, row_pos, row_data) c_specs = [ ('functional_area_title', 1, 0, 'text', _('Functional Area'), None, cell_style_title), ('functional_area_value', 1, 0, 'text', '%s%s' % (_p.functional_area.code and '[' + _p.functional_area.code + '] ' or '', _p.functional_area.name_short and _p.functional_area.name_short or _p.functional_area.name or ''), None, cell_style_value) ] row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs]) row_pos = self.xls_write_row(ws, row_pos, row_data) c_specs = [ ('program_group_title', 1, 0, 'text', _('Program Group'), None, cell_style_title), ('program_group_value', 1, 0, 'text', '%s%s' % (_p.program_group.code and '[' + _p.program_group.code + '] ' or '', _p.program_group.name_short and _p.program_group.name_short or _p.program_group.name or ''), None, cell_style_value), ] row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs]) row_pos = self.xls_write_row(ws, row_pos, row_data) c_specs = [ ('program_title', 1, 0, 'text', _('Program'), None, cell_style_title), ('program_value', 1, 0, 'text', '%s%s' % (_p.program.code and '[' + _p.program.code + '] ' or '', _p.program.name_short and _p.program.name_short or _p.program.name or ''), None, cell_style_value), ] row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs]) row_pos = self.xls_write_row(ws, row_pos, row_data) c_specs = [ ('project_group_title', 1, 0, 'text', _('Project Group'), None, cell_style_title), ('project_group_value', 1, 0, 'text', '%s%s' % (_p.project_group.code and '[' + _p.project_group.code + '] ' or '', _p.project_group.name_short and _p.project_group.name_short or _p.project_group.name or ''), None, cell_style_value), ] row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs]) row_pos = self.xls_write_row(ws, row_pos, row_data) c_specs = [ ('project_title', 1, 0, 'text', _('Project'), None, cell_style_title), ('project_value', 1, 0, 'text', '%s%s' % (_p.project.code and '[' + _p.project.code + '] ' or '', _p.project.name_short and _p.project.name_short or _p.project.name or ''), None, cell_style_value), ] row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs]) row_pos = self.xls_write_row(ws, row_pos, row_data) c_specs = [('export_date_title', 1, 0, 'text', _('Export Date'), None, cell_style_title), ('export_date_value', 1, 0, 'text', datetime.datetime.now().strftime('%d-%m-%Y'), None, cell_style_value)] row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs]) row_pos = self.xls_write_row(ws, row_pos, row_data) user = self.pool.get('res.users').browse(self.cr, self.uid, self.uid) c_specs = [ ('responsible_by_title', 1, 0, 'text', _('Responsible by'), None, cell_style_title), ('responsible_by_value', 1, 0, 'text', user.name, None, cell_style_value), ] row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs]) row_pos = self.xls_write_row(ws, row_pos, row_data) c_sizes = self.column_sizes c_specs = [('empty%s' % i, 1, c_sizes[i], 'text', None) for i in range(0, len(c_sizes))] row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs]) row_pos = self.xls_write_row(ws, row_pos, row_data, set_column_size=True) # Column Header cell_style = xlwt.easyxf( _xs['bold'] + _xs['center'] + _xs['borders_all'] + "pattern: pattern solid, fore_color ice_blue;") c_specs = [ ('project', 1, 0, 'text', _('Project'), None, cell_style), ('name', 1, 0, 'text', _('Project Name'), None, cell_style), ('c_or_n', 1, 0, 'text', _('C/N'), None, cell_style), ('functional_area', 1, 0, 'text', _('Functional Area'), None, cell_style), ('program', 1, 0, 'text', _('Program'), None, cell_style), ('project_group', 1, 0, 'text', _('Project Group'), None, cell_style), ('nstda_strategy', 1, 0, 'text', _('NSTDA Strategy'), None, cell_style), ('project_objective', 1, 0, 'text', _('Objective'), None, cell_style), ('section_program', 1, 0, 'text', _('Section Program'), None, cell_style), ('mission', 1, 0, 'text', _('Mission'), None, cell_style), ('project_kind', 1, 0, 'text', _('Project Kind'), None, cell_style), ('project_type', 1, 0, 'text', _('Project Type'), None, cell_style), ('org', 1, 0, 'text', _('Org'), None, cell_style), ('costcenter', 1, 0, 'text', _('Costcenter'), None, cell_style), ('owner_division', 1, 0, 'text', _('Owner Division'), None, cell_style), ('pm_employee', 1, 0, 'text', _('Project Manager'), None, cell_style), ('budget_method', 1, 0, 'text', _('Budget Method'), None, cell_style), ('date_start', 1, 0, 'text', _('Start Date'), None, cell_style), ('date_end', 1, 0, 'text', _('End Date'), None, cell_style), ('project_duration', 1, 0, 'text', _('Duration'), None, cell_style), ('project_status', 1, 0, 'text', _('Project Status'), None, cell_style), ('analyst_employee', 1, 0, 'text', _('Project Analyst'), None, cell_style), ('ref_program', 1, 0, 'text', _('Program Reference'), None, cell_style), ('external_fund_type', 1, 0, 'text', _('External Fund Type'), None, cell_style), ('external_fund_name', 1, 0, 'text', _('External Fund Name'), None, cell_style), ('priority', 1, 0, 'text', _('Priority'), None, cell_style), ('fy1', 1, 0, 'text', _('FY1'), None, cell_style), ('fy2', 1, 0, 'text', _('FY2'), None, cell_style), ('fy3', 1, 0, 'text', _('FY3'), None, cell_style), ('fy4', 1, 0, 'text', _('FY4'), None, cell_style), ('fy5', 1, 0, 'text', _('FY5'), None, cell_style), ('revenue_budget', 1, 0, 'text', _('Revenue Budget'), None, cell_style), ('overall_revenue_plan', 1, 0, 'text', _('Overall Revenue Plan'), None, cell_style), ('pfm_publications', 1, 0, 'text', _('Publication'), None, cell_style), ('pfm_patents', 1, 0, 'text', _('Patent'), None, cell_style), ('pfm_petty_patents', 1, 0, 'text', _('Petty Patent'), None, cell_style), ('pfm_copyrights', 1, 0, 'text', _('Copy Right'), None, cell_style), ('pfm_trademarks', 1, 0, 'text', _('Trademark'), None, cell_style), ('pfm_plant_varieties', 1, 0, 'text', _('Plant Varieties'), None, cell_style), ('pfm_laboratory_prototypes', 1, 0, 'text', _('Laboratory Prototype'), None, cell_style), ('pfm_field_prototypes', 1, 0, 'text', _('Field Prototype'), None, cell_style), ('pfm_commercial_prototypes', 1, 0, 'text', _('Commercial Prototype'), None, cell_style), ('overall_revenue', 1, 0, 'text', _('Accum. Revenue'), None, cell_style), ('current_revenue', 1, 0, 'text', _('Current Year Revenue'), None, cell_style), ('overall_expense_budget', 1, 0, 'text', _('Overall Expense Budget'), None, cell_style), ('overall_actual', 1, 0, 'text', _('Accum. Expense'), None, cell_style), ('overall_commit', 1, 0, 'text', _('Accum. Commitment'), None, cell_style), ('overall_expense_balance', 1, 0, 'text', _('Remaining Expense Budget'), None, cell_style), ('planned', 1, 0, 'text', _('Current Budget'), None, cell_style), ('released', 1, 0, 'text', _('Current Released'), None, cell_style), ('all_commit', 1, 0, 'text', _('Current All Commit'), None, cell_style), ('actual', 1, 0, 'text', _('Current Actual'), None, cell_style), ('balance', 1, 0, 'text', _('Remaining Budget'), None, cell_style), ('est_commit', 1, 0, 'text', _('Estimated Commitment'), None, cell_style), ('m1', 1, 0, 'text', _('Oct'), None, cell_style), ('m2', 1, 0, 'text', _('Nov'), None, cell_style), ('m3', 1, 0, 'text', _('Dec'), None, cell_style), ('m4', 1, 0, 'text', _('Jan'), None, cell_style), ('m5', 1, 0, 'text', _('Feb'), None, cell_style), ('m6', 1, 0, 'text', _('Mar'), None, cell_style), ('m7', 1, 0, 'text', _('Apr'), None, cell_style), ('m8', 1, 0, 'text', _('May'), None, cell_style), ('m9', 1, 0, 'text', _('Jun'), None, cell_style), ('m10', 1, 0, 'text', _('Jul'), None, cell_style), ('m11', 1, 0, 'text', _('Aug'), None, cell_style), ('m12', 1, 0, 'text', _('Sep'), None, cell_style), ('planned_amount', 1, 0, 'text', _('Planned Amount'), None, cell_style), ] row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs]) row_pos = self.xls_write_row(ws, row_pos, row_data) row_start = row_pos # Column Detail cell_format = _xs['borders_all'] cell_style = xlwt.easyxf(cell_format) cell_style_integer = xlwt.easyxf(cell_format + _xs['right']) cell_style_decimal = xlwt.easyxf( cell_format + _xs['right'], num_format_str=report_xls.decimal_format) for line in _p.report: c_specs = [ ('project', 1, 0, 'text', '%s%s' % (line.project_id.code and '[' + line.project_id.code + '] ' or '', line.project_id.name_short and line.project_id.name_short or line.project_id.name or ''), None, cell_style), ('name', 1, 0, 'text', line.name, None, cell_style), ('c_or_n', 1, 0, 'text', C_OR_N.get(line.c_or_n, None), None, cell_style), ('functional_area', 1, 0, 'text', '%s%s' % (line.functional_area_id.code and '[' + line.functional_area_id.code + '] ' or '', line.functional_area_id.name_short and line.functional_area_id.name_short or line.functional_area_id.name or ''), None, cell_style), ('program', 1, 0, 'text', '%s%s' % (line.program_id.code and '[' + line.program_id.code + '] ' or '', line.program_id.name_short and line.program_id.name_short or line.program_id.name or ''), None, cell_style), ('project_group', 1, 0, 'text', '%s%s' % (line.project_group_id.code and '[' + line.project_group_id.code + '] ' or '', line.project_group_id.name_short and line.project_group_id.name_short or line.project_group_id.name or ''), None, cell_style), ('nstda_strategy', 1, 0, 'text', '%s%s' % (line.nstda_strategy_id.code and '[' + line.nstda_strategy_id.code + '] ' or '', line.nstda_strategy_id.name_short and line.nstda_strategy_id.name_short or line.nstda_strategy_id.name or ''), None, cell_style), ('project_objective', 1, 0, 'text', line.project_objective, None, cell_style), ('section_program', 1, 0, 'text', '%s%s' % (line.section_program_id.code and '[' + line.section_program_id.code + '] ' or '', line.section_program_id.name_short and line.section_program_id.name_short or line.section_program_id.name or ''), None, cell_style), ('mission', 1, 0, 'text', line.mission_id.name, None, cell_style), ('project_kind', 1, 0, 'text', PROJECT_KIND.get(line.project_kind, None), None, cell_style), ('project_type', 1, 0, 'text', line.project_type, None, cell_style), ('org', 1, 0, 'text', '%s%s' % (line.org_id.code and '[' + line.org_id.code + '] ' or '', line.org_id.name_short and line.org_id.name_short or line.org_id.name or ''), None, cell_style), ('costcenter', 1, 0, 'text', '%s%s' % (line.costcenter_id.code and '[' + line.costcenter_id.code + '] ' or '', line.costcenter_id.name_short and line.costcenter_id.name_short or line.costcenter_id.name or ''), None, cell_style), ('owner_division', 1, 0, 'text', '%s%s' % (line.owner_division_id.code and '[' + line.owner_division_id.code + '] ' or '', line.owner_division_id.name_short and line.owner_division_id.name_short or line.owner_division_id.name or ''), None, cell_style), ('pm_employee', 1, 0, 'text', line.pm_employee_id.name, None, cell_style), ('budget_method', 1, 0, 'text', BUDGET_METHOD.get(line.budget_method, None), None, cell_style), ('date_start', 1, 0, 'text', line.date_start, None, cell_style), ('date_end', 1, 0, 'text', line.date_end, None, cell_style), ('project_duration', 1, 0, 'number', line.project_duration, None, cell_style_integer), ('project_status', 1, 0, 'text', line.project_status, None, cell_style), ('analyst_employee', 1, 0, 'text', line.analyst_employee_id.name, None, cell_style), ('ref_program', 1, 0, 'text', '%s%s' % (line.ref_program_id.code and '[' + line.ref_program_id.code + '] ' or '', line.ref_program_id.name_short and line.ref_program_id.name_short and line.ref_program_id.name or ''), None, cell_style), ('external_fund_type', 1, 0, 'text', EXTERNAL_FUND_TYPE.get(line.external_fund_type, None), None, cell_style), ('external_fund_name', 1, 0, 'text', line.external_fund_name, None, cell_style), ('priority', 1, 0, 'text', line.priority, None, cell_style), ('fy1', 1, 0, 'number', line.fy1, None, cell_style_decimal), ('fy2', 1, 0, 'number', line.fy2, None, cell_style_decimal), ('fy3', 1, 0, 'number', line.fy3, None, cell_style_decimal), ('fy4', 1, 0, 'number', line.fy4, None, cell_style_decimal), ('fy5', 1, 0, 'number', line.fy5, None, cell_style_decimal), ('revenue_budget', 1, 0, 'number', line.revenue_budget, None, cell_style_decimal), ('overall_revenue_plan', 1, 0, 'number', line.overall_revenue_plan, None, cell_style_decimal), ('pfm_publications', 1, 0, 'number', line.pfm_publications, None, cell_style_integer), ('pfm_patents', 1, 0, 'number', line.pfm_patents, None, cell_style_integer), ('pfm_petty_patents', 1, 0, 'number', line.pfm_petty_patents, None, cell_style_integer), ('pfm_copyrights', 1, 0, 'number', line.pfm_copyrights, None, cell_style_integer), ('pfm_trademarks', 1, 0, 'number', line.pfm_trademarks, None, cell_style_integer), ('pfm_plant_varieties', 1, 0, 'number', line.pfm_plant_varieties, None, cell_style_integer), ('pfm_laboratory_prototypes', 1, 0, 'number', line.pfm_laboratory_prototypes, None, cell_style_integer), ('pfm_field_prototypes', 1, 0, 'number', line.pfm_field_prototypes, None, cell_style_integer), ('pfm_commercial_prototypes', 1, 0, 'number', line.pfm_commercial_prototypes, None, cell_style_integer), ('overall_revenue', 1, 0, 'number', line.overall_revenue, None, cell_style_decimal), ('current_revenue', 1, 0, 'number', line.current_revenue, None, cell_style_decimal), ('overall_expense_budget', 1, 0, 'number', line.overall_expense_budget, None, cell_style_decimal), ('overall_actual', 1, 0, 'number', line.overall_actual, None, cell_style_decimal), ('overall_commit', 1, 0, 'number', line.overall_commit, None, cell_style_decimal), ('overall_expense_balance', 1, 0, 'number', line.overall_expense_balance, None, cell_style_decimal), ('planned', 1, 0, 'number', line.planned, None, cell_style_decimal), ('released', 1, 0, 'number', line.released, None, cell_style_decimal), ('all_commit', 1, 0, 'number', line.all_commit, None, cell_style_decimal), ('actual', 1, 0, 'number', line.actual, None, cell_style_decimal), ('balance', 1, 0, 'number', line.balance, None, cell_style_decimal), ('est_commit', 1, 0, 'number', line.est_commit, None, cell_style_decimal), ('m1', 1, 0, 'number', line.m1, None, cell_style_decimal), ('m2', 1, 0, 'number', line.m2, None, cell_style_decimal), ('m3', 1, 0, 'number', line.m3, None, cell_style_decimal), ('m4', 1, 0, 'number', line.m4, None, cell_style_decimal), ('m5', 1, 0, 'number', line.m5, None, cell_style_decimal), ('m6', 1, 0, 'number', line.m6, None, cell_style_decimal), ('m7', 1, 0, 'number', line.m7, None, cell_style_decimal), ('m8', 1, 0, 'number', line.m8, None, cell_style_decimal), ('m9', 1, 0, 'number', line.m9, None, cell_style_decimal), ('m10', 1, 0, 'number', line.m10, None, cell_style_decimal), ('m11', 1, 0, 'number', line.m11, None, cell_style_decimal), ('m12', 1, 0, 'number', line.m12, None, cell_style_decimal), ('planned_amount', 1, 0, 'number', line.planned_amount, None, cell_style_decimal), ] row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs]) row_pos = self.xls_write_row(ws, row_pos, row_data) # Column Footer cell_format = _xs['borders_all'] + _xs['bold'] cell_style = xlwt.easyxf(cell_format) cell_style_total = xlwt.easyxf( cell_format + "pattern: pattern solid, fore_color ice_blue;") cell_style_decimal = xlwt.easyxf( cell_format + _xs['right'], num_format_str=report_xls.decimal_format) fy1_start = rowcol_to_cell(row_start, 26) fy1_end = rowcol_to_cell(row_pos - 1, 26) fy1_formula = 'SUM(' + fy1_start + ':' + fy1_end + ')' fy2_start = rowcol_to_cell(row_start, 27) fy2_end = rowcol_to_cell(row_pos - 1, 27) fy2_formula = 'SUM(' + fy2_start + ':' + fy2_end + ')' fy3_start = rowcol_to_cell(row_start, 28) fy3_end = rowcol_to_cell(row_pos - 1, 28) fy3_formula = 'SUM(' + fy3_start + ':' + fy3_end + ')' fy4_start = rowcol_to_cell(row_start, 29) fy4_end = rowcol_to_cell(row_pos - 1, 29) fy4_formula = 'SUM(' + fy4_start + ':' + fy4_end + ')' fy5_start = rowcol_to_cell(row_start, 30) fy5_end = rowcol_to_cell(row_pos - 1, 30) fy5_formula = 'SUM(' + fy5_start + ':' + fy5_end + ')' revenue_budget_start = rowcol_to_cell(row_start, 31) revenue_budget_end = rowcol_to_cell(row_pos - 1, 31) revenue_budget_formula = \ 'SUM(' + revenue_budget_start + ':' + revenue_budget_end + ')' overall_revenue_plan_start = rowcol_to_cell(row_start, 32) overall_revenue_plan_end = rowcol_to_cell(row_pos - 1, 32) overall_revenue_plan_formula = \ 'SUM(' + overall_revenue_plan_start + ':' + \ overall_revenue_plan_end + ')' overall_revenue_start = rowcol_to_cell(row_start, 42) overall_revenue_end = rowcol_to_cell(row_pos - 1, 42) overall_revenue_formula = \ 'SUM(' + overall_revenue_start + ':' + overall_revenue_end + ')' current_revenue_start = rowcol_to_cell(row_start, 43) current_revenue_end = rowcol_to_cell(row_pos - 1, 43) current_revenue_formula = \ 'SUM(' + current_revenue_start + ':' + current_revenue_end + ')' overall_expense_budget_start = rowcol_to_cell(row_start, 44) overall_expense_budget_end = rowcol_to_cell(row_pos - 1, 44) overall_expense_budget_formula = \ 'SUM(' + overall_expense_budget_start + ':' + \ overall_expense_budget_end + ')' overall_actual_start = rowcol_to_cell(row_start, 45) overall_actual_end = rowcol_to_cell(row_pos - 1, 45) overall_actual_formula = \ 'SUM(' + overall_actual_start + ':' + overall_actual_end + ')' overall_commit_start = rowcol_to_cell(row_start, 46) overall_commit_end = rowcol_to_cell(row_pos - 1, 46) overall_commit_formula = \ 'SUM(' + overall_commit_start + ':' + overall_commit_end + ')' overall_expense_balance_start = rowcol_to_cell(row_start, 47) overall_expense_balance_end = rowcol_to_cell(row_pos - 1, 47) overall_expense_balance_formula = \ 'SUM(' + overall_expense_balance_start + ':' + \ overall_expense_balance_end + ')' planned_start = rowcol_to_cell(row_start, 48) planned_end = rowcol_to_cell(row_pos - 1, 48) planned_formula = 'SUM(' + planned_start + ':' + planned_end + ')' released_start = rowcol_to_cell(row_start, 49) released_end = rowcol_to_cell(row_pos - 1, 49) released_formula = 'SUM(' + released_start + ':' + released_end + ')' all_commit_start = rowcol_to_cell(row_start, 50) all_commit_end = rowcol_to_cell(row_pos - 1, 50) all_commit_formula = \ 'SUM(' + all_commit_start + ':' + all_commit_end + ')' actual_start = rowcol_to_cell(row_start, 51) actual_end = rowcol_to_cell(row_pos - 1, 51) actual_formula = 'SUM(' + actual_start + ':' + actual_end + ')' balance_start = rowcol_to_cell(row_start, 52) balance_end = rowcol_to_cell(row_pos - 1, 52) balance_formula = 'SUM(' + balance_start + ':' + balance_end + ')' est_commit_start = rowcol_to_cell(row_start, 53) est_commit_end = rowcol_to_cell(row_pos - 1, 53) est_formula = 'SUM(' + est_commit_start + ':' + est_commit_end + ')' m1_start = rowcol_to_cell(row_start, 54) m1_end = rowcol_to_cell(row_pos - 1, 54) m1_formula = 'SUM(' + m1_start + ':' + m1_end + ')' m2_start = rowcol_to_cell(row_start, 55) m2_end = rowcol_to_cell(row_pos - 1, 55) m2_formula = 'SUM(' + m2_start + ':' + m2_end + ')' m3_start = rowcol_to_cell(row_start, 56) m3_end = rowcol_to_cell(row_pos - 1, 56) m3_formula = 'SUM(' + m3_start + ':' + m3_end + ')' m4_start = rowcol_to_cell(row_start, 57) m4_end = rowcol_to_cell(row_pos - 1, 57) m4_formula = 'SUM(' + m4_start + ':' + m4_end + ')' m5_start = rowcol_to_cell(row_start, 58) m5_end = rowcol_to_cell(row_pos - 1, 58) m5_formula = 'SUM(' + m5_start + ':' + m5_end + ')' m6_start = rowcol_to_cell(row_start, 59) m6_end = rowcol_to_cell(row_pos - 1, 59) m6_formula = 'SUM(' + m6_start + ':' + m6_end + ')' m7_start = rowcol_to_cell(row_start, 60) m7_end = rowcol_to_cell(row_pos - 1, 60) m7_formula = 'SUM(' + m7_start + ':' + m7_end + ')' m8_start = rowcol_to_cell(row_start, 61) m8_end = rowcol_to_cell(row_pos - 1, 61) m8_formula = 'SUM(' + m8_start + ':' + m8_end + ')' m9_start = rowcol_to_cell(row_start, 62) m9_end = rowcol_to_cell(row_pos - 1, 62) m9_formula = 'SUM(' + m9_start + ':' + m9_end + ')' m10_start = rowcol_to_cell(row_start, 63) m10_end = rowcol_to_cell(row_pos - 1, 63) m10_formula = 'SUM(' + m10_start + ':' + m10_end + ')' m11_start = rowcol_to_cell(row_start, 64) m11_end = rowcol_to_cell(row_pos - 1, 64) m11_formula = 'SUM(' + m11_start + ':' + m11_end + ')' m12_start = rowcol_to_cell(row_start, 65) m12_end = rowcol_to_cell(row_pos - 1, 65) m12_formula = 'SUM(' + m12_start + ':' + m12_end + ')' planned_amount_start = rowcol_to_cell(row_start, 66) planned_amount_end = rowcol_to_cell(row_pos - 1, 66) planned_amount_formula = \ 'SUM(' + planned_amount_start + ':' + planned_amount_end + ')' c_specs = [ ('project', 1, 0, 'text', None, None, cell_style), ('name', 1, 0, 'text', None, None, cell_style), ('c_or_n', 1, 0, 'text', None, None, cell_style), ('functional_area', 1, 0, 'text', None, None, cell_style), ('program', 1, 0, 'text', None, None, cell_style), ('project_group', 1, 0, 'text', None, None, cell_style), ('nstda_strategy', 1, 0, 'text', None, None, cell_style), ('project_objective', 1, 0, 'text', None, None, cell_style), ('section_program', 1, 0, 'text', None, None, cell_style), ('mission', 1, 0, 'text', None, None, cell_style), ('project_kind', 1, 0, 'text', None, None, cell_style), ('project_type', 1, 0, 'text', None, None, cell_style), ('org', 1, 0, 'text', None, None, cell_style), ('costcenter', 1, 0, 'text', None, None, cell_style), ('owner_division', 1, 0, 'text', None, None, cell_style), ('pm_employee', 1, 0, 'text', None, None, cell_style), ('budget_method', 1, 0, 'text', None, None, cell_style), ('date_start', 1, 0, 'text', None, None, cell_style), ('date_end', 1, 0, 'text', None, None, cell_style), ('project_duration', 1, 0, 'number', None, None, cell_style_integer), ('project_status', 1, 0, 'text', None, None, cell_style), ('analyst_employee', 1, 0, 'text', None, None, cell_style), ('ref_program', 1, 0, 'text', None, None, cell_style), ('external_fund_type', 1, 0, 'text', None, None, cell_style), ('external_fund_name', 1, 0, 'text', None, None, cell_style), ('priority', 1, 0, 'text', _('Total'), None, cell_style_total), ('fy1', 1, 0, 'number', None, fy1_formula, cell_style_decimal), ('fy2', 1, 0, 'number', None, fy2_formula, cell_style_decimal), ('fy3', 1, 0, 'number', None, fy3_formula, cell_style_decimal), ('fy4', 1, 0, 'number', None, fy4_formula, cell_style_decimal), ('fy5', 1, 0, 'number', None, fy5_formula, cell_style_decimal), ('revenue_budget', 1, 0, 'number', None, revenue_budget_formula, cell_style_decimal), ('overall_revenue_plan', 1, 0, 'number', None, overall_revenue_plan_formula, cell_style_decimal), ('pfm_publications', 1, 0, 'text', None, None, cell_style), ('pfm_patents', 1, 0, 'text', None, None, cell_style), ('pfm_petty_patents', 1, 0, 'text', None, None, cell_style), ('pfm_copyrights', 1, 0, 'text', None, None, cell_style), ('pfm_trademarks', 1, 0, 'text', None, None, cell_style), ('pfm_plant_varieties', 1, 0, 'text', None, None, cell_style), ('pfm_laboratory_prototypes', 1, 0, 'text', None, None, cell_style), ('pfm_field_prototypes', 1, 0, 'text', None, None, cell_style), ('pfm_commercial_prototypes', 1, 0, 'text', None, None, cell_style), ('overall_revenue', 1, 0, 'number', None, overall_revenue_formula, cell_style_decimal), ('current_revenue', 1, 0, 'number', None, current_revenue_formula, cell_style_decimal), ('overall_expense_budget', 1, 0, 'number', None, overall_expense_budget_formula, cell_style_decimal), ('overall_actual', 1, 0, 'number', None, overall_actual_formula, cell_style_decimal), ('overall_commit', 1, 0, 'number', None, overall_commit_formula, cell_style_decimal), ('overall_expense_balance', 1, 0, 'number', None, overall_expense_balance_formula, cell_style_decimal), ('planned', 1, 0, 'number', None, planned_formula, cell_style_decimal), ('released', 1, 0, 'number', None, released_formula, cell_style_decimal), ('all_commit', 1, 0, 'number', None, all_commit_formula, cell_style_decimal), ('actual', 1, 0, 'number', None, actual_formula, cell_style_decimal), ('balance', 1, 0, 'number', None, balance_formula, cell_style_decimal), ('est_commit', 1, 0, 'number', None, est_formula, cell_style_decimal), ('m1', 1, 0, 'number', None, m1_formula, cell_style_decimal), ('m2', 1, 0, 'number', None, m2_formula, cell_style_decimal), ('m3', 1, 0, 'number', None, m3_formula, cell_style_decimal), ('m4', 1, 0, 'number', None, m4_formula, cell_style_decimal), ('m5', 1, 0, 'number', None, m5_formula, cell_style_decimal), ('m6', 1, 0, 'number', None, m6_formula, cell_style_decimal), ('m7', 1, 0, 'number', None, m7_formula, cell_style_decimal), ('m8', 1, 0, 'number', None, m8_formula, cell_style_decimal), ('m9', 1, 0, 'number', None, m9_formula, cell_style_decimal), ('m10', 1, 0, 'number', None, m10_formula, cell_style_decimal), ('m11', 1, 0, 'number', None, m11_formula, cell_style_decimal), ('m12', 1, 0, 'number', None, m12_formula, cell_style_decimal), ('planned_amount', 1, 0, 'number', None, planned_amount_formula, cell_style_decimal), ] row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs]) row_pos = self.xls_write_row(ws, row_pos, row_data)
def generate_xls_report(self, _p, _xs, data, objects, wb): context = {'lang': (_p.get('lang') or 'en_US')} ws = wb.add_sheet(_p.report_name[:31]) ws.panes_frozen = True ws.remove_splits = True ws.portrait = 0 # Landscape ws.fit_width_to_pages = 1 row_pos = 0 # set print header/footer ws.header_str = self.xls_headers['standard'] ws.footer_str = self.xls_footers['standard'] # cf. account_report_general_ledger.mako initial_balance_text = { 'initial_balance': _('Computed'), 'opening_balance': _('Opening Entries'), False: _('No') } # Title cell_style = xlwt.easyxf(_xs['xls_title']) report_name = ' - '.join([ _p.report_name.upper(), _p.company.partner_id.name, _p.company.currency_id.name ]) c_specs = [ ('report_name', 1, 0, 'text', report_name), ] row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs]) row_pos = self.xls_write_row(ws, row_pos, row_data, row_style=cell_style) # write empty row to define column sizes c_sizes = self.column_sizes c_specs = [('empty%s' % i, 1, c_sizes[i], 'text', None) for i in range(0, len(c_sizes))] row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs]) row_pos = self.xls_write_row(ws, row_pos, row_data, set_column_size=True) # Alternative Currency base_currency_id = _p.company.currency_id.id currency_obj = self.pool.get('res.currency') alt_curr_ids = currency_obj.search(self.cr, self.uid, [('alt_currency', '=', True)]) alt_curr_id = alt_curr_ids and alt_curr_ids[0] or False usd_curr_ids = currency_obj.search(self.cr, self.uid, [('name', '=', 'USD')]) usd_curr_id = usd_curr_ids and usd_curr_ids[0] or False display_curr_columns = data.get('form',{}).get('display_curr_columns', False) and \ (alt_curr_id and base_currency_id != alt_curr_id or False) or False ## Alternative currency rate options context.update({ 'curr_rate_option': data.get('form', {}).get('curr_rate_option', False), 'curr_rate_date': data.get('form', {}).get('curr_rate_date', False), 'curr_rate': data.get('form', {}).get('curr_rate', False), }) # Header Table cell_format = _xs['bold'] + _xs['fill_blue'] + _xs['borders_all'] cell_style = xlwt.easyxf(cell_format) cell_style_center = xlwt.easyxf(cell_format + _xs['center']) c_specs = [ ('coa', 2, 0, 'text', _('Chart of Account')), ('fy', 1, 0, 'text', _('Fiscal Year')), ('df', 3, 0, 'text', _p.filter_form(data) == 'filter_date' and _('Dates Filter') or _('Periods Filter')), ('af', 2, 0, 'text', _('Accounts Filter')), ('tm', 1, 0, 'text', _('Target Moves')), ('ib', 1, 0, 'text', _('Initial Balance')), ] if data.get('form', {}).get('filter_partner_ids', False): c_specs += [('partf', 2, 0, 'text', _('Partners Filter'))] if data.get('form', {}).get('filter_operating_unit_ids', False): c_specs += [('ouf', 2, 0, 'text', _('Operating Units Filter'))] if display_curr_columns: c_specs += [('altc', 2, 0, 'text', _('Alt. Currency'))] c_specs += [('altcro', 2, 0, 'text', _('Alt. Curr. Rate Option'))] row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs]) row_pos = self.xls_write_row(ws, row_pos, row_data, row_style=cell_style_center) cell_format = _xs['borders_all'] cell_style = xlwt.easyxf(cell_format) cell_style_center = xlwt.easyxf(cell_format + _xs['center']) c_specs = [ ('coa', 2, 0, 'text', _p.chart_account.name), ('fy', 1, 0, 'text', _p.fiscalyear.name if _p.fiscalyear else '-'), ] df = _('From') + ': ' if _p.filter_form(data) == 'filter_date': df += _p.start_date if _p.start_date else u'' else: df += _p.start_period.name if _p.start_period else u'' df += ' ' + _('To') + ': ' if _p.filter_form(data) == 'filter_date': df += _p.stop_date if _p.stop_date else u'' else: df += _p.stop_period.name if _p.stop_period else u'' c_specs += [ ('df', 3, 0, 'text', df), ('af', 2, 0, 'text', _p.accounts(data) and ', '.join([account.code for account in _p.accounts(data)]) or _('All')), ('tm', 1, 0, 'text', _p.display_target_move(data)), ('ib', 1, 0, 'text', initial_balance_text[_p.initial_balance_mode]), ] # if data.get('form',{}).get('filter_location_ids', False): # c_specs += [('locf', 2, 0, 'text', ', '.join(data['form']['filter_location_names']) )] if data.get('form', {}).get('filter_partner_ids', False): c_specs += [('partf', 2, 0, 'text', ', '.join(data['form']['filter_partner_names']))] if data.get('form', {}).get('filter_operating_unit_ids', False): c_specs += [ ('ouf', 2, 0, 'text', ', '.join(data['form']['filter_operating_unit_names'])) ] if display_curr_columns: c_specs += [('altc', 2, 0, 'text', currency_obj.read(self.cr, self.uid, alt_curr_id, ['name'])['name'])] rate_option = _("Transaction Date") if data.get('form', {}).get('curr_rate_option', False) == 'set_date': rate_option = _("Custom Date: ") + data.get('form', {}).get( 'curr_rate_date', '') elif data.get('form', {}).get('curr_rate_option', False) == 'set_curr_rate': rate_option = _("Currency Rate: ") + str( data.get('form', {}).get('curr_rate', 0.0)) c_specs += [('altcro', 2, 0, 'text', rate_option)] row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs]) row_pos = self.xls_write_row(ws, row_pos, row_data, row_style=cell_style_center) ws.set_horz_split_pos(row_pos) row_pos += 1 # Column Title Row cell_format = _xs['bold'] c_title_cell_style = xlwt.easyxf(cell_format) # Column Header Row cell_format = _xs['bold'] + _xs['fill'] + _xs['borders_all'] c_hdr_cell_style = xlwt.easyxf(cell_format) c_hdr_cell_style_right = xlwt.easyxf(cell_format + _xs['right']) c_hdr_cell_style_center = xlwt.easyxf(cell_format + _xs['center']) c_hdr_cell_style_decimal = xlwt.easyxf( cell_format + _xs['right'], num_format_str=report_xls.decimal_format) # Column Initial Balance Row cell_format = _xs['italic'] + _xs['borders_all'] c_init_cell_style = xlwt.easyxf(cell_format) c_init_cell_style_decimal = xlwt.easyxf( cell_format + _xs['right'], num_format_str=report_xls.decimal_format) c_specs = [ ('date', 1, 0, 'text', _('Date'), None, c_hdr_cell_style), ('period', 1, 0, 'text', _('Period'), None, c_hdr_cell_style), ('move', 1, 0, 'text', _('Entry'), None, c_hdr_cell_style), ('journal', 1, 0, 'text', _('Journal'), None, c_hdr_cell_style), ('account_code', 1, 0, 'text', _('Account'), None, c_hdr_cell_style), ('partner', 1, 0, 'text', _('Customer'), None, c_hdr_cell_style), ] # if data.get('form',{}).get('filter_location_ids', False): # c_specs += [('location', 1, 0, 'text', _('Location'), None, c_hdr_cell_style)] c_specs += [ ('label', 1, 0, 'text', _('Label'), None, c_hdr_cell_style), ('ref', 1, 0, 'text', _('Reference'), None, c_hdr_cell_style), ('counterpart', 1, 0, 'text', _('Counterpart'), None, c_hdr_cell_style), ('debit', 1, 0, 'text', _('Debit'), None, c_hdr_cell_style_right), ('credit', 1, 0, 'text', _('Credit'), None, c_hdr_cell_style_right), ('cumul_bal', 1, 0, 'text', _('Cumul. Bal.'), None, c_hdr_cell_style_right), ] if display_curr_columns: c_specs += [ ('curr_debit', 1, 0, 'text', _('Curr. Debit'), None, c_hdr_cell_style_right), ('curr_credit', 1, 0, 'text', _('Curr. Credit'), None, c_hdr_cell_style_right), ('curr_cumul_bal', 1, 0, 'text', _('Curr. Cumul. Bal.'), None, c_hdr_cell_style_right), ] if _p.amount_currency(data): c_specs += [ ('curr_bal', 1, 0, 'text', _('Curr. Bal.'), None, c_hdr_cell_style_right), ('curr_code', 1, 0, 'text', _('Curr.'), None, c_hdr_cell_style_center), ] c_specs += [('move_ref', 1, 0, 'text', _('Move Ref.'), None, c_hdr_cell_style)] c_hdr_data = self.xls_row_template(c_specs, [x[0] for x in c_specs]) # cell styles for ledger lines ll_cell_format = _xs['borders_all'] ll_cell_style = xlwt.easyxf(ll_cell_format) ll_cell_style_center = xlwt.easyxf(ll_cell_format + _xs['center']) ll_cell_style_date = xlwt.easyxf(ll_cell_format + _xs['left'], num_format_str=report_xls.date_format) ll_cell_style_decimal = xlwt.easyxf( ll_cell_format + _xs['right'], num_format_str=report_xls.decimal_format) account_move_obj = self.pool.get('account.move') account_move_line_obj = self.pool.get('account.move.line') account_voucher_obj = self.pool.get('account.voucher') invoice_obj = self.pool.get('account.invoice') cnt = 0 ## Excel 2003 Límite Número de filas => 65.536 rows_qty = sum([len(v) for v in _p['ledger_lines'].values()]) if rows_qty > 65535: raise osv.except_osv( u'Advertencia', u'Excel (*.xls) no permite más de 65 mil filas, por favor agregue filtros para reducir la cantidad de registros.' ) ## for account in objects: display_initial_balance = _p['init_balance'][account.id] #display_initial_balance = _p['init_balance'][account.id] and \ # (_p['init_balance'][account.id].get( # 'debit', 0.0) != 0.0 or # _p['init_balance'][account.id].get('credit', 0.0) # != 0.0) display_ledger_lines = _p['ledger_lines'][account.id] if _p.display_account_raw(data) == 'all' or \ (display_ledger_lines or display_initial_balance): ### cnt += 1 cumul_debit = 0.0 cumul_credit = 0.0 cumul_balance = 0.0 cumul_balance_curr = 0.0 if display_curr_columns: cumul_alt_curr_balance = 0.0 c_specs = [ ('acc_title', 10, 0, 'text', ' - '.join([account.code, account.name])), ] row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs]) row_pos = self.xls_write_row(ws, row_pos, row_data, c_title_cell_style) row_pos = self.xls_write_row(ws, row_pos, c_hdr_data) row_start = row_pos if display_initial_balance: init_balance = _p['init_balance'][account.id] cumul_debit = init_balance.get('debit') or 0.0 cumul_credit = init_balance.get('credit') or 0.0 cumul_balance = init_balance.get('init_balance') or 0.0 cumul_balance_curr = init_balance.get( 'init_balance_currency') or 0.0 c_specs = [('empty%s' % x, 1, 0, 'text', None) for x in range(6)] c_specs += [ ('init_bal', 1, 0, 'text', _('Initial Balance')), ('ref', 1, 0, 'text', None), ('counterpart', 1, 0, 'text', None), ('debit', 1, 0, 'number', cumul_debit, None, c_init_cell_style_decimal), ('credit', 1, 0, 'number', cumul_credit, None, c_init_cell_style_decimal), ('cumul_bal', 1, 0, 'number', cumul_balance, None, c_init_cell_style_decimal), ] if display_curr_columns: if context.get( 'curr_rate_option' ) == 'trans_date' and alt_curr_id == usd_curr_id: curr_cumul_debit = init_balance.get( 'usd_debit') or 0.0 curr_cumul_credit = init_balance.get( 'usd_credit') or 0.0 cumul_alt_curr_balance = init_balance.get( 'usd_init_balance') or 0.0 else: curr_cumul_debit = compute_amounts_in_currency( self, self.cr, self.uid, cumul_debit, base_currency_id, alt_curr_id, context=context) curr_cumul_credit = compute_amounts_in_currency( self, self.cr, self.uid, cumul_credit, base_currency_id, alt_curr_id, context=context) cumul_alt_curr_balance = compute_amounts_in_currency( self, self.cr, self.uid, cumul_balance, base_currency_id, alt_curr_id, context=context) c_specs += [ ('curr_debit', 1, 0, 'number', curr_cumul_debit, None, c_init_cell_style_decimal), ('curr_credit', 1, 0, 'number', curr_cumul_credit, None, c_init_cell_style_decimal), ('curr_cumul_bal', 1, 0, 'number', cumul_alt_curr_balance, None, c_init_cell_style_decimal), ] if _p.amount_currency(data): c_specs += [ ('curr_bal', 1, 0, 'number', cumul_balance_curr, None, c_init_cell_style_decimal), ('curr_code', 1, 0, 'text', None), ] row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs]) row_pos = self.xls_write_row(ws, row_pos, row_data, c_init_cell_style) for line in _p['ledger_lines'][account.id]: cumul_debit += line.get('debit') or 0.0 cumul_credit += line.get('credit') or 0.0 cumul_balance_curr += line.get('amount_currency') or 0.0 cumul_balance += line.get('balance') or 0.0 label_elements = [line.get('lname') or ''] ref_elements = [] # Origin of this Journal Item move_id = line.get('move_id', False) if line.get('invoice_id', False): # Check for invoice if line.get('invoice_type', False) == 'out_invoice': ref_elements.append( "%s" % (u"Factura Cliente " + (line.get('invoice_number') or ''))) elif line.get('invoice_type', False) == 'out_refund': ref_elements.append( "%s" % (u"Nota de Crédito Cliente " + (line.get('invoice_number') or ''))) else: s_inv_nbr = invoice_obj.read( self.cr, self.uid, [line['invoice_id']], ['supplier_invoice_number' ])[0]['supplier_invoice_number'] if line.get('invoice_type', False) == 'in_invoice': ref_elements.append( "%s" % (u"Factura Proveedor " + (s_inv_nbr and s_inv_nbr or (line.get('invoice_number') or '')))) elif line.get('invoice_type', False) == 'in_refund': ref_elements.append( "%s" % (u"Nota de Crédito Proveedor " + (s_inv_nbr and s_inv_nbr or (line.get('invoice_number') or '')))) else: # Check for voucher if move_id: voucher_ids = account_voucher_obj.search( self.cr, self.uid, [('move_id', '=', move_id)]) if voucher_ids: voucher = account_voucher_obj.browse( self.cr, self.uid, voucher_ids[0]) if voucher.journal_id.type in [ 'bank', 'cash' ] and voucher.type == 'receipt': ref_elements.append( u"Pago Cliente %s" % (voucher.number or voucher.reference)) if voucher.journal_id.type in [ 'bank', 'cash' ] and voucher.type == 'payment': ref_elements.append( u"Pago Proveedor %s" % (voucher.number or voucher.reference)) if voucher.journal_id.type in [ 'sale', 'sale_refund' ] and voucher.type == 'sale': ref_elements.append( u"Recibo de venta %s" % (voucher.number or voucher.reference)) if voucher.journal_id.type in [ 'purchase', 'purchase_refund' ] and voucher.type == 'purchase': ref_elements.append( u"Recibo de compra %s" % (voucher.number or voucher.reference)) if not ref_elements and line.get('lref', False): ref_elements.append("%s" % (line['lref'])) label = ' '.join(label_elements) reference = ' '.join(ref_elements) if line.get('ldate'): c_specs = [ ('ldate', 1, 0, 'date', datetime.strptime(line['ldate'], '%Y-%m-%d'), None, ll_cell_style_date), ] else: c_specs = [ ('ldate', 1, 0, 'text', None), ] c_specs += [ ('period', 1, 0, 'text', line.get('period_code') or ''), ('move', 1, 0, 'text', line.get('move_name') or ''), ('journal', 1, 0, 'text', line.get('jcode') or ''), ('account_code', 1, 0, 'text', account.code), ('partner', 1, 0, 'text', line.get('partner_name') or ''), ('label', 1, 0, 'text', label), ('ref', 1, 0, 'text', reference), ('counterpart', 1, 0, 'text', line.get('counterparts') or ''), ('debit', 1, 0, 'number', line.get('debit', 0.0), None, ll_cell_style_decimal), ('credit', 1, 0, 'number', line.get('credit', 0.0), None, ll_cell_style_decimal), ('cumul_bal', 1, 0, 'number', cumul_balance, None, ll_cell_style_decimal), ] if display_curr_columns: curr_debit = line.get('curr_debit', 0.0) curr_credit = line.get('curr_credit', 0.0) #is_change_diff = account_move_line_obj.read(self.cr, self.uid, line['id'], ['change_diff'])['change_diff'] #curr_debit = 0.0 #curr_credit = 0.0 #if line.get('debit', 0.0) and line.get('currency_id', False)==alt_curr_id: # curr_debit = line.get('amount_currency') < 0 and -line.get('amount_currency') or (line.get('amount_currency') or 0.0) #else: # if not is_change_diff: # curr_debit = compute_amounts_in_currency(self, self.cr, self.uid, line.get('debit', 0.0), base_currency_id, alt_curr_id, date=line.get('ldate', False), context=context) #if line.get('credit', 0.0) and line.get('currency_id', False)==alt_curr_id: # curr_credit = line.get('amount_currency') < 0 and -line.get('amount_currency') or (line.get('amount_currency') or 0.0) #else: # if not is_change_diff: # curr_credit = compute_amounts_in_currency(self, self.cr, self.uid, line.get('credit', 0.0), base_currency_id, alt_curr_id, date=line.get('ldate', False), context=context) cumul_alt_curr_balance += curr_debit - curr_credit c_specs += [ ('curr_debit', 1, 0, 'number', curr_debit, None, ll_cell_style_decimal), ('curr_credit', 1, 0, 'number', curr_credit, None, ll_cell_style_decimal), ('curr_cumul_bal', 1, 0, 'number', cumul_alt_curr_balance, None, ll_cell_style_decimal), ] if _p.amount_currency(data): c_specs += [ ('curr_bal', 1, 0, 'number', line.get('amount_currency') or 0.0, None, ll_cell_style_decimal), ('curr_code', 1, 0, 'text', line.get('currency_code') or '', None, ll_cell_style_center), ] if move_id: move_ref = account_move_obj.browse( self.cr, self.uid, move_id).ref or '' else: move_ref = '' c_specs += [('move_ref', 1, 0, 'text', move_ref, None)] row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs]) row_pos = self.xls_write_row(ws, row_pos, row_data, ll_cell_style) debit_start = rowcol_to_cell(row_start, 9) debit_end = rowcol_to_cell(row_pos - 1, 9) debit_formula = 'SUM(' + debit_start + ':' + debit_end + ')' credit_start = rowcol_to_cell(row_start, 10) credit_end = rowcol_to_cell(row_pos - 1, 10) credit_formula = 'SUM(' + credit_start + ':' + credit_end + ')' balance_debit = rowcol_to_cell(row_pos, 9) balance_credit = rowcol_to_cell(row_pos, 10) balance_formula = balance_debit + '-' + balance_credit c_specs = [ ('acc_title', 7, 0, 'text', ' - '.join([account.code, account.name])), ('cum_bal', 2, 0, 'text', _('Cumulated Balance on Account'), None, c_hdr_cell_style_right), ('debit', 1, 0, 'number', None, debit_formula, c_hdr_cell_style_decimal), ('credit', 1, 0, 'number', None, credit_formula, c_hdr_cell_style_decimal), ('balance', 1, 0, 'number', None, balance_formula, c_hdr_cell_style_decimal), ] if display_curr_columns: curr_debit_start = rowcol_to_cell(row_start, 12) curr_debit_end = rowcol_to_cell(row_pos - 1, 12) curr_debit_formula = 'SUM(' + curr_debit_start + ':' + curr_debit_end + ')' curr_credit_start = rowcol_to_cell(row_start, 13) curr_credit_end = rowcol_to_cell(row_pos - 1, 13) curr_credit_formula = 'SUM(' + curr_credit_start + ':' + curr_credit_end + ')' curr_balance_debit = rowcol_to_cell(row_pos, 12) curr_balance_credit = rowcol_to_cell(row_pos, 13) curr_balance_formula = curr_balance_debit + '-' + curr_balance_credit c_specs += [ ('curr_debit', 1, 0, 'number', None, curr_debit_formula, c_hdr_cell_style_decimal), ('curr_credit', 1, 0, 'number', None, curr_credit_formula, c_hdr_cell_style_decimal), ('curr_balance', 1, 0, 'number', None, curr_balance_formula, c_hdr_cell_style_decimal), ] if _p.amount_currency(data): if account.currency_id: c_specs += [ ('curr_bal', 1, 0, 'number', cumul_balance_curr, None, c_hdr_cell_style_decimal) ] else: c_specs += [('curr_bal', 1, 0, 'text', None)] c_specs += [('curr_code', 1, 0, 'text', None)] row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs]) row_pos = self.xls_write_row(ws, row_pos, row_data, c_hdr_cell_style) row_pos += 1