[pep8] - account_journal_report_xls
parent
bff5f4222c
commit
a066faee80
|
@ -26,6 +26,7 @@ try:
|
|||
from . import report
|
||||
except ImportError:
|
||||
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''')
|
||||
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||
|
|
|
@ -21,8 +21,6 @@
|
|||
##############################################################################
|
||||
|
||||
from openerp.osv import orm
|
||||
from openerp.addons.report_xls.utils import rowcol_to_cell, _render
|
||||
from openerp.tools.translate import _
|
||||
|
||||
|
||||
class account_journal(orm.Model):
|
||||
|
@ -59,17 +57,18 @@ class account_journal(orm.Model):
|
|||
'credit', # account.move.line,credit
|
||||
'balance', # debit-credit
|
||||
'docname', # origin document if any
|
||||
#'date_maturity', # account.move.line,date_maturity
|
||||
#'reconcile', # account.move.line,reconcile_id.name
|
||||
#'reconcile_partial', # account.move.line,reconcile_partial_id.name
|
||||
#'partner_ref', # res.partner,ref
|
||||
#'move_ref', # account.move,ref
|
||||
#'move_id', # account.move,id
|
||||
#'acc_name', # account.account,name
|
||||
#'journal', # account.journal,name
|
||||
#'journal_code', # account.journal,code
|
||||
#'analytic_account', # account.analytic.account,name
|
||||
#'analytic_account_code', # account.analytic.account,code
|
||||
# 'date_maturity', # account.move.line,date_maturity
|
||||
# 'reconcile', # account.move.line,reconcile_id.name
|
||||
# 'reconcile_partial',
|
||||
# account.move.line,reconcile_partial_id.name
|
||||
# 'partner_ref', # res.partner,ref
|
||||
# 'move_ref', # account.move,ref
|
||||
# 'move_id', # account.move,id
|
||||
# 'acc_name', # account.account,name
|
||||
# 'journal', # account.journal,name
|
||||
# 'journal_code', # account.journal,code
|
||||
# 'analytic_account', # account.analytic.account,name
|
||||
# 'analytic_account_code', # account.analytic.account,code
|
||||
]
|
||||
return res
|
||||
|
||||
|
@ -81,7 +80,8 @@ class account_journal(orm.Model):
|
|||
my_change = {
|
||||
'move_name':{
|
||||
'header': [1, 20, 'text', _render("_('My Move Title')")],
|
||||
'lines': [1, 0, 'text', _render("l['move_name'] != '/' and l['move_name'] or ('*'+str(l['move_id']))")],
|
||||
'lines': [1, 0, 'text', _render("l['move_name'] != '/' and
|
||||
l['move_name'] or ('*'+str(l['move_id']))")],
|
||||
'totals': [1, 0, 'text', None]},
|
||||
}
|
||||
return my_change
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
|
||||
import time
|
||||
from openerp.report import report_sxw
|
||||
from openerp.tools.translate import translate, _
|
||||
from openerp.tools.translate import translate
|
||||
import logging
|
||||
_logger = logging.getLogger(__name__)
|
||||
|
||||
|
@ -32,7 +32,8 @@ _ir_translation_name = 'nov.account.journal.print'
|
|||
class nov_journal_print(report_sxw.rml_parse):
|
||||
|
||||
def set_context(self, objects, data, ids, report_type=None):
|
||||
#_logger.warn('set_context, objects = %s, data = %s, ids = %s', objects, data, ids)
|
||||
# _logger.warn('set_context, objects = %s, data = %s,
|
||||
# ids = %s', objects, data, ids)
|
||||
super(nov_journal_print, self).set_context(objects, data, ids)
|
||||
j_obj = self.pool.get('account.journal')
|
||||
p_obj = self.pool.get('account.period')
|
||||
|
@ -42,7 +43,8 @@ class nov_journal_print(report_sxw.rml_parse):
|
|||
self.move_states = ['posted']
|
||||
else:
|
||||
self.move_states = ['draft', 'posted']
|
||||
self.display_currency = self.localcontext['display_currency'] = data['display_currency']
|
||||
self.display_currency = self.localcontext[
|
||||
'display_currency'] = data['display_currency']
|
||||
self.group_entries = data['group_entries']
|
||||
self.print_by = data['print_by']
|
||||
self.report_type = report_type
|
||||
|
@ -59,7 +61,8 @@ class nov_journal_print(report_sxw.rml_parse):
|
|||
objects = []
|
||||
for jf in journal_fy_ids:
|
||||
journal = j_obj.browse(self.cr, self.uid, jf[0], self.context)
|
||||
fiscalyear = fy_obj.browse(self.cr, self.uid, jf[1], self.context)
|
||||
fiscalyear = fy_obj.browse(
|
||||
self.cr, self.uid, jf[1], self.context)
|
||||
objects.append((journal, fiscalyear))
|
||||
self.localcontext['objects'] = self.objects = objects
|
||||
|
||||
|
@ -82,16 +85,20 @@ class nov_journal_print(report_sxw.rml_parse):
|
|||
|
||||
def _(self, src):
|
||||
lang = self.context.get('lang', 'en_US')
|
||||
return translate(self.cr, _ir_translation_name, 'report', lang, src) or src
|
||||
return translate(self.cr, _ir_translation_name, 'report', lang, src)\
|
||||
or src
|
||||
|
||||
def _title(self, object):
|
||||
return ((self.print_by == 'period' and self._('Period') or self._('Fiscal Year')) + ' ' + object[1].name, object[0].name)
|
||||
return ((self.print_by == 'period' and self._('Period') or
|
||||
self._('Fiscal Year')) + ' ' + object[1].name, object[0].name)
|
||||
|
||||
def _amount_title(self):
|
||||
return self.display_currency and (self._('Amount'), self._('Currency')) or (self._('Debit'), self._('Credit'))
|
||||
return self.display_currency and\
|
||||
(self._('Amount'), self._('Currency')) or (
|
||||
self._('Debit'), self._('Credit'))
|
||||
|
||||
def _lines(self, object):
|
||||
j_obj = self.pool.get('account.journal')
|
||||
j_obj = self.pool['account.journal']
|
||||
_ = self._
|
||||
journal = object[0]
|
||||
journal_id = journal.id
|
||||
|
@ -100,74 +107,115 @@ class nov_journal_print(report_sxw.rml_parse):
|
|||
period_id = period.id
|
||||
period_ids = [period_id]
|
||||
# update status period
|
||||
ids_journal_period = self.pool.get('account.journal.period').search(self.cr, self.uid,
|
||||
[('journal_id', '=', journal_id), ('period_id', '=', period_id)])
|
||||
ids_journal_period = self.pool['account.journal.period'].\
|
||||
search(self.cr, self.uid, [('journal_id', '=', journal_id),
|
||||
('period_id', '=', period_id)])
|
||||
if ids_journal_period:
|
||||
self.cr.execute(
|
||||
'update account_journal_period set state=%s where journal_id=%s and period_id=%s and state=%s',
|
||||
'''update account_journal_period set state=%s
|
||||
where journal_id=%s and period_id=%s and state=%s''',
|
||||
('printed', journal_id, period_id, 'draft'))
|
||||
else:
|
||||
self.pool.get('account.journal.period').create(self.cr, self.uid, {
|
||||
'name': (journal.code or journal.name) + ':' + (period.name or ''),
|
||||
'journal_id': journal.id,
|
||||
'period_id': period.id,
|
||||
'state': 'printed',
|
||||
self.pool.get('account.journal.period').create(
|
||||
self.cr, self.uid,
|
||||
{'name': (journal.code or journal.name) + ':' +
|
||||
(period.name or ''),
|
||||
'journal_id': journal.id,
|
||||
'period_id': period.id,
|
||||
'state': 'printed',
|
||||
})
|
||||
_logger.error("The Entry for Period '%s', Journal '%s' was missing in 'account.journal.period' and has been fixed now !",
|
||||
period.name, journal.name)
|
||||
_logger.error("""The Entry for Period '%s', Journal '%s' was
|
||||
missing in 'account.journal.period' and
|
||||
has been fixed now !""",
|
||||
period.name, journal.name)
|
||||
else:
|
||||
fiscalyear = object[1]
|
||||
period_ids = [x.id for x in fiscalyear.period_ids]
|
||||
|
||||
select_extra, join_extra, where_extra = j_obj._report_xls_query_extra(self.cr, self.uid, self.context)
|
||||
select_extra, join_extra, where_extra = j_obj._report_xls_query_extra(
|
||||
self.cr, self.uid, self.context)
|
||||
|
||||
# SQL select for performance reasons, as a consequence, there are no field value translations.
|
||||
# If performance is no issue, you can adapt the _report_xls_template in an inherited module to add field value translations.
|
||||
# SQL select for performance reasons, as a consequence, there are no
|
||||
# field value translations.
|
||||
# If performance is no issue, you can adapt the _report_xls_template in
|
||||
# an inherited module to add field value translations.
|
||||
self.cr.execute("SELECT l.move_id AS move_id, l.id AS aml_id, "
|
||||
"am.name AS move_name, coalesce(am.ref,'') AS move_ref, am.date AS move_date, "
|
||||
"aa.id AS account_id, aa.code AS acc_code, aa.name AS acc_name, "
|
||||
"aj.name AS journal, aj.code AS journal_code, "
|
||||
"coalesce(rp.name,'') AS partner_name, coalesce(rp.ref,'') AS partner_ref, rp.id AS partner_id, "
|
||||
"coalesce(l.name,'') AS aml_name, "
|
||||
"l.date_maturity AS date_maturity, "
|
||||
"coalesce(ap.code, ap.name) AS period, "
|
||||
"coalesce(atc.code,'') AS tax_code, atc.id AS tax_code_id, coalesce(l.tax_amount,0.0) AS tax_amount, "
|
||||
"coalesce(l.debit,0.0) AS debit, coalesce(l.credit,0.0) AS credit, "
|
||||
"coalesce(amr.name,'') AS reconcile, coalesce(amrp.name,'') AS reconcile_partial, "
|
||||
"ana.name AS an_acc_name, coalesce(ana.code,'') AS an_acc_code, "
|
||||
"coalesce(l.amount_currency,0.0) AS amount_currency, "
|
||||
"rc.id AS currency_id, rc.name AS currency_name, rc.symbol AS currency_symbol, "
|
||||
"coalesce(ai.internal_number,'-') AS inv_number, coalesce(abs.name,'-') AS st_number, coalesce(av.number,'-') AS voucher_number "
|
||||
+ select_extra +
|
||||
"FROM account_move_line l "
|
||||
"INNER JOIN account_move am ON l.move_id = am.id "
|
||||
"INNER JOIN account_account aa ON l.account_id = aa.id "
|
||||
"INNER JOIN account_journal aj ON l.journal_id = aj.id "
|
||||
"INNER JOIN account_period ap ON l.period_id = ap.id "
|
||||
"LEFT OUTER JOIN account_invoice ai ON ai.move_id = am.id "
|
||||
"LEFT OUTER JOIN account_voucher av ON av.move_id = am.id "
|
||||
"LEFT OUTER JOIN account_bank_statement abs ON l.statement_id = abs.id "
|
||||
"LEFT OUTER JOIN res_partner rp ON l.partner_id = rp.id "
|
||||
"LEFT OUTER JOIN account_tax_code atc ON l.tax_code_id = atc.id "
|
||||
"LEFT OUTER JOIN account_move_reconcile amr ON l.reconcile_id = amr.id "
|
||||
"LEFT OUTER JOIN account_move_reconcile amrp ON l.reconcile_partial_id = amrp.id "
|
||||
"LEFT OUTER JOIN account_analytic_account ana ON l.analytic_account_id = ana.id "
|
||||
"LEFT OUTER JOIN res_currency rc ON l.currency_id = rc.id "
|
||||
+ join_extra +
|
||||
"WHERE l.period_id IN %s AND l.journal_id = %s "
|
||||
"AND am.state IN %s "
|
||||
+ where_extra +
|
||||
"ORDER BY " + self.sort_selection + ", move_date, move_id, acc_code",
|
||||
(tuple(period_ids), journal_id, tuple(self.move_states)))
|
||||
"am.name AS move_name,"
|
||||
"coalesce(am.ref,'') AS move_ref,"
|
||||
"am.date AS move_date, "
|
||||
"aa.id AS account_id, aa.code AS acc_code,"
|
||||
"aa.name AS acc_name, "
|
||||
"aj.name AS journal, aj.code AS journal_code, "
|
||||
"coalesce(rp.name,'') AS partner_name,"
|
||||
"coalesce(rp.ref,'') AS partner_ref,"
|
||||
"rp.id AS partner_id, "
|
||||
"coalesce(l.name,'') AS aml_name, "
|
||||
"l.date_maturity AS date_maturity, "
|
||||
"coalesce(ap.code, ap.name) AS period, "
|
||||
"coalesce(atc.code,'') AS tax_code,"
|
||||
"atc.id AS tax_code_id,"
|
||||
"coalesce(l.tax_amount,0.0) AS tax_amount, "
|
||||
"coalesce(l.debit,0.0) AS debit,"
|
||||
"coalesce(l.credit,0.0) AS credit, "
|
||||
"coalesce(amr.name,'') AS reconcile,"
|
||||
"coalesce(amrp.name,'') AS reconcile_partial, "
|
||||
"ana.name AS an_acc_name,"
|
||||
"coalesce(ana.code,'') AS an_acc_code, "
|
||||
"coalesce(l.amount_currency,0.0) AS amount_currency, "
|
||||
"rc.id AS currency_id, rc.name AS currency_name,"
|
||||
"rc.symbol AS currency_symbol, "
|
||||
"coalesce(ai.internal_number,'-') AS inv_number,"
|
||||
"coalesce(abs.name,'-') AS st_number,"
|
||||
"coalesce(av.number,'-') AS voucher_number "
|
||||
+ select_extra +
|
||||
"FROM account_move_line l "
|
||||
"INNER JOIN account_move am ON l.move_id = am.id "
|
||||
"INNER JOIN account_account aa"
|
||||
"ON l.account_id = aa.id "
|
||||
"INNER JOIN account_journal aj"
|
||||
"ON l.journal_id = aj.id "
|
||||
"INNER JOIN account_period ap ON l.period_id = ap.id "
|
||||
"LEFT OUTER JOIN account_invoice ai"
|
||||
"ON ai.move_id = am.id "
|
||||
"LEFT OUTER JOIN account_voucher av"
|
||||
"ON av.move_id = am.id "
|
||||
"LEFT OUTER JOIN account_bank_statement abs"
|
||||
"ON l.statement_id = abs.id "
|
||||
"LEFT OUTER JOIN res_partner rp"
|
||||
"ON l.partner_id = rp.id "
|
||||
"LEFT OUTER JOIN account_tax_code atc"
|
||||
"ON l.tax_code_id = atc.id "
|
||||
"LEFT OUTER JOIN account_move_reconcile amr"
|
||||
"ON l.reconcile_id = amr.id "
|
||||
"LEFT OUTER JOIN account_move_reconcile amrp"
|
||||
"ON l.reconcile_partial_id = amrp.id "
|
||||
"LEFT OUTER JOIN account_analytic_account ana"
|
||||
"ON l.analytic_account_id = ana.id "
|
||||
"LEFT OUTER JOIN res_currency rc"
|
||||
"ON l.currency_id = rc.id "
|
||||
+ join_extra +
|
||||
"WHERE l.period_id IN %s AND l.journal_id = %s "
|
||||
"AND am.state IN %s "
|
||||
+ where_extra +
|
||||
"ORDER BY " + self.sort_selection +
|
||||
", move_date, move_id, acc_code",
|
||||
(tuple(period_ids), journal_id,
|
||||
tuple(self.move_states)))
|
||||
lines = self.cr.dictfetchall()
|
||||
|
||||
# add reference of corresponding origin document
|
||||
if journal.type in ('sale', 'sale_refund', 'purchase', 'purchase_refund'):
|
||||
[x.update({'docname': (_('Invoice') + ': ' + x['inv_number']) or (_('Voucher') + ': ' + x['voucher_number']) or '-'}) for x in lines]
|
||||
if journal.type in ('sale', 'sale_refund', 'purchase',
|
||||
'purchase_refund'):
|
||||
[x.update({'docname': (_('Invoice') + ': ' + x['inv_number'])
|
||||
or (_('Voucher') + ': ' + x['voucher_number']) or '-'})
|
||||
for x in lines]
|
||||
elif journal.type in ('bank', 'cash'):
|
||||
[x.update({'docname': (_('Statement') + ': ' + x['st_number']) or (_('Voucher') + ': ' + x['voucher_number']) or '-'}) for x in lines]
|
||||
[x.update({'docname': (_('Statement') + ': ' + x['st_number'])
|
||||
or (_('Voucher') + ': ' + x['voucher_number']) or '-'})
|
||||
for x in lines]
|
||||
else:
|
||||
code_string = j_obj._report_xls_document_extra(self.cr, self.uid, self.context)
|
||||
code_string = j_obj._report_xls_document_extra(
|
||||
self.cr, self.uid, self.context)
|
||||
#_logger.warn('code_string= %s', code_string)
|
||||
[x.update({'docname': eval(code_string) or '-'}) for x in lines]
|
||||
|
||||
|
@ -180,10 +228,15 @@ class nov_journal_print(report_sxw.rml_parse):
|
|||
curr_obj = self.pool.get('res.currency')
|
||||
[x.update({
|
||||
'amount1': self.formatLang(x['debit'] - x['credit']),
|
||||
'amount2': self.formatLang(x['amount_currency'], monetary=True, currency_obj=curr_obj.browse(self.cr, self.uid, x['currency_id'])),
|
||||
}) for x in lines]
|
||||
'amount2': self.formatLang(
|
||||
x['amount_currency'], monetary=True,
|
||||
currency_obj=curr_obj.browse(self.cr,
|
||||
self.uid, x['currency_id'])),
|
||||
}) for x in lines]
|
||||
else:
|
||||
[x.update({'amount1': self.formatLang(x['debit']), 'amount2': self.formatLang(x['credit'])}) for x in lines]
|
||||
[x.update({'amount1': self.formatLang(x['debit']),
|
||||
'amount2': self.formatLang(x['credit'])})
|
||||
for x in lines]
|
||||
|
||||
# insert a flag in every move_line to indicate the end of a move
|
||||
# this flag will be used to draw a full line between moves
|
||||
|
@ -205,7 +258,9 @@ class nov_journal_print(report_sxw.rml_parse):
|
|||
return lines_in
|
||||
lines_grouped = {}
|
||||
for line in lines_in:
|
||||
key = (line['account_id'], line['tax_code_id'], line['partner_id'])
|
||||
key = (line['account_id'],
|
||||
line['tax_code_id'],
|
||||
line['partner_id'])
|
||||
if not key in lines_grouped:
|
||||
lines_grouped[key] = line
|
||||
else:
|
||||
|
@ -245,15 +300,19 @@ class nov_journal_print(report_sxw.rml_parse):
|
|||
self.cr.execute(
|
||||
"SELECT distinct tax_code_id FROM account_move_line l "
|
||||
"INNER JOIN account_move am ON l.move_id = am.id "
|
||||
"WHERE l.period_id in %s AND l.journal_id=%s AND l.tax_code_id IS NOT NULL AND am.state IN %s",
|
||||
"WHERE l.period_id in %s AND l.journal_id=%s"
|
||||
"AND l.tax_code_id IS NOT NULL AND am.state IN %s",
|
||||
(tuple(period_ids), journal_id, tuple(self.move_states)))
|
||||
ids = map(lambda x: x[0], self.cr.fetchall())
|
||||
if ids:
|
||||
self.cr.execute('SELECT id FROM account_tax_code WHERE id IN %s ORDER BY code', (tuple(ids),))
|
||||
self.cr.execute(
|
||||
'SELECT id FROM account_tax_code WHERE id IN %s ORDER BY code',
|
||||
(tuple(ids),))
|
||||
tax_code_ids = map(lambda x: x[0], self.cr.fetchall())
|
||||
else:
|
||||
tax_code_ids = []
|
||||
tax_codes = self.pool.get('account.tax.code').browse(self.cr, self.uid, tax_code_ids, self.context)
|
||||
tax_codes = self.pool.get('account.tax.code').browse(
|
||||
self.cr, self.uid, tax_code_ids, self.context)
|
||||
return tax_codes
|
||||
|
||||
def _totals(self, field, object, tax_code_id=None):
|
||||
|
@ -269,7 +328,8 @@ class nov_journal_print(report_sxw.rml_parse):
|
|||
"WHERE l.period_id IN %s AND l.journal_id=%s AND am.state IN %s"
|
||||
if field == 'tax_amount':
|
||||
select += " AND tax_code_id=%s" % tax_code_id
|
||||
self.cr.execute(select, (tuple(period_ids), journal_id, tuple(self.move_states)))
|
||||
self.cr.execute(
|
||||
select, (tuple(period_ids), journal_id, tuple(self.move_states)))
|
||||
return self.cr.fetchone()[0] or 0.0
|
||||
|
||||
def _sum1(self, object):
|
||||
|
@ -277,20 +337,25 @@ class nov_journal_print(report_sxw.rml_parse):
|
|||
|
||||
def _sum2(self, object):
|
||||
if self.display_currency:
|
||||
return ''
|
||||
return ''
|
||||
else:
|
||||
return self._totals('credit', object)
|
||||
|
||||
def _sum_vat(self, object, tax_code):
|
||||
return self._totals('tax_amount', object, tax_code.id)
|
||||
|
||||
def formatLang(self, value, digits=None, date=False, date_time=False, grouping=True, monetary=False, dp=False, currency_obj=False):
|
||||
def formatLang(self, value, digits=None, date=False, date_time=False,
|
||||
grouping=True, monetary=False, dp=False,
|
||||
currency_obj=False):
|
||||
if isinstance(value, (float, int)) and not value:
|
||||
return ''
|
||||
else:
|
||||
return super(nov_journal_print, self).formatLang(value, digits, date, date_time, grouping, monetary, dp, currency_obj)
|
||||
return super(nov_journal_print, self).formatLang(
|
||||
value, digits,
|
||||
date, date_time, grouping, monetary, dp, currency_obj)
|
||||
|
||||
report_sxw.report_sxw('report.nov.account.journal.print', 'account.journal',
|
||||
report_sxw.report_sxw(
|
||||
'report.nov.account.journal.print', 'account.journal',
|
||||
'addons/account_journal_report_xls/report/nov_account_journal.rml',
|
||||
parser=nov_journal_print, header=False)
|
||||
|
||||
|
|
|
@ -21,10 +21,8 @@
|
|||
##############################################################################
|
||||
|
||||
import xlwt
|
||||
import time
|
||||
from datetime import datetime
|
||||
from openerp.osv import orm
|
||||
from openerp.report import report_sxw
|
||||
from openerp.addons.report_xls.report_xls import report_xls
|
||||
from openerp.addons.report_xls.utils import rowcol_to_cell, _render
|
||||
from .nov_account_journal import nov_journal_print
|
||||
|
@ -36,7 +34,8 @@ _logger = logging.getLogger(__name__)
|
|||
class account_journal_xls_parser(nov_journal_print):
|
||||
|
||||
def __init__(self, cr, uid, name, context):
|
||||
super(account_journal_xls_parser, self).__init__(cr, uid, name, context=context)
|
||||
super(account_journal_xls_parser, self).__init__(cr, uid, name,
|
||||
context=context)
|
||||
journal_obj = self.pool.get('account.journal')
|
||||
self.context = context
|
||||
wanted_list = journal_obj._report_xls_fields(cr, uid, context)
|
||||
|
@ -50,8 +49,10 @@ class account_journal_xls_parser(nov_journal_print):
|
|||
|
||||
class account_journal_xls(report_xls):
|
||||
|
||||
def __init__(self, name, table, rml=False, parser=False, header=True, store=False):
|
||||
super(account_journal_xls, self).__init__(name, table, rml, parser, header, store)
|
||||
def __init__(self, name, table, rml=False, parser=False, header=True,
|
||||
store=False):
|
||||
super(account_journal_xls, self).__init__(
|
||||
name, table, rml, parser, header, store)
|
||||
|
||||
# Cell Styles
|
||||
_xs = self.xls_styles
|
||||
|
@ -63,24 +64,36 @@ class account_journal_xls(report_xls):
|
|||
# lines
|
||||
aml_cell_format = _xs['borders_all']
|
||||
self.aml_cell_style = xlwt.easyxf(aml_cell_format)
|
||||
self.aml_cell_style_center = xlwt.easyxf(aml_cell_format + _xs['center'])
|
||||
self.aml_cell_style_date = xlwt.easyxf(aml_cell_format + _xs['left'], num_format_str=report_xls.date_format)
|
||||
self.aml_cell_style_decimal = xlwt.easyxf(aml_cell_format + _xs['right'], num_format_str=report_xls.decimal_format)
|
||||
self.aml_cell_style_center = xlwt.easyxf(
|
||||
aml_cell_format + _xs['center'])
|
||||
self.aml_cell_style_date = xlwt.easyxf(
|
||||
aml_cell_format + _xs['left'],
|
||||
num_format_str=report_xls.date_format)
|
||||
self.aml_cell_style_decimal = xlwt.easyxf(
|
||||
aml_cell_format + _xs['right'],
|
||||
num_format_str=report_xls.decimal_format)
|
||||
# totals
|
||||
rt_cell_format = _xs['bold'] + _xs['fill'] + _xs['borders_all']
|
||||
self.rt_cell_style = xlwt.easyxf(rt_cell_format)
|
||||
self.rt_cell_style_right = xlwt.easyxf(rt_cell_format + _xs['right'])
|
||||
self.rt_cell_style_decimal = xlwt.easyxf(rt_cell_format + _xs['right'], num_format_str=report_xls.decimal_format)
|
||||
self.rt_cell_style_decimal = xlwt.easyxf(
|
||||
rt_cell_format + _xs['right'],
|
||||
num_format_str=report_xls.decimal_format)
|
||||
|
||||
# XLS Template Journal Items
|
||||
self.col_specs_lines_template = {
|
||||
'move_name': {
|
||||
'header': [1, 20, 'text', _render("_('Entry')")],
|
||||
'lines': [1, 0, 'text', _render("l['move_name'] != '/' and l['move_name'] or ('*'+str(l['move_id']))")],
|
||||
'lines':
|
||||
[1, 0, 'text',
|
||||
_render("l['move_name'] != '/' and l['move_name'] or ('*'+str(l['move_id']))")],
|
||||
'totals': [1, 0, 'text', None]},
|
||||
'move_date': {
|
||||
'header': [1, 13, 'text', _render("_('Date')")],
|
||||
'lines': [1, 0, 'date', _render("datetime.strptime(l['move_date'],'%Y-%m-%d')"), None, self.aml_cell_style_date],
|
||||
'lines':
|
||||
[1, 0, 'date',
|
||||
_render("datetime.strptime(l['move_date'],'%Y-%m-%d')"),
|
||||
None, self.aml_cell_style_date],
|
||||
'totals': [1, 0, 'text', None]},
|
||||
'acc_code': {
|
||||
'header': [1, 12, 'text', _render("_('Account')")],
|
||||
|
@ -124,47 +137,72 @@ class account_journal_xls(report_xls):
|
|||
'totals': [1, 0, 'text', None]},
|
||||
'date_maturity': {
|
||||
'header': [1, 13, 'text', _render("_('Maturity Date')")],
|
||||
'lines': [1, 0, _render("l['date_maturity'] and 'date' or 'text'"),
|
||||
_render("l['date_maturity'] and datetime.strptime(l['date_maturity'],'%Y-%m-%d') or None"),
|
||||
'lines':
|
||||
[1, 0,
|
||||
_render("l['date_maturity'] and 'date' or 'text'"),
|
||||
_render(
|
||||
"l['date_maturity'] and datetime.strptime(l['date_maturity'],'%Y-%m-%d') or None"),
|
||||
None, self.aml_cell_style_date],
|
||||
'totals': [1, 0, 'text', None]},
|
||||
'debit': {
|
||||
'header': [1, 18, 'text', _render("_('Debit')"), None, self.rh_cell_style_right],
|
||||
'lines': [1, 0, 'number', _render("l['debit']"), None, self.aml_cell_style_decimal],
|
||||
'totals': [1, 0, 'number', None, _render("debit_formula"), self.rt_cell_style_decimal]},
|
||||
'header': [1, 18, 'text', _render("_('Debit')"), None,
|
||||
self.rh_cell_style_right],
|
||||
'lines': [1, 0, 'number', _render("l['debit']"), None,
|
||||
self.aml_cell_style_decimal],
|
||||
'totals': [1, 0, 'number', None, _render("debit_formula"),
|
||||
self.rt_cell_style_decimal]},
|
||||
'credit': {
|
||||
'header': [1, 18, 'text', _render("_('Credit')"), None, self.rh_cell_style_right],
|
||||
'lines': [1, 0, 'number', _render("l['credit']"), None, self.aml_cell_style_decimal],
|
||||
'totals': [1, 0, 'number', None, _render("credit_formula"), self.rt_cell_style_decimal]},
|
||||
'header': [1, 18, 'text', _render("_('Credit')"), None,
|
||||
self.rh_cell_style_right],
|
||||
'lines': [1, 0, 'number', _render("l['credit']"), None,
|
||||
self.aml_cell_style_decimal],
|
||||
'totals': [1, 0, 'number', None, _render("credit_formula"),
|
||||
self.rt_cell_style_decimal]},
|
||||
'balance': {
|
||||
'header': [1, 18, 'text', _render("_('Balance')"), None, self.rh_cell_style_right],
|
||||
'lines': [1, 0, 'number', None, _render("bal_formula"), self.aml_cell_style_decimal],
|
||||
'totals': [1, 0, 'number', None, _render("bal_formula"), self.rt_cell_style_decimal]},
|
||||
'header': [1, 18, 'text', _render("_('Balance')"), None,
|
||||
self.rh_cell_style_right],
|
||||
'lines': [1, 0, 'number', None, _render("bal_formula"),
|
||||
self.aml_cell_style_decimal],
|
||||
'totals': [1, 0, 'number', None, _render("bal_formula"),
|
||||
self.rt_cell_style_decimal]},
|
||||
'reconcile': {
|
||||
'header': [1, 12, 'text', _render("_('Rec.')"), None, self.rh_cell_style_center],
|
||||
'lines': [1, 0, 'text', _render("l['reconcile']"), None, self.aml_cell_style_center],
|
||||
'header': [1, 12, 'text', _render("_('Rec.')"), None,
|
||||
self.rh_cell_style_center],
|
||||
'lines': [1, 0, 'text', _render("l['reconcile']"), None,
|
||||
self.aml_cell_style_center],
|
||||
'totals': [1, 0, 'text', None]},
|
||||
'reconcile_partial': {
|
||||
'header': [1, 12, 'text', _render("_('Part. Rec.')"), None, self.rh_cell_style_center],
|
||||
'lines': [1, 0, 'text', _render("l['reconcile_partial']"), None, self.aml_cell_style_center],
|
||||
'header': [1, 12, 'text', _render("_('Part. Rec.')"), None,
|
||||
self.rh_cell_style_center],
|
||||
'lines': [1, 0, 'text', _render("l['reconcile_partial']"),
|
||||
None, self.aml_cell_style_center],
|
||||
'totals': [1, 0, 'text', None]},
|
||||
'tax_code': {
|
||||
'header': [1, 6, 'text', _render("_('VAT')"), None, self.rh_cell_style_center],
|
||||
'lines': [1, 0, 'text', _render("l['tax_code']"), None, self.aml_cell_style_center],
|
||||
'header': [1, 6, 'text', _render("_('VAT')"), None,
|
||||
self.rh_cell_style_center],
|
||||
'lines': [1, 0, 'text', _render("l['tax_code']"), None,
|
||||
self.aml_cell_style_center],
|
||||
'totals': [1, 0, 'text', None]},
|
||||
'tax_amount': {
|
||||
'header': [1, 18, 'text', _render("_('VAT Amount')"), None, self.rh_cell_style_right],
|
||||
'lines': [1, 0, 'number', _render("l['tax_amount']"), None, self.aml_cell_style_decimal],
|
||||
'header': [1, 18, 'text', _render("_('VAT Amount')"), None,
|
||||
self.rh_cell_style_right],
|
||||
'lines': [1, 0, 'number', _render("l['tax_amount']"), None,
|
||||
self.aml_cell_style_decimal],
|
||||
'totals': [1, 0, 'text', None]},
|
||||
'amount_currency': {
|
||||
'header': [1, 18, 'text', _render("_('Am. Currency')"), None, self.rh_cell_style_right],
|
||||
'lines': [1, 0, _render("l['amount_currency'] and 'number' or 'text'"),
|
||||
_render("l['amount_currency'] or None"),
|
||||
None, self.aml_cell_style_decimal],
|
||||
'header': [1, 18, 'text', _render("_('Am. Currency')"), None,
|
||||
self.rh_cell_style_right],
|
||||
'lines':
|
||||
[1, 0,
|
||||
_render("l['amount_currency'] and 'number' or 'text'"),
|
||||
_render("l['amount_currency'] or None"),
|
||||
None, self.aml_cell_style_decimal],
|
||||
'totals': [1, 0, 'text', None]},
|
||||
'currency_name': {
|
||||
'header': [1, 6, 'text', _render("_('Curr.')"), None, self.rh_cell_style_center],
|
||||
'lines': [1, 0, 'text', _render("l['currency_name']"), None, self.aml_cell_style_center],
|
||||
'header': [1, 6, 'text', _render("_('Curr.')"), None,
|
||||
self.rh_cell_style_center],
|
||||
'lines': [1, 0, 'text', _render("l['currency_name']"), None,
|
||||
self.aml_cell_style_center],
|
||||
'totals': [1, 0, 'text', None]},
|
||||
'docname': {
|
||||
'header': [1, 35, 'text', _render("_('Document')")],
|
||||
|
@ -189,8 +227,10 @@ class account_journal_xls(report_xls):
|
|||
'header': [1, 6, 'text', _render("_('Case')")],
|
||||
'tax_totals': [1, 0, 'text', _render("t.code")]},
|
||||
'tax_amount': {
|
||||
'header': [1, 18, 'text', _render("_('Amount')"), None, self.rh_cell_style_right],
|
||||
'tax_totals': [1, 0, 'number', _render("sum_vat(o,t)"), None, self.aml_cell_style_decimal]},
|
||||
'header': [1, 18, 'text', _render("_('Amount')"), None,
|
||||
self.rh_cell_style_right],
|
||||
'tax_totals': [1, 0, 'number', _render("sum_vat(o,t)"), None,
|
||||
self.aml_cell_style_decimal]},
|
||||
}
|
||||
|
||||
def _journal_title(self, o, ws, _p, row_pos, xlwt, _xs):
|
||||
|
@ -200,12 +240,13 @@ class account_journal_xls(report_xls):
|
|||
_p.title(o)[0],
|
||||
_p.title(o)[1],
|
||||
_p._("Journal Overview") + ' - ' + _p.company.currency_id.name,
|
||||
])
|
||||
])
|
||||
c_specs = [
|
||||
('report_name', 1, 0, 'text', report_name),
|
||||
]
|
||||
row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs])
|
||||
row_pos = self.xls_write_row(ws, row_pos, row_data, row_style=cell_style)
|
||||
row_pos = self.xls_write_row(
|
||||
ws, row_pos, row_data, row_style=cell_style)
|
||||
return row_pos + 1
|
||||
|
||||
def _journal_lines(self, o, ws, _p, row_pos, xlwt, _xs):
|
||||
|
@ -215,9 +256,13 @@ class account_journal_xls(report_xls):
|
|||
credit_pos = self.credit_pos
|
||||
|
||||
# Column headers
|
||||
c_specs = map(lambda x: self.render(x, self.col_specs_lines_template, 'header', render_space={'_': _p._}), wanted_list)
|
||||
c_specs = map(lambda x: self.render(
|
||||
x, self.col_specs_lines_template, 'header',
|
||||
render_space={'_': _p._}), wanted_list)
|
||||
row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs])
|
||||
row_pos = self.xls_write_row(ws, row_pos, row_data, row_style=self.rh_cell_style, set_column_size=True)
|
||||
row_pos = self.xls_write_row(
|
||||
ws, row_pos, row_data, row_style=self.rh_cell_style,
|
||||
set_column_size=True)
|
||||
ws.set_horz_split_pos(row_pos)
|
||||
|
||||
# account move lines
|
||||
|
@ -229,9 +274,12 @@ class account_journal_xls(report_xls):
|
|||
debit_cell = rowcol_to_cell(row_pos, debit_pos)
|
||||
credit_cell = rowcol_to_cell(row_pos, credit_pos)
|
||||
bal_formula = debit_cell + '-' + credit_cell
|
||||
c_specs = map(lambda x: self.render(x, self.col_specs_lines_template, 'lines'), wanted_list)
|
||||
c_specs = map(
|
||||
lambda x: self.render(x, self.col_specs_lines_template,
|
||||
'lines'), wanted_list)
|
||||
row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs])
|
||||
row_pos = self.xls_write_row(ws, row_pos, row_data, row_style=self.aml_cell_style)
|
||||
row_pos = self.xls_write_row(
|
||||
ws, row_pos, row_data, row_style=self.aml_cell_style)
|
||||
if l['draw_line'] and cnt != aml_cnt:
|
||||
row_pos += 1
|
||||
|
||||
|
@ -245,9 +293,11 @@ class account_journal_xls(report_xls):
|
|||
debit_cell = rowcol_to_cell(row_pos, debit_pos)
|
||||
credit_cell = rowcol_to_cell(row_pos, credit_pos)
|
||||
bal_formula = debit_cell + '-' + credit_cell
|
||||
c_specs = map(lambda x: self.render(x, self.col_specs_lines_template, 'totals'), wanted_list)
|
||||
c_specs = map(lambda x: self.render(
|
||||
x, self.col_specs_lines_template, 'totals'), wanted_list)
|
||||
row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs])
|
||||
row_pos = self.xls_write_row(ws, row_pos, row_data, row_style=self.rt_cell_style_right)
|
||||
row_pos = self.xls_write_row(
|
||||
ws, row_pos, row_data, row_style=self.rt_cell_style_right)
|
||||
return row_pos + 1
|
||||
|
||||
def _journal_vat_summary(self, o, ws, _p, row_pos, xlwt, _xs):
|
||||
|
@ -258,7 +308,8 @@ class account_journal_xls(report_xls):
|
|||
title_cell_style = xlwt.easyxf(_xs['bold'])
|
||||
c_specs = [('summary_title', 1, 0, 'text', _p._("VAT Declaration"))]
|
||||
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=title_cell_style) + 1
|
||||
row_pos = self.xls_write_row(
|
||||
ws, row_pos, row_data, row_style=title_cell_style) + 1
|
||||
|
||||
wanted_list = self.wanted_list
|
||||
vat_summary_wanted_list = ['tax_case_name', 'tax_code', 'tax_amount']
|
||||
|
@ -267,33 +318,45 @@ class account_journal_xls(report_xls):
|
|||
cols_number = len(wanted_list)
|
||||
vat_summary_cols_number = len(vat_summary_wanted_list)
|
||||
if vat_summary_cols_number > cols_number:
|
||||
raise orm.except_orm(_('Programming Error!'),
|
||||
raise orm.except_orm(
|
||||
_('Programming Error!'),
|
||||
_("vat_summary_cols_number should be < cols_number !"))
|
||||
index = 0
|
||||
for i in range(vat_summary_cols_number):
|
||||
col = vat_summary_wanted_list[i]
|
||||
col_size = self.col_specs_lines_template[wanted_list[index]]['header'][1]
|
||||
templ_col_size = self.col_specs_vat_summary_template[col]['header'][1]
|
||||
#_logger.warn("col=%s, col_size=%s, templ_col_size=%s", col, col_size, templ_col_size)
|
||||
col_size = self.col_specs_lines_template[
|
||||
wanted_list[index]]['header'][1]
|
||||
templ_col_size = self.col_specs_vat_summary_template[
|
||||
col]['header'][1]
|
||||
# _logger.warn("col=%s, col_size=%s, templ_col_size=%s",
|
||||
# col, col_size, templ_col_size)
|
||||
col_span = 1
|
||||
if templ_col_size > col_size:
|
||||
new_size = col_size
|
||||
while templ_col_size > new_size:
|
||||
col_span += 1
|
||||
index += 1
|
||||
new_size += self.col_specs_lines_template[wanted_list[index]]['header'][1]
|
||||
new_size += self.col_specs_lines_template[
|
||||
wanted_list[index]]['header'][1]
|
||||
self.col_specs_vat_summary_template[col]['header'][0] = col_span
|
||||
self.col_specs_vat_summary_template[col]['tax_totals'][0] = col_span
|
||||
self.col_specs_vat_summary_template[
|
||||
col]['tax_totals'][0] = col_span
|
||||
index += 1
|
||||
|
||||
c_specs = map(lambda x: self.render(x, self.col_specs_vat_summary_template, 'header'), vat_summary_wanted_list)
|
||||
c_specs = map(lambda x: self.render(
|
||||
x, self.col_specs_vat_summary_template, 'header'),
|
||||
vat_summary_wanted_list)
|
||||
row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs])
|
||||
row_pos = self.xls_write_row(ws, row_pos, row_data, row_style=self.rh_cell_style)
|
||||
row_pos = self.xls_write_row(
|
||||
ws, row_pos, row_data, row_style=self.rh_cell_style)
|
||||
|
||||
for t in _p.tax_codes(o):
|
||||
c_specs = map(lambda x: self.render(x, self.col_specs_vat_summary_template, 'tax_totals'), vat_summary_wanted_list)
|
||||
c_specs = map(lambda x: self.render(
|
||||
x, self.col_specs_vat_summary_template, 'tax_totals'),
|
||||
vat_summary_wanted_list)
|
||||
row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs])
|
||||
row_pos = self.xls_write_row(ws, row_pos, row_data, row_style=self.aml_cell_style)
|
||||
row_pos = self.xls_write_row(
|
||||
ws, row_pos, row_data, row_style=self.aml_cell_style)
|
||||
|
||||
return row_pos
|
||||
|
||||
|
@ -306,14 +369,17 @@ class account_journal_xls(report_xls):
|
|||
self.col_specs_lines_template.update(_p.template_changes)
|
||||
|
||||
self.debit_pos = 'debit' in wanted_list and wanted_list.index('debit')
|
||||
self.credit_pos = 'credit' in wanted_list and wanted_list.index('credit')
|
||||
if not (self.credit_pos and self.debit_pos) and 'balance' in wanted_list:
|
||||
self.credit_pos = 'credit' in wanted_list and wanted_list.index(
|
||||
'credit')
|
||||
if not (self.credit_pos and self.debit_pos) and 'balance'\
|
||||
in wanted_list:
|
||||
raise orm.except_orm(_('Customisation Error!'),
|
||||
_("The 'Balance' field is a calculated XLS field requiring the presence of the 'Debit' and 'Credit' fields !"))
|
||||
_("The 'Balance' field is a calculated XLS field requiring the presence of the 'Debit' and 'Credit' fields !"))
|
||||
|
||||
for o in objects:
|
||||
|
||||
sheet_name = ' - '.join([o[1].code, o[0].code])[:31].replace('/', '-')
|
||||
sheet_name = ' - '.join([o[1].code, o[0].code]
|
||||
)[:31].replace('/', '-')
|
||||
sheet_name = sheet_name[:31].replace('/', '-')
|
||||
ws = wb.add_sheet(sheet_name)
|
||||
ws.panes_frozen = True
|
||||
|
@ -332,6 +398,6 @@ class account_journal_xls(report_xls):
|
|||
row_pos = self._journal_vat_summary(o, ws, _p, row_pos, xlwt, _xs)
|
||||
|
||||
account_journal_xls('report.nov.account.journal.xls', 'account.journal.period',
|
||||
parser=account_journal_xls_parser)
|
||||
parser=account_journal_xls_parser)
|
||||
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||
|
|
|
@ -22,8 +22,8 @@
|
|||
|
||||
from openerp.tools.translate import _
|
||||
from openerp.osv import orm, fields
|
||||
from openerp.addons.account.wizard.account_report_common_journal import account_common_journal_report
|
||||
import time
|
||||
from openerp.addons.account.wizard.account_report_common_journal\
|
||||
import account_common_journal_report
|
||||
import logging
|
||||
_logger = logging.getLogger(__name__)
|
||||
|
||||
|
@ -33,15 +33,19 @@ class account_print_journal_xls(orm.TransientModel):
|
|||
_name = 'account.print.journal.xls'
|
||||
_description = 'Print/Export Journal'
|
||||
_columns = {
|
||||
'journal_ids': fields.many2many('account.journal', string='Journals', required=True),
|
||||
'group_entries': fields.boolean('Group Entries', help="Group entries with same General Account & Tax Code."),
|
||||
}
|
||||
'journal_ids': fields.many2many('account.journal', string='Journals',
|
||||
required=True),
|
||||
'group_entries': fields.boolean(
|
||||
'Group Entries',
|
||||
help="Group entries with same General Account & Tax Code."),
|
||||
}
|
||||
_defaults = {
|
||||
'group_entries': True,
|
||||
}
|
||||
|
||||
def fields_get(self, cr, uid, fields=None, context=None):
|
||||
res = super(account_print_journal_xls, self).fields_get(cr, uid, fields, context)
|
||||
res = super(account_print_journal_xls, self).fields_get(
|
||||
cr, uid, fields, context)
|
||||
if context.get('print_by') == 'fiscalyear':
|
||||
if 'fiscalyear_id' in res:
|
||||
res['fiscalyear_id']['required'] = True
|
||||
|
@ -59,15 +63,18 @@ class account_print_journal_xls(orm.TransientModel):
|
|||
def fy_period_ids(self, cr, uid, fiscalyear_id):
|
||||
""" returns all periods from a fiscalyear sorted by date """
|
||||
fy_period_ids = []
|
||||
cr.execute('SELECT id, coalesce(special, False) AS special FROM account_period '
|
||||
'WHERE fiscalyear_id=%s ORDER BY date_start, special DESC',
|
||||
cr.execute('''
|
||||
SELECT id, coalesce(special, False) AS special
|
||||
FROM account_period
|
||||
WHERE fiscalyear_id=%s ORDER BY date_start, special DESC''',
|
||||
(fiscalyear_id,))
|
||||
res = cr.fetchall()
|
||||
if res:
|
||||
fy_period_ids = [x[0] for x in res]
|
||||
return fy_period_ids
|
||||
|
||||
def onchange_fiscalyear_id(self, cr, uid, ids, fiscalyear_id=False, context=None):
|
||||
def onchange_fiscalyear_id(self, cr, uid, ids, fiscalyear_id=False,
|
||||
context=None):
|
||||
res = {'value': {}}
|
||||
if context.get('print_by') == 'fiscalyear':
|
||||
# get period_from/to with opening/close periods
|
||||
|
@ -77,9 +84,13 @@ class account_print_journal_xls(orm.TransientModel):
|
|||
res['value']['period_to'] = fy_period_ids[-1]
|
||||
return res
|
||||
|
||||
def fields_view_get(self, cr, uid, view_id=None, view_type='form', context=None, toolbar=False, submenu=False):
|
||||
""" skip account.common.journal.report,fields_view_get (adds domain filter on journal type) """
|
||||
return super(account_common_journal_report, self).fields_view_get(cr, uid, view_id, view_type, context, toolbar, submenu)
|
||||
def fields_view_get(self, cr, uid, view_id=None, view_type='form',
|
||||
context=None, toolbar=False, submenu=False):
|
||||
""" skip account.common.journal.report,fields_view_get
|
||||
(adds domain filter on journal type) """
|
||||
return super(account_common_journal_report, self).\
|
||||
fields_view_get(cr, uid, view_id, view_type, context, toolbar,
|
||||
submenu)
|
||||
|
||||
def xls_export(self, cr, uid, ids, context=None):
|
||||
return self.print_report(cr, uid, ids, context=context)
|
||||
|
@ -93,14 +104,16 @@ class account_print_journal_xls(orm.TransientModel):
|
|||
fiscalyear_id = wiz_form.fiscalyear_id.id
|
||||
company_id = wiz_form.company_id.id
|
||||
|
||||
if print_by == 'fiscalyear':
|
||||
if print_by == 'fiscalyear':
|
||||
wiz_period_ids = self.fy_period_ids(cr, uid, fiscalyear_id)
|
||||
else:
|
||||
period_from = wiz_form.period_from
|
||||
period_to = wiz_form.period_to
|
||||
cr.execute("SELECT id, coalesce(special, False) AS special FROM account_period ap "
|
||||
"WHERE ap.date_start>=%s AND ap.date_stop<=%s AND company_id=%s "
|
||||
"ORDER BY date_start, special DESC",
|
||||
cr.execute("""
|
||||
SELECT id, coalesce(special, False) AS special
|
||||
FROM account_period ap
|
||||
WHERE ap.date_start>=%s AND ap.date_stop<=%s AND company_id=%s
|
||||
ORDER BY date_start, special DESC""",
|
||||
(period_from.date_start, period_to.date_stop, company_id))
|
||||
wiz_period_ids = map(lambda x: x[0], cr.fetchall())
|
||||
wiz_journal_ids = [j.id for j in wiz_form.journal_ids]
|
||||
|
@ -129,34 +142,43 @@ class account_print_journal_xls(orm.TransientModel):
|
|||
journal_fy_ids = []
|
||||
for journal_id in wiz_journal_ids:
|
||||
aml_ids = move_obj.search(cr, uid,
|
||||
[('journal_id', '=', journal_id), ('period_id', 'in', wiz_period_ids), ('state', 'in', move_states)],
|
||||
limit=1)
|
||||
[('journal_id', '=', journal_id),
|
||||
('period_id', 'in', wiz_period_ids),
|
||||
('state', 'in', move_states)],
|
||||
limit=1)
|
||||
if aml_ids:
|
||||
journal_fy_ids.append((journal_id, fiscalyear_id))
|
||||
if not journal_fy_ids:
|
||||
raise orm.except_orm(_('No Data Available'), _('No records found for your selection!'))
|
||||
raise orm.except_orm(
|
||||
_('No Data Available'),
|
||||
_('No records found for your selection!'))
|
||||
datas.update({
|
||||
'ids': [x[0] for x in journal_fy_ids],
|
||||
'ids': [x[0] for x in journal_fy_ids],
|
||||
'journal_fy_ids': journal_fy_ids,
|
||||
})
|
||||
else:
|
||||
# perform account.move.line query in stead of 'account.journal.period' since this table is not always reliable
|
||||
# perform account.move.line query in stead of
|
||||
# 'account.journal.period' since this table is not always reliable
|
||||
journal_period_ids = []
|
||||
for journal_id in wiz_journal_ids:
|
||||
period_ids = []
|
||||
for period_id in wiz_period_ids:
|
||||
aml_ids = move_obj.search(cr, uid,
|
||||
[('journal_id', '=', journal_id), ('period_id', '=', period_id), ('state', 'in', move_states)],
|
||||
limit=1)
|
||||
[('journal_id', '=', journal_id),
|
||||
('period_id', '=', period_id),
|
||||
('state', 'in', move_states)],
|
||||
limit=1)
|
||||
if aml_ids:
|
||||
period_ids.append(period_id)
|
||||
if period_ids:
|
||||
journal_period_ids.append((journal_id, period_ids))
|
||||
if not journal_period_ids:
|
||||
raise orm.except_orm(_('No Data Available'), _('No records found for your selection!'))
|
||||
raise orm.except_orm(
|
||||
_('No Data Available'),
|
||||
_('No records found for your selection!'))
|
||||
datas.update({
|
||||
'ids': [x[0] for x in journal_period_ids],
|
||||
'journal_period_ids': journal_period_ids,
|
||||
'ids': [x[0] for x in journal_period_ids],
|
||||
'journal_period_ids': journal_period_ids,
|
||||
})
|
||||
|
||||
if context.get('xls_export'):
|
||||
|
|
Loading…
Reference in New Issue