Browse Source

[pep8] - account_financial_report_webkit_xls

pull/6/head
laetitia.gangloff@acsone.eu 11 years ago
parent
commit
23e9b1534e
  1. 4
      account_financial_report_webkit_xls/__init__.py
  2. 183
      account_financial_report_webkit_xls/report/general_ledger_xls.py
  3. 585
      account_financial_report_webkit_xls/report/open_invoices_xls.py
  4. 272
      account_financial_report_webkit_xls/report/partner_ledger_xls.py
  5. 273
      account_financial_report_webkit_xls/report/partners_balance_xls.py
  6. 183
      account_financial_report_webkit_xls/report/trial_balance_xls.py
  7. 5
      account_financial_report_webkit_xls/wizard/general_ledger_wizard.py
  8. 4
      account_financial_report_webkit_xls/wizard/open_invoices_wizard.py
  9. 8
      account_financial_report_webkit_xls/wizard/partners_balance_wizard.py
  10. 4
      account_financial_report_webkit_xls/wizard/partners_ledger_wizard.py
  11. 5
      account_financial_report_webkit_xls/wizard/trial_balance_wizard.py

4
account_financial_report_webkit_xls/__init__.py

@ -25,5 +25,5 @@ try:
from . import report from . import report
except ImportError: except ImportError:
import logging import logging
logging.getLogger('openerp.module').warning('report_xls not available in addons path. account_financial_report_webkit_xls will not be usable')
logging.getLogger('openerp.module').warning('''report_xls not available in
addons path. account_financial_report_webkit_xls will not be usable''')

183
account_financial_report_webkit_xls/report/general_ledger_xls.py

@ -21,12 +21,11 @@
############################################################################## ##############################################################################
import xlwt import xlwt
import time
from datetime import datetime from datetime import datetime
from openerp.report import report_sxw
from openerp.addons.report_xls.report_xls import report_xls from openerp.addons.report_xls.report_xls import report_xls
from openerp.addons.report_xls.utils import rowcol_to_cell from openerp.addons.report_xls.utils import rowcol_to_cell
from openerp.addons.account_financial_report_webkit.report.general_ledger import GeneralLedgerWebkit
from openerp.addons.account_financial_report_webkit.report.general_ledger\
import GeneralLedgerWebkit
from openerp.tools.translate import _ from openerp.tools.translate import _
#import logging #import logging
#_logger = logging.getLogger(__name__) #_logger = logging.getLogger(__name__)
@ -47,6 +46,7 @@ _column_sizes = [
('curr_code', 7), ('curr_code', 7),
] ]
class general_ledger_xls(report_xls): class general_ledger_xls(report_xls):
column_sizes = [x[1] for x in _column_sizes] column_sizes = [x[1] for x in _column_sizes]
@ -64,22 +64,29 @@ class general_ledger_xls(report_xls):
ws.footer_str = self.xls_footers['standard'] ws.footer_str = self.xls_footers['standard']
# cf. account_report_general_ledger.mako # cf. account_report_general_ledger.mako
initial_balance_text = {'initial_balance': _('Computed'), 'opening_balance': _('Opening Entries'), False: _('No')}
initial_balance_text = {'initial_balance': _('Computed'),
'opening_balance': _('Opening Entries'),
False: _('No')}
# Title # Title
cell_style = xlwt.easyxf(_xs['xls_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])
report_name = ' - '.join([_p.report_name.upper(),
_p.company.partner_id.name,
_p.company.currency_id.name])
c_specs = [ c_specs = [
('report_name', 1, 0, 'text', report_name), ('report_name', 1, 0, 'text', report_name),
] ]
row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs]) 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 = self.xls_write_row(
ws, row_pos, row_data, row_style=cell_style)
# write empty row to define column sizes # write empty row to define column sizes
c_sizes = self.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))]
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_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)
row_pos = self.xls_write_row(
ws, row_pos, row_data, set_column_size=True)
# Header Table # Header Table
cell_format = _xs['bold'] + _xs['fill_blue'] + _xs['borders_all'] cell_format = _xs['bold'] + _xs['fill_blue'] + _xs['borders_all']
@ -88,14 +95,16 @@ class general_ledger_xls(report_xls):
c_specs = [ c_specs = [
('coa', 2, 0, 'text', _('Chart of Account')), ('coa', 2, 0, 'text', _('Chart of Account')),
('fy', 1, 0, 'text', _('Fiscal Year')), ('fy', 1, 0, 'text', _('Fiscal Year')),
('df', 3, 0, 'text', _p.filter_form(data) == 'filter_date' and _('Dates Filter') or _('Periods Filter')),
('df', 3, 0, 'text', _p.filter_form(data) ==
'filter_date' and _('Dates Filter') or _('Periods Filter')),
('af', 1, 0, 'text', _('Accounts Filter')), ('af', 1, 0, 'text', _('Accounts Filter')),
('tm', 2, 0, 'text', _('Target Moves')), ('tm', 2, 0, 'text', _('Target Moves')),
('ib', 2, 0, 'text', _('Initial Balance')), ('ib', 2, 0, 'text', _('Initial Balance')),
] ]
row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs]) 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 = self.xls_write_row(
ws, row_pos, row_data, row_style=cell_style_center)
cell_format = _xs['borders_all'] cell_format = _xs['borders_all']
cell_style = xlwt.easyxf(cell_format) cell_style = xlwt.easyxf(cell_format)
@ -116,12 +125,15 @@ class general_ledger_xls(report_xls):
df += _p.stop_period.name if _p.stop_period else u'' df += _p.stop_period.name if _p.stop_period else u''
c_specs += [ c_specs += [
('df', 3, 0, 'text', df), ('df', 3, 0, 'text', df),
('af', 1, 0, 'text', _p.accounts(data) and ', '.join([account.code for account in _p.accounts(data)]) or _('All')),
('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)), ('tm', 2, 0, 'text', _p.display_target_move(data)),
('ib', 2, 0, 'text', initial_balance_text[_p.initial_balance_mode]),
('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_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 = self.xls_write_row(
ws, row_pos, row_data, row_style=cell_style_center)
ws.set_horz_split_pos(row_pos) ws.set_horz_split_pos(row_pos)
row_pos += 1 row_pos += 1
@ -134,32 +146,41 @@ class general_ledger_xls(report_xls):
c_hdr_cell_style = xlwt.easyxf(cell_format) c_hdr_cell_style = xlwt.easyxf(cell_format)
c_hdr_cell_style_right = xlwt.easyxf(cell_format + _xs['right']) 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_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)
c_hdr_cell_style_decimal = xlwt.easyxf(cell_format + _xs['right'],
num_format_str=report_xls.decimal_format)
# Column Initial Balance Row # Column Initial Balance Row
cell_format = _xs['italic'] + _xs['borders_all'] cell_format = _xs['italic'] + _xs['borders_all']
c_init_cell_style = xlwt.easyxf(cell_format) c_init_cell_style = xlwt.easyxf(cell_format)
c_init_cell_style_right = xlwt.easyxf(cell_format + _xs['right']) 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_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_init_cell_style_decimal = xlwt.easyxf(
cell_format + _xs['right'],
num_format_str=report_xls.decimal_format)
c_specs = [ c_specs = [
('date', 1, 0, 'text', _('Date'), None, c_hdr_cell_style), ('date', 1, 0, 'text', _('Date'), None, c_hdr_cell_style),
('period', 1, 0, 'text', _('Period'), 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), ('move', 1, 0, 'text', _('Entry'), None, c_hdr_cell_style),
('journal', 1, 0, 'text', _('Journal'), 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),
('account_code', 1, 0, 'text',
_('Account'), None, c_hdr_cell_style),
('partner', 1, 0, 'text', _('Partner'), 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), ('label', 1, 0, 'text', _('Label'), None, c_hdr_cell_style),
('counterpart', 1, 0, 'text', _('Counterpart'), 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), ('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),
('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): if _p.amount_currency(data):
c_specs += [ 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),
('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]) c_hdr_data = self.xls_row_template(c_specs, [x[0] for x in c_specs])
@ -168,16 +189,24 @@ class general_ledger_xls(report_xls):
ll_cell_style = xlwt.easyxf(ll_cell_format) ll_cell_style = xlwt.easyxf(ll_cell_format)
ll_cell_style_right = xlwt.easyxf(ll_cell_format + _xs['right']) 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_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)
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 cnt = 0
for account in objects: 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_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 display_ledger_lines = account.ledger_lines
if _p.display_account_raw(data) == 'all' or (display_ledger_lines or display_initial_balance):
if _p.display_account_raw(data) == 'all' or\
(display_ledger_lines or display_initial_balance):
# TO DO : replace cumul amounts by xls formulas # TO DO : replace cumul amounts by xls formulas
cnt += 1 cnt += 1
cumul_debit = 0.0 cumul_debit = 0.0
@ -185,36 +214,48 @@ class general_ledger_xls(report_xls):
cumul_balance = 0.0 cumul_balance = 0.0
cumul_balance_curr = 0.0 cumul_balance_curr = 0.0
c_specs = [ c_specs = [
('acc_title', 11, 0, 'text', ' - '.join([account.code, account.name])),
('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_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_pos = self.xls_write_row(ws, row_pos, c_hdr_data)
row_start = row_pos row_start = row_pos
if display_initial_balance: if display_initial_balance:
cumul_debit = account.init_balance.get('debit') or 0.0 cumul_debit = account.init_balance.get('debit') or 0.0
cumul_credit = account.init_balance.get('credit') 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
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) debit_cell = rowcol_to_cell(row_pos, 8)
credit_cell = rowcol_to_cell(row_pos, 9) credit_cell = rowcol_to_cell(row_pos, 9)
bal_formula = debit_cell + '-' + credit_cell bal_formula = debit_cell + '-' + credit_cell
c_specs = [('empty%s' %x, 1, 0, 'text', None) for x in range(6)]
c_specs = [('empty%s' % x, 1, 0, 'text', None)
for x in range(6)]
c_specs += [ c_specs += [
('init_bal', 1, 0, 'text', _('Initial Balance')), ('init_bal', 1, 0, 'text', _('Initial Balance')),
('counterpart', 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),
('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): if _p.amount_currency(data):
c_specs += [ c_specs += [
('curr_bal', 1, 0, 'number', cumul_balance_curr, None, c_init_cell_style_decimal),
('curr_bal', 1, 0, 'number', cumul_balance_curr,
None, c_init_cell_style_decimal),
('curr_code', 1, 0, 'text', None), ('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)
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: for line in account.ledger_lines:
@ -224,36 +265,51 @@ class general_ledger_xls(report_xls):
cumul_balance += line.get('balance') or 0.0 cumul_balance += line.get('balance') or 0.0
label_elements = [line.get('lname') or ''] label_elements = [line.get('lname') or '']
if line.get('invoice_number'): if line.get('invoice_number'):
label_elements.append("(%s)" % (line['invoice_number'],))
label_elements.append(
"(%s)" % (line['invoice_number'],))
label = ' '.join(label_elements) label = ' '.join(label_elements)
if line.get('ldate'): if line.get('ldate'):
c_specs = [ c_specs = [
('ldate', 1, 0, 'date', datetime.strptime(line['ldate'],'%Y-%m-%d'), None, ll_cell_style_date),
('ldate', 1, 0, 'date', datetime.strptime(
line['ldate'], '%Y-%m-%d'), None,
ll_cell_style_date),
] ]
else: else:
c_specs = [ c_specs = [
('ldate', 1, 0, 'text', None), ('ldate', 1, 0, 'text', None),
] ]
c_specs += [ c_specs += [
('period', 1, 0, 'text', line.get('period_code') or ''),
('period', 1, 0, 'text',
line.get('period_code') or ''),
('move', 1, 0, 'text', line.get('move_name') or ''), ('move', 1, 0, 'text', line.get('move_name') or ''),
('journal', 1, 0, 'text', line.get('jcode') or ''), ('journal', 1, 0, 'text', line.get('jcode') or ''),
('account_code', 1, 0, 'text', account.code), ('account_code', 1, 0, 'text', account.code),
('partner', 1, 0, 'text', line.get('partner_name') or ''),
('partner', 1, 0, 'text',
line.get('partner_name') or ''),
('label', 1, 0, 'text', label), ('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),
('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): if _p.amount_currency(data):
c_specs += [ 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),
('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)
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_start = rowcol_to_cell(row_start, 8)
debit_end = rowcol_to_cell(row_pos - 1, 8) debit_end = rowcol_to_cell(row_pos - 1, 8)
@ -265,22 +321,33 @@ class general_ledger_xls(report_xls):
balance_credit = rowcol_to_cell(row_pos, 9) balance_credit = rowcol_to_cell(row_pos, 9)
balance_formula = balance_debit + '-' + balance_credit balance_formula = balance_debit + '-' + balance_credit
c_specs = [ 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),
('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 _p.amount_currency(data):
if account.currency_id: if account.currency_id:
c_specs += [('curr_bal', 1, 0, 'number', cumul_balance_curr, None, c_hdr_cell_style_decimal)]
c_specs += [('curr_bal', 1, 0, 'number',
cumul_balance_curr, None,
c_hdr_cell_style_decimal)]
else: else:
c_specs += [('curr_bal', 1, 0, 'text', None)] c_specs += [('curr_bal', 1, 0, 'text', None)]
c_specs += [('curr_code', 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_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 row_pos += 1
general_ledger_xls('report.account.account_report_general_ledger_xls', 'account.account',
general_ledger_xls('report.account.account_report_general_ledger_xls',
'account.account',
parser=GeneralLedgerWebkit) parser=GeneralLedgerWebkit)
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

585
account_financial_report_webkit_xls/report/open_invoices_xls.py

@ -21,21 +21,22 @@
############################################################################## ##############################################################################
import xlwt import xlwt
import time
from datetime import datetime from datetime import datetime
from openerp.report import report_sxw
from openerp.addons.report_xls.report_xls import report_xls from openerp.addons.report_xls.report_xls import report_xls
from openerp.addons.report_xls.utils import rowcol_to_cell from openerp.addons.report_xls.utils import rowcol_to_cell
from openerp.addons.account_financial_report_webkit.report.open_invoices import PartnersOpenInvoicesWebkit
from openerp.addons.account_financial_report_webkit.report.open_invoices\
import PartnersOpenInvoicesWebkit
from openerp.tools.translate import _ from openerp.tools.translate import _
#import logging #import logging
#_logger = logging.getLogger(__name__) #_logger = logging.getLogger(__name__)
class open_invoices_xls(report_xls): class open_invoices_xls(report_xls):
column_sizes = [12, 12, 20, 15, 30, 30, 14, 14, 14, 14, 14, 14, 10] column_sizes = [12, 12, 20, 15, 30, 30, 14, 14, 14, 14, 14, 14, 10]
def global_initializations(self, wb, _p, xlwt, _xs, objects, data): def global_initializations(self, wb, _p, xlwt, _xs, objects, data):
# this procedure will initialise variables and Excel cell styles and return them as global ones
# this procedure will initialise variables and Excel cell styles and
# return them as global ones
global ws global ws
ws = wb.add_sheet(_p.report_name[:31]) ws = wb.add_sheet(_p.report_name[:31])
ws.panes_frozen = True ws.panes_frozen = True
@ -45,9 +46,14 @@ class open_invoices_xls(report_xls):
ws.header_str = self.xls_headers['standard'] ws.header_str = self.xls_headers['standard']
ws.footer_str = self.xls_footers['standard'] ws.footer_str = self.xls_footers['standard']
#------------------------------------------------------- #-------------------------------------------------------
global nbr_columns #number of columns is 11 in case of normal report, 13 in case the option currency is selected and 12 in case of the regroup by currency option is checked
# number of columns is 11 in case of normal report, 13 in case the
# option currency is selected and 12 in case of the regroup by currency
# option is checked
global nbr_columns
group_lines = False group_lines = False
for acc in objects: #search if the regroup option is selected by browsing the accounts defined in objects - see account_report_open_invoices.mako
# search if the regroup option is selected by browsing the accounts
# defined in objects - see account_report_open_invoices.mako
for acc in objects:
if hasattr(acc, 'grouped_ledger_lines'): if hasattr(acc, 'grouped_ledger_lines'):
group_lines = True group_lines = True
if group_lines: if group_lines:
@ -70,98 +76,151 @@ class open_invoices_xls(report_xls):
style_bold = xlwt.easyxf(_xs['bold'] + _xs['borders_all']) style_bold = xlwt.easyxf(_xs['bold'] + _xs['borders_all'])
#------------------------------------------------------- #-------------------------------------------------------
global style_bold_center global style_bold_center
style_bold_center = xlwt.easyxf(_xs['bold'] + _xs['borders_all'] + _xs['center'])
style_bold_center = xlwt.easyxf(
_xs['bold'] + _xs['borders_all'] + _xs['center'])
#------------------------------------------------------- #-------------------------------------------------------
global style_bold_italic global style_bold_italic
style_bold_italic = xlwt.easyxf(_xs['bold'] + _xs['borders_all'] + _xs['italic'])
style_bold_italic = xlwt.easyxf(
_xs['bold'] + _xs['borders_all'] + _xs['italic'])
#------------------------------------------------------- #-------------------------------------------------------
global style_bold_italic_decimal global style_bold_italic_decimal
style_bold_italic_decimal = xlwt.easyxf(_xs['bold'] + _xs['borders_all'] + _xs['italic'] + _xs['right'], num_format_str = report_xls.decimal_format)
style_bold_italic_decimal = xlwt.easyxf(
_xs['bold'] + _xs['borders_all'] + _xs['italic'] + _xs['right'],
num_format_str=report_xls.decimal_format)
#------------------------------------------------------- #-------------------------------------------------------
global style_bold_blue global style_bold_blue
style_bold_blue = xlwt.easyxf(_xs['bold'] + _xs['fill_blue'] + _xs['borders_all'] )
style_bold_blue = xlwt.easyxf(
_xs['bold'] + _xs['fill_blue'] + _xs['borders_all'])
#------------------------------------------------------- #-------------------------------------------------------
global style_bold_blue_italic_decimal global style_bold_blue_italic_decimal
style_bold_blue_italic_decimal = xlwt.easyxf(_xs['bold'] + _xs['fill_blue'] + _xs['borders_all'] + _xs['italic'], num_format_str = report_xls.decimal_format)
style_bold_blue_italic_decimal = xlwt.easyxf(
_xs['bold'] + _xs['fill_blue'] +
_xs['borders_all'] + _xs['italic'],
num_format_str=report_xls.decimal_format)
#------------------------------------------------------- #-------------------------------------------------------
global style_bold_blue_center #cell style for header titles: 'Chart of accounts' - 'Fiscal year' ...
style_bold_blue_center= xlwt.easyxf(_xs['bold'] + _xs['fill_blue'] + _xs['borders_all'] + _xs['center'])
# cell style for header titles: 'Chart of accounts' - 'Fiscal year' ...
global style_bold_blue_center
style_bold_blue_center = xlwt.easyxf(
_xs['bold'] + _xs['fill_blue'] + _xs['borders_all'] +
_xs['center'])
#------------------------------------------------------- #-------------------------------------------------------
global style_center #cell style for header data: 'Chart of accounts' - 'Fiscal year' ...
style_center = xlwt.easyxf(_xs['borders_all'] + _xs['wrap'] + _xs['center'])
# cell style for header data: 'Chart of accounts' - 'Fiscal year' ...
global style_center
style_center = xlwt.easyxf(
_xs['borders_all'] + _xs['wrap'] + _xs['center'])
#------------------------------------------------------- #-------------------------------------------------------
global style_yellow_bold #cell style for columns titles 'Date'- 'Period' - 'Entry'...
style_yellow_bold = xlwt.easyxf(_xs['bold'] + _xs['fill'] + _xs['borders_all'])
# cell style for columns titles 'Date'- 'Period' - 'Entry'...
global style_yellow_bold
style_yellow_bold = xlwt.easyxf(
_xs['bold'] + _xs['fill'] + _xs['borders_all'])
#------------------------------------------------------- #-------------------------------------------------------
global style_yellow_bold_right #cell style for columns titles 'Date'- 'Period' - 'Entry'...
style_yellow_bold_right = xlwt.easyxf(_xs['bold'] + _xs['fill'] + _xs['borders_all'] + _xs['right'])
# cell style for columns titles 'Date'- 'Period' - 'Entry'...
global style_yellow_bold_right
style_yellow_bold_right = xlwt.easyxf(
_xs['bold'] + _xs['fill'] + _xs['borders_all'] + _xs['right'])
#------------------------------------------------------- #-------------------------------------------------------
global style_right global style_right
style_right = xlwt.easyxf(_xs['borders_all'] + _xs['right']) style_right = xlwt.easyxf(_xs['borders_all'] + _xs['right'])
#------------------------------------------------------- #-------------------------------------------------------
global style_right_italic global style_right_italic
style_right_italic = xlwt.easyxf(_xs['borders_all'] + _xs['right'] + _xs['italic'])
style_right_italic = xlwt.easyxf(
_xs['borders_all'] + _xs['right'] + _xs['italic'])
#------------------------------------------------------- #-------------------------------------------------------
global style_decimal global style_decimal
style_decimal = xlwt.easyxf(_xs['borders_all'] + _xs['right'], num_format_str = report_xls.decimal_format)
style_decimal = xlwt.easyxf(
_xs['borders_all'] + _xs['right'],
num_format_str=report_xls.decimal_format)
#------------------------------------------------------- #-------------------------------------------------------
global style_decimal_italic global style_decimal_italic
style_decimal_italic = xlwt.easyxf(_xs['borders_all'] + _xs['right'] + _xs['italic'], num_format_str = report_xls.decimal_format)
style_decimal_italic = xlwt.easyxf(
_xs['borders_all'] + _xs['right'] + _xs['italic'],
num_format_str=report_xls.decimal_format)
#------------------------------------------------------- #-------------------------------------------------------
global style_date global style_date
style_date = xlwt.easyxf(_xs['borders_all'] + _xs['left'], num_format_str = report_xls.date_format)
style_date = xlwt.easyxf(
_xs['borders_all'] + _xs['left'],
num_format_str=report_xls.date_format)
#------------------------------------------------------- #-------------------------------------------------------
global style_date_italic global style_date_italic
style_date_italic = xlwt.easyxf(_xs['borders_all'] + _xs['left'] + _xs['italic'], num_format_str = report_xls.date_format)
style_date_italic = xlwt.easyxf(
_xs['borders_all'] + _xs['left'] + _xs['italic'],
num_format_str=report_xls.date_format)
#------------------------------------------------------- #-------------------------------------------------------
global style_account_title, style_account_title_right, style_account_title_decimal
cell_format = _xs['xls_title'] + _xs['bold'] + _xs['fill'] + _xs['borders_all']
global style_account_title, style_account_title_right,\
style_account_title_decimal
cell_format = _xs['xls_title'] + _xs['bold'] + \
_xs['fill'] + _xs['borders_all']
style_account_title = xlwt.easyxf(cell_format) style_account_title = xlwt.easyxf(cell_format)
style_account_title_right = xlwt.easyxf(cell_format + _xs['right']) style_account_title_right = xlwt.easyxf(cell_format + _xs['right'])
style_account_title_decimal = xlwt.easyxf(cell_format + _xs['right'], num_format_str = report_xls.decimal_format)
style_account_title_decimal = xlwt.easyxf(
cell_format + _xs['right'],
num_format_str=report_xls.decimal_format)
#------------------------------------------------------- #-------------------------------------------------------
global style_partner_row global style_partner_row
cell_format = _xs['bold'] cell_format = _xs['bold']
style_partner_row = xlwt.easyxf(cell_format) style_partner_row = xlwt.easyxf(cell_format)
#------------------------------------------------------- #-------------------------------------------------------
global style_partner_cumul, style_partner_cumul_right, style_partner_cumul_center, style_partner_cumul_decimal
global style_partner_cumul, style_partner_cumul_right,\
style_partner_cumul_center, style_partner_cumul_decimal
cell_format = _xs['bold'] + _xs['fill'] + _xs['borders_all'] cell_format = _xs['bold'] + _xs['fill'] + _xs['borders_all']
style_partner_cumul = xlwt.easyxf(cell_format) style_partner_cumul = xlwt.easyxf(cell_format)
style_partner_cumul_right = xlwt.easyxf(cell_format + _xs['right']) style_partner_cumul_right = xlwt.easyxf(cell_format + _xs['right'])
style_partner_cumul_center = xlwt.easyxf(cell_format + _xs['center']) style_partner_cumul_center = xlwt.easyxf(cell_format + _xs['center'])
style_partner_cumul_decimal = xlwt.easyxf(cell_format + _xs['right'], num_format_str = report_xls.decimal_format)
def print_title(self, _p, row_position): # print the first line "OPEN INVOICE REPORT - db name - Currency
report_name = ' - '.join([_p.report_name.upper(), _p.company.partner_id.name, _p.company.currency_id.name])
style_partner_cumul_decimal = xlwt.easyxf(
cell_format + _xs['right'],
num_format_str=report_xls.decimal_format)
# print the first line "OPEN INVOICE REPORT - db name - Currency
def print_title(self, _p, row_position):
report_name = ' - '.join([_p.report_name.upper(),
_p.company.partner_id.name,
_p.company.currency_id.name])
c_specs = [('report_name', nbr_columns, 0, 'text', report_name), ] c_specs = [('report_name', nbr_columns, 0, 'text', report_name), ]
row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs]) 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, row_style=style_font12)
row_position = self.xls_write_row(
ws, row_position, row_data, row_style=style_font12)
return row_position return row_position
def print_empty_row(self, row_position): #send an empty row to the Excel document
# send an empty row to the Excel document
def print_empty_row(self, row_position):
c_sizes = self.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))]
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_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, set_column_size=True)
row_position = self.xls_write_row(
ws, row_position, row_data, set_column_size=True)
return row_position return row_position
def print_header_titles(self, _p, data, row_position): #Fill in the titles of the header summary tables: Chart of account - Fiscal year - ...
# Fill in the titles of the header summary tables: Chart of account -
# Fiscal year - ...
def print_header_titles(self, _p, data, row_position):
c_specs = [ c_specs = [
('coa', 2, 0, 'text', _('Chart of Account'), None, style_bold_blue_center),
('fy', 2, 0, 'text', _('Fiscal Year'), None, style_bold_blue_center),
('df', 2, 0, 'text', _p.filter_form(data) == 'filter_date' and _('Dates Filter') or _('Periods Filter'), None, style_bold_blue_center),
('cd', 1 if nbr_columns == 11 else 2 , 0, 'text', _('Clearance Date'), None, style_bold_blue_center),
('af', 2, 0, 'text', _('Accounts Filter'), None, style_bold_blue_center),
('tm', 3 if nbr_columns == 13 else 2, 0, 'text', _('Target Moves'), None, style_bold_blue_center),
('coa', 2, 0, 'text', _('Chart of Account'),
None, style_bold_blue_center),
('fy', 2, 0, 'text', _('Fiscal Year'),
None, style_bold_blue_center),
('df', 2, 0, 'text', _p.filter_form(data) == 'filter_date' and _(
'Dates Filter') or _('Periods Filter'), None,
style_bold_blue_center),
('cd', 1 if nbr_columns == 11 else 2, 0, 'text',
_('Clearance Date'), None, style_bold_blue_center),
('af', 2, 0, 'text', _('Accounts Filter'),
None, style_bold_blue_center),
('tm', 3 if nbr_columns == 13 else 2, 0, 'text',
_('Target Moves'), None, style_bold_blue_center),
] ]
row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs]) 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, row_style=style_bold_blue_center)
row_position = self.xls_write_row(
ws, row_position, row_data, row_style=style_bold_blue_center)
return row_position return row_position
def print_header_data(self, _p, data, row_position): #Fill in the data of the header summary tables: Chart of account - Fiscal year - ...
# Fill in the data of the header summary tables: Chart of account - Fiscal
# year - ...
def print_header_data(self, _p, data, row_position):
c_specs = [ c_specs = [
('coa', 2, 0, 'text', _p.chart_account.name, None, style_center), ('coa', 2, 0, 'text', _p.chart_account.name, None, style_center),
('fy', 2, 0, 'text', _p.fiscalyear.name if _p.fiscalyear else '-', None, style_center),
('fy', 2, 0, 'text', _p.fiscalyear.name if _p.fiscalyear else '-',
None, style_center),
] ]
df = _('From') + ': ' df = _('From') + ': '
if _p.filter_form(data) == 'filter_date': if _p.filter_form(data) == 'filter_date':
@ -175,15 +234,22 @@ class open_invoices_xls(report_xls):
df += _p.stop_period.name if _p.stop_period else u'' df += _p.stop_period.name if _p.stop_period else u''
c_specs += [ c_specs += [
('df', 2, 0, 'text', df, None, style_center), ('df', 2, 0, 'text', df, None, style_center),
('cd', 1 if nbr_columns == 11 else 2, 0, 'text', _p.date_until, None, style_center), #clearance date
('af', 2, 0, 'text', _('Custom Filter') if _p.partner_ids else _p.display_partner_account(data), None, style_center),
('tm', 3 if nbr_columns == 13 else 2, 0, 'text', _p.display_target_move(data), None, style_center),
('cd', 1 if nbr_columns == 11 else 2, 0, 'text',
_p.date_until, None, style_center), # clearance date
('af', 2, 0, 'text', _('Custom Filter')
if _p.partner_ids else _p.display_partner_account(data), None,
style_center),
('tm', 3 if nbr_columns == 13 else 2, 0, 'text',
_p.display_target_move(data), None, style_center),
] ]
row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs]) 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, row_style=style_center)
row_position = self.xls_write_row(
ws, row_position, row_data, row_style=style_center)
return row_position return row_position
def print_columns_title(self, _p, row_position, data, group_lines=False): # Fill in a row with the titles of the columns for the invoice lines: Date - Period - Entry -...
# Fill in a row with the titles of the columns for the invoice lines: Date
# - Period - Entry -...
def print_columns_title(self, _p, row_position, data, group_lines=False):
c_specs = [ c_specs = [
('date', 1, 0, 'text', _('Date'), None, style_yellow_bold), ('date', 1, 0, 'text', _('Date'), None, style_yellow_bold),
('period', 1, 0, 'text', _('Period'), None, style_yellow_bold), ('period', 1, 0, 'text', _('Period'), None, style_yellow_bold),
@ -191,60 +257,87 @@ class open_invoices_xls(report_xls):
('journal', 1, 0, 'text', _('Journal'), None, style_yellow_bold), ('journal', 1, 0, 'text', _('Journal'), None, style_yellow_bold),
] ]
if not group_lines: if not group_lines:
c_specs += [('partner', 1, 0, 'text', _('Partner'),None,style_yellow_bold),]
c_specs += [('partner', 1, 0, 'text', _('Partner'),
None, style_yellow_bold), ]
c_specs += [ c_specs += [
('label', 1, 0, 'text', _('Label'), None, style_yellow_bold), ('label', 1, 0, 'text', _('Label'), None, style_yellow_bold),
('rec', 1, 0, 'text', _('Rec.'), None, style_yellow_bold), ('rec', 1, 0, 'text', _('Rec.'), None, style_yellow_bold),
('due_date', 1, 0, 'text', _('Due Date'), None, style_yellow_bold), ('due_date', 1, 0, 'text', _('Due Date'), None, style_yellow_bold),
('debit', 1, 0, 'text', _('Debit'), None, style_yellow_bold_right), ('debit', 1, 0, 'text', _('Debit'), None, style_yellow_bold_right),
('credit', 1, 0, 'text', _('Credit'),None,style_yellow_bold_right),
('cumul', 1, 0, 'text', _('Cumul. Bal.'),None,style_yellow_bold_right),
('credit', 1, 0, 'text', _('Credit'),
None, style_yellow_bold_right),
('cumul', 1, 0, 'text', _('Cumul. Bal.'),
None, style_yellow_bold_right),
] ]
if group_lines: if group_lines:
c_specs += [ c_specs += [
('currbal', 1, 0, 'text', _('Curr. Balance'),None,style_yellow_bold_right),
('curr', 1, 0, 'text', _('Curr.'),None,style_yellow_bold_right),
('currbal', 1, 0, 'text', _('Curr. Balance'),
None, style_yellow_bold_right),
('curr', 1, 0, 'text', _('Curr.'),
None, style_yellow_bold_right),
] ]
else: else:
if _p.amount_currency(data): if _p.amount_currency(data):
c_specs += [ c_specs += [
('currbal', 1, 0, 'text', _('Curr. Balance'),None,style_yellow_bold_right),
('curr', 1, 0, 'text', _('Curr.'), None, style_yellow_bold_right),
('currbal', 1, 0, 'text', _('Curr. Balance'),
None, style_yellow_bold_right),
('curr', 1, 0, 'text', _('Curr.'),
None, style_yellow_bold_right),
] ]
row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs]) 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, row_style=style_yellow_bold)
row_position = self.xls_write_row(
ws, row_position, row_data, row_style=style_yellow_bold)
return row_position return row_position
def print_row_code_account(self, regroupmode, account, row_position, partner_name): # Fill in a row with the code and the name of an account + the partner name in case of currency regrouping
# Fill in a row with the code and the name of an account + the partner
# name in case of currency regrouping
def print_row_code_account(self, regroupmode, account, row_position,
partner_name):
if regroupmode == "regroup": if regroupmode == "regroup":
c_specs = [ ('acc_title', nbr_columns, 0, 'text', ' - '.join([account.code, account.name, partner_name or _('No partner')])), ]
c_specs = [('acc_title', nbr_columns, 0, 'text',
' - '.join([account.code, account.name, partner_name
or _('No partner')])), ]
else: else:
c_specs = [ ('acc_title', nbr_columns, 0, 'text', ' - '.join([account.code, account.name])), ]
c_specs = [
('acc_title', nbr_columns, 0, 'text', ' - '.
join([account.code, account.name])), ]
row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs]) 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)
row_position = self.xls_write_row(
ws, row_position, row_data, style_account_title)
return row_position + 1 return row_position + 1
def print_row_partner(self, row_position, partner_name): def print_row_partner(self, row_position, partner_name):
c_specs = [ ('partner', nbr_columns, 0, 'text', partner_name or _('No partner')), ]
c_specs = [
('partner', nbr_columns, 0, 'text',
partner_name or _('No partner')), ]
row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs]) 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_row)
row_position = self.xls_write_row(
ws, row_position, row_data, style_partner_row)
return row_position return row_position
def print_group_currency(self, row_position, curr, _p): def print_group_currency(self, row_position, curr, _p):
c_specs = [ ('curr', nbr_columns, 0, 'text', curr or _p.company.currency_id.name), ]
c_specs = [
('curr', nbr_columns, 0, 'text',
curr or _p.company.currency_id.name), ]
row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs]) 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_bold)
row_position = self.xls_write_row(
ws, row_position, row_data, style_bold)
return row_position return row_position
def print_lines(self, row_position, account, line,_p, data, line_number): # Fill in rows of invoice line
# Fill in rows of invoice line
def print_lines(self, row_position, account, line, _p, data, line_number):
label_elements = [line.get('lname') or ''] label_elements = [line.get('lname') or '']
if line.get('invoice_number'): if line.get('invoice_number'):
label_elements.append("(%s)" % (line['invoice_number'],)) label_elements.append("(%s)" % (line['invoice_number'],))
label = ' '.join(label_elements) 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'):
# 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_default = style_default_italic
style_line_right = style_right_italic style_line_right = style_right_italic
style_line_date = style_date_italic style_line_date = style_date_italic
@ -255,7 +348,8 @@ class open_invoices_xls(report_xls):
style_line_date = style_date style_line_date = style_date
style_line_decimal = style_decimal style_line_decimal = style_decimal
if line.get('ldate'): if line.get('ldate'):
c_specs = [('date', 1, 0, 'date', datetime.strptime(line['ldate'],'%Y-%m-%d'), None, style_line_date)]
c_specs = [('date', 1, 0, 'date', datetime.strptime(
line['ldate'], '%Y-%m-%d'), None, style_line_date)]
else: else:
c_specs = [('date', 1, 0, 'text', None)] c_specs = [('date', 1, 0, 'text', None)]
c_specs += [ c_specs += [
@ -267,12 +361,16 @@ class open_invoices_xls(report_xls):
('rec', 1, 0, 'text', line.get('rec_name') or ''), ('rec', 1, 0, 'text', line.get('rec_name') or ''),
] ]
if line.get('date_maturity'): if line.get('date_maturity'):
c_specs += [('datedue', 1, 0, 'date', datetime.strptime(line['date_maturity'],'%Y-%m-%d'), None, style_line_date)]
c_specs += [('datedue', 1, 0, 'date',
datetime.strptime(line['date_maturity'], '%Y-%m-%d'),
None, style_line_date)]
else: else:
c_specs += [('datedue', 1, 0, 'text', None)] c_specs += [('datedue', 1, 0, 'text', None)]
c_specs += [ 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),
('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 # determine the formula of the cumulated balance
@ -280,18 +378,24 @@ class open_invoices_xls(report_xls):
credit_cell = rowcol_to_cell(row_position, 9) credit_cell = rowcol_to_cell(row_position, 9)
previous_balance = rowcol_to_cell(row_position - 1, 10) previous_balance = rowcol_to_cell(row_position - 1, 10)
if line_number == 1: #if it is the first line, the balance is only debit - credit
# if it is the first line, the balance is only debit - credit
if line_number == 1:
cumul_balance = debit_cell + '-' + credit_cell cumul_balance = debit_cell + '-' + credit_cell
else: # cumulate debit - credit and balance of previous line
cumul_balance = debit_cell + '-' + credit_cell + '+' + previous_balance
# 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)]
c_specs += [('cumul', 1, 0, 'number', None,
cumul_balance, style_line_decimal)]
if _p.amount_currency(data): if _p.amount_currency(data):
if account.currency_id: if account.currency_id:
c_specs += [ 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),
('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: else:
c_specs += [ c_specs += [
@ -300,17 +404,23 @@ class open_invoices_xls(report_xls):
] ]
row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs]) 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)
row_position = self.xls_write_row(
ws, row_position, row_data, style_line_default)
return row_position return row_position
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
# Fill in rows of invoice line when the option currency regroup is selected
def print_group_lines(self, row_position, account, line, _p, line_number):
label_elements = [line.get('lname') or ''] label_elements = [line.get('lname') or '']
if line.get('invoice_number'): if line.get('invoice_number'):
label_elements.append("(%s)" % (line['invoice_number'],)) label_elements.append("(%s)" % (line['invoice_number'],))
label = ' '.join(label_elements) 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'):
# 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_default = style_default_italic
style_line_right = style_right_italic style_line_right = style_right_italic
style_line_date = style_date_italic style_line_date = style_date_italic
@ -325,13 +435,17 @@ class open_invoices_xls(report_xls):
credit_cell = rowcol_to_cell(row_position, 8) credit_cell = rowcol_to_cell(row_position, 8)
previous_balance = rowcol_to_cell(row_position - 1, 9) 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
# if it is the first line, the balance is only debit - credit
if line_number == 1:
cumul_balance = debit_cell + '-' + credit_cell cumul_balance = debit_cell + '-' + credit_cell
else: # cumulate devit - credit and balance of previous line
cumul_balance = debit_cell + '-' + credit_cell + '+' + previous_balance
# cumulate devit - credit and balance of previous line
else:
cumul_balance = debit_cell + '-' + \
credit_cell + '+' + previous_balance
if line.get('ldate'): if line.get('ldate'):
c_specs = [('date', 1, 0, 'date', datetime.strptime(line['ldate'],'%Y-%m-%d'), None, style_line_date)]
c_specs = [('date', 1, 0, 'date', datetime.strptime(
line['ldate'], '%Y-%m-%d'), None, style_line_date)]
else: else:
c_specs = [('date', 1, 0, 'text', None)] c_specs = [('date', 1, 0, 'text', None)]
c_specs += [ c_specs += [
@ -342,18 +456,24 @@ class open_invoices_xls(report_xls):
('rec', 1, 0, 'text', line.get('rec_name') or ''), ('rec', 1, 0, 'text', line.get('rec_name') or ''),
] ]
if line.get('date_maturity'): if line.get('date_maturity'):
c_specs += [('datedue', 1, 0, 'date', datetime.strptime(line['date_maturity'],'%Y-%m-%d'), None, style_line_date)]
c_specs += [('datedue', 1, 0, 'date',
datetime.strptime(line['date_maturity'], '%Y-%m-%d'),
None, style_line_date)]
else: else:
c_specs += [('datedue', 1, 0, 'text', None)] c_specs += [('datedue', 1, 0, 'text', None)]
c_specs += [ 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),
('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), ('cumul', 1, 0, 'number', None, cumul_balance, style_line_decimal),
] ]
if account.currency_id: if account.currency_id:
c_specs += [ 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),
('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: else:
c_specs += [ c_specs += [
@ -362,65 +482,88 @@ class open_invoices_xls(report_xls):
] ]
row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs]) 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)
row_position = self.xls_write_row(
ws, row_position, row_data, style_line_default)
return (row_position, cumul_balance) return (row_position, cumul_balance)
def print_cumul_partner(self, row_position, row_start_partner, account, _p, data): #print by partner the totals and cumulated balance (Excel formulas)
# print by partner the totals and cumulated balance (Excel formulas)
def print_cumul_partner(self, row_position, row_start_partner, account, _p,
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
# 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_start = rowcol_to_cell(row_start_partner, start_col + 3)
debit_partner_end = rowcol_to_cell(row_position - 1, 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 + ')'
debit_partner_total = 'SUM(' + debit_partner_start + \
':' + debit_partner_end + ')'
credit_partner_start = rowcol_to_cell(row_start_partner, start_col + 4) 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_end = rowcol_to_cell(row_position - 1, start_col + 4)
credit_partner_total = 'SUM(' + credit_partner_start + ':' + credit_partner_end + ')'
credit_partner_total = 'SUM(' + credit_partner_start + \
':' + credit_partner_end + ')'
bal_curr_start = rowcol_to_cell(row_start_partner, start_col + 6) bal_curr_start = rowcol_to_cell(row_start_partner, start_col + 6)
bal_curr_end = rowcol_to_cell(row_position - 1, 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 + ')' cumul_balance_curr = 'SUM(' + bal_curr_start + ':' + bal_curr_end + ')'
bal_partner_debit = rowcol_to_cell(row_position, start_col + 3) bal_partner_debit = rowcol_to_cell(row_position, start_col + 3)
bal_partner_credit = rowcol_to_cell(row_position, start_col + 4) bal_partner_credit = rowcol_to_cell(row_position, start_col + 4)
bal_partner_total = bal_partner_debit + '-' + bal_partner_credit 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 = [('empty%s' % x, 1, 0, 'text', None)
for x in range(start_col)]
c_specs += [ c_specs += [
('init_bal', 1, 0, 'text', _('Cumulated Balance on Partner')), ('init_bal', 1, 0, 'text', _('Cumulated Balance on Partner')),
('rec', 1, 0, 'text', None), ('rec', 1, 0, 'text', None),
('empty5', 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),
('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 _p.amount_currency(data): if _p.amount_currency(data):
if account.currency_id: 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),
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: else:
c_specs += [('cumul_bal_curr', 1, 0, 'text', '-', None, style_partner_cumul_right),
('curr_name', 1, 0, 'text', '', None, style_partner_cumul_right)
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_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)
row_position = self.xls_write_row(
ws, row_position, row_data, style_partner_cumul)
return row_position + 1 return row_position + 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
# print by partner the totals and cumulated balance (Excel formulas) when
# the option currency regroup is selected
def print_group_cumul_partner(self, row_position, row_start_partner,
account, _p, data):
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
# 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_start = rowcol_to_cell(row_start_partner, start_col + 3)
debit_partner_end = rowcol_to_cell(row_position - 1, 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 + ')'
debit_partner_total = 'SUM(' + debit_partner_start + \
':' + debit_partner_end + ')'
credit_partner_start = rowcol_to_cell(row_start_partner, start_col + 4) 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_end = rowcol_to_cell(row_position - 1, start_col + 4)
credit_partner_total = 'SUM(' + credit_partner_start + ':' + credit_partner_end + ')'
credit_partner_total = 'SUM(' + credit_partner_start + \
':' + credit_partner_end + ')'
bal_curr_start = rowcol_to_cell(row_start_partner, start_col + 5) bal_curr_start = rowcol_to_cell(row_start_partner, start_col + 5)
bal_curr_end = rowcol_to_cell(row_position - 1, start_col + 5) bal_curr_end = rowcol_to_cell(row_position - 1, start_col + 5)
@ -430,47 +573,72 @@ class open_invoices_xls(report_xls):
bal_partner_credit = rowcol_to_cell(row_position, start_col + 4) bal_partner_credit = rowcol_to_cell(row_position, start_col + 4)
bal_partner_total = bal_partner_debit + '-' + bal_partner_credit 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 = [('empty%s' % x, 1, 0, 'text', None)
for x in range(start_col)]
c_specs += [ c_specs += [
('init_bal', 1, 0, 'text', _('Cumulated Balance on Partner')), #, style_bold_italic),
# , style_bold_italic),
('init_bal', 1, 0, 'text', _('Cumulated Balance on Partner')),
('rec', 1, 0, 'text', None), ('rec', 1, 0, 'text', None),
('empty5', 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),
('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: if account.currency_id:
c_specs += [ 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),
('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: else:
c_specs += [ c_specs += [
('cumul_bal_curr', 1, 0, 'text', "-", None, style_partner_cumul_right),
('curr_name', 1, 0, 'text', "", None, style_partner_cumul_right),
('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_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)
row_position = self.xls_write_row(
ws, row_position, row_data, style_partner_cumul)
return row_position + 1 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
# print by account the totals of the credit and debit + balance calculation
def print_cumul_account(self, row_position, row_start_account, account, _p,
data):
#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
# 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 = 5
reference_start = rowcol_to_cell(row_start_account, start_col) #range in which we search for the text "Cumulated Balance on Partner"
# 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) 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 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_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 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) range_credit_stop = rowcol_to_cell(row_position - 1, start_col + 4)
search_key = _('Cumulated Balance on Partner') 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 + ')'
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_debit = rowcol_to_cell(row_position, start_col + 3)
bal_account_credit = rowcol_to_cell(row_position, start_col + 4) bal_account_credit = rowcol_to_cell(row_position, start_col + 4)
@ -478,45 +646,73 @@ class open_invoices_xls(report_xls):
bal_curr_start = rowcol_to_cell(row_start_account, start_col + 6) bal_curr_start = rowcol_to_cell(row_start_account, start_col + 6)
bal_curr_end = rowcol_to_cell(row_position - 1, 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 + ')'
cumul_balance_curr = 'SUMIF(' + reference_start + ':' +\
reference_stop + ';"' + search_key + '";' + \
bal_curr_start + ':' + bal_curr_end + ')'
c_specs = [ c_specs = [
('acc_title', start_col, 0, 'text', ' - '.join([account.code, account.name])),
('init_bal', 2, 0, 'text', _('Cumulated Balance on Account')),
('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), ('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),
('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 _p.amount_currency(data):
if account.currency_id: 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),
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: else:
c_specs += [('cumul_bal_curr', 1, 0, 'text', "-", None, style_account_title_right),
('curr_name', 1, 0, 'text', "", None, style_account_title_right)
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_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)
row_position = self.xls_write_row(
ws, row_position, row_data, style_account_title)
return row_position + 1 return row_position + 1
def print_group_cumul_account(self,row_position, row_start_account, account): #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 = 4 #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"
# print by account the totals of the credit and debit + balance calculation
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) 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 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_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 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) range_credit_stop = rowcol_to_cell(row_position - 1, start_col + 4)
search_key = _('Cumulated Balance on Partner') 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 + ')'
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_debit = rowcol_to_cell(row_position, start_col + 3)
bal_account_credit = rowcol_to_cell(row_position, start_col + 4) bal_account_credit = rowcol_to_cell(row_position, start_col + 4)
@ -524,76 +720,102 @@ class open_invoices_xls(report_xls):
bal_curr_start = rowcol_to_cell(row_start_account, start_col + 6) bal_curr_start = rowcol_to_cell(row_start_account, start_col + 6)
bal_curr_end = rowcol_to_cell(row_position - 1, 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 + ')'
cumul_balance_curr = 'SUMIF(' + reference_start + ':' +\
reference_stop + ';"' + search_key + '";' + \
bal_curr_start + ':' + bal_curr_end + ')'
c_specs = [ c_specs = [
('acc_title', start_col, 0, 'text', ' - '.join([account.code, account.name])),
('init_bal', 2, 0, 'text', _('Cumulated Balance on Account')),
('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), ('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),
('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 account.currency_id: if account.currency_id:
c_specs += [('cumul_bal_curr', 1, 0, 'number', None, cumul_balance_curr, style_account_title_decimal),
('curr_name', 1, 0, 'text', account.currency_id.name, None, style_account_title_decimal),
c_specs += [('cumul_bal_curr', 1, 0, 'number', None,
cumul_balance_curr, style_account_title_decimal),
('curr_name', 1, 0, 'text', account.currency_id.name,
None, style_account_title_decimal),
] ]
else: else:
c_specs += [('cumul_bal_curr', 1, 0, 'text', "-", None, style_account_title_right),
('curr_name', 1, 0, 'text', "", None, style_account_title_right)
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_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)
row_position = self.xls_write_row(
ws, row_position, row_data, style_account_title)
return row_position + 1 return row_position + 1
def print_grouped_line_report(self, row_pos, account, _xs, xlwt, _p, data): # export the invoice AR/AP lines when the option currency regroup is selected
# export the invoice AR/AP lines when the option currency regroup is
# selected
def print_grouped_line_report(self, row_pos, account, _xs, xlwt, _p, data):
if account.grouped_ledger_lines and account.partners_order: if account.grouped_ledger_lines and account.partners_order:
row_start_account = row_pos row_start_account = row_pos
for partner_name, p_id, p_ref, p_name in account.partners_order: for partner_name, p_id, p_ref, p_name in account.partners_order:
row_pos = self.print_row_code_account("regroup", account,row_pos, partner_name)
row_pos = self.print_row_code_account(
"regroup", account, row_pos, partner_name)
for curr, grouped_lines in account.grouped_ledger_lines.get(p_id, []):
for curr, grouped_lines in account.grouped_ledger_lines.\
get(p_id, []):
row_pos = self.print_group_currency(row_pos, curr, _p) row_pos = self.print_group_currency(row_pos, curr, _p)
# Print row: Titles "Date-Period-Entry-Journal..." # Print row: Titles "Date-Period-Entry-Journal..."
row_pos = self.print_columns_title(_p, row_pos, data, group_lines=True)
row_pos = self.print_columns_title(
_p, row_pos, data, group_lines=True)
row_pos_start = row_pos row_pos_start = row_pos
line_number = 0 line_number = 0
for line in grouped_lines: for line in grouped_lines:
line_number += 1 line_number += 1
row_pos, cumul_balance = self.print_group_lines(row_pos, account, line, _p, line_number)
row_pos = self.print_group_cumul_partner(row_pos,row_pos_start, account, _p, data)
row_pos, cumul_balance = self.print_group_lines(
row_pos, account, line, _p, line_number)
row_pos = self.print_group_cumul_partner(
row_pos, row_pos_start, account, _p, data)
row_pos = self.print_group_cumul_account(row_pos, row_start_account, account)
row_pos = self.print_group_cumul_account(
row_pos, row_start_account, account)
return row_pos return row_pos
def print_ledger_lines(self, row_pos, account, _xs, xlwt, _p, data): # export the invoice AR/AP lines
# export the invoice AR/AP lines
def print_ledger_lines(self, row_pos, account, _xs, xlwt, _p, data):
if account.ledger_lines and account.partners_order: if account.ledger_lines and account.partners_order:
row_start_account = row_pos row_start_account = row_pos
# Print account line: code - account # Print account line: code - account
row_pos = self.print_row_code_account("noregroup",account,row_pos, "")
row_pos = self.print_row_code_account(
"noregroup", account, row_pos, "")
for partner_name, p_id, p_ref, p_name in account.partners_order: for partner_name, p_id, p_ref, p_name in account.partners_order:
# Print partner row # Print partner row
row_pos = self.print_row_partner(row_pos, partner_name) row_pos = self.print_row_partner(row_pos, partner_name)
# Print row: Titles "Date-Period-Entry-Journal..." # Print row: Titles "Date-Period-Entry-Journal..."
row_pos = self.print_columns_title(_p, row_pos, data, group_lines=False)
row_pos = self.print_columns_title(
_p, row_pos, data, group_lines=False)
row_pos_start = row_pos row_pos_start = row_pos
line_number = 0 line_number = 0
for line in account.ledger_lines.get(p_id, []): for line in account.ledger_lines.get(p_id, []):
line_number += 1 line_number += 1
# print ledger lines # print ledger lines
row_pos = self.print_lines(row_pos, account, line, _p, data, line_number)
row_pos = self.print_cumul_partner(row_pos, row_pos_start, account, _p, data)
row_pos = self.print_lines(
row_pos, account, line, _p, data, line_number)
row_pos = self.print_cumul_partner(
row_pos, row_pos_start, account, _p, data)
row_pos = self.print_cumul_account(row_pos, row_start_account, account, _p, data)
row_pos = self.print_cumul_account(
row_pos, row_start_account, account, _p, data)
return row_pos return row_pos
@ -606,7 +828,8 @@ class open_invoices_xls(report_xls):
row_pos = self.print_title(_p, row_pos) row_pos = self.print_title(_p, row_pos)
# Print empty row to define column sizes # Print empty row to define column sizes
row_pos = self.print_empty_row(row_pos) row_pos = self.print_empty_row(row_pos)
# Print Header Table titles (Fiscal Year - Accounts Filter - Periods Filter...)
# Print Header Table titles (Fiscal Year - Accounts Filter - Periods
# Filter...)
row_pos = self.print_header_titles(_p, data, row_pos) row_pos = self.print_header_titles(_p, data, row_pos)
# Print Header Table data # Print Header Table data
row_pos = self.print_header_data(_p, data, row_pos) row_pos = self.print_header_data(_p, data, row_pos)
@ -617,11 +840,15 @@ class open_invoices_xls(report_xls):
for acc in objects: for acc in objects:
if hasattr(acc, 'grouped_ledger_lines'): if hasattr(acc, 'grouped_ledger_lines'):
# call xls equivalent of "grouped_by_curr_open_invoices_inclusion.mako.html"
row_pos = self.print_grouped_line_report(row_pos, acc, _xs, xlwt, _p, data)
# call xls equivalent of
# "grouped_by_curr_open_invoices_inclusion.mako.html"
row_pos = self.print_grouped_line_report(
row_pos, acc, _xs, xlwt, _p, data)
else: else:
# call xls equivalent of "open_invoices_inclusion.mako.html" # call xls equivalent of "open_invoices_inclusion.mako.html"
row_pos = self.print_ledger_lines(row_pos, acc, _xs, xlwt, _p, data)
row_pos = self.print_ledger_lines(
row_pos, acc, _xs, xlwt, _p, data)
row_pos += 1 row_pos += 1
open_invoices_xls('report.account.account_report_open_invoices_xls', 'account.account', parser=PartnersOpenInvoicesWebkit)
open_invoices_xls('report.account.account_report_open_invoices_xls',
'account.account', parser=PartnersOpenInvoicesWebkit)

272
account_financial_report_webkit_xls/report/partner_ledger_xls.py

@ -21,12 +21,11 @@
############################################################################## ##############################################################################
import xlwt import xlwt
import time
from datetime import datetime from datetime import datetime
from openerp.report import report_sxw
from openerp.addons.report_xls.report_xls import report_xls from openerp.addons.report_xls.report_xls import report_xls
from openerp.addons.report_xls.utils import rowcol_to_cell from openerp.addons.report_xls.utils import rowcol_to_cell
from openerp.addons.account_financial_report_webkit.report.partners_ledger import PartnersLedgerWebkit
from openerp.addons.account_financial_report_webkit.report.partners_ledger\
import PartnersLedgerWebkit
from openerp.tools.translate import _ from openerp.tools.translate import _
#import logging #import logging
#_logger = logging.getLogger(__name__) #_logger = logging.getLogger(__name__)
@ -46,6 +45,7 @@ _column_sizes = [
('curr_code', 7), ('curr_code', 7),
] ]
class partner_ledger_xls(report_xls): class partner_ledger_xls(report_xls):
column_sizes = [x[1] for x in _column_sizes] column_sizes = [x[1] for x in _column_sizes]
@ -63,22 +63,29 @@ class partner_ledger_xls(report_xls):
ws.footer_str = self.xls_footers['standard'] ws.footer_str = self.xls_footers['standard']
# cf. account_report_partner_ledger.mako # cf. account_report_partner_ledger.mako
initial_balance_text = {'initial_balance': _('Computed'), 'opening_balance': _('Opening Entries'), False: _('No')}
initial_balance_text = {'initial_balance': _('Computed'),
'opening_balance': _('Opening Entries'),
False: _('No')}
# Title # Title
cell_style = xlwt.easyxf(_xs['xls_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])
report_name = ' - '.join([_p.report_name.upper(),
_p.company.partner_id.name,
_p.company.currency_id.name])
c_specs = [ c_specs = [
('report_name', 1, 0, 'text', report_name), ('report_name', 1, 0, 'text', report_name),
] ]
row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs]) 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 = self.xls_write_row(
ws, row_pos, row_data, row_style=cell_style)
# write empty row to define column sizes # write empty row to define column sizes
c_sizes = self.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))]
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_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)
row_pos = self.xls_write_row(
ws, row_pos, row_data, set_column_size=True)
# Header Table # Header Table
nbr_columns = 10 nbr_columns = 10
@ -90,14 +97,16 @@ class partner_ledger_xls(report_xls):
c_specs = [ c_specs = [
('coa', 2, 0, 'text', _('Chart of Account')), ('coa', 2, 0, 'text', _('Chart of Account')),
('fy', 1, 0, 'text', _('Fiscal Year')), ('fy', 1, 0, 'text', _('Fiscal Year')),
('df', 2, 0, 'text', _p.filter_form(data) == 'filter_date' and _('Dates Filter') or _('Periods Filter')),
('df', 2, 0, 'text', _p.filter_form(data) ==
'filter_date' and _('Dates Filter') or _('Periods Filter')),
('af', 1, 0, 'text', _('Accounts Filter')), ('af', 1, 0, 'text', _('Accounts Filter')),
('tm', 2, 0, 'text', _('Target Moves')), ('tm', 2, 0, 'text', _('Target Moves')),
('ib', nbr_columns - 8, 0, 'text', _('Initial Balance')), ('ib', nbr_columns - 8, 0, 'text', _('Initial Balance')),
] ]
row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs]) 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 = self.xls_write_row(
ws, row_pos, row_data, row_style=cell_style_center)
cell_format = _xs['borders_all'] cell_format = _xs['borders_all']
cell_style = xlwt.easyxf(cell_format) cell_style = xlwt.easyxf(cell_format)
@ -118,20 +127,26 @@ class partner_ledger_xls(report_xls):
df += _p.stop_period.name if _p.stop_period else u'' df += _p.stop_period.name if _p.stop_period else u''
c_specs += [ c_specs += [
('df', 2, 0, 'text', df), ('df', 2, 0, 'text', df),
('af', 1, 0, 'text', _('Custom Filter') if _p.partner_ids else _p.display_partner_account(data)),
('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)), ('tm', 2, 0, 'text', _p.display_target_move(data)),
('ib', nbr_columns-8, 0, 'text', initial_balance_text[_p.initial_balance_mode]),
('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_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 = self.xls_write_row(
ws, row_pos, row_data, row_style=cell_style_center)
ws.set_horz_split_pos(row_pos) ws.set_horz_split_pos(row_pos)
row_pos += 1 row_pos += 1
# Account Title Row # Account Title Row
cell_format = _xs['xls_title'] + _xs['bold'] + _xs['fill'] + _xs['borders_all']
cell_format = _xs['xls_title'] + _xs['bold'] + \
_xs['fill'] + _xs['borders_all']
account_cell_style = xlwt.easyxf(cell_format) account_cell_style = xlwt.easyxf(cell_format)
account_cell_style_right = xlwt.easyxf(cell_format + _xs['right']) 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)
account_cell_style_decimal = xlwt.easyxf(
cell_format + _xs['right'],
num_format_str=report_xls.decimal_format)
# Column Title Row # Column Title Row
cell_format = _xs['bold'] cell_format = _xs['bold']
@ -142,21 +157,27 @@ class partner_ledger_xls(report_xls):
c_hdr_cell_style = xlwt.easyxf(cell_format) c_hdr_cell_style = xlwt.easyxf(cell_format)
c_hdr_cell_style_right = xlwt.easyxf(cell_format + _xs['right']) 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_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)
c_hdr_cell_style_decimal = xlwt.easyxf(
cell_format + _xs['right'],
num_format_str=report_xls.decimal_format)
# Column Initial Balance Row # Column Initial Balance Row
cell_format = _xs['italic'] + _xs['borders_all'] cell_format = _xs['italic'] + _xs['borders_all']
c_init_cell_style = xlwt.easyxf(cell_format) c_init_cell_style = xlwt.easyxf(cell_format)
c_init_cell_style_right = xlwt.easyxf(cell_format + _xs['right']) 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_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_init_cell_style_decimal = xlwt.easyxf(
cell_format + _xs['right'],
num_format_str=report_xls.decimal_format)
# Column Cumulated balance Row # Column Cumulated balance Row
cell_format = _xs['bold'] + _xs['fill'] + _xs['borders_all'] cell_format = _xs['bold'] + _xs['fill'] + _xs['borders_all']
c_cumul_cell_style = xlwt.easyxf(cell_format) c_cumul_cell_style = xlwt.easyxf(cell_format)
c_cumul_cell_style_right = xlwt.easyxf(cell_format + _xs['right']) 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_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)
c_cumul_cell_style_decimal = xlwt.easyxf(
cell_format + _xs['right'],
num_format_str=report_xls.decimal_format)
# Column Partner Row # Column Partner Row
cell_format = _xs['bold'] cell_format = _xs['bold']
@ -171,13 +192,17 @@ class partner_ledger_xls(report_xls):
('label', 1, 0, 'text', _('Label'), 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), ('rec', 1, 0, 'text', _('Rec.'), None, c_hdr_cell_style),
('debit', 1, 0, 'text', _('Debit'), None, c_hdr_cell_style_right), ('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),
('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): if _p.amount_currency(data):
c_specs += [ 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),
('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]) c_hdr_data = self.xls_row_template(c_specs, [x[0] for x in c_specs])
@ -186,8 +211,12 @@ class partner_ledger_xls(report_xls):
ll_cell_style = xlwt.easyxf(ll_cell_format) ll_cell_style = xlwt.easyxf(ll_cell_format)
ll_cell_style_right = xlwt.easyxf(ll_cell_format + _xs['right']) 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_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)
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 cnt = 0
for account in objects: for account in objects:
@ -200,14 +229,19 @@ class partner_ledger_xls(report_xls):
account_balance_cumul = 0.0 account_balance_cumul = 0.0
account_balance_cumul_curr = 0.0 account_balance_cumul_curr = 0.0
c_specs = [ c_specs = [
('acc_title', nbr_columns, 0, 'text', ' - '.join([account.code, account.name]), None, account_cell_style),
('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_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_pos += 1
row_start_account = row_pos row_start_account = row_pos
for partner_name, p_id, p_ref, p_name in account.partners_order:
for partner_name, p_id, p_ref, p_name in\
account.partners_order:
total_debit = 0.0 total_debit = 0.0
total_credit = 0.0 total_credit = 0.0
@ -216,23 +250,33 @@ class partner_ledger_xls(report_xls):
part_cumul_balance = 0.0 part_cumul_balance = 0.0
part_cumul_balance_curr = 0.0 part_cumul_balance_curr = 0.0
c_specs = [ c_specs = [
('partner_title', nbr_columns, 0, 'text', partner_name or _('No Partner'), None, c_part_cell_style),
('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_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_pos = self.xls_write_row(ws, row_pos, c_hdr_data)
row_start_partner = row_pos 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
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 init_line = False
if _p.initial_balance_mode and (total_debit or total_credit):
if _p.initial_balance_mode and\
(total_debit or total_credit):
init_line = True 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 ''
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 += part_cumul_balance
cumul_balance_curr += part_cumul_balance_curr cumul_balance_curr += part_cumul_balance_curr
@ -241,22 +285,31 @@ class partner_ledger_xls(report_xls):
credit_cell = rowcol_to_cell(row_pos, 8) credit_cell = rowcol_to_cell(row_pos, 8)
init_bal_formula = debit_cell + '-' + credit_cell 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)]
# Print row 'Initial Balance' by partn
c_specs = [('empty%s' % x, 1, 0, 'text', None)
for x in range(5)]
c_specs += [ c_specs += [
('init_bal', 1, 0, 'text', _('Initial Balance')), ('init_bal', 1, 0, 'text', _('Initial Balance')),
('rec', 1, 0, 'text', None), ('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),
('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): if _p.amount_currency(data):
c_specs += [ 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),
('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)
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, []): for line in account.ledger_lines.get(p_id, []):
@ -265,101 +318,148 @@ class partner_ledger_xls(report_xls):
label_elements = [line.get('lname') or ''] label_elements = [line.get('lname') or '']
if line.get('invoice_number'): if line.get('invoice_number'):
label_elements.append("(%s)" % (line['invoice_number'],))
label_elements.append(
"(%s)" % (line['invoice_number'],))
label = ' '.join(label_elements) label = ' '.join(label_elements)
cumul_balance += line.get('balance') or 0.0 cumul_balance += line.get('balance') or 0.0
if init_line or row_pos > row_start_partner: if init_line or row_pos > row_start_partner:
cumbal_formula = rowcol_to_cell(row_pos-1, 9) + '+'
cumbal_formula = rowcol_to_cell(
row_pos - 1, 9) + '+'
else: else:
cumbal_formula = '' cumbal_formula = ''
debit_cell = rowcol_to_cell(row_pos, 7) debit_cell = rowcol_to_cell(row_pos, 7)
credit_cell = rowcol_to_cell(row_pos, 8) credit_cell = rowcol_to_cell(row_pos, 8)
cumbal_formula += debit_cell + '-' + credit_cell cumbal_formula += debit_cell + '-' + credit_cell
################## Print row ledger line data #################
################## Print row ledger line data #########
if line.get('ldate'): if line.get('ldate'):
c_specs = [ c_specs = [
('ldate', 1, 0, 'date', datetime.strptime(line['ldate'],'%Y-%m-%d'), None, ll_cell_style_date),
('ldate', 1, 0, 'date', datetime.strptime(
line['ldate'], '%Y-%m-%d'), None,
ll_cell_style_date),
] ]
else: else:
c_specs = [ c_specs = [
('ldate', 1, 0, 'text', None), ('ldate', 1, 0, 'text', None),
] ]
c_specs += [ c_specs += [
('period', 1, 0, 'text', line.get('period_code') or ''),
('move', 1, 0, 'text', line.get('move_name') or ''),
('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 ''), ('journal', 1, 0, 'text', line.get('jcode') or ''),
('partner', 1, 0, 'text', line.get('partner_name') or ''),
('partner', 1, 0, 'text',
line.get('partner_name') or ''),
('label', 1, 0, 'text', label), ('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),
('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): if _p.amount_currency(data):
c_specs += [ 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),
('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)
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 # end for line
################## Print row Cumulated Balance by partner #################
################## Print row Cumulated Balance by partner #
debit_partner_start = rowcol_to_cell(row_start_partner, 7) debit_partner_start = rowcol_to_cell(row_start_partner, 7)
debit_partner_end = rowcol_to_cell(row_pos - 1, 7) debit_partner_end = rowcol_to_cell(row_pos - 1, 7)
debit_partner_total = 'SUM(' + debit_partner_start + ':' + debit_partner_end + ')'
debit_partner_total = 'SUM(' + debit_partner_start + \
':' + debit_partner_end + ')'
credit_partner_start = rowcol_to_cell(row_start_partner, 8) credit_partner_start = rowcol_to_cell(row_start_partner, 8)
credit_partner_end = rowcol_to_cell(row_pos - 1, 8) credit_partner_end = rowcol_to_cell(row_pos - 1, 8)
credit_partner_total = 'SUM(' + credit_partner_start + ':' + credit_partner_end + ')'
credit_partner_total = 'SUM(' + credit_partner_start + \
':' + credit_partner_end + ')'
bal_partner_debit = rowcol_to_cell(row_pos, 7) bal_partner_debit = rowcol_to_cell(row_pos, 7)
bal_partner_credit = rowcol_to_cell(row_pos, 8) bal_partner_credit = rowcol_to_cell(row_pos, 8)
bal_partner_total = bal_partner_debit + '-' + bal_partner_credit
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 = [('empty%s' % x, 1, 0, 'text', None)
for x in range(5)]
c_specs += [ c_specs += [
('init_bal', 1, 0, 'text', _('Cumulated balance on Partner')),
('init_bal', 1, 0, 'text',
_('Cumulated balance on Partner')),
('rec', 1, 0, 'text', None), ('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),
('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 _p.amount_currency(data):
if account.currency_id: if account.currency_id:
c_specs += [('curr_bal', 1, 0, 'number', cumul_balance_curr or 0.0, None, c_cumul_cell_style_decimal)]
c_specs += [('curr_bal', 1, 0, 'number',
cumul_balance_curr or 0.0, None,
c_cumul_cell_style_decimal)]
else: 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)
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 row_pos += 1
account_total_debit += total_debit account_total_debit += total_debit
account_total_credit += total_credit account_total_credit += total_credit
account_balance_cumul += cumul_balance account_balance_cumul += cumul_balance
account_balance_cumul_curr += cumul_balance_curr 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])), ]
################## Print row Cumulated Balance by account #####
c_specs = [
('acc_title', 5, 0, 'text', ' - '.
join([account.code, account.name])), ]
c_specs += [ c_specs += [
('label', 1, 0, 'text', _('Cumulated balance on Account')), ('label', 1, 0, 'text', _('Cumulated balance on Account')),
('rec', 1, 0, 'text', None), ('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),
('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 _p.amount_currency(data):
if account.currency_id: if account.currency_id:
c_specs += [('curr_bal', 1, 0, 'number', account_balance_cumul_curr or 0.0, None, account_cell_style_decimal)]
c_specs += [('curr_bal', 1, 0, 'number',
account_balance_cumul_curr or 0.0, None,
account_cell_style_decimal)]
else: 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)
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 row_pos += 2
partner_ledger_xls('report.account.account_report_partner_ledger_xls', 'account.account',
partner_ledger_xls('report.account.account_report_partner_ledger_xls',
'account.account',
parser=PartnersLedgerWebkit) parser=PartnersLedgerWebkit)
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

273
account_financial_report_webkit_xls/report/partners_balance_xls.py

@ -21,36 +21,42 @@
############################################################################## ##############################################################################
import xlwt import xlwt
import time
from openerp.report import report_sxw
from openerp.addons.report_xls.report_xls import report_xls from openerp.addons.report_xls.report_xls import report_xls
from openerp.addons.report_xls.utils import rowcol_to_cell from openerp.addons.report_xls.utils import rowcol_to_cell
from openerp.addons.account_financial_report_webkit.report.partner_balance import PartnerBalanceWebkit
from openerp.addons.account_financial_report_webkit.report.partner_balance\
import PartnerBalanceWebkit
from openerp.tools.translate import _ from openerp.tools.translate import _
#import logging #import logging
#_logger = logging.getLogger(__name__) #_logger = logging.getLogger(__name__)
def display_line(all_comparison_lines): def display_line(all_comparison_lines):
return any([line.get('balance') for line in all_comparison_lines]) return any([line.get('balance') for line in all_comparison_lines])
class partners_balance_xls(report_xls): class partners_balance_xls(report_xls):
column_sizes = [12, 40, 25, 17, 17, 17, 17, 17] column_sizes = [12, 40, 25, 17, 17, 17, 17, 17]
def print_title(self, ws, _p, row_position, xlwt, _xs): def print_title(self, ws, _p, row_position, xlwt, _xs):
cell_style = xlwt.easyxf(_xs['xls_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])
report_name = ' - '.join([_p.report_name.upper(),
_p.company.partner_id.name,
_p.company.currency_id.name])
c_specs = [ c_specs = [
('report_name', 1, 0, 'text', report_name), ('report_name', 1, 0, 'text', report_name),
] ]
row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs]) 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, row_style=cell_style)
row_position = self.xls_write_row(
ws, row_position, row_data, row_style=cell_style)
return row_position return row_position
def print_empty_row(self, ws, row_position): def print_empty_row(self, ws, row_position):
c_sizes = self.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))]
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_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, set_column_size=True)
row_position = self.xls_write_row(
ws, row_position, row_data, set_column_size=True)
return row_position return row_position
def print_header_titles(self, ws, _p, data, row_position, xlwt, _xs): def print_header_titles(self, ws, _p, data, row_position, xlwt, _xs):
@ -60,24 +66,35 @@ class partners_balance_xls(report_xls):
c_specs = [ c_specs = [
('fy', 1, 0, 'text', _('Fiscal Year'), None, cell_style_center), ('fy', 1, 0, 'text', _('Fiscal Year'), None, cell_style_center),
('af', 1, 0, 'text', _('Accounts Filter'), None, cell_style_center),
('df', 1, 0, 'text', _p.filter_form(data) == 'filter_date' and _('Dates Filter') or _('Periods Filter'), None, cell_style_center),
('pf', 1, 0, 'text', _('Partners Filter'), None, cell_style_center),
('af', 1, 0, 'text', _('Accounts Filter'),
None, cell_style_center),
('df', 1, 0, 'text', _p.filter_form(data) == 'filter_date' and _(
'Dates Filter') or _('Periods Filter'), None,
cell_style_center),
('pf', 1, 0, 'text', _('Partners Filter'),
None, cell_style_center),
('tm', 1, 0, 'text', _('Target Moves'), None, cell_style_center), ('tm', 1, 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),
('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_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, row_style=cell_style)
row_position = self.xls_write_row(
ws, row_position, row_data, row_style=cell_style)
return row_position return row_position
def print_header_data(self, ws, _p, data, row_position, xlwt, _xs, initial_balance_text):
def print_header_data(self, ws, _p, data, row_position, xlwt, _xs,
initial_balance_text):
cell_format = _xs['borders_all'] + _xs['wrap'] + _xs['top'] cell_format = _xs['borders_all'] + _xs['wrap'] + _xs['top']
cell_style = xlwt.easyxf(cell_format) cell_style = xlwt.easyxf(cell_format)
cell_style_center = xlwt.easyxf(cell_format + _xs['center']) cell_style_center = xlwt.easyxf(cell_format + _xs['center'])
c_specs = [ c_specs = [
('fy', 1, 0, 'text', _p.fiscalyear.name if _p.fiscalyear else '-', None, cell_style_center),
('af', 1, 0, 'text', _p.accounts(data) and ', '.join([account.code for account in _p.accounts(data)]) or _('All'), None, cell_style_center),
('fy', 1, 0, 'text', _p.fiscalyear.name if _p.fiscalyear else '-',
None, cell_style_center),
('af', 1, 0, 'text', _p.accounts(data) and ', '.join(
[account.code for account in _p.accounts(data)]) or _('All'),
None, cell_style_center),
] ]
df = _('From') + ': ' df = _('From') + ': '
if _p.filter_form(data) == 'filter_date': if _p.filter_form(data) == 'filter_date':
@ -91,38 +108,56 @@ class partners_balance_xls(report_xls):
df += _p.stop_period.name if _p.stop_period else u'' df += _p.stop_period.name if _p.stop_period else u''
c_specs += [ c_specs += [
('df', 1, 0, 'text', df, None, cell_style_center), ('df', 1, 0, 'text', df, None, cell_style_center),
('tm', 1, 0, 'text', _p.display_partner_account(data), None, cell_style_center),
('pf', 1, 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),
('tm', 1, 0, 'text', _p.display_partner_account(
data), None, cell_style_center),
('pf', 1, 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_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, row_style=cell_style)
row_position = self.xls_write_row(
ws, row_position, row_data, row_style=cell_style)
return row_position return row_position
def print_comparison_header(self, _xs, xlwt, row_position, _p, ws, initial_balance_text ):
def print_comparison_header(self, _xs, xlwt, row_position, _p, ws,
initial_balance_text):
cell_format_ct = _xs['bold'] + _xs['fill_blue'] + _xs['borders_all'] cell_format_ct = _xs['bold'] + _xs['fill_blue'] + _xs['borders_all']
cell_style_ct = xlwt.easyxf(cell_format_ct) cell_style_ct = xlwt.easyxf(cell_format_ct)
c_specs = [('ct', 7, 0, 'text', _('Comparisons'))] c_specs = [('ct', 7, 0, 'text', _('Comparisons'))]
row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs]) 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, row_style=cell_style_ct)
row_position = self.xls_write_row(
ws, row_position, row_data, row_style=cell_style_ct)
cell_format = _xs['borders_all'] + _xs['wrap'] + _xs['top'] cell_format = _xs['borders_all'] + _xs['wrap'] + _xs['top']
cell_style_center = xlwt.easyxf(cell_format) cell_style_center = xlwt.easyxf(cell_format)
for index, params in enumerate(_p.comp_params): for index, params in enumerate(_p.comp_params):
c_specs = [('c', 2, 0, 'text', _('Comparison') + str(index + 1) + ' (C' + str(index + 1) + ')')]
c_specs = [
('c', 2, 0, 'text', _('Comparison') + str(index + 1) +
' (C' + str(index + 1) + ')')]
if params['comparison_filter'] == 'filter_date': if params['comparison_filter'] == 'filter_date':
c_specs += [('f', 2, 0, 'text', _('Dates Filter') + ': ' + _p.formatLang(params['start'], date=True) + ' - ' + _p.formatLang(params['stop'], date=True))]
c_specs += [('f', 2, 0, 'text', _('Dates Filter') + ': ' +
_p.formatLang(params['start'], date=True) + ' - '
+ _p.formatLang(params['stop'], date=True))]
elif params['comparison_filter'] == 'filter_period': elif params['comparison_filter'] == 'filter_period':
c_specs += [('f', 2, 0, 'text', _('Periods Filter') + ': ' + params['start'].name + ' - ' + params['stop'].name)]
c_specs += [('f', 2, 0, 'text', _('Periods Filter') +
': ' + params['start'].name + ' - ' +
params['stop'].name)]
else: else:
c_specs += [('f', 2, 0, 'text', _('Fiscal Year') + ': ' + params['fiscalyear'].name)]
c_specs += [('ib', 2, 0, 'text', _('Initial Balance') + ': ' + initial_balance_text[params['initial_balance_mode']])]
c_specs += [('f', 2, 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_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, row_style=cell_style_center)
row_position = self.xls_write_row(
ws, row_position, row_data, row_style=cell_style_center)
return row_position return row_position
def print_account_header(self, ws, _p, _xs, xlwt, row_position): def print_account_header(self, ws, _p, _xs, xlwt, row_position):
cell_format = _xs['bold'] + _xs['fill'] + _xs['borders_all'] + _xs['wrap'] + _xs['top']
cell_format = _xs['bold'] + _xs['fill'] + \
_xs['borders_all'] + _xs['wrap'] + _xs['top']
cell_style = xlwt.easyxf(cell_format) cell_style = xlwt.easyxf(cell_format)
cell_style_right = xlwt.easyxf(cell_format + _xs['right']) cell_style_right = xlwt.easyxf(cell_format + _xs['right'])
cell_style_center = xlwt.easyxf(cell_format + _xs['center']) cell_style_center = xlwt.easyxf(cell_format + _xs['center'])
@ -136,59 +171,86 @@ class partners_balance_xls(report_xls):
] ]
if _p.comparison_mode == 'no_comparison': if _p.comparison_mode == 'no_comparison':
if _p.initial_balance_mode: if _p.initial_balance_mode:
c_specs += [('init_bal', 1, 0, 'text', _('Initial Balance'), None, cell_style_right)]
c_specs += [('init_bal', 1, 0, 'text',
_('Initial Balance'), None, cell_style_right)]
c_specs += [ c_specs += [
('debit', 1, 0, 'text', _('Debit'), None, cell_style_right), ('debit', 1, 0, 'text', _('Debit'), None, cell_style_right),
('credit', 1, 0, 'text', _('Credit'), None, cell_style_right), ('credit', 1, 0, 'text', _('Credit'), None, cell_style_right),
] ]
if _p.comparison_mode == 'no_comparison' or not _p.fiscalyear: if _p.comparison_mode == 'no_comparison' or not _p.fiscalyear:
c_specs += [('balance', 1, 0, 'text', _('Balance'), None, cell_style_right)]
c_specs += [('balance', 1, 0, 'text',
_('Balance'), None, cell_style_right)]
else: else:
c_specs += [('balance_fy', 1, 0, 'text', _('Balance %s') % _p.fiscalyear.name, None, cell_style_right)]
c_specs += [('balance_fy', 1, 0, 'text', _('Balance %s') %
_p.fiscalyear.name, None, cell_style_right)]
if _p.comparison_mode in ('single', 'multiple'): if _p.comparison_mode in ('single', 'multiple'):
for index in range(_p.nb_comparison): 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)]
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: else:
c_specs += [('balance_%s' %index, 1, 0, 'text', _('Balance C%s') % (index + 1), None, cell_style_right)]
c_specs += [('balance_%s' % index, 1, 0, 'text',
_('Balance C%s') % (index + 1), None,
cell_style_right)]
if _p.comparison_mode == 'single': if _p.comparison_mode == 'single':
c_specs += [ c_specs += [
('diff', 1, 0, 'text', _('Difference'), None, cell_style_right),
('diff_percent', 1, 0, 'text', _('% Difference'), None, cell_style_center),
('diff', 1, 0, 'text', _('Difference'),
None, cell_style_right),
('diff_percent', 1, 0, 'text',
_('% Difference'), None, cell_style_center),
] ]
row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs]) 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, row_style=cell_style)
row_position = self.xls_write_row(
ws, row_position, row_data, row_style=cell_style)
return row_position return row_position
def print_row_code_account(self, ws, current_account, row_position, _xs, xlwt):
cell_format = _xs['xls_title'] + _xs['bold'] + _xs['fill'] + _xs['borders_all']
def print_row_code_account(self, ws, current_account, row_position, _xs,
xlwt):
cell_format = _xs['xls_title'] + _xs['bold'] + \
_xs['fill'] + _xs['borders_all']
cell_style = xlwt.easyxf(cell_format) cell_style = xlwt.easyxf(cell_format)
c_specs = [ ('acc_title', 7, 0, 'text', ' - '.join([current_account.code, current_account.name])), ]
c_specs = [
('acc_title', 7, 0, 'text', ' - '.join([current_account.code,
current_account.name])), ]
row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs]) 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)
row_position = self.xls_write_row(
ws, row_position, row_data, cell_style)
return row_position return row_position
def print_account_totals(self, _xs, xlwt, ws, row_start_account, row_position, current_account,_p):
cell_format = _xs['bold'] + _xs['fill'] + _xs['borders_all'] + _xs['wrap'] + _xs['top']
def print_account_totals(self, _xs, xlwt, ws, row_start_account,
row_position, current_account, _p):
cell_format = _xs['bold'] + _xs['fill'] + \
_xs['borders_all'] + _xs['wrap'] + _xs['top']
cell_style = xlwt.easyxf(cell_format) cell_style = xlwt.easyxf(cell_format)
cell_style_decimal = xlwt.easyxf(cell_format + _xs['right'], num_format_str = report_xls.decimal_format)
cell_style_decimal = xlwt.easyxf(
cell_format + _xs['right'],
num_format_str=report_xls.decimal_format)
c_specs = [ c_specs = [
('acc_title', 2, 0, 'text', current_account.name), ('acc_title', 2, 0, 'text', current_account.name),
('code', 1, 0, 'text', current_account.code), ('code', 1, 0, 'text', current_account.code),
] ]
for column in range(3, 7): for column in range(3, 7):
if (_p.comparison_mode == 'single' and column == 6): #in case of one single comparison, the column 6 will contain percentages
# 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_diff = rowcol_to_cell(row_position, column - 1)
total_balance = rowcol_to_cell(row_position, column - 2) total_balance = rowcol_to_cell(row_position, column - 2)
account_formula = 'Round('+ total_diff + '/' + total_balance + '*100;0)'
account_formula = 'Round(' + total_diff + \
'/' + total_balance + '*100;0)'
else: else:
account_start = rowcol_to_cell(row_start_account, column) account_start = rowcol_to_cell(row_start_account, column)
account_end = rowcol_to_cell(row_position - 1, 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)]
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_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)
row_position = self.xls_write_row(
ws, row_position, row_data, cell_style)
return row_position + 1 return row_position + 1
def generate_xls_report(self, _p, _xs, data, objects, wb): def generate_xls_report(self, _p, _xs, data, objects, wb):
@ -207,16 +269,22 @@ class partners_balance_xls(report_xls):
row_pos = self.print_title(ws, _p, row_pos, xlwt, _xs) row_pos = self.print_title(ws, _p, row_pos, xlwt, _xs)
# Print empty row to define column sizes # Print empty row to define column sizes
row_pos = self.print_empty_row(ws, row_pos) row_pos = self.print_empty_row(ws, row_pos)
# Print Header Table titles (Fiscal Year - Accounts Filter - Periods Filter...)
# Print Header Table titles (Fiscal Year - Accounts Filter - Periods
# Filter...)
row_pos = self.print_header_titles(ws, _p, data, row_pos, xlwt, _xs) 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
initial_balance_text = {
'initial_balance': _('Computed'),
'opening_balance': _('Opening Entries'),
False: _('No')} # cf. account_report_partner_balance.mako
# Print Header Table data # Print Header Table data
row_pos = self.print_header_data(ws, _p, data, row_pos, xlwt, _xs, initial_balance_text)
row_pos = self.print_header_data(
ws, _p, data, row_pos, xlwt, _xs, initial_balance_text)
# Print comparison header table # Print comparison header table
if _p.comparison_mode in ('single', 'multiple'): if _p.comparison_mode in ('single', 'multiple'):
row_pos += 1 row_pos += 1
row_pos = self.print_comparison_header(_xs, xlwt, row_pos, _p, ws, initial_balance_text)
row_pos = self.print_comparison_header(
_xs, xlwt, row_pos, _p, ws, initial_balance_text)
# Freeze the line # Freeze the line
ws.set_horz_split_pos(row_pos) ws.set_horz_split_pos(row_pos)
@ -224,9 +292,12 @@ class partners_balance_xls(report_xls):
# cell styles for account data # cell styles for account data
regular_cell_format = _xs['borders_all'] regular_cell_format = _xs['borders_all']
regular_cell_style = xlwt.easyxf(regular_cell_format) 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')
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')
row_pos += 1 row_pos += 1
for current_account in objects: for current_account in objects:
@ -239,7 +310,8 @@ class partners_balance_xls(report_xls):
comparisons = current_account.comparisons comparisons = current_account.comparisons
# in multiple columns mode, we do not want to print accounts without any rows
# in multiple columns mode, we do not want to print accounts
# without any rows
if _p.comparison_mode in ('single', 'multiple'): if _p.comparison_mode in ('single', 'multiple'):
all_comparison_lines = [comp['partners_amounts'][partner_id[1]] all_comparison_lines = [comp['partners_amounts'][partner_id[1]]
for partner_id in partners_order for partner_id in partners_order
@ -255,19 +327,28 @@ class partners_balance_xls(report_xls):
comparison_total[i] = {'balance': 0.0} comparison_total[i] = {'balance': 0.0}
# print row: Code - Account name # print row: Code - Account name
row_pos = self.print_row_code_account(ws, current_account, row_pos, _xs, xlwt)
row_pos = self.print_row_code_account(
ws, current_account, row_pos, _xs, xlwt)
row_account_start = row_pos 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"
# 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) 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:
for (partner_code_name, partner_id, partner_ref, partner_name)\
in partners_order:
partner = current_partner_amounts.get(partner_id, {}) 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
# 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'): if _p.comparison_mode in ('single', 'multiple'):
all_comparison_lines = [comp['partners_amounts'][partner_id]
all_comparison_lines = [comp['partners_amounts']
[partner_id]
for comp in comparisons for comp in comparisons
if comp['partners_amounts'].get(partner_id)]
if comp['partners_amounts'].
get(partner_id)]
if not display_line(all_comparison_lines): if not display_line(all_comparison_lines):
continue continue
@ -277,8 +358,11 @@ class partners_balance_xls(report_xls):
else: else:
account_span = _p.initial_balance_mode and 2 or 3 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 '')]
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': if _p.comparison_mode == 'no_comparison':
bal_formula = '' bal_formula = ''
if _p.initial_balance_mode: if _p.initial_balance_mode:
@ -286,20 +370,27 @@ class partners_balance_xls(report_xls):
bal_formula = init_bal_cell + '+' bal_formula = init_bal_cell + '+'
debit_col = 4 debit_col = 4
c_specs += [ c_specs += [
('init_bal', 1, 0, 'number', partner.get('init_balance', 0.0), None, regular_cell_style_decimal),
('init_bal', 1, 0, 'number', partner.get(
'init_balance', 0.0), None,
regular_cell_style_decimal),
] ]
else: else:
debit_col = 3 debit_col = 3
c_specs += [ 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', 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) debit_cell = rowcol_to_cell(row_pos, debit_col)
credit_cell = rowcol_to_cell(row_pos, debit_col + 1) credit_cell = rowcol_to_cell(row_pos, debit_col + 1)
bal_formula += debit_cell + '-' + credit_cell bal_formula += debit_cell + '-' + credit_cell
c_specs += [('bal', 1, 0, 'number', None, bal_formula, regular_cell_style_decimal),]
c_specs += [('bal', 1, 0, 'number', None,
bal_formula, regular_cell_style_decimal), ]
else: else:
c_specs += [('bal', 1, 0, 'number', partner.get('balance', 0.0), None, regular_cell_style_decimal),]
c_specs += [('bal', 1, 0, 'number', partner.get('balance',
0.0),
None, regular_cell_style_decimal), ]
if _p.comparison_mode in ('single', 'multiple'): if _p.comparison_mode in ('single', 'multiple'):
for i, comp in enumerate(comparisons): for i, comp in enumerate(comparisons):
@ -308,21 +399,33 @@ class partners_balance_xls(report_xls):
if comp_partners.get(partner_id): if comp_partners.get(partner_id):
balance = comp_partners[partner_id]['balance'] balance = comp_partners[partner_id]['balance']
diff = comp_partners[partner_id]['diff'] diff = comp_partners[partner_id]['diff']
percent_diff = comp_partners[partner_id]['percent_diff']
percent_diff = comp_partners[
partner_id]['percent_diff']
comparison_total[i]['balance'] += balance comparison_total[i]['balance'] += balance
c_specs += [('balance_%s' %i, 1, 0, 'number', balance, None, regular_cell_style_decimal), ]
if _p.comparison_mode == 'single': ## no diff in multiple comparisons because it shows too much data
c_specs += [('balance_diff', 1, 0, 'number', diff, None, regular_cell_style_decimal), ]
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: if percent_diff is False:
c_specs += [('balance', 1, 0, 'number', diff, None, regular_cell_style_decimal), ]
c_specs += [('balance', 1, 0, 'number',
diff, None, regular_cell_style_decimal), ]
else: 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)
partners_balance_xls('report.account.account_report_partner_balance_xls', 'account.account',
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)
partners_balance_xls('report.account.account_report_partner_balance_xls',
'account.account',
parser=PartnerBalanceWebkit) parser=PartnerBalanceWebkit)
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

183
account_financial_report_webkit_xls/report/trial_balance_xls.py

@ -21,15 +21,15 @@
############################################################################## ##############################################################################
import xlwt import xlwt
import time
from openerp.report import report_sxw
from openerp.addons.report_xls.report_xls import report_xls from openerp.addons.report_xls.report_xls import report_xls
from openerp.addons.report_xls.utils import rowcol_to_cell from openerp.addons.report_xls.utils import rowcol_to_cell
from openerp.addons.account_financial_report_webkit.report.trial_balance import TrialBalanceWebkit
from openerp.addons.account_financial_report_webkit.report.trial_balance\
import TrialBalanceWebkit
from openerp.tools.translate import _ from openerp.tools.translate import _
#import logging #import logging
#_logger = logging.getLogger(__name__) #_logger = logging.getLogger(__name__)
class trial_balance_xls(report_xls): class trial_balance_xls(report_xls):
column_sizes = [12, 60, 17, 17, 17, 17, 17, 17] column_sizes = [12, 60, 17, 17, 17, 17, 17, 17]
@ -47,22 +47,29 @@ class trial_balance_xls(report_xls):
ws.footer_str = self.xls_footers['standard'] ws.footer_str = self.xls_footers['standard']
# cf. account_report_trial_balance.mako # cf. account_report_trial_balance.mako
initial_balance_text = {'initial_balance': _('Computed'), 'opening_balance': _('Opening Entries'), False: _('No')}
initial_balance_text = {'initial_balance': _('Computed'),
'opening_balance': _('Opening Entries'),
False: _('No')}
# Title # Title
cell_style = xlwt.easyxf(_xs['xls_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])
report_name = ' - '.join([_p.report_name.upper(),
_p.company.partner_id.name,
_p.company.currency_id.name])
c_specs = [ c_specs = [
('report_name', 1, 0, 'text', report_name), ('report_name', 1, 0, 'text', report_name),
] ]
row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs]) 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 = self.xls_write_row(
ws, row_pos, row_data, row_style=cell_style)
# write empty row to define column sizes # write empty row to define column sizes
c_sizes = self.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))]
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_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)
row_pos = self.xls_write_row(
ws, row_pos, row_data, set_column_size=True)
# Header Table # Header Table
cell_format = _xs['bold'] + _xs['fill_blue'] + _xs['borders_all'] cell_format = _xs['bold'] + _xs['fill_blue'] + _xs['borders_all']
@ -71,20 +78,25 @@ class trial_balance_xls(report_xls):
c_specs = [ c_specs = [
('fy', 1, 0, 'text', _('Fiscal Year')), ('fy', 1, 0, 'text', _('Fiscal Year')),
('af', 2, 0, 'text', _('Accounts Filter')), ('af', 2, 0, 'text', _('Accounts Filter')),
('df', 1, 0, 'text', _p.filter_form(data) == 'filter_date' and _('Dates Filter') or _('Periods 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), ('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),
('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_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 = self.xls_write_row(
ws, row_pos, row_data, row_style=cell_style)
cell_format = _xs['borders_all'] + _xs['wrap'] + _xs['top'] cell_format = _xs['borders_all'] + _xs['wrap'] + _xs['top']
cell_style = xlwt.easyxf(cell_format) cell_style = xlwt.easyxf(cell_format)
cell_style_center = xlwt.easyxf(cell_format + _xs['center']) cell_style_center = xlwt.easyxf(cell_format + _xs['center'])
c_specs = [ c_specs = [
('fy', 1, 0, 'text', _p.fiscalyear.name if _p.fiscalyear else '-'), ('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')),
('af', 2, 0, 'text', _p.accounts(data) and ', '.join(
[account.code for account in _p.accounts(data)]) or _('All')),
] ]
df = _('From') + ': ' df = _('From') + ': '
if _p.filter_form(data) == 'filter_date': if _p.filter_form(data) == 'filter_date':
@ -98,38 +110,58 @@ class trial_balance_xls(report_xls):
df += _p.stop_period.name if _p.stop_period else u'' df += _p.stop_period.name if _p.stop_period else u''
c_specs += [ c_specs += [
('df', 1, 0, 'text', df), ('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),
('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_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 = self.xls_write_row(
ws, row_pos, row_data, row_style=cell_style)
# comparison header table # comparison header table
if _p.comparison_mode in ('single', 'multiple'): if _p.comparison_mode in ('single', 'multiple'):
row_pos += 1 row_pos += 1
cell_format_ct = _xs['bold'] + _xs['fill_blue'] + _xs['borders_all']
cell_format_ct = _xs['bold'] + \
_xs['fill_blue'] + _xs['borders_all']
cell_style_ct = xlwt.easyxf(cell_format_ct) cell_style_ct = xlwt.easyxf(cell_format_ct)
c_specs = [('ct', 8, 0, 'text', _('Comparisons'))] c_specs = [('ct', 8, 0, 'text', _('Comparisons'))]
row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs]) 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)
row_pos = self.xls_write_row(
ws, row_pos, row_data, row_style=cell_style_ct)
cell_style_center = xlwt.easyxf(cell_format) cell_style_center = xlwt.easyxf(cell_format)
for index, params in enumerate(_p.comp_params): for index, params in enumerate(_p.comp_params):
c_specs = [('c', 3, 0, 'text', _('Comparison') + str(index + 1) + ' (C' + str(index + 1) + ')')]
c_specs = [
('c', 3, 0, 'text', _('Comparison') + str(index + 1) +
' (C' + str(index + 1) + ')')]
if params['comparison_filter'] == 'filter_date': 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))]
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': elif params['comparison_filter'] == 'filter_period':
c_specs += [('f', 3, 0, 'text', _('Periods Filter') + ': ' + params['start'].name + ' - ' + params['stop'].name)]
c_specs += [('f', 3, 0, 'text', _('Periods Filter') +
': ' + params['start'].name + ' - ' +
params['stop'].name)]
else: 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)
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 row_pos += 1
# Column Header Row # Column Header Row
cell_format = _xs['bold'] + _xs['fill_blue'] + _xs['borders_all'] + _xs['wrap'] + _xs['top']
cell_format = _xs['bold'] + _xs['fill_blue'] + \
_xs['borders_all'] + _xs['wrap'] + _xs['top']
cell_style = xlwt.easyxf(cell_format) cell_style = xlwt.easyxf(cell_format)
cell_style_right = xlwt.easyxf(cell_format + _xs['right']) cell_style_right = xlwt.easyxf(cell_format + _xs['right'])
cell_style_center = xlwt.easyxf(cell_format + _xs['center']) cell_style_center = xlwt.easyxf(cell_format + _xs['center'])
@ -143,30 +175,42 @@ class trial_balance_xls(report_xls):
] ]
if _p.comparison_mode == 'no_comparison': if _p.comparison_mode == 'no_comparison':
if _p.initial_balance_mode: if _p.initial_balance_mode:
c_specs += [('init_bal', 1, 0, 'text', _('Initial Balance'), None, cell_style_right)]
c_specs += [('init_bal', 1, 0, 'text',
_('Initial Balance'), None, cell_style_right)]
c_specs += [ c_specs += [
('debit', 1, 0, 'text', _('Debit'), None, cell_style_right), ('debit', 1, 0, 'text', _('Debit'), None, cell_style_right),
('credit', 1, 0, 'text', _('Credit'), None, cell_style_right), ('credit', 1, 0, 'text', _('Credit'), None, cell_style_right),
] ]
if _p.comparison_mode == 'no_comparison' or not _p.fiscalyear: if _p.comparison_mode == 'no_comparison' or not _p.fiscalyear:
c_specs += [('balance', 1, 0, 'text', _('Balance'), None, cell_style_right)]
c_specs += [('balance', 1, 0, 'text',
_('Balance'), None, cell_style_right)]
else: else:
c_specs += [('balance_fy', 1, 0, 'text', _('Balance %s') % _p.fiscalyear.name, None, cell_style_right)]
c_specs += [('balance_fy', 1, 0, 'text', _('Balance %s') %
_p.fiscalyear.name, None, cell_style_right)]
if _p.comparison_mode in ('single', 'multiple'): if _p.comparison_mode in ('single', 'multiple'):
for index in range(_p.nb_comparison): 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)]
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: else:
c_specs += [('balance_%s' %index, 1, 0, 'text', _('Balance C%s') % (index + 1), None, cell_style_right)]
c_specs += [('balance_%s' % index, 1, 0, 'text',
_('Balance C%s') % (index + 1), None,
cell_style_right)]
if _p.comparison_mode == 'single': if _p.comparison_mode == 'single':
c_specs += [ c_specs += [
('diff', 1, 0, 'text', _('Difference'), None, cell_style_right),
('diff_percent', 1, 0, 'text', _('% Difference'), None, cell_style_center),
('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)] 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_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 = self.xls_write_row(
ws, row_pos, row_data, row_style=cell_style)
ws.set_horz_split_pos(row_pos) ws.set_horz_split_pos(row_pos)
last_child_consol_ids = [] last_child_consol_ids = []
@ -176,13 +220,20 @@ class trial_balance_xls(report_xls):
view_cell_format = _xs['bold'] + _xs['fill'] + _xs['borders_all'] view_cell_format = _xs['bold'] + _xs['fill'] + _xs['borders_all']
view_cell_style = xlwt.easyxf(view_cell_format) view_cell_style = xlwt.easyxf(view_cell_format)
view_cell_style_center = xlwt.easyxf(view_cell_format + _xs['center']) 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')
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_format = _xs['borders_all']
regular_cell_style = xlwt.easyxf(regular_cell_format) 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')
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: for current_account in objects:
@ -203,14 +254,18 @@ class trial_balance_xls(report_xls):
comparisons = current_account.comparisons comparisons = current_account.comparisons
if current_account.id in last_child_consol_ids: if current_account.id in last_child_consol_ids:
# current account is a consolidation child of the last account: use the level of last account
# current account is a consolidation child of the last account:
# use the level of last account
level = last_level level = last_level
level_class = 'account_level_consol' level_class = 'account_level_consol'
else: else:
# current account is a not a consolidation child: use its own level
# current account is a not a consolidation child: use its own
# level
level = current_account.level or 0 level = current_account.level or 0
level_class = "account_level_%s" % (level,) level_class = "account_level_%s" % (level,)
last_child_consol_ids = [child_consol_id.id for child_consol_id in current_account.child_consol_ids]
last_child_consol_ids = [
child_consol_id.id for child_consol_id in
current_account.child_consol_ids]
last_level = current_account.level last_level = current_account.level
c_specs = [ c_specs = [
@ -227,32 +282,48 @@ class trial_balance_xls(report_xls):
init_cell = rowcol_to_cell(row_pos, 3) init_cell = rowcol_to_cell(row_pos, 3)
debit_cell = rowcol_to_cell(row_pos, 4) debit_cell = rowcol_to_cell(row_pos, 4)
credit_cell = rowcol_to_cell(row_pos, 5) 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)]
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 += [ c_specs += [
('debit', 1, 0, 'number', current_account.debit, None, cell_style_decimal),
('credit', 1, 0, 'number', current_account.credit, None, cell_style_decimal),
('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)]
c_specs += [('balance', 1, 0, 'number', None,
bal_formula, cell_style_decimal)]
else: else:
c_specs += [('balance', 1, 0, 'number', current_account.balance, None, cell_style_decimal)]
c_specs += [('balance', 1, 0, 'number',
current_account.balance, None,
cell_style_decimal)]
if _p.comparison_mode in ('single', 'multiple'): if _p.comparison_mode in ('single', 'multiple'):
c = 1 c = 1
for comp_account in comparisons: for comp_account in comparisons:
c_specs += [('balance_%s' %c, 1, 0, 'number', comp_account['balance'], None, cell_style_decimal)]
c_specs += [('balance_%s' % c, 1, 0, 'number',
comp_account['balance'], None,
cell_style_decimal)]
c += 1 c += 1
if _p.comparison_mode == 'single': if _p.comparison_mode == 'single':
c_specs += [ 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),
('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)]
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_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 = self.xls_write_row(
ws, row_pos, row_data, row_style=cell_style)
trial_balance_xls('report.account.account_report_trial_balance_xls', 'account.account',
trial_balance_xls('report.account.account_report_trial_balance_xls',
'account.account',
parser=TrialBalanceWebkit) parser=TrialBalanceWebkit)
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

5
account_financial_report_webkit_xls/wizard/general_ledger_wizard.py

@ -24,6 +24,7 @@ from openerp.osv import orm
#import logging #import logging
#_logger = logging.getLogger(__name__) #_logger = logging.getLogger(__name__)
class general_ledger_webkit_wizard(orm.TransientModel): class general_ledger_webkit_wizard(orm.TransientModel):
_inherit = 'general.ledger.webkit' _inherit = 'general.ledger.webkit'
@ -39,5 +40,5 @@ class general_ledger_webkit_wizard(orm.TransientModel):
'report_name': 'account.account_report_general_ledger_xls', 'report_name': 'account.account_report_general_ledger_xls',
'datas': data} 'datas': data}
else: else:
return super(general_ledger_webkit_wizard, self)._print_report(cr, uid, ids, data, context=context)
return super(general_ledger_webkit_wizard, self)._print_report(
cr, uid, ids, data, context=context)

4
account_financial_report_webkit_xls/wizard/open_invoices_wizard.py

@ -24,6 +24,7 @@ from openerp.osv import orm
#import logging #import logging
#_logger = logging.getLogger(__name__) #_logger = logging.getLogger(__name__)
class open_invoices_webkit_wizard(orm.TransientModel): class open_invoices_webkit_wizard(orm.TransientModel):
_inherit = 'open.invoices.webkit' _inherit = 'open.invoices.webkit'
@ -39,4 +40,5 @@ class open_invoices_webkit_wizard(orm.TransientModel):
'report_name': 'account.account_report_open_invoices_xls', 'report_name': 'account.account_report_open_invoices_xls',
'datas': data} 'datas': data}
else: else:
return super(open_invoices_webkit_wizard, self)._print_report(cr, uid, ids, data, context=context)
return super(open_invoices_webkit_wizard, self)._print_report(
cr, uid, ids, data, context=context)

8
account_financial_report_webkit_xls/wizard/partners_balance_wizard.py

@ -24,6 +24,7 @@ from openerp.osv import orm
#import logging #import logging
#_logger = logging.getLogger(__name__) #_logger = logging.getLogger(__name__)
class partner_balance_wizard(orm.TransientModel): class partner_balance_wizard(orm.TransientModel):
_inherit = 'partner.balance.webkit' _inherit = 'partner.balance.webkit'
@ -35,9 +36,10 @@ class partner_balance_wizard(orm.TransientModel):
if context.get('xls_export'): if context.get('xls_export'):
# we update form with display account value # we update form with display account value
data = self.pre_print_report(cr, uid, ids, data, context=context) data = self.pre_print_report(cr, uid, ids, data, context=context)
return {'type': 'ir.actions.report.xml',
return {
'type': 'ir.actions.report.xml',
'report_name': 'account.account_report_partner_balance_xls', 'report_name': 'account.account_report_partner_balance_xls',
'datas': data} 'datas': data}
else: else:
return super(partner_balance_wizard, self)._print_report(cr, uid, ids, data, context=context)
return super(partner_balance_wizard, self)._print_report(
cr, uid, ids, data, context=context)

4
account_financial_report_webkit_xls/wizard/partners_ledger_wizard.py

@ -24,6 +24,7 @@ from openerp.osv import orm
#import logging #import logging
#_logger = logging.getLogger(__name__) #_logger = logging.getLogger(__name__)
class partner_ledger_webkit_wizard(orm.TransientModel): class partner_ledger_webkit_wizard(orm.TransientModel):
_inherit = 'partners.ledger.webkit' _inherit = 'partners.ledger.webkit'
@ -39,4 +40,5 @@ class partner_ledger_webkit_wizard(orm.TransientModel):
'report_name': 'account.account_report_partner_ledger_xls', 'report_name': 'account.account_report_partner_ledger_xls',
'datas': data} 'datas': data}
else: else:
return super(partner_ledger_webkit_wizard, self)._print_report(cr, uid, ids, data, context=context)
return super(partner_ledger_webkit_wizard, self)._print_report(
cr, uid, ids, data, context=context)

5
account_financial_report_webkit_xls/wizard/trial_balance_wizard.py

@ -24,6 +24,7 @@ from openerp.osv import orm
#import logging #import logging
#_logger = logging.getLogger(__name__) #_logger = logging.getLogger(__name__)
class trial_balance_wizard(orm.TransientModel): class trial_balance_wizard(orm.TransientModel):
_inherit = 'trial.balance.webkit' _inherit = 'trial.balance.webkit'
@ -39,5 +40,5 @@ class trial_balance_wizard(orm.TransientModel):
'report_name': 'account.account_report_trial_balance_xls', 'report_name': 'account.account_report_trial_balance_xls',
'datas': data} 'datas': data}
else: else:
return super(trial_balance_wizard, self)._print_report(cr, uid, ids, data, context=context)
return super(trial_balance_wizard, self)._print_report(
cr, uid, ids, data, context=context)
Loading…
Cancel
Save