diff --git a/account_financial_report/model/__init__.py b/account_financial_report/model/__init__.py index a59a5350..9c8007c1 100755 --- a/account_financial_report/model/__init__.py +++ b/account_financial_report/model/__init__.py @@ -4,8 +4,8 @@ # Module Writen to OpenERP, Open Source Management Solution # Copyright (C) OpenERP Venezuela (). # All Rights Reserved -###############Credits###################################################### -# Coded by: Humberto Arocha +# Credits###################################################### +# Coded by: Humberto Arocha # Planified by: Rafael Silva # Audited by: Nhomar Hernandez ############################################################################# @@ -21,7 +21,7 @@ # # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . -################################################################################ +########################################################################## import account_financial_report import res_company diff --git a/account_financial_report/report/__init__.py b/account_financial_report/report/__init__.py index 5eadef5a..25fa8f3b 100644 --- a/account_financial_report/report/__init__.py +++ b/account_financial_report/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 diff --git a/account_financial_report/report/parser.py b/account_financial_report/report/parser.py index 9e718d4e..75678dc4 100644 --- a/account_financial_report/report/parser.py +++ b/account_financial_report/report/parser.py @@ -38,6 +38,7 @@ from osv import osv import pdb from openerp.tools.safe_eval import safe_eval as eval + class account_balance(report_sxw.rml_parse): def __init__(self, cr, uid, name, context): @@ -348,12 +349,12 @@ class account_balance(report_sxw.rml_parse): ################################################################ # Get the accounts # ################################################################ - all_account_ids = _get_children_and_consol(self.cr, self.uid, account_ids, 100, self.context) - + 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) - credit_account_ids = _get_children_and_consol( self.cr, self.uid, credit_account_ids, 100, self.context, change_sign=True) @@ -394,7 +395,7 @@ class account_balance(report_sxw.rml_parse): tot_bal2 = 0.0 tot_bal3 = 0.0 tot_bal4 = 0.0 - tot_bal5 = 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') @@ -430,14 +431,14 @@ class account_balance(report_sxw.rml_parse): ############################################################### account_black_ids = account_obj.search(self.cr, self.uid, ( - [('id', 'in', [i[0] for i in all_account_ids]), - ('type', 'not in', + [('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', 'in', ('view', 'consolidation'))])) - #This could be done quickly with a sql sentence + # This could be done quickly with a sql sentence account_not_black = account_obj.browse( self.cr, self.uid, account_not_black_ids) account_not_black.sort(key=lambda x: x.level) @@ -445,7 +446,7 @@ class account_balance(report_sxw.rml_parse): account_not_black_ids = [i.id for i in account_not_black] all_account_period = {} # Todas las cuentas por periodo - + # Iteration limit depending on the number of columns if form['columns'] == 'thirteen': limit = 13 @@ -453,7 +454,7 @@ class account_balance(report_sxw.rml_parse): limit = 5 else: limit = 1 - + for p_act in range(limit): if limit != 1: if p_act == limit-1: @@ -483,15 +484,15 @@ class account_balance(report_sxw.rml_parse): d = i.debit c = i.credit dict_black[i.id] = { - 'obj': i, - 'debit': d, - 'credit': c, - 'balance': d-c - } + 'obj': i, + 'debit': d, + 'credit': c, + 'balance': d-c + } if form['inf_type'] == 'BS': dict_black.get(i.id)['balanceinit'] = 0.0 - #Se adicionan los valores de balanceinit al diccionario + # Se adicionan los valores de balanceinit al diccionario if form['inf_type'] == 'BS': for i in account_black_init: dict_black.get(i.id)['balanceinit'] = i.balance @@ -499,7 +500,8 @@ class account_balance(report_sxw.rml_parse): #~ Not black dict_not_black = {} for i in account_not_black: - dict_not_black[i.id] = {'obj': i, 'debit': 0.0, 'credit':0.0, 'balance':0.0} + dict_not_black[i.id] = { + 'obj': i, 'debit': 0.0, 'credit': 0.0, 'balance': 0.0} if form['inf_type'] == 'BS': dict_not_black.get(i.id)['balanceinit'] = 0.0 @@ -509,7 +511,7 @@ class account_balance(report_sxw.rml_parse): for acc_id in account_not_black_ids: acc_childs = dict_not_black.get(acc_id).get('obj').child_id for child_id in acc_childs: - #pdb.set_trace() + # pdb.set_trace() dict_not_black.get(acc_id)['debit'] += all_account.get( child_id.id).get('debit') dict_not_black.get(acc_id)['credit'] += all_account.get( @@ -534,7 +536,6 @@ class account_balance(report_sxw.rml_parse): # ############################################################### - for aa_id in account_ids: id = aa_id[0] @@ -555,7 +556,7 @@ class account_balance(report_sxw.rml_parse): } if form['columns'] == 'qtr': - for pn in range(1,5): + for pn in range(1, 5): if form['inf_type'] == 'IS': d, c, b = map(z, [ @@ -733,7 +734,7 @@ class account_balance(report_sxw.rml_parse): tot_bal2 += res.get('bal2', 0.0) tot_bal3 += res.get('bal3', 0.0) tot_bal4 += res.get('bal4', 0.0) - tot_bal5 += res.get('bal5', 0.0) + tot_bal5 += res.get('bal5', 0.0) elif form['columns'] == 'thirteen': tot_check = True @@ -750,7 +751,7 @@ class account_balance(report_sxw.rml_parse): tot_bal10 += res.get('bal10', 0.0) tot_bal11 += res.get('bal11', 0.0) tot_bal12 += res.get('bal12', 0.0) - tot_bal13 += res.get('bal13', 0.0) + tot_bal13 += res.get('bal13', 0.0) else: tot_check = True #~ tot[res['id']] = True @@ -760,7 +761,7 @@ class account_balance(report_sxw.rml_parse): tot_ytd += res['ytd'] tot_eje += res['balance'] - #pdb.set_trace() + # pdb.set_trace() if tot_check: str_label = form['lab_str'] res2 = { diff --git a/account_financial_report/wizard/__init__.py b/account_financial_report/wizard/__init__.py index 4192914a..5c4250d1 100644 --- a/account_financial_report/wizard/__init__.py +++ b/account_financial_report/wizard/__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 diff --git a/account_financial_report/wizard/wizard.py b/account_financial_report/wizard/wizard.py index 34b46e41..be9ff1eb 100644 --- a/account_financial_report/wizard/wizard.py +++ b/account_financial_report/wizard/wizard.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 @@ -26,138 +26,153 @@ # along with this program. If not, see . ############################################################################## -from osv import osv,fields +from osv import osv, fields import pooler import time from 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.'), - 'company_id': fields.many2one('res.company','Company',required=True), + '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'), - + '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"), - + '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), - + 'lab_str': fields.char('Description', help='Description for the Summary', size=128), + #~ Deprecated fields - 'filter': fields.selection([('bydate','By Date'),('byperiod','By Period'),('all','By Date and Period'),('none','No Filter')],'Date/Period Filter'), + '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'), } - + _defaults = { 'date_from': lambda *a: time.strftime('%Y-%m-%d'), 'date_to': lambda *a: time.strftime('%Y-%m-%d'), - 'filter': lambda *a:'byperiod', + '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), + '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), - 'display_account': lambda *a:'bal_mov', - 'columns': lambda *a:'five', + 'display_account': lambda *a: 'bal_mov', + 'columns': lambda *a: 'five', } - def onchange_inf_type(self,cr,uid,ids,inf_type,context=None): + def onchange_inf_type(self, cr, uid, ids, inf_type, context=None): if context is None: context = {} - res = {'value':{}} - + res = {'value': {}} + if inf_type != 'BS': - res['value'].update({'analytic_ledger':False}) - + res['value'].update({'analytic_ledger': False}) + 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':{}} - + 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 - + if columns != 'four': - res['value'].update({'analytic_ledger':False}) - + res['value'].update({'analytic_ledger': False}) + if columns in ('qtr', 'thirteen'): - res['value'].update({'periods':all_periods}) + res['value'].update({'periods': all_periods}) else: if go: - res['value'].update({'periods':periods}) + res['value'].update({'periods': periods}) else: - res['value'].update({'periods':[]}) + 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 - res = {'value':{}} - cur_id = self.pool.get('res.company').browse(cr,uid,company_id,context=context).currency_id.id - res['value'].update({'currency_id':cur_id}) + context['company_id'] = company_id + res = {'value': {}} + cur_id = self.pool.get('res.company').browse( + cr, uid, company_id, context=context).currency_id.id + res['value'].update({'currency_id': cur_id}) return res - - def onchange_company_id(self,cr,uid,ids,company_id,context=None): + + def onchange_company_id(self, cr, uid, ids, company_id, context=None): if context is None: context = {} - context['company_id']=company_id - res = {'value':{}} - + context['company_id'] = company_id + res = {'value': {}} + if not company_id: return res - - cur_id = self.pool.get('res.company').browse(cr,uid,company_id,context=context).currency_id.id - fy_id = self.pool.get('account.fiscalyear').find(cr, uid,context=context) - res['value'].update({'fiscalyear':fy_id}) - res['value'].update({'currency_id':cur_id}) - res['value'].update({'account_list':[]}) - res['value'].update({'periods':[]}) - res['value'].update({'afr_id':None}) + + cur_id = self.pool.get('res.company').browse( + cr, uid, company_id, context=context).currency_id.id + fy_id = self.pool.get('account.fiscalyear').find( + cr, uid, context=context) + res['value'].update({'fiscalyear': fy_id}) + res['value'].update({'currency_id': cur_id}) + res['value'].update({'account_list': []}) + res['value'].update({'periods': []}) + res['value'].update({'afr_id': None}) return res - def onchange_afr_id(self,cr,uid,ids,afr_id,context=None): + def onchange_afr_id(self, cr, uid, ids, afr_id, context=None): if context is None: context = {} - res = {'value':{}} - if not afr_id: 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}) - 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'}) - res['value'].update({'display_account_level':afr_brw.display_account_level or 0}) - res['value'].update({'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}) - 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')}) + res = {'value': {}} + if not afr_id: + 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}) + 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'}) + res['value'].update({ + 'display_account_level': afr_brw.display_account_level or 0}) + res['value'].update({ + '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}) + 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')}) return res - + 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 = pooler.get_pool(cr.dbname).get( + 'res.users').browse(cr, uid, uid, context=context) if user.company_id: - company_id = user.company_id.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 = pooler.get_pool(cr.dbname).get( + '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') data['form']['fiscalyear'] = fiscalyear_obj.find(cr, uid) @@ -168,49 +183,51 @@ class wizard_report(osv.osv_memory): if context is None: context = {} if data['form']['filter'] == 'bydate': - self._check_date(cr, uid, data, context) + self._check_date(cr, uid, data, context) return data['form'] - + def _check_date(self, cr, uid, data, context=None): if context is None: context = {} - + if data['form']['date_from'] > data['form']['date_to']: - raise osv.except_osv(_('Error !'),('La fecha final debe ser mayor a la inicial')) - + raise osv.except_osv(_('Error !'), ( + 'La fecha final debe ser mayor a la inicial')) + sql = """SELECT f.id, f.date_start, f.date_stop FROM account_fiscalyear f - WHERE '%s' = f.id """%(data['form']['fiscalyear']) + WHERE '%s' = f.id """ % (data['form']['fiscalyear']) cr.execute(sql) 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'])) + 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: - raise osv.except_osv(_('UserError'),'No existe periodo fiscal') + raise osv.except_osv(_('UserError'), 'No existe periodo fiscal') def period_span(self, cr, uid, ids, fy_id, context=None): if context is None: context = {} 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 + 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') - + 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: context = {} - + data = {} data['ids'] = context.get('active_ids', []) data['model'] = context.get('active_model', 'ir.ui.menu') @@ -220,7 +237,8 @@ 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) @@ -231,16 +249,18 @@ class wizard_report(osv.osv_memory): del data['form']['periods'] else: 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 + 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 cr.execute(sqlmm) minmax = cr.dictfetchall() if minmax: 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')) - + raise osv.except_osv(_('Error !'), _( + 'La interseccion entre el periodo y fecha es vacio')) + if data['form']['columns'] == 'one': name = 'afr.1cols' if data['form']['columns'] == 'two': @@ -256,7 +276,7 @@ class wizard_report(osv.osv_memory): name = 'afr.qtrcols' if data['form']['columns'] == 'thirteen': name = 'afr.13cols' - + return {'type': 'ir.actions.report.xml', 'report_name': name, 'datas': data} - + wizard_report()