From 4c518c56fab04dbad639361ba65936aac9383b19 Mon Sep 17 00:00:00 2001 From: "laetitia.gangloff@acsone.eu" Date: Fri, 8 Aug 2014 13:18:16 +0200 Subject: [PATCH] [pep8] - account_financial_report --- account_financial_report/__init__.py | 8 +- account_financial_report/model/__init__.py | 8 +- .../model/account_financial_report.py | 119 ++-- account_financial_report/model/res_company.py | 11 +- account_financial_report/report/__init__.py | 2 +- account_financial_report/report/parser.py | 602 +++++++++++------- account_financial_report/wizard/__init__.py | 2 +- account_financial_report/wizard/wizard.py | 201 ++++-- 8 files changed, 613 insertions(+), 340 deletions(-) diff --git a/account_financial_report/__init__.py b/account_financial_report/__init__.py index 64829f5d..75a8a42b 100644 --- a/account_financial_report/__init__.py +++ b/account_financial_report/__init__.py @@ -3,7 +3,7 @@ # Module Writen to OpenERP, Open Source Management Solution # Copyright (C) OpenERP Venezuela (). # All Rights Reserved -###############Credits###################################################### +# Credits###################################################### # Coded by: Humberto Arocha humberto@openerp.com.ve # Angelica Barrios angelicaisabelb@gmail.com # Jordi Esteve @@ -25,6 +25,6 @@ # along with this program. If not, see . ############################################################################## -import model -import report -import wizard +from . import model +from . import report +from . import wizard diff --git a/account_financial_report/model/__init__.py b/account_financial_report/model/__init__.py index 9c8007c1..bb6a98b0 100755 --- a/account_financial_report/model/__init__.py +++ b/account_financial_report/model/__init__.py @@ -10,8 +10,8 @@ # Audited by: Nhomar Hernandez ############################################################################# # This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as published by -# the Free Software Foundation, either version 3 of the License, or +# it under the terms of the GNU Affero General Public License as published +# by the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, @@ -23,5 +23,5 @@ # along with this program. If not, see . ########################################################################## -import account_financial_report -import res_company +from . import account_financial_report +from . import res_company diff --git a/account_financial_report/model/account_financial_report.py b/account_financial_report/model/account_financial_report.py index fd848349..ccb1e28f 100644 --- a/account_financial_report/model/account_financial_report.py +++ b/account_financial_report/model/account_financial_report.py @@ -26,10 +26,9 @@ # along with this program. If not, see . ############################################################################## -from osv import osv, fields -import pooler +from openerp.osv import osv, fields import time -from tools.translate import _ +from openerp.tools.translate import _ class account_financial_report(osv.osv): @@ -38,45 +37,77 @@ class account_financial_report(osv.osv): _columns = { 'name': fields.char('Name', size=128, required=True), 'company_id': fields.many2one('res.company', 'Company', required=True), - 'currency_id': fields.many2one( - 'res.currency', 'Currency', help="Currency at which this report will be expressed. If not selected will be used the one set in the company"), - 'inf_type': fields.selection( - [('BS', 'Balance Sheet'), ('IS', 'Income Statement')], 'Type', required=True), - 'columns': fields.selection([('one', 'End. Balance'), ('two', 'Debit | Credit'), ('four', 'Initial | Debit | Credit | YTD'), - ('five', 'Initial | Debit | Credit | Period | YTD'), ('qtr', "4 QTR's | YTD"), ('thirteen', '12 Months | YTD')], 'Columns', required=True), - 'display_account': fields.selection([('all', 'All Accounts'), ('bal', 'With Balance'), - ('mov', 'With movements'), ('bal_mov', 'With Balance / Movements')], 'Display accounts'), - 'display_account_level': fields.integer( - 'Up to level', help='Display accounts up to this level (0 to show all)'), - 'account_ids': fields.many2many( - 'account.account', 'afr_account_rel', 'afr_id', 'account_id', 'Root accounts', required=True), - 'fiscalyear_id': fields.many2one( - 'account.fiscalyear', 'Fiscal year', help='Fiscal Year for this report', required=True), - 'period_ids': fields.many2many('account.period', 'afr_period_rel', 'afr_id', - 'period_id', 'Periods', help='All periods in the fiscal year if empty'), - - 'analytic_ledger': fields.boolean( - 'Analytic Ledger', help="Allows to Generate an Analytic Ledger for accounts with moves. Available when Balance Sheet and 'Initial | Debit | Credit | YTD' are selected"), - 'journal_ledger': fields.boolean( - 'journal Ledger', help="Allows to Generate an journal Ledger for accounts with moves. Available when Balance Sheet and 'Initial | Debit | Credit | YTD' are selected"), - 'partner_balance': fields.boolean('Partner Balance', help="Allows to " - "Generate a Partner Balance for accounts with moves. Available when " - "Balance Sheet and 'Initial | Debit | Credit | YTD' are selected"), + 'currency_id': fields.many2one('res.currency', 'Currency', + help="Currency at which this report\ + will be expressed. If not selected will\ + be used the one set in the company"), + 'inf_type': fields.selection([('BS', 'Balance Sheet'), + ('IS', 'Income Statement')], + 'Type', + required=True), + 'columns': fields.selection( + [('one', 'End. Balance'), + ('two', 'Debit | Credit'), + ('four', 'Initial | Debit | Credit | YTD'), + ('five', 'Initial | Debit | Credit | Period | YTD'), + ('qtr', "4 QTR's | YTD"), + ('thirteen', '12 Months | YTD')], 'Columns', required=True), + 'display_account': fields.selection( + [('all', 'All Accounts'), + ('bal', 'With Balance'), + ('mov', 'With movements'), + ('bal_mov', 'With Balance / Movements')], 'Display accounts'), + 'display_account_level': fields.integer('Up to level', + help='Display accounts up to\ + this level (0 to show all)'), + 'account_ids': fields.many2many('account.account', 'afr_account_rel', + 'afr_id', 'account_id', + 'Root accounts', required=True), + 'fiscalyear_id': fields.many2one('account.fiscalyear', 'Fiscal year', + help='Fiscal Year for this report', + required=True), + 'period_ids': fields.many2many( + 'account.period', 'afr_period_rel', 'afr_id', 'period_id', + 'Periods', help='All periods in the fiscal year if empty'), + + 'analytic_ledger': fields.boolean('Analytic Ledger', + help="Allows to Generate an Analytic\ + Ledger for accounts with moves.\ + Available when Balance Sheet and\ + 'Initial | Debit | Credit | YTD'\ + are selected"), + 'journal_ledger': fields.boolean('journal Ledger', + help="Allows to Generate an journal\ + Ledger for accounts with moves.\ + Available when Balance Sheet and\ + 'Initial | Debit | Credit | YTD'\ + are selected"), + 'partner_balance': fields.boolean('Partner Balance', + help="Allows to Generate a Partner\ + Balance for accounts with moves.\ + Available when Balance Sheet and\ + 'Initial | Debit | Credit | YTD'\ + are selected"), 'tot_check': fields.boolean( - 'Summarize?', help='Checking will add a new line at the end of the Report which will Summarize Columns in Report'), - 'lab_str': - fields.char( - 'Description', - help='Description for the Summary', - size=128), - 'target_move': fields.selection([('posted', 'All Posted Entries'), - ('all', 'All Entries'), - ], 'Entries to Include', required=True, - help='Print All Accounting Entries or just Posted Accounting Entries'), - - #~ Deprecated fields - 'filter': fields.selection([('bydate', 'By Date'), ('byperiod', 'By Period'), - ('all', 'By Date and Period'), ('none', 'No Filter')], 'Date/Period Filter'), + 'Summarize?', + help='Checking will add a new line at the end of the Report which\ + will Summarize Columns in Report'), + 'lab_str': fields.char('Description', + help='Description for the Summary', + size=128), + 'target_move': fields.selection( + [('posted', 'All Posted Entries'), + ('all', 'All Entries'), ], + 'Entries to Include', required=True, + help='Print All Accounting Entries or just Posted\ + Accounting Entries'), + + # ~ Deprecated fields + 'filter': fields.selection([('bydate', 'By Date'), + ('byperiod', 'By Period'), + ('all', 'By Date and Period'), + ('none', 'No Filter')], + 'Date/Period Filter'), 'date_to': fields.date('End date'), 'date_from': fields.date('Start date'), } @@ -144,8 +175,10 @@ class account_financial_report(osv.osv): if columns in ('qtr', 'thirteen'): p_obj = self.pool.get("account.period") - period_ids = p_obj.search(cr, uid, [('fiscalyear_id', '=', fiscalyear_id), ( - 'special', '=', False)], context=context) + period_ids = p_obj.search(cr, uid, + [('fiscalyear_id', '=', fiscalyear_id), + ('special', '=', False)], + context=context) res['value'].update({'period_ids': period_ids}) else: res['value'].update({'period_ids': []}) diff --git a/account_financial_report/model/res_company.py b/account_financial_report/model/res_company.py index d6afd580..639f29c4 100755 --- a/account_financial_report/model/res_company.py +++ b/account_financial_report/model/res_company.py @@ -10,8 +10,8 @@ # Audited by: Nhomar Hernandez ############################################################################# # This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as published by -# the Free Software Foundation, either version 3 of the License, or +# it under the terms of the GNU Affero General Public License as published +# by the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, @@ -23,12 +23,10 @@ # along with this program. If not, see . ########################################################################## -from osv import osv -from osv import fields -from tools.translate import _ +from openerp.osv import orm, fields -class res_company(osv.osv): +class res_company(orm.Model): _inherit = 'res.company' _columns = { 'credit_account_ids': fields.many2many('account.account', @@ -40,4 +38,3 @@ class res_company(osv.osv): 'company_id', 'account_id', 'Debitable Accounts'), } -res_company() diff --git a/account_financial_report/report/__init__.py b/account_financial_report/report/__init__.py index 25fa8f3b..ab266206 100644 --- a/account_financial_report/report/__init__.py +++ b/account_financial_report/report/__init__.py @@ -25,4 +25,4 @@ # along with this program. If not, see . ############################################################################## -import parser +from . import parser diff --git a/account_financial_report/report/parser.py b/account_financial_report/report/parser.py index 7e67c6cc..cf6a271b 100644 --- a/account_financial_report/report/parser.py +++ b/account_financial_report/report/parser.py @@ -26,16 +26,10 @@ # along with this program. If not, see . ############################################################################## -import xml -import copy -from operator import itemgetter import time -import datetime -from report import report_sxw -from tools import config -from tools.translate import _ -from osv import osv -from openerp.tools.safe_eval import safe_eval as eval +from openerp.report import report_sxw +from openerp.tools.translate import _ +from openerp.osv import osv class account_balance(report_sxw.rml_parse): @@ -68,14 +62,17 @@ class account_balance(report_sxw.rml_parse): """ rc_obj = self.pool.get('res.company') country_code = rc_obj.browse(self.cr, self.uid, - form['company_id'][0]).partner_id.country_id.code or '' + form['company_id'][0]).partner_id.\ + country_id.code or '' string_vat = rc_obj.browse(self.cr, self.uid, form['company_id'][0]).partner_id.vat or '' if string_vat: if country_code == 'MX': return '%s' % (string_vat[2:]) elif country_code == 'VE': - return '- %s-%s-%s' % (string_vat[2:3], string_vat[3:11], string_vat[11:12]) + return '- %s-%s-%s' % (string_vat[2:3], + string_vat[3:11], + string_vat[11:12]) else: return string_vat else: @@ -85,7 +82,7 @@ class account_balance(report_sxw.rml_parse): """ Returns the fiscal year text used on the report. """ - fiscalyear_obj = self.pool.get('account.fiscalyear') + fiscalyear_obj = self.pool['account.fiscalyear'] fiscalyear = None if form.get('fiscalyear'): fiscalyear = fiscalyear_obj.browse( @@ -104,7 +101,8 @@ class account_balance(report_sxw.rml_parse): list, tuple) and form['afr_id'][0] or form['afr_id'] if afr_id: name = self.pool.get('afr').browse(self.cr, self.uid, afr_id).name - elif form['analytic_ledger'] and form['columns'] == 'four' and form['inf_type'] == 'BS': + elif form['analytic_ledger'] and form['columns'] == 'four'\ + and form['inf_type'] == 'BS': name = _('Analytic Ledger') elif form['inf_type'] == 'BS': name = _('Balance Sheet') @@ -118,41 +116,43 @@ class account_balance(report_sxw.rml_parse): return day, year and month ''' if form['filter'] in ['bydate', 'all']: - months = ["Enero", "Febrero", "Marzo", "Abril", "Mayo", "Junio", - "Julio", "Agosto", "Septiembre", "Octubre", "Noviembre", "Diciembre"] - mes = months[time.strptime(form['date_to'], "%Y-%m-%d")[1] - 1] - ano = time.strptime(form['date_to'], "%Y-%m-%d")[0] - dia = time.strptime(form['date_to'], "%Y-%m-%d")[2] - return _('From ') + self.formatLang(form['date_from'], date=True) + _(' to ') + self.formatLang(form['date_to'], date=True) + return _('From ') + self.formatLang(form['date_from'], date=True)\ + + _(' to ') + self.formatLang(form['date_to'], date=True) elif form['filter'] in ['byperiod', 'all']: aux = [] period_obj = self.pool.get('account.period') - for period in period_obj.browse(self.cr, self.uid, form['periods']): + for period in period_obj.browse(self.cr, self.uid, + form['periods']): aux.append(period.date_start) aux.append(period.date_stop) sorted(aux) - return _('From ') + self.formatLang(aux[0], date=True) + _(' to ') + self.formatLang(aux[-1], date=True) + return _('From ') + self.formatLang(aux[0], date=True) + _(' to ')\ + + self.formatLang(aux[-1], date=True) def get_periods_and_date_text(self, form): """ Returns the text with the periods/dates used on the report. """ - period_obj = self.pool.get('account.period') - periods_str = None + period_obj = self.pool['account.period'] + fiscalyear_obj = self.pool['account.fiscalyear'] fiscalyear_id = form[ 'fiscalyear'] or fiscalyear_obj.find(self.cr, self.uid) period_ids = period_obj.search(self.cr, self.uid, [( 'fiscalyear_id', '=', fiscalyear_id), ('special', '=', False)]) if form['filter'] in ['byperiod', 'all']: period_ids = form['periods'] - periods_str = ', '.join([period.name or period.code for period in period_obj.browse( - self.cr, self.uid, period_ids)]) + periods_str = ', '.join([period.name or period.code + for period in period_obj.browse(self.cr, + self.uid, + period_ids)]) dates_str = None if form['filter'] in ['bydate', 'all']: dates_str = self.formatLang(form[ - 'date_from'], date=True) + ' - ' + self.formatLang(form['date_to'], date=True) + ' ' + 'date_from'], date=True) + ' - ' +\ + self.formatLang(form['date_to'], + date=True) + ' ' return {'periods': periods_str, 'date': dates_str} def special_period(self, periods): @@ -164,20 +164,26 @@ class account_balance(report_sxw.rml_parse): return False def exchange_name(self, form): - self.from_currency_id = self.get_company_currency(form['company_id'] and type(form[ - 'company_id']) in (list, tuple) and form['company_id'][0] or form['company_id']) + self.from_currency_id = self.\ + get_company_currency(form['company_id'] + and type(form['company_id']) in (list, tuple) + and form['company_id'][0] + or form['company_id']) if not form['currency_id']: self.to_currency_id = self.from_currency_id else: - self.to_currency_id = form['currency_id'] and type(form['currency_id']) in ( - list, tuple) and form['currency_id'][0] or form['currency_id'] - return self.pool.get('res.currency').browse(self.cr, self.uid, self.to_currency_id).name + self.to_currency_id = form['currency_id']\ + and type(form['currency_id']) in (list, tuple)\ + and form['currency_id'][0] or form['currency_id'] + return self.pool.get('res.currency').browse(self.cr, self.uid, + self.to_currency_id).name def exchange(self, from_amount): if self.from_currency_id == self.to_currency_id: return from_amount curr_obj = self.pool.get('res.currency') - return curr_obj.compute(self.cr, self.uid, self.from_currency_id, self.to_currency_id, from_amount) + return curr_obj.compute(self.cr, self.uid, self.from_currency_id, + self.to_currency_id, from_amount) def get_company_currency(self, company_id): rc_obj = self.pool.get('res.company') @@ -186,20 +192,25 @@ class account_balance(report_sxw.rml_parse): def get_company_accounts(self, company_id, acc='credit'): rc_obj = self.pool.get('res.company') if acc == 'credit': - return [brw.id for brw in rc_obj.browse(self.cr, self.uid, company_id).credit_account_ids] + return [brw.id for brw in rc_obj.browse( + self.cr, self.uid, + company_id).credit_account_ids] else: - return [brw.id for brw in rc_obj.browse(self.cr, self.uid, company_id).debit_account_ids] + return [brw.id for brw in rc_obj.browse( + self.cr, self.uid, + company_id).debit_account_ids] def _get_partner_balance(self, account, init_period, ctx=None): - rp_obj = self.pool.get('res.partner') res = [] ctx = ctx or {} if account['type'] in ('other', 'liquidity', 'receivable', 'payable'): sql_query = """ - SELECT + SELECT CASE WHEN aml.partner_id IS NOT NULL - THEN (SELECT name FROM res_partner WHERE aml.partner_id = id) + THEN (SELECT name + FROM res_partner + WHERE aml.partner_id = id) ELSE 'UNKNOWN' END AS partner_name, CASE @@ -213,7 +224,7 @@ class account_balance(report_sxw.rml_parse): %s FROM account_move_line AS aml INNER JOIN account_account aa ON aa.id = aml.account_id - INNER JOIN account_move am ON am.id = aml.move_id + INNER JOIN account_move am ON am.id = aml.move_id %s GROUP BY p_idx, partner_name """ @@ -226,8 +237,8 @@ class account_balance(report_sxw.rml_parse): init_periods = ', '.join([str(i) for i in init_period]) WHERE = """ - WHERE aml.period_id IN (%s) - AND aa.id = %s + WHERE aml.period_id IN (%s) + AND aa.id = %s AND aml.state <> 'draft' """ % (init_periods, account['id']) query_init = sql_query % ('SUM(aml.debit) AS init_dr', @@ -237,8 +248,8 @@ class account_balance(report_sxw.rml_parse): WHERE + WHERE_POSTED) WHERE = """ - WHERE aml.period_id IN (%s) - AND aa.id = %s + WHERE aml.period_id IN (%s) + AND aa.id = %s AND aml.state <> 'draft' """ % (cur_periods, account['id']) @@ -250,12 +261,13 @@ class account_balance(report_sxw.rml_parse): query = ''' SELECT - partner_name, - p_idx, + partner_name, + p_idx, SUM(init_dr)-SUM(init_cr) AS balanceinit, SUM(bal_dr) AS debit, SUM(bal_cr) AS credit, - SUM(init_dr) - SUM(init_cr) + SUM(bal_dr) - SUM(bal_cr) AS balance + SUM(init_dr) - SUM(init_cr) + + SUM(bal_dr) - SUM(bal_cr) AS balance FROM ( SELECT * @@ -292,29 +304,50 @@ class account_balance(report_sxw.rml_parse): res = [] if account['type'] in ('other', 'liquidity', 'receivable', 'payable'): - #~ TODO: CUANDO EL PERIODO ESTE VACIO LLENARLO CON LOS PERIODOS DEL EJERCICIO - #~ FISCAL, SIN LOS PERIODOS ESPECIALES + # ~ TODO: CUANDO EL PERIODO ESTE VACIO LLENARLO CON LOS PERIODOS + # DEL EJERCICIO + # ~ FISCAL, SIN LOS PERIODOS ESPECIALES periods = ', '.join([str(i) for i in ctx['periods']]) - #~ periods = str(tuple(ctx['periods'])) - where = """where aml.period_id in (%s) and aa.id = %s and aml.state <> 'draft'""" % ( - periods, account['id']) + # ~ periods = str(tuple(ctx['periods'])) + where = """where aml.period_id in (%s) + and aa.id = %s + and aml.state <> 'draft'""" % (periods, account['id']) if ctx.get('state', 'posted') == 'posted': where += "AND am.state = 'posted'" - sql_detalle = """select aml.id as id, aj.name as diario, aa.name as descripcion, - (select name from res_partner where aml.partner_id = id) as partner, - aa.code as cuenta, aml.name as name, - aml.ref as ref, - case when aml.debit is null then 0.00 else aml.debit end as debit, - case when aml.credit is null then 0.00 else aml.credit end as credit, - (select code from account_analytic_account where aml.analytic_account_id = id) as analitica, - aml.date as date, ap.name as periodo, - am.name as asiento - from account_move_line aml - inner join account_journal aj on aj.id = aml.journal_id - inner join account_account aa on aa.id = aml.account_id - inner join account_period ap on ap.id = aml.period_id - inner join account_move am on am.id = aml.move_id """ + where +\ - """ order by date, am.name""" + sql_detalle = """select aml.id as id, + aj.name as diario, + aa.name as descripcion, + (select name + from res_partner + where aml.partner_id = id) as partner, + aa.code as cuenta, + aml.name as name, + aml.ref as ref, + case when aml.debit is null + then 0.00 + else aml.debit + end as debit, + case when aml.credit is null + then 0.00 + else aml.credit + end as credit, + (select code + from account_analytic_account + where aml.analytic_account_id = id) + as analitica, + aml.date as date, + ap.name as periodo, + am.name as asiento + from account_move_line aml + inner join account_journal aj + on aj.id = aml.journal_id + inner join account_account aa + on aa.id = aml.account_id + inner join account_period ap + on ap.id = aml.period_id + inner join account_move am + on am.id = aml.move_id """\ + + where + """ order by date, am.name""" self.cr.execute(sql_detalle) resultat = self.cr.dictfetchall() @@ -342,26 +375,28 @@ class account_balance(report_sxw.rml_parse): am_obj = self.pool.get('account.move') print 'AM OBJ ', am_obj if account['type'] in ('other', 'liquidity', 'receivable', 'payable'): - #~ TODO: CUANDO EL PERIODO ESTE VACIO LLENARLO CON LOS PERIODOS DEL EJERCICIO - #~ FISCAL, SIN LOS PERIODOS ESPECIALES + # ~ TODO: CUANDO EL PERIODO ESTE VACIO LLENARLO CON LOS PERIODOS + # DEL EJERCICIO + # ~ FISCAL, SIN LOS PERIODOS ESPECIALES periods = ', '.join([str(i) for i in ctx['periods']]) - #~ periods = str(tuple(ctx['periods'])) - where = """where aml.period_id in (%s) and aa.id = %s and aml.state <> 'draft'""" % ( - periods, account['id']) + # ~ periods = str(tuple(ctx['periods'])) + where = """where aml.period_id in (%s) + and aa.id = %s + and aml.state <> 'draft'""" % (periods, account['id']) if ctx.get('state', 'posted') == 'posted': where += "AND am.state = 'posted'" - sql_detalle = """SELECT + sql_detalle = """SELECT DISTINCT am.id as am_id, aj.name as diario, am.name as name, - am.date as date, + am.date as date, ap.name as periodo from account_move_line aml inner join account_journal aj on aj.id = aml.journal_id inner join account_account aa on aa.id = aml.account_id inner join account_period ap on ap.id = aml.period_id - inner join account_move am on am.id = aml.move_id """ + where +\ - """ order by date, am.name""" + inner join account_move am on am.id = aml.move_id """\ + + where + """ order by date, am.name""" self.cr.execute(sql_detalle) resultat = self.cr.dictfetchall() @@ -374,7 +409,8 @@ class account_balance(report_sxw.rml_parse): 'period': det['periodo'], 'obj': am_obj.browse(self.cr, self.uid, det['am_id']) }) - print 'ACCOUNT NAME', am_obj.browse(self.cr, self.uid, det['am_id']).name + print 'ACCOUNT NAME', am_obj.browse(self.cr, self.uid, + det['am_id']).name return res def lines(self, form, level=0): @@ -387,15 +423,18 @@ class account_balance(report_sxw.rml_parse): period_obj = self.pool.get('account.period') fiscalyear_obj = self.pool.get('account.fiscalyear') - def _get_children_and_consol(cr, uid, ids, level, context={}, change_sign=False): + def _get_children_and_consol(cr, uid, ids, level, context={}, + change_sign=False): aa_obj = self.pool.get('account.account') ids2 = [] for aa_brw in aa_obj.browse(cr, uid, ids, context): - if aa_brw.child_id and aa_brw.level < level and aa_brw.type != 'consolidation': + if aa_brw.child_id and aa_brw.level < level\ + and aa_brw.type != 'consolidation': if not change_sign: ids2.append([aa_brw.id, True, False, aa_brw]) - ids2 += _get_children_and_consol(cr, uid, [ - x.id for x in aa_brw.child_id], level, context, change_sign=change_sign) + ids2 += _get_children_and_consol( + cr, uid, [x.id for x in aa_brw.child_id], level, + context, change_sign=change_sign) if change_sign: ids2.append(aa_brw.id) else: @@ -408,13 +447,15 @@ class account_balance(report_sxw.rml_parse): return ids2 ####################################################################### - # CONTEXT FOR ENDIND BALANCE # + # CONTEXT FOR ENDIND BALANCE # ####################################################################### def _ctx_end(ctx): ctx_end = ctx ctx_end['filter'] = form.get('filter', 'all') ctx_end['fiscalyear'] = fiscalyear.id - #~ ctx_end['periods'] = period_obj.search(self.cr, self.uid, [('fiscalyear_id','=',fiscalyear.id),('special','=',False)]) + # ~ ctx_end['periods'] = period_obj.\ + # search(self.cr, self.uid, [('fiscalyear_id','=',fiscalyear.id), + # ('special','=',False)]) if ctx_end['filter'] not in ['bydate', 'none']: special = self.special_period(form['periods']) @@ -423,11 +464,16 @@ class account_balance(report_sxw.rml_parse): if form['filter'] in ['byperiod', 'all']: if special: - ctx_end['periods'] = period_obj.search(self.cr, self.uid, [( - 'id', 'in', form['periods'] or ctx_end.get('periods', False))]) + ctx_end['periods'] = period_obj.search( + self.cr, self.uid, + [('id', 'in', form['periods'] or ctx_end.get('periods', + False))]) else: - ctx_end['periods'] = period_obj.search(self.cr, self.uid, [('id', 'in', form[ - 'periods'] or ctx_end.get('periods', False)), ('special', '=', False)]) + ctx_end['periods'] = period_obj.search( + self.cr, self.uid, + [('id', 'in', form['periods'] or ctx_end.get('periods', + False)), + ('special', '=', False)]) if form['filter'] in ['bydate', 'all', 'none']: ctx_end['date_from'] = form['date_from'] @@ -437,14 +483,22 @@ class account_balance(report_sxw.rml_parse): def missing_period(ctx_init): - ctx_init['fiscalyear'] = fiscalyear_obj.search(self.cr, self.uid, [('date_stop', '<', fiscalyear.date_start)], order='date_stop') and \ - fiscalyear_obj.search(self.cr, self.uid, [( - 'date_stop', '<', fiscalyear.date_start)], order='date_stop')[-1] or [] - ctx_init['periods'] = period_obj.search(self.cr, self.uid, [( - 'fiscalyear_id', '=', ctx_init['fiscalyear']), ('date_stop', '<', fiscalyear.date_start)]) + ctx_init['fiscalyear'] = \ + fiscalyear_obj.search(self.cr, self.uid, + [('date_stop', '<', + fiscalyear.date_start)], + order='date_stop')\ + and fiscalyear_obj.search(self.cr, self.uid, + [('date_stop', '<', + fiscalyear.date_start)], + order='date_stop')[-1] or [] + ctx_init['periods'] = period_obj.search( + self.cr, self.uid, + [('fiscalyear_id', '=', ctx_init['fiscalyear']), + ('date_stop', '<', fiscalyear.date_start)]) return ctx_init ####################################################################### - # CONTEXT FOR INITIAL BALANCE # + # CONTEXT FOR INITIAL BALANCE # ####################################################################### def _ctx_init(ctx): @@ -456,22 +510,30 @@ class account_balance(report_sxw.rml_parse): ctx_init['periods'] = form['periods'] if not ctx_init['periods']: ctx_init = missing_period(ctx_init.copy()) - date_start = min([period.date_start for period in period_obj.browse( - self.cr, self.uid, ctx_init['periods'])]) - ctx_init['periods'] = period_obj.search(self.cr, self.uid, [( - 'fiscalyear_id', '=', fiscalyear.id), ('date_stop', '<=', date_start)]) + date_start = min([period.date_start for period in period_obj. + browse(self.cr, self.uid, + ctx_init['periods'])]) + ctx_init['periods'] = period_obj.search( + self.cr, self.uid, [('fiscalyear_id', '=', fiscalyear.id), + ('date_stop', '<=', date_start)]) elif form['filter'] in ['bydate']: ctx_init['date_from'] = fiscalyear.date_start ctx_init['date_to'] = form['date_from'] - ctx_init['periods'] = period_obj.search(self.cr, self.uid, [( - 'fiscalyear_id', '=', fiscalyear.id), ('date_stop', '<=', ctx_init['date_to'])]) + ctx_init['periods'] = period_obj.search( + self.cr, self.uid, + [('fiscalyear_id', '=', fiscalyear.id), + ('date_stop', '<=', ctx_init['date_to'])]) elif form['filter'] == 'none': - ctx_init['periods'] = period_obj.search(self.cr, self.uid, [( - 'fiscalyear_id', '=', fiscalyear.id), ('special', '=', True)]) - date_start = min([period.date_start for period in period_obj.browse( - self.cr, self.uid, ctx_init['periods'])]) - ctx_init['periods'] = period_obj.search(self.cr, self.uid, [( - 'fiscalyear_id', '=', fiscalyear.id), ('date_start', '<=', date_start), ('special', '=', True)]) + ctx_init['periods'] = period_obj.search( + self.cr, self.uid, [('fiscalyear_id', '=', fiscalyear.id), + ('special', '=', True)]) + date_start = min([period.date_start for period in period_obj. + browse(self.cr, self.uid, + ctx_init['periods'])]) + ctx_init['periods'] = period_obj.search( + self.cr, self.uid, [('fiscalyear_id', '=', fiscalyear.id), + ('date_start', '<=', date_start), + ('special', '=', True)]) return ctx_init.copy() @@ -480,24 +542,35 @@ class account_balance(report_sxw.rml_parse): self.context['state'] = form['target_move'] or 'posted' - self.from_currency_id = self.get_company_currency(form['company_id'] and type(form[ - 'company_id']) in (list, tuple) and form['company_id'][0] or form['company_id']) + self.from_currency_id = self.\ + get_company_currency(form['company_id'] + and type(form['company_id']) in (list, tuple) + and form['company_id'][0] + or form['company_id']) if not form['currency_id']: self.to_currency_id = self.from_currency_id else: - self.to_currency_id = form['currency_id'] and type(form['currency_id']) in ( - list, tuple) and form['currency_id'][0] or form['currency_id'] + self.to_currency_id = form['currency_id']\ + and type(form['currency_id']) in (list, tuple)\ + and form['currency_id'][0]\ + or form['currency_id'] if 'account_list' in form and form['account_list']: account_ids = form['account_list'] account_list = form['account_list'] del form['account_list'] - credit_account_ids = self.get_company_accounts(form['company_id'] and type(form[ - 'company_id']) in (list, tuple) and form['company_id'][0] or form['company_id'], 'credit') + credit_account_ids = self.\ + get_company_accounts(form['company_id'] + and type(form['company_id']) in (list, tuple) + and form['company_id'][0] + or form['company_id'], 'credit') - debit_account_ids = self.get_company_accounts(form['company_id'] and type(form[ - 'company_id']) in (list, tuple) and form['company_id'][0] or form['company_id'], 'debit') + debit_account_ids = self.\ + get_company_accounts(form['company_id'] + and type(form['company_id']) in (list, tuple) + and form['company_id'][0] + or form['company_id'], 'debit') if form.get('fiscalyear'): if type(form.get('fiscalyear')) in (list, tuple): @@ -512,14 +585,19 @@ class account_balance(report_sxw.rml_parse): all_account_ids = _get_children_and_consol( self.cr, self.uid, account_ids, 100, self.context) - account_ids = _get_children_and_consol(self.cr, self.uid, account_ids, form[ - 'display_account_level'] and form['display_account_level'] or 100, self.context) + account_ids = _get_children_and_consol( + self.cr, self.uid, account_ids, + form['display_account_level'] + and form['display_account_level'] + or 100, self.context) credit_account_ids = _get_children_and_consol( - self.cr, self.uid, credit_account_ids, 100, self.context, change_sign=True) + self.cr, self.uid, credit_account_ids, 100, self.context, + change_sign=True) debit_account_ids = _get_children_and_consol( - self.cr, self.uid, debit_account_ids, 100, self.context, change_sign=True) + self.cr, self.uid, debit_account_ids, 100, self.context, + change_sign=True) credit_account_ids = list(set( credit_account_ids) - set(debit_account_ids)) @@ -530,35 +608,41 @@ class account_balance(report_sxw.rml_parse): tot_check = False if not form['periods']: - form['periods'] = period_obj.search(self.cr, self.uid, [( - 'fiscalyear_id', '=', fiscalyear.id), ('special', '=', False)], order='date_start asc') + form['periods'] = period_obj.search( + self.cr, self.uid, [('fiscalyear_id', '=', fiscalyear.id), + ('special', '=', False)], + order='date_start asc') if not form['periods']: raise osv.except_osv(_('UserError'), _( 'The Selected Fiscal Year Does not have Regular Periods')) if form['columns'] == 'qtr': - period_ids = period_obj.search(self.cr, self.uid, [( - 'fiscalyear_id', '=', fiscalyear.id), ('special', '=', False)], order='date_start asc') + period_ids = period_obj.search( + self.cr, self.uid, [('fiscalyear_id', '=', fiscalyear.id), + ('special', '=', False)], + order='date_start asc') a = 0 l = [] p = [] for x in period_ids: a += 1 if a < 3: - l.append(x) + l.append(x) else: - l.append(x) - p.append(l) - l = [] - a = 0 + l.append(x) + p.append(l) + l = [] + a = 0 tot_bal1 = 0.0 tot_bal2 = 0.0 tot_bal3 = 0.0 tot_bal4 = 0.0 tot_bal5 = 0.0 elif form['columns'] == 'thirteen': - period_ids = period_obj.search(self.cr, self.uid, [( - 'fiscalyear_id', '=', fiscalyear.id), ('special', '=', False)], order='date_start asc') + period_ids = period_obj.search( + self.cr, self.uid, [('fiscalyear_id', '=', fiscalyear.id), + ('special', '=', False)], + order='date_start asc') tot_bal1 = 0.0 tot_bal1 = 0.0 tot_bal2 = 0.0 @@ -590,19 +674,21 @@ class account_balance(report_sxw.rml_parse): # without repeating operations. ############################################################### - account_black_ids = account_obj.search(self.cr, self.uid, ( - [('id', 'in', [i[0] for i in all_account_ids]), - ('type', 'not in', - ('view', 'consolidation'))])) + account_black_ids = account_obj.search( + self.cr, self.uid, ( + [('id', 'in', [i[0] for i in all_account_ids]), + ('type', 'not in', ('view', 'consolidation'))])) - account_not_black_ids = account_obj.search(self.cr, self.uid, ([('id', 'in', [ - i[0] for i in all_account_ids]), ('type', '=', 'view')])) + account_not_black_ids = account_obj.search( + self.cr, self.uid, ([('id', 'in', [i[0] for i in all_account_ids]), + ('type', '=', 'view')])) - acc_cons_ids = account_obj.search(self.cr, self.uid, ([('id', 'in', [ - i[0] for i in all_account_ids]), ('type', 'in', ('consolidation',))])) + acc_cons_ids = account_obj.search( + self.cr, self.uid, ([('id', 'in', [i[0] for i in all_account_ids]), + ('type', 'in', ('consolidation',))])) - account_consol_ids = acc_cons_ids and account_obj._get_children_and_consol( - self.cr, self.uid, acc_cons_ids) or [] + account_consol_ids = acc_cons_ids and account_obj.\ + _get_children_and_consol(self.cr, self.uid, acc_cons_ids) or [] account_black_ids += account_obj.search(self.cr, self.uid, ( [('id', 'in', account_consol_ids), @@ -612,8 +698,7 @@ class account_balance(report_sxw.rml_parse): account_black_ids = list(set(account_black_ids)) c_account_not_black_ids = account_obj.search(self.cr, self.uid, ([ - ('id', 'in', - account_consol_ids), + ('id', 'in', account_consol_ids), ('type', '=', 'view')])) delete_cons = False if c_account_not_black_ids: @@ -684,7 +769,7 @@ class account_balance(report_sxw.rml_parse): account_black_init = account_obj.browse( self.cr, self.uid, account_black_ids, ctx_i) - #~ Black + # ~ Black dict_black = {} for i in account_black: d = i.debit @@ -704,7 +789,7 @@ class account_balance(report_sxw.rml_parse): for i in account_black_init: dict_black.get(i.id)['balanceinit'] = i.balance - #~ Not black + # ~ Not black dict_not_black = {} for i in account_not_black: dict_not_black[i.id] = { @@ -716,7 +801,8 @@ class account_balance(report_sxw.rml_parse): ) # It makes a copy because they modify for acc_id in account_not_black_ids: - acc_childs = dict_not_black.get(acc_id).get('obj').type == 'view' \ + acc_childs = dict_not_black.get(acc_id).get('obj').\ + type == 'view' \ and dict_not_black.get(acc_id).get('obj').child_id \ or dict_not_black.get(acc_id).get('obj').child_consol_ids for child_id in acc_childs: @@ -729,8 +815,8 @@ class account_balance(report_sxw.rml_parse): dict_not_black.get(acc_id)['balance'] += all_account.get( child_id.id).get('balance') if form['inf_type'] == 'BS': - dict_not_black.get(acc_id)['balanceinit'] += all_account.get( - child_id.id).get('balanceinit') + dict_not_black.get(acc_id)['balanceinit'] +=\ + all_account.get(child_id.id).get('balanceinit') all_account[acc_id] = dict_not_black[acc_id] if p_act == limit - 1: @@ -753,17 +839,21 @@ class account_balance(report_sxw.rml_parse): # # Check if we need to include this level # - if not form['display_account_level'] or aa_id[3].level <= form['display_account_level']: + if not form['display_account_level']\ + or aa_id[3].level <= form['display_account_level']: res = { 'id': id, 'type': aa_id[3].type, 'code': aa_id[3].code, - 'name': (aa_id[2] and not aa_id[1]) and 'TOTAL %s' % (aa_id[3].name.upper()) or aa_id[3].name, + 'name': (aa_id[2] and not aa_id[1]) + and 'TOTAL %s' % (aa_id[3].name.upper()) + or aa_id[3].name, 'parent_id': aa_id[3].parent_id and aa_id[3].parent_id.id, 'level': aa_id[3].level, 'label': aa_id[1], 'total': aa_id[2], - 'change_sign': credit_account_ids and (id in credit_account_ids and -1 or 1) or 1 + 'change_sign': credit_account_ids + and (id in credit_account_ids and -1 or 1) or 1 } if form['columns'] == 'qtr': @@ -771,7 +861,12 @@ class account_balance(report_sxw.rml_parse): if form['inf_type'] == 'IS': d, c, b = map(z, [ - all_account_period.get(pn - 1).get(id).get('debit', 0.0), all_account_period.get(pn - 1).get(id).get('credit', 0.0), all_account_period.get(pn - 1).get(id).get('balance', 0.0)]) + all_account_period.get(pn - 1). + get(id).get('debit', 0.0), + all_account_period.get(pn - 1). + get(id).get('credit', 0.0), + all_account_period.get(pn - 1). + get(id).get('balance', 0.0)]) res.update({ 'dbr%s' % pn: self.exchange(d), 'cdr%s' % pn: self.exchange(c), @@ -779,7 +874,12 @@ class account_balance(report_sxw.rml_parse): }) else: i, d, c = map(z, [ - all_account_period.get(pn - 1).get(id).get('balanceinit', 0.0), all_account_period.get(pn - 1).get(id).get('debit', 0.0), all_account_period.get(pn - 1).get(id).get('credit', 0.0)]) + all_account_period.get(pn - 1). + get(id).get('balanceinit', 0.0), + all_account_period.get(pn - 1). + get(id).get('debit', 0.0), + all_account_period.get(pn - 1). + get(id).get('credit', 0.0)]) b = z(i + d - c) res.update({ 'dbr%s' % pn: self.exchange(d), @@ -789,7 +889,12 @@ class account_balance(report_sxw.rml_parse): if form['inf_type'] == 'IS': d, c, b = map(z, [ - all_account_period.get('all').get(id).get('debit', 0.0), all_account_period.get('all').get(id).get('credit', 0.0), all_account_period.get('all').get(id).get('balance')]) + all_account_period.get('all').get(id). + get('debit', 0.0), + all_account_period.get('all').get(id). + get('credit', 0.0), + all_account_period.get('all').get(id). + get('balance')]) res.update({ 'dbr5': self.exchange(d), 'cdr5': self.exchange(c), @@ -797,7 +902,12 @@ class account_balance(report_sxw.rml_parse): }) else: i, d, c = map(z, [ - all_account_period.get('all').get(id).get('balanceinit', 0.0), all_account_period.get('all').get(id).get('debit', 0.0), all_account_period.get('all').get(id).get('credit', 0.0)]) + all_account_period.get('all').get(id). + get('balanceinit', 0.0), + all_account_period.get('all').get(id). + get('debit', 0.0), + all_account_period.get('all').get(id). + get('credit', 0.0)]) b = z(i + d - c) res.update({ 'dbr5': self.exchange(d), @@ -811,7 +921,12 @@ class account_balance(report_sxw.rml_parse): if form['inf_type'] == 'IS': d, c, b = map(z, [ - all_account_period.get(p_num).get(id).get('debit', 0.0), all_account_period.get(p_num).get(id).get('credit', 0.0), all_account_period.get(p_num).get(id).get('balance', 0.0)]) + all_account_period.get(p_num). + get(id).get('debit', 0.0), + all_account_period.get(p_num). + get(id).get('credit', 0.0), + all_account_period.get(p_num). + get(id).get('balance', 0.0)]) res.update({ 'dbr%s' % pn: self.exchange(d), 'cdr%s' % pn: self.exchange(c), @@ -819,7 +934,12 @@ class account_balance(report_sxw.rml_parse): }) else: i, d, c = map(z, [ - all_account_period.get(p_num).get(id).get('balanceinit', 0.0), all_account_period.get(p_num).get(id).get('debit', 0.0), all_account_period.get(p_num).get(id).get('credit', 0.0)]) + all_account_period.get(p_num). + get(id).get('balanceinit', 0.0), + all_account_period.get(p_num). + get(id).get('debit', 0.0), + all_account_period.get(p_num). + get(id).get('credit', 0.0)]) b = z(i + d - c) res.update({ 'dbr%s' % pn: self.exchange(d), @@ -831,7 +951,12 @@ class account_balance(report_sxw.rml_parse): if form['inf_type'] == 'IS': d, c, b = map(z, [ - all_account_period.get('all').get(id).get('debit', 0.0), all_account_period.get('all').get(id).get('credit', 0.0), all_account_period.get('all').get(id).get('balance', 0.0)]) + all_account_period.get('all').get(id). + get('debit', 0.0), + all_account_period.get('all').get(id). + get('credit', 0.0), + all_account_period.get('all').get(id). + get('balance', 0.0)]) res.update({ 'dbr13': self.exchange(d), 'cdr13': self.exchange(c), @@ -839,7 +964,12 @@ class account_balance(report_sxw.rml_parse): }) else: i, d, c = map(z, [ - all_account_period.get('all').get(id).get('balanceinit', 0.0), all_account_period.get('all').get(id).get('debit', 0.0), all_account_period.get('all').get(id).get('credit', 0.0)]) + all_account_period.get('all').get(id). + get('balanceinit', 0.0), + all_account_period.get('all').get(id). + get('debit', 0.0), + all_account_period.get('all').get(id). + get('credit', 0.0)]) b = z(i + d - c) res.update({ 'dbr13': self.exchange(d), @@ -849,7 +979,12 @@ class account_balance(report_sxw.rml_parse): else: i, d, c = map(z, [ - all_account_period.get('all').get(id).get('balanceinit', 0.0), all_account_period.get('all').get(id).get('debit', 0.0), all_account_period.get('all').get(id).get('credit', 0.0)]) + all_account_period.get('all').get(id). + get('balanceinit', 0.0), + all_account_period.get('all').get(id). + get('debit', 0.0), + all_account_period.get('all').get(id). + get('credit', 0.0)]) b = z(i + d - c) res.update({ 'balanceinit': self.exchange(i), @@ -884,7 +1019,8 @@ class account_balance(report_sxw.rml_parse): if any(to_test): to_include = True - elif form['display_account'] == 'bal' and aa_id[3].parent_id: + elif form['display_account'] == 'bal' and aa_id[3].\ + parent_id: # Include accounts with balance for x in range(pn - 1): to_test.append(res.get( @@ -892,7 +1028,8 @@ class account_balance(report_sxw.rml_parse): if any(to_test): to_include = True - elif form['display_account'] == 'bal_mov' and aa_id[3].parent_id: + elif form['display_account'] == 'bal_mov' and aa_id[3].\ + parent_id: # Include accounts with balance or movements for x in range(pn - 1): to_test.append(res.get( @@ -913,24 +1050,40 @@ class account_balance(report_sxw.rml_parse): # Include accounts with movements if abs(d) >= 0.005 or abs(c) >= 0.005: to_include = True - elif form['display_account'] == 'bal' and aa_id[3].parent_id: + elif form['display_account'] == 'bal' and aa_id[3].\ + parent_id: # Include accounts with balance if abs(b) >= 0.005: to_include = True - elif form['display_account'] == 'bal_mov' and aa_id[3].parent_id: + elif form['display_account'] == 'bal_mov' and aa_id[3].\ + parent_id: # Include accounts with balance or movements - if abs(b) >= 0.005 or abs(d) >= 0.005 or abs(c) >= 0.005: + if abs(b) >= 0.005\ + or abs(d) >= 0.005\ + or abs(c) >= 0.005: to_include = True else: # Include all accounts to_include = True - #~ ANALYTIC LEDGER - if to_include and form['analytic_ledger'] and form['columns'] == 'four' and form['inf_type'] == 'BS' and res['type'] in ('other', 'liquidity', 'receivable', 'payable'): + # ~ ANALYTIC LEDGER + if to_include and form['analytic_ledger']\ + and form['columns'] == 'four'\ + and form['inf_type'] == 'BS'\ + and res['type'] in ('other', 'liquidity', + 'receivable', 'payable'): res['mayor'] = self._get_analytic_ledger(res, ctx=ctx_end) - elif to_include and form['journal_ledger'] and form['columns'] == 'four' and form['inf_type'] == 'BS' and res['type'] in ('other', 'liquidity', 'receivable', 'payable'): + elif to_include and form['journal_ledger']\ + and form['columns'] == 'four'\ + and form['inf_type'] == 'BS'\ + and res['type'] in ('other', 'liquidity', + 'receivable', 'payable'): res['journal'] = self._get_journal_ledger(res, ctx=ctx_end) - elif to_include and form['partner_balance'] and form['columns'] == 'four' and form['inf_type'] == 'BS' and res['type'] in ('other', 'liquidity', 'receivable', 'payable'): + elif to_include and form['partner_balance']\ + and form['columns'] == 'four'\ + and form['inf_type'] == 'BS'\ + and res['type'] in ('other', 'liquidity', + 'receivable', 'payable'): res['partner'] = self._get_partner_balance( res, ctx_i['periods'], ctx=ctx_end) else: @@ -939,9 +1092,11 @@ class account_balance(report_sxw.rml_parse): if to_include: result_acc.append(res) # - # Check whether we must sumarize this line in the report or not + # Check whether we must sumarize this line in the report + # or not # - if form['tot_check'] and (res['id'] in account_list) and (res['id'] not in tot): + if form['tot_check'] and (res['id'] in account_list)\ + and (res['id'] not in tot): if form['columns'] == 'qtr': tot_check = True tot[res['id']] = True @@ -1019,56 +1174,65 @@ class account_balance(report_sxw.rml_parse): result_acc.append(res2) return result_acc -report_sxw.report_sxw('report.afr.1cols', - 'wizard.report', - 'account_financial_report/report/balance_full.rml', - parser=account_balance, - header=False) - -report_sxw.report_sxw('report.afr.2cols', - 'wizard.report', - 'account_financial_report/report/balance_full_2_cols.rml', - parser=account_balance, - header=False) - -report_sxw.report_sxw('report.afr.4cols', - 'wizard.report', - 'account_financial_report/report/balance_full_4_cols.rml', - parser=account_balance, - header=False) - -report_sxw.report_sxw('report.afr.analytic.ledger', - 'wizard.report', - 'account_financial_report/report/balance_full_4_cols_analytic_ledger.rml', - parser=account_balance, - header=False) - -report_sxw.report_sxw('report.afr.partner.balance', - 'wizard.report', - 'account_financial_report/report/balance_full_4_cols_partner_balance.rml', - parser=account_balance, - header=False) - -report_sxw.report_sxw('report.afr.journal.ledger', - 'wizard.report', - 'account_financial_report/report/balance_full_4_cols_journal_ledger.rml', - parser=account_balance, - header=False) - -report_sxw.report_sxw('report.afr.5cols', - 'wizard.report', - 'account_financial_report/report/balance_full_5_cols.rml', - parser=account_balance, - header=False) - -report_sxw.report_sxw('report.afr.qtrcols', - 'wizard.report', - 'account_financial_report/report/balance_full_qtr_cols.rml', - parser=account_balance, - header=False) - -report_sxw.report_sxw('report.afr.13cols', - 'wizard.report', - 'account_financial_report/report/balance_full_13_cols.rml', - parser=account_balance, - header=False) +report_sxw.report_sxw( + 'report.afr.1cols', + 'wizard.report', + 'account_financial_report/report/balance_full.rml', + parser=account_balance, + header=False) + +report_sxw.report_sxw( + 'report.afr.2cols', + 'wizard.report', + 'account_financial_report/report/balance_full_2_cols.rml', + parser=account_balance, + header=False) + +report_sxw.report_sxw( + 'report.afr.4cols', + 'wizard.report', + 'account_financial_report/report/balance_full_4_cols.rml', + parser=account_balance, + header=False) + +report_sxw.report_sxw( + 'report.afr.analytic.ledger', + 'wizard.report', + 'account_financial_report/report/balance_full_4_cols_analytic_ledger.rml', + parser=account_balance, + header=False) + +report_sxw.report_sxw( + 'report.afr.partner.balance', + 'wizard.report', + 'account_financial_report/report/balance_full_4_cols_partner_balance.rml', + parser=account_balance, + header=False) + +report_sxw.report_sxw( + 'report.afr.journal.ledger', + 'wizard.report', + 'account_financial_report/report/balance_full_4_cols_journal_ledger.rml', + parser=account_balance, + header=False) + +report_sxw.report_sxw( + 'report.afr.5cols', + 'wizard.report', + 'account_financial_report/report/balance_full_5_cols.rml', + parser=account_balance, + header=False) + +report_sxw.report_sxw( + 'report.afr.qtrcols', + 'wizard.report', + 'account_financial_report/report/balance_full_qtr_cols.rml', + parser=account_balance, + header=False) + +report_sxw.report_sxw( + 'report.afr.13cols', + 'wizard.report', + 'account_financial_report/report/balance_full_13_cols.rml', + parser=account_balance, + header=False) diff --git a/account_financial_report/wizard/__init__.py b/account_financial_report/wizard/__init__.py index 5c4250d1..8ee75c16 100644 --- a/account_financial_report/wizard/__init__.py +++ b/account_financial_report/wizard/__init__.py @@ -25,4 +25,4 @@ # along with this program. If not, see . ############################################################################## -import wizard +from . import wizard diff --git a/account_financial_report/wizard/wizard.py b/account_financial_report/wizard/wizard.py index 5708402f..ea2f649e 100644 --- a/account_financial_report/wizard/wizard.py +++ b/account_financial_report/wizard/wizard.py @@ -26,43 +26,94 @@ # along with this program. If not, see . ############################################################################## -from osv import osv, fields -import pooler +from openerp.osv import osv, fields import time -from tools.translate import _ +from openerp.tools.translate import _ class wizard_report(osv.osv_memory): _name = "wizard.report" _columns = { - 'afr_id': fields.many2one('afr', 'Custom Report', help='If you have already set a Custom Report, Select it Here.'), + 'afr_id': fields.many2one( + 'afr', 'Custom Report', + help='If you have already set a Custom Report, Select it Here.'), 'company_id': fields.many2one('res.company', 'Company', required=True), - 'currency_id': fields.many2one('res.currency', 'Currency', help="Currency at which this report will be expressed. If not selected will be used the one set in the company"), - 'inf_type': fields.selection([('BS', 'Balance Sheet'), ('IS', 'Income Statement')], 'Type', required=True), - 'columns': fields.selection([('one', 'End. Balance'), ('two', 'Debit | Credit'), ('four', 'Initial | Debit | Credit | YTD'), ('five', 'Initial | Debit | Credit | Period | YTD'), ('qtr', "4 QTR's | YTD"), ('thirteen', '12 Months | YTD')], 'Columns', required=True), - 'display_account': fields.selection([('all', 'All Accounts'), ('bal', 'With Balance'), ('mov', 'With movements'), ('bal_mov', 'With Balance / Movements')], 'Display accounts'), - 'display_account_level': fields.integer('Up to level', help='Display accounts up to this level (0 to show all)'), - - 'account_list': fields.many2many('account.account', 'rel_wizard_account', 'account_list', 'account_id', 'Root accounts', required=True), - - 'fiscalyear': fields.many2one('account.fiscalyear', 'Fiscal year', help='Fiscal Year for this report', required=True), - 'periods': fields.many2many('account.period', 'rel_wizard_period', 'wizard_id', 'period_id', 'Periods', help='All periods in the fiscal year if empty'), - - 'analytic_ledger': fields.boolean('Analytic Ledger', help="Allows to Generate an Analytic Ledger for accounts with moves. Available when Balance Sheet and 'Initial | Debit | Credit | YTD' are selected"), - 'journal_ledger': fields.boolean('Journal Ledger', help="Allows to Generate an Journal Ledger for accounts with moves. Available when Balance Sheet and 'Initial | Debit | Credit | YTD' are selected"), - 'partner_balance': fields.boolean('Partner Balance', help="Allows to " - "Generate a Partner Balance for accounts with moves. Available when " - "Balance Sheet and 'Initial | Debit | Credit | YTD' are selected"), - 'tot_check': fields.boolean('Summarize?', help='Checking will add a new line at the end of the Report which will Summarize Columns in Report'), - 'lab_str': fields.char('Description', help='Description for the Summary', size=128), - - 'target_move': fields.selection([('posted', 'All Posted Entries'), - ('all', 'All Entries'), - ], 'Entries to Include', required=True, - help='Print All Accounting Entries or just Posted Accounting Entries'), - #~ Deprecated fields - 'filter': fields.selection([('bydate', 'By Date'), ('byperiod', 'By Period'), ('all', 'By Date and Period'), ('none', 'No Filter')], 'Date/Period Filter'), + 'currency_id': fields.many2one('res.currency', 'Currency', + help="Currency at which this report\ + will be expressed. If not selected will\ + be used the one set in the company"), + 'inf_type': fields.selection([('BS', 'Balance Sheet'), + ('IS', 'Income Statement')], + 'Type', + required=True), + 'columns': fields.selection( + [('one', 'End. Balance'), + ('two', 'Debit | Credit'), + ('four', 'Initial | Debit | Credit | YTD'), + ('five', 'Initial | Debit | Credit | Period | YTD'), + ('qtr', "4 QTR's | YTD"), ('thirteen', '12 Months | YTD')], + 'Columns', required=True), + 'display_account': fields.selection( + [('all', 'All Accounts'), + ('bal', 'With Balance'), + ('mov', 'With movements'), + ('bal_mov', 'With Balance / Movements')], + 'Display accounts'), + 'display_account_level': fields.integer( + 'Up to level', + help='Display accounts up to this level (0 to show all)'), + + 'account_list': fields.many2many('account.account', + 'rel_wizard_account', + 'account_list', + 'account_id', + 'Root accounts', + required=True), + + 'fiscalyear': fields.many2one('account.fiscalyear', 'Fiscal year', + help='Fiscal Year for this report', + required=True), + 'periods': fields.many2many( + 'account.period', 'rel_wizard_period', + 'wizard_id', 'period_id', 'Periods', + help='All periods in the fiscal year if empty'), + + 'analytic_ledger': fields.boolean( + 'Analytic Ledger', + help="Allows to Generate an Analytic Ledger for accounts with\ + moves. Available when Balance Sheet and 'Initial | Debit | Credit\ + | YTD' are selected"), + 'journal_ledger': fields.boolean( + 'Journal Ledger', + help="Allows to Generate an Journal Ledger for accounts with\ + moves. Available when Balance Sheet and 'Initial | Debit | Credit\ + | YTD' are selected"), + 'partner_balance': fields.boolean( + 'Partner Balance', + help="Allows to Generate a Partner Balance for accounts with\ + moves. Available when Balance Sheet and 'Initial | Debit | Credit\ + | YTD' are selected"), + 'tot_check': fields.boolean('Summarize?', + help='Checking will add a new line at the\ + end of the Report which will Summarize\ + Columns in Report'), + 'lab_str': fields.char('Description', + help='Description for the Summary', size=128), + + 'target_move': fields.selection( + [('posted', 'All Posted Entries'), + ('all', 'All Entries'), + ], 'Entries to Include', + required=True, + help='Print All Accounting Entries or just Posted Accounting\ + Entries'), + # ~ Deprecated fields + 'filter': fields.selection([('bydate', 'By Date'), + ('byperiod', 'By Period'), + ('all', 'By Date and Period'), + ('none', 'No Filter')], + 'Date/Period Filter'), 'date_to': fields.date('End date'), 'date_from': fields.date('Start date'), } @@ -73,8 +124,10 @@ class wizard_report(osv.osv_memory): 'filter': lambda *a: 'byperiod', 'display_account_level': lambda *a: 0, 'inf_type': lambda *a: 'BS', - 'company_id': lambda self, cr, uid, c: self.pool.get('res.company')._company_default_get(cr, uid, 'account.invoice', context=c), - 'fiscalyear': lambda self, cr, uid, c: self.pool.get('account.fiscalyear').find(cr, uid), + 'company_id': lambda self, cr, uid, c: self.pool['res.company']. + _company_default_get(cr, uid, 'account.invoice', context=c), + 'fiscalyear': lambda self, cr, uid, c: self. + pool['account.fiscalyear'].find(cr, uid), 'display_account': lambda *a: 'bal_mov', 'columns': lambda *a: 'five', 'target_move': 'posted', @@ -90,14 +143,16 @@ class wizard_report(osv.osv_memory): return res - def onchange_columns(self, cr, uid, ids, columns, fiscalyear, periods, context=None): + def onchange_columns(self, cr, uid, ids, columns, fiscalyear, periods, + context=None): if context is None: context = {} res = {'value': {}} p_obj = self.pool.get("account.period") - all_periods = p_obj.search(cr, uid, [('fiscalyear_id', '=', fiscalyear), ( - 'special', '=', False)], context=context) + all_periods = p_obj.search(cr, uid, + [('fiscalyear_id', '=', fiscalyear), + ('special', '=', False)], context=context) s = set(periods[0][2]) t = set(all_periods) go = periods[0][2] and s.issubset(t) or False @@ -114,7 +169,8 @@ class wizard_report(osv.osv_memory): res['value'].update({'periods': []}) return res - def onchange_analytic_ledger(self, cr, uid, ids, company_id, analytic_ledger, context=None): + def onchange_analytic_ledger(self, cr, uid, ids, company_id, + analytic_ledger, context=None): if context is None: context = {} context['company_id'] = company_id @@ -152,20 +208,26 @@ class wizard_report(osv.osv_memory): return res afr_brw = self.pool.get('afr').browse(cr, uid, afr_id, context=context) res['value'].update({ - 'currency_id': afr_brw.currency_id and afr_brw.currency_id.id or afr_brw.company_id.currency_id.id}) + 'currency_id': afr_brw.currency_id + and afr_brw.currency_id.id + or afr_brw.company_id.currency_id.id}) res['value'].update({'inf_type': afr_brw.inf_type or 'BS'}) res['value'].update({'columns': afr_brw.columns or 'five'}) res['value'].update({ - 'display_account': afr_brw.display_account or 'bal_mov'}) + 'display_account': afr_brw.display_account + or 'bal_mov'}) res['value'].update({ - 'display_account_level': afr_brw.display_account_level or 0}) + 'display_account_level': afr_brw. + display_account_level or 0}) res['value'].update({ - 'fiscalyear': afr_brw.fiscalyear_id and afr_brw.fiscalyear_id.id}) + 'fiscalyear': afr_brw.fiscalyear_id + and afr_brw.fiscalyear_id.id}) res['value'].update({'account_list': [ acc.id for acc in afr_brw.account_ids]}) res['value'].update({'periods': [p.id for p in afr_brw.period_ids]}) res['value'].update({ - 'analytic_ledger': afr_brw.analytic_ledger or False}) + 'analytic_ledger': + afr_brw.analytic_ledger or False}) res['value'].update({'tot_check': afr_brw.tot_check or False}) res['value'].update({'lab_str': afr_brw.lab_str or _( 'Write a Description for your Summary Total')}) @@ -174,15 +236,14 @@ class wizard_report(osv.osv_memory): def _get_defaults(self, cr, uid, data, context=None): if context is None: context = {} - user = pooler.get_pool(cr.dbname).get( - 'res.users').browse(cr, uid, uid, context=context) + user = self.pool['res.users'].browse(cr, uid, uid, context=context) if user.company_id: company_id = user.company_id.id else: - company_id = pooler.get_pool(cr.dbname).get( - 'res.company').search(cr, uid, [('parent_id', '=', False)])[0] + company_id = self.pool['res.company'].search( + cr, uid, [('parent_id', '=', False)])[0] data['form']['company_id'] = company_id - fiscalyear_obj = pooler.get_pool(cr.dbname).get('account.fiscalyear') + fiscalyear_obj = self.pool['account.fiscalyear'] data['form']['fiscalyear'] = fiscalyear_obj.find(cr, uid) data['form']['context'] = context return data['form'] @@ -209,9 +270,12 @@ class wizard_report(osv.osv_memory): res = cr.dictfetchall() if res: - if (data['form']['date_to'] > res[0]['date_stop'] or data['form']['date_from'] < res[0]['date_start']): - raise osv.except_osv(_('UserError'), 'Las fechas deben estar entre %s y %s' % ( - res[0]['date_start'], res[0]['date_stop'])) + if (data['form']['date_to'] > res[0]['date_stop'] + or data['form']['date_from'] < res[0]['date_start']): + raise osv.except_osv(_('UserError'), + 'Las fechas deben estar entre %s y %s' + % (res[0]['date_start'], + res[0]['date_stop'])) else: return 'report' else: @@ -223,14 +287,20 @@ class wizard_report(osv.osv_memory): ap_obj = self.pool.get('account.period') fy_id = fy_id and type(fy_id) in (list, tuple) and fy_id[0] or fy_id if not ids: - #~ No hay periodos - return ap_obj.search(cr, uid, [('fiscalyear_id', '=', fy_id), ('special', '=', False)], order='date_start asc') + # ~ No hay periodos + return ap_obj.search(cr, uid, [('fiscalyear_id', '=', fy_id), + ('special', '=', False)], + order='date_start asc') ap_brws = ap_obj.browse(cr, uid, ids, context=context) date_start = min([period.date_start for period in ap_brws]) date_stop = max([period.date_stop for period in ap_brws]) - return ap_obj.search(cr, uid, [('fiscalyear_id', '=', fy_id), ('special', '=', False), ('date_start', '>=', date_start), ('date_stop', '<=', date_stop)], order='date_start asc') + return ap_obj.search(cr, uid, [('fiscalyear_id', '=', fy_id), + ('special', '=', False), + ('date_start', '>=', date_start), + ('date_stop', '<=', date_stop)], + order='date_start asc') def print_report(self, cr, uid, ids, data, context=None): if context is None: @@ -245,8 +315,10 @@ class wizard_report(osv.osv_memory): del data['form']['date_from'] del data['form']['date_to'] - data['form']['periods'] = self.period_span(cr, uid, data[ - 'form']['periods'], data['form']['fiscalyear']) + data['form']['periods'] = self.period_span( + cr, uid, + data['form']['periods'], + data['form']['fiscalyear']) elif data['form']['filter'] == 'bydate': self._check_date(cr, uid, data) @@ -259,13 +331,15 @@ class wizard_report(osv.osv_memory): self._check_date(cr, uid, data) lis2 = str(data['form']['periods']).replace( "[", "(").replace("]", ")") - sqlmm = """select min(p.date_start) as inicio, max(p.date_stop) as fin - from account_period p - where p.id in %s""" % lis2 + sqlmm = """select min(p.date_start) as inicio, + max(p.date_stop) as fin + from account_period p + where p.id in %s""" % lis2 cr.execute(sqlmm) minmax = cr.dictfetchall() if minmax: - if (data['form']['date_to'] < minmax[0]['inicio']) or (data['form']['date_from'] > minmax[0]['fin']): + if (data['form']['date_to'] < minmax[0]['inicio'])\ + or (data['form']['date_from'] > minmax[0]['fin']): raise osv.except_osv(_('Error !'), _( 'La interseccion entre el periodo y fecha es vacio')) @@ -274,11 +348,14 @@ class wizard_report(osv.osv_memory): if data['form']['columns'] == 'two': name = 'afr.2cols' if data['form']['columns'] == 'four': - if data['form']['analytic_ledger'] and data['form']['inf_type'] == 'BS': + if data['form']['analytic_ledger']\ + and data['form']['inf_type'] == 'BS': name = 'afr.analytic.ledger' - elif data['form']['journal_ledger'] and data['form']['inf_type'] == 'BS': + elif data['form']['journal_ledger']\ + and data['form']['inf_type'] == 'BS': name = 'afr.journal.ledger' - elif data['form']['partner_balance'] and data['form']['inf_type'] == 'BS': + elif data['form']['partner_balance']\ + and data['form']['inf_type'] == 'BS': name = 'afr.partner.balance' else: name = 'afr.4cols' @@ -289,6 +366,8 @@ class wizard_report(osv.osv_memory): if data['form']['columns'] == 'thirteen': name = 'afr.13cols' - return {'type': 'ir.actions.report.xml', 'report_name': name, 'datas': data} + return {'type': 'ir.actions.report.xml', + 'report_name': name, + 'datas': data} wizard_report()