diff --git a/addons/account/__openerp__.py b/addons/account/__openerp__.py index a6d2f0c9e69..b91de72dff6 100644 --- a/addons/account/__openerp__.py +++ b/addons/account/__openerp__.py @@ -41,9 +41,9 @@ The processes like maintaining of general ledger is done through the defined fin grouping is maintained through journal) for a particular financial year and for preparation of vouchers there is a module named account_vouchers """, - "depends" : ["product", "analytic", "process","board"], 'website': 'http://www.openerp.com', 'init_xml': [], + "depends" : ["product", "analytic", "process","board"], 'update_xml': [ #'test/test_parent_structure.yml', 'security/account_security.xml', @@ -55,6 +55,7 @@ module named account_vouchers 'wizard/account_use_model_view.xml', 'account_view.xml', 'account_report.xml', + 'wizard/account_report_common_view.xml', 'wizard/account_invoice_refund_view.xml', 'wizard/account_period_close_view.xml', 'wizard/account_fiscalyear_close_state.xml', @@ -64,9 +65,9 @@ module named account_vouchers 'wizard/account_open_closed_fiscalyear_view.xml', 'wizard/account_move_line_unreconcile_select_view.xml', 'wizard/account_vat_view.xml', - 'wizard/account_print_journal_view.xml', - 'wizard/account_general_journal_view.xml', - 'wizard/account_central_journal_view.xml', + 'wizard/account_report_print_journal_view.xml', + 'wizard/account_report_general_journal_view.xml', + 'wizard/account_report_central_journal_view.xml', 'wizard/account_subscription_generate_view.xml', 'wizard/account_fiscalyear_close_view.xml', 'wizard/account_state_open_view.xml', @@ -75,14 +76,14 @@ module named account_vouchers 'wizard/account_validate_move_view.xml', 'wizard/account_pay_invoice_view.xml', 'wizard/account_unreconcile_view.xml', - 'wizard/account_general_ledger_report_view.xml', + 'wizard/account_report_general_ledger_view.xml', 'wizard/account_invoice_state_view.xml', - 'wizard/account_partner_balance_report_view.xml', - 'wizard/account_balance_report_view.xml', + 'wizard/account_report_partner_balance_view.xml', + 'wizard/account_report_account_balance_view.xml', # 'wizard/account_move_line_select_view.xml', - 'wizard/account_aged_trial_balance_view.xml', + 'wizard/account_report_aged_partner_balance_view.xml', 'wizard/account_compare_account_balance_report_view.xml', - 'wizard/account_third_party_ledger.xml', + 'wizard/account_report_partner_ledger_view.xml', 'wizard/account_reconcile_view.xml', 'wizard/account_reconcile_partner_process_view.xml', 'wizard/account_automatic_reconcile_view.xml', @@ -113,12 +114,15 @@ module named account_vouchers 'report/account_invoice_report_view.xml', 'report/account_entries_report_view.xml', 'report/account_report_view.xml', + 'report/account_analytic_report_view.xml', + 'report/account_account_report_view.xml', 'report/account_analytic_entries_report_view.xml', 'board_account_view.xml', - "wizard/account_pl_report_view.xml", - "wizard/account_bs_report_view.xml" + "wizard/account_report_profit_loss_view.xml", + "wizard/account_report_balance_sheet_view.xml" ], 'demo_xml': [ + #'demo/price_accuracy00.yml', 'account_demo.xml', 'project/project_demo.xml', 'project/analytic_account_demo.xml', diff --git a/addons/account/account.py b/addons/account/account.py index 2e7ce17196b..c5efb062570 100644 --- a/addons/account/account.py +++ b/addons/account/account.py @@ -81,7 +81,7 @@ class account_payment_term(osv.osv): if amt: next_date = datetime.strptime(date_ref, '%Y-%m-%d') + relativedelta(days=line.days) if line.days2 < 0: - next_date += relativedelta(day=31) + next_date += relativedelta(day=line.days2) if line.days2 > 0: next_date += relativedelta(day=line.days2, months=1) result.append( (next_date.strftime('%Y-%m-%d'), amt) ) @@ -860,7 +860,7 @@ class account_period(osv.osv): 'fiscalyear_id': fields.many2one('account.fiscalyear', 'Fiscal Year', required=True, states={'done':[('readonly',True)]}, select=True), 'state': fields.selection([('draft','Draft'), ('done','Done')], 'State', readonly=True, help='When monthly periods are created. The state is \'Draft\'. At the end of monthly period it is in \'Done\' state.'), - 'company_id': fields.related('fiscalyear_id', 'company_id', type='many2one', relation='res.company', string='Company'), + 'company_id': fields.related('fiscalyear_id', 'company_id', type='many2one', relation='res.company', string='Company', store=True) } _defaults = { 'state': lambda *a: 'draft', @@ -1236,7 +1236,7 @@ class account_move(osv.osv): return amount def _centralise(self, cr, uid, move, mode, context=None): - assert mode in ('debit', 'credit'), 'Invalid Mode' #to prevent sql injection + assert(mode in ('debit', 'credit'), 'Invalid Mode') #to prevent sql injection if context is None: context = {} @@ -1292,11 +1292,10 @@ class account_move(osv.osv): # # Validate a balanced move. If it is a centralised journal, create a move. # - def validate(self, cr, uid, ids, context={}): if context and ('__last_update' in context): del context['__last_update'] - + valid_moves = [] #Maintains a list of moves which can be responsible to create analytic entries for move in self.browse(cr, uid, ids, context): @@ -1332,7 +1331,7 @@ class account_move(osv.osv): valid_moves.append(move) # Check whether the move lines are confirmed - + if not len(line_draft_ids): continue # Update the move lines (set them as valid) @@ -1345,7 +1344,7 @@ class account_move(osv.osv): account = {} account2 = {} - + if journal.type in ('purchase','sale'): for line in move.line_id: code = amount = 0 @@ -2196,6 +2195,7 @@ class account_add_tmpl_wizard(osv.osv_memory): def _get_def_cparent(self, cr, uid, context): acc_obj=self.pool.get('account.account') tmpl_obj=self.pool.get('account.account.template') + #print "Searching for ",context tids=tmpl_obj.read(cr, uid, [context['tmpl_ids']], ['parent_id']) if not tids or not tids[0]['parent_id']: return False @@ -2237,6 +2237,7 @@ class account_add_tmpl_wizard(osv.osv_memory): # 'tax_ids': [(6,0,tax_ids)], todo!! 'company_id': company_id, } + # print "Creating:", vals new_account = acc_obj.create(cr, uid, vals) return {'type':'state', 'state': 'end' } @@ -2257,7 +2258,7 @@ class account_tax_code_template(osv.osv): 'info': fields.text('Description'), 'parent_id': fields.many2one('account.tax.code.template', 'Parent Code', select=True), 'child_ids': fields.one2many('account.tax.code.template', 'parent_id', 'Child Codes'), - 'sign': fields.float('Sign for parent', required=True, help="Choose 1.00 to add the total to the parent account or -1.00 to subtract it"), + 'sign': fields.float('Sign for parent', required=True), 'notprintable':fields.boolean("Not Printable in Invoice", help="Check this box if you don't want any VAT related to this Tax Code to appear on invoices"), } @@ -2289,7 +2290,7 @@ class account_chart_template(osv.osv): _columns={ 'name': fields.char('Name', size=64, required=True), - 'account_root_id': fields.many2one('account.account.template','Root Account',required=True,domain=[('parent_id','=',False)], help=""), + 'account_root_id': fields.many2one('account.account.template','Root Account',required=True,domain=[('parent_id','=',False)]), 'tax_code_root_id': fields.many2one('account.tax.code.template','Root Tax Code',required=True,domain=[('parent_id','=',False)]), 'tax_template_ids': fields.one2many('account.tax.template', 'chart_template_id', 'Tax Template List', help='List of all the taxes that have to be installed by the wizard'), 'bank_account_view_id': fields.many2one('account.account.template','Bank Account',required=True), diff --git a/addons/account/account_analytic_line.py b/addons/account/account_analytic_line.py index 2cd1b4d17bd..c1c6e3f854b 100644 --- a/addons/account/account_analytic_line.py +++ b/addons/account/account_analytic_line.py @@ -96,7 +96,7 @@ class account_analytic_line(osv.osv): # Take the company currency as the reference one context['currency_id']=company_obj.browse(cr, uid, company_id).currency_id.id amount_unit=prod.price_get(pricetype.field, context)[prod.id] - amount=amount_unit*unit_amount or 1.0 + amount = amount_unit*unit_amount or 1.0 return {'value': { 'amount': - round(amount, 2), 'general_account_id': a, diff --git a/addons/account/account_move_line.py b/addons/account/account_move_line.py index a29f32105a5..39c8e6fea2f 100644 --- a/addons/account/account_move_line.py +++ b/addons/account/account_move_line.py @@ -20,6 +20,7 @@ ############################################################################## import time from datetime import datetime + import netsvc from osv import fields, osv from tools.translate import _ @@ -35,8 +36,10 @@ class account_move_line(osv.osv): fiscalperiod_obj = self.pool.get('account.period') fiscalyear_ids = [] fiscalperiod_ids = [] - if not context.get('fiscalyear', False): + if not context.get('fiscalyear', False) and not context.get('empty_fy_allow', False): fiscalyear_ids = fiscalyear_obj.search(cr, uid, [('state', '=', 'draft')]) + elif context.get('empty_fy_allow', False): + fiscalyear_ids = context['fiscalyear'] else: fiscalyear_ids = [context['fiscalyear']] @@ -53,13 +56,19 @@ class account_move_line(osv.osv): if state.lower() not in ['all']: where_move_state= " AND "+obj+".move_id in (select id from account_move where account_move.state = '"+state+"')" - if context.get('periods', False): ids = ','.join([str(x) for x in context['periods']]) - query = obj+".state<>'draft' AND "+obj+".period_id in (SELECT id from account_period WHERE fiscalyear_id in (%s) AND id in (%s)) %s %s" % (fiscalyear_clause, ids,where_move_state,where_move_lines_by_date) + query = obj+".state<>'draft' AND "+obj+".period_id in (SELECT id from account_period WHERE fiscalyear_id in (%s) AND id in (%s)) %s %s" % (fiscalyear_clause, ids, where_move_state, where_move_lines_by_date) else: query = obj+".state<>'draft' AND "+obj+".period_id in (SELECT id from account_period WHERE fiscalyear_id in (%s) %s %s)" % (fiscalyear_clause,where_move_state,where_move_lines_by_date) + if context.get('journal_ids', False): + query += ' AND '+obj+'.journal_id in (%s)' % ','.join(map(str, context['journal_ids'])) + + if context.get('chart_account_id', False): + child_ids = self.pool.get('account.account')._get_children_and_consol(cr, uid, [context['chart_account_id']], context=context) + query += ' AND '+obj+'.account_id in (%s)' % ','.join(map(str, child_ids)) + if context.get('period_manner','') == 'created': #the query have to be build with no reference to periods but thanks to the creation date if context.get('periods',False): @@ -452,7 +461,7 @@ class account_move_line(osv.osv): context=context) dt = period.date_start return dt - + def _get_currency(self, cr, uid, context={}): if not context.get('journal_id', False): return False @@ -506,7 +515,7 @@ class account_move_line(osv.osv): _constraints = [ (_check_no_view, 'You can not create move line on view account.', ['account_id']), (_check_no_closed, 'You can not create move line on closed account.', ['account_id']), - (_check_company_id, 'Company must be same for its related account and period.', ['company_id']), + (_check_company_id,'Company must be same for its related account and period.',['company_id'] ), ] #TODO: ONCHANGE_ACCOUNT_ID: set account_tax_id @@ -677,7 +686,7 @@ class account_move_line(osv.osv): account_id = line['account_id']['id'] partner_id = (line['partner_id'] and line['partner_id']['id']) or False writeoff = debit - credit - + # Ifdate_p in context => take this date if context.has_key('date_p') and context['date_p']: date=context['date_p'] @@ -1111,7 +1120,7 @@ class account_move_line(osv.osv): #if not 'currency_id' in vals: # vals['currency_id'] = account.company_id.currency_id.id - + result = super(osv.osv, self).create(cr, uid, vals, context) # CREATE Taxes if vals.get('account_tax_id', False): diff --git a/addons/account/account_report.xml b/addons/account/account_report.xml index 8b4aa147a95..8e26ee8553b 100644 --- a/addons/account/account_report.xml +++ b/addons/account/account_report.xml @@ -1,14 +1,14 @@ - - - + + + - - - - + + + + --> - - - - @@ -103,21 +98,6 @@ - - - - - - - diff --git a/addons/account/report/__init__.py b/addons/account/report/__init__.py index f6dfd51b729..eb6695264de 100644 --- a/addons/account/report/__init__.py +++ b/addons/account/report/__init__.py @@ -19,13 +19,13 @@ # ############################################################################## -import central_journal -import general_journal +import account_central_journal +import account_general_journal import account_journal import account_balance -import partner_balance -import general_ledger -import third_party_ledger +import account_partner_balance +import account_general_ledger +import account_partner_ledger import invoice import overdue import aged_trial_balance @@ -35,12 +35,12 @@ import account_balance_landscape import compare_account_balance import account_invoice_report import account_report -#import account_analytic_report +import account_analytic_report import account_account_report import account_entries_report import account_analytic_entries_report import voucher_print -import report_bs -import report_pl +import account_balance_sheet +import account_profit_loss # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/addons/account/report/account_account_report_view.xml b/addons/account/report/account_account_report_view.xml new file mode 100644 index 00000000000..bd9101a3382 --- /dev/null +++ b/addons/account/report/account_account_report_view.xml @@ -0,0 +1,94 @@ + + + + + account.account.report.tree + account.account.report + tree + + + + + + + + + + + + + + + + + + + + + account.account.report.graph + account.account.report + graph + + + + + + + + + + + + account.account.report.search + account.account.report + search + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Accounts Analysis + account.account.report + form + tree,graph + {"search_default_Account":1,"search_default_At Date":1,'group_by_no_leaf':1,'group_by':[]} + + + + + + + diff --git a/addons/account/report/account_analytic_report.py b/addons/account/report/account_analytic_report.py new file mode 100644 index 00000000000..a740076ad09 --- /dev/null +++ b/addons/account/report/account_analytic_report.py @@ -0,0 +1,94 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# Copyright (C) 2004-2010 Tiny SPRL (). +# +# 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 (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## + +import tools +from osv import fields,osv + +class analytic_report(osv.osv): + _name = "analytic.report" + _description = "Analytic Accounts Statistics" + _auto = False + _columns = { + 'date_start': fields.date('Date Start', readonly=True), + 'date_end': fields.date('Date End', readonly=True), + 'name' : fields.char('Analytic Account', size=128, readonly=True), + 'partner_id' : fields.many2one('res.partner', 'Associated Partner', readonly=True), + 'journal_id' : fields.many2one('account.analytic.journal', 'Analytic Journal', readonly=True), + 'parent_id': fields.many2one('account.analytic.account', 'Parent Analytic Account', readonly=True), + 'user_id' : fields.many2one('res.users', 'Account Manager', readonly=True), + 'product_id' : fields.many2one('product.product', 'Product', readonly=True), + 'total_quantity': fields.float('# Total Quantity', readonly=True), + 'debit' : fields.float('Debit', readonly=True), + 'credit' : fields.float('Credit', readonly=True), + 'balance' : fields.float('Balance', readonly=True), + 'year': fields.char('Year', size=4, readonly=True), + 'month':fields.selection([('01','January'), ('02','February'), ('03','March'), ('04','April'), + ('05','May'), ('06','June'), ('07','July'), ('08','August'), ('09','September'), + ('10','October'), ('11','November'), ('12','December')], 'Month', readonly=True), + 'day': fields.char('Day', size=128, readonly=True), + 'nbr':fields.integer('# of Lines', readonly=True), + 'company_id': fields.many2one('res.company', 'Company', readonly=True), + 'type': fields.selection([('view','View'), ('normal','Normal')], 'Account Type'), + + 'state': fields.selection([('draft','Draft'), + ('open','Open'), + ('pending','Pending'), + ('cancelled', 'Cancelled'), + ('close','Close'), + ('template', 'Template')], + 'State', readonly=True), + + } + _order = 'date_start desc' + def init(self, cr): + tools.drop_view_if_exists(cr, 'analytic_report') + cr.execute(""" + create or replace view analytic_report as ( + select + min(s.id) as id, + to_char(s.create_date, 'YYYY') as year, + to_char(s.create_date, 'MM') as month, + to_char(s.create_date, 'YYYY-MM-DD') as day, + l.journal_id, + l.product_id, + s.parent_id, + s.date_start, + s.date as date_end, + s.user_id, + s.company_id, + s.type, + s.name, + s.partner_id, + sum(s.quantity) as total_quantity, + s.debit, + s.credit, + s.balance, + count(*) as nbr, + s.state + from account_analytic_account s + left join account_analytic_line l on (s.id=l.account_id) + GROUP BY s.create_date,s.state,l.journal_id,s.name, + s.partner_id,s.date_start,s.date,s.user_id, + s.company_id,s.type, + s.debit,s.credit,s.balance,s.parent_id,l.product_id + ) + """) +analytic_report() diff --git a/addons/account/report/account_analytic_report_view.xml b/addons/account/report/account_analytic_report_view.xml index b3570a73da0..070b3a8c10a 100644 --- a/addons/account/report/account_analytic_report_view.xml +++ b/addons/account/report/account_analytic_report_view.xml @@ -1,6 +1,128 @@ + + analytic.report.tree + analytic.report + tree + + + + + + + + + + + + + + + + + + + + + + + + + + analytic.report.search + analytic.report + search + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + account.analytic.report.graph + analytic.report + graph + + + + + + + + + + + + Analytic Accounts Analysis + analytic.report + form + tree,graph + {'search_default_This Month':1,'search_default_User':1,'group_by_no_leaf':1,'group_by':[]} + + + diff --git a/addons/account/report/account_balance.py b/addons/account/report/account_balance.py index 93a09db9edf..bcc9c75be57 100644 --- a/addons/account/report/account_balance.py +++ b/addons/account/report/account_balance.py @@ -19,169 +19,137 @@ # ############################################################################## -import xml -import copy -from operator import itemgetter -import datetime +import time + from report import report_sxw -import xml.dom.minidom -import os, time -import osv -import re -import tools -import pooler -import sys +from common_report_header import common_report_header -class account_balance(report_sxw.rml_parse): - _name = 'report.account.account.balance' - def __init__(self, cr, uid, name, context): - super(account_balance, self).__init__(cr, uid, name, context=context) - self.sum_debit = 0.00 - self.sum_credit = 0.00 - self.date_lst = [] - self.date_lst_string = '' - self.localcontext.update({ - 'time': time, - 'lines': self.lines, - 'sum_debit': self._sum_debit, - 'sum_credit': self._sum_credit, - 'get_fiscalyear':self.get_fiscalyear, - 'get_periods':self.get_periods, - }) - self.context = context +class account_balance(report_sxw.rml_parse, common_report_header): + _name = 'report.account.account.balance' - def _add_header(self, node, header=1): - if header==0: - self.rml_header = "" - return True - def get_fiscalyear(self, form): - res=[] - if form.has_key('fiscalyear'): - fisc_id = form['fiscalyear'] - if not (fisc_id): - return '' - self.cr.execute("select name from account_fiscalyear where id = %s" , (int(fisc_id),)) - res=self.cr.fetchone() - return res and res[0] or '' + def __init__(self, cr, uid, name, context=None): + super(account_balance, self).__init__(cr, uid, name, context=context) + self.sum_debit = 0.00 + self.sum_credit = 0.00 + self.date_lst = [] + self.date_lst_string = '' + self.localcontext.update({ + 'time': time, + 'lines': self.lines, + 'sum_debit': self._sum_debit, + 'sum_credit': self._sum_credit, + 'get_fiscalyear':self._get_fiscalyear, + 'get_filter': self._get_filter, + 'get_start_period': self.get_start_period, + 'get_end_period': self.get_end_period , + 'get_account': self._get_account, + 'get_journal': self._get_journal, + 'get_start_date':self._get_start_date, + 'get_end_date':self._get_end_date, + }) + self.context = context - def get_periods(self, form): - result='' - if form.has_key('periods') and form['periods']: - period_ids = form['periods'] - per_ids = self.pool.get('account.period').browse(self.cr, self.uid, form['periods']) - for r in per_ids: - if r == per_ids[len(per_ids)-1]: - result+=r.name+". " - else: - result+=r.name+", " - else: - fy_obj = self.pool.get('account.fiscalyear').browse(self.cr, self.uid, form['fiscalyear']) - res = fy_obj.period_ids - len_res = len(res) - for r in res: - if r == res[len_res-1]: - result+=r.name+". " - else: - result+=r.name+", " + def set_context(self, objects, data, ids, report_type=None): + new_ids = ids + if (data['model'] == 'ir.ui.menu'): + new_ids = 'chart_account_id' in data['form'] and [data['form']['chart_account_id']] or [] + objects = self.pool.get('account.account').browse(self.cr, self.uid, new_ids) + self.query_get_clause = data['form'].get('query_line', False) or '' + return super(account_balance, self).set_context(objects, data, new_ids, report_type=report_type) - return str(result and result[:-1]) or '' + def _add_header(self, node, header=1): + if header == 0: + self.rml_header = "" + return True + def _get_account(self, data): + if data['model']=='account.account': + return self.pool.get('account.account').browse(self.cr, self.uid, data['form']['id']).company_id.name + return super(account_balance ,self)._get_account(data) - def lines(self, form, ids={}, done=None, level=1): - if not ids: - ids = self.ids - if not ids: - return [] - if not done: - done={} - if form.has_key('Account_list') and form['Account_list']: - ids = [form['Account_list']] - del form['Account_list'] - res={} - result_acc=[] - ctx = self.context.copy() - ctx['state'] = form['context'].get('state','all') - ctx['fiscalyear'] = form['fiscalyear'] - if form['state']=='byperiod' : - ctx['periods'] = form['periods'] - elif form['state']== 'bydate': - ctx['date_from'] = form['date_from'] - ctx['date_to'] = form['date_to'] - elif form['state'] == 'all' : - ctx['periods'] = form['periods'] - ctx['date_from'] = form['date_from'] - ctx['date_to'] = form['date_to'] -# accounts = self.pool.get('account.account').browse(self.cr, self.uid, ids, ctx) -# def cmp_code(x, y): -# return cmp(x.code, y.code) -# accounts.sort(cmp_code) - child_ids = self.pool.get('account.account')._get_children_and_consol(self.cr, self.uid, ids, ctx) - if child_ids: - ids = child_ids - accounts = self.pool.get('account.account').read(self.cr, self.uid, ids, ['type','code','name','debit','credit','balance','parent_id'], ctx) - for account in accounts: - if account['id'] in done: - continue - done[account['id']] = 1 - res = { - 'id' : account['id'], - 'type' : account['type'], - 'code': account['code'], - 'name': account['name'], - 'level': level, - 'debit': account['debit'], - 'credit': account['credit'], - 'balance': account['balance'], - # 'leef': not bool(account['child_id']), - 'parent_id':account['parent_id'], - 'bal_type':'', - } - self.sum_debit += account['debit'] - self.sum_credit += account['credit'] -# if account.child_id: -# def _check_rec(account): -# if not account.child_id: -# return bool(account.credit or account.debit) -# for c in account.child_id: -# if not _check_rec(c) or _check_rec(c): -# return True -# return False -# if not _check_rec(account) : -# continue - if account['parent_id']: -# acc = self.pool.get('account.account').read(self.cr, self.uid, [ account['parent_id'][0] ] ,['name'], ctx) - for r in result_acc: - if r['id'] == account['parent_id'][0]: - res['level'] = r['level'] + 1 - break - if form['display_account'] == 'bal_mouvement': - if res['credit'] > 0 or res['debit'] > 0 or res['balance'] > 0 : - result_acc.append(res) - elif form['display_account'] == 'bal_solde': - if res['balance'] != 0: - result_acc.append(res) - else: + def lines(self, form, ids=[], done=None, level=1): + obj_account = self.pool.get('account.account') + if not ids: + ids = self.ids + if not ids: + return [] + if not done: + done={} + + res = {} + result_acc = [] + ctx = self.context.copy() + + ctx['fiscalyear'] = form['fiscalyear_id'] + if form['filter'] == 'filter_period': + ctx['periods'] = form['periods'] + elif form['filter'] == 'filter_date': + ctx['date_from'] = form['date_from'] + ctx['date_to'] = form['date_to'] +# accounts = obj_account.browse(self.cr, self.uid, ids, ctx) +# def cmp_code(x, y): +# return cmp(x.code, y.code) +# accounts.sort(cmp_code) + + child_ids = obj_account._get_children_and_consol(self.cr, self.uid, ids, ctx) + if child_ids: + ids = child_ids + accounts = obj_account.read(self.cr, self.uid, ids, ['type','code','name','debit','credit','balance','parent_id'], ctx) + for account in accounts: + if account['id'] in done: + continue + done[account['id']] = 1 + res = { + 'id': account['id'], + 'type': account['type'], + 'code': account['code'], + 'name': account['name'], + 'level': level, + 'debit': account['debit'], + 'credit': account['credit'], + 'balance': account['balance'], + # 'leef': not bool(account['child_id']), + 'parent_id':account['parent_id'], + 'bal_type':'', + } + self.sum_debit += account['debit'] + self.sum_credit += account['credit'] +# if account.child_id: +# def _check_rec(account): +# if not account.child_id: +# return bool(account.credit or account.debit) +# for c in account.child_id: +# if not _check_rec(c) or _check_rec(c): +# return True +# return False +# if not _check_rec(account) : +# continue + if account['parent_id']: +# acc = obj_account.read(self.cr, self.uid, [ account['parent_id'][0] ] ,['name'], ctx) + for r in result_acc: + if r['id'] == account['parent_id'][0]: + res['level'] = r['level'] + 1 + break + if form['display_account'] == 'bal_movement': + if res['credit'] > 0 or res['debit'] > 0 or res['balance'] > 0 : result_acc.append(res) -# if account.child_id: -# acc_id = [acc.id for acc in account.child_id] -# lst_string = '' -# lst_string = '\'' + '\',\''.join(map(str,acc_id)) + '\'' -# self.cr.execute("select code,id from account_account where id IN (%s)"%(lst_string)) -# a_id = self.cr.fetchall() -# a_id.sort() -# ids2 = [x[1] for x in a_id] + elif form['display_account'] == 'bal_solde': + if res['balance'] != 0: + result_acc.append(res) + else: + result_acc.append(res) +# if account.child_id: +# acc_id = [acc.id for acc in account.child_id] +# lst_string = '' +# lst_string = '\'' + '\',\''.join(map(str,acc_id)) + '\'' +# self.cr.execute("select code,id from account_account where id IN (%s)"%(lst_string)) +# a_id = self.cr.fetchall() +# a_id.sort() +# ids2 = [x[1] for x in a_id] # -# result_acc += self.lines(form, ids2, done, level+1) - return result_acc +# result_acc += self.lines(form, ids2, done, level+1) + return result_acc - def _sum_credit(self): - return self.sum_credit +report_sxw.report_sxw('report.account.account.balance', 'account.account', 'addons/account/report/account_balance.rml', parser=account_balance, header="internal") - def _sum_debit(self): - return self.sum_debit - - - - -report_sxw.report_sxw('report.account.account.balance', 'account.account', 'addons/account/report/account_balance.rml', parser=account_balance, header=0) -# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: +# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: \ No newline at end of file diff --git a/addons/account/report/account_balance.rml b/addons/account/report/account_balance.rml index 8ee7e3e17dc..a5b4e211b33 100644 --- a/addons/account/report/account_balance.rml +++ b/addons/account/report/account_balance.rml @@ -2,26 +2,7 @@ @@ -29,186 +10,280 @@ - + - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - + + + + + - - - - - - - + - - - - - - - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + - - + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - + + + + + + Account Balance + + + + + + + + + + + + Company [[ data['model']=='account.account' or removeParentNode('para') ]] + [[ data['model']=='ir.ui.menu' and 'Chart of Account' or removeParentNode('para') ]] Fiscal Year - - End Date - - - Start Date - Display Account - Periods + Filter By [[ get_filter(data)!='No Filter' and get_filter(data) ]] + + + Printing Date - - - [[ get_fiscalyear(data['form']) ]] + [[ get_account(data) or '' ]] - [[ data['form']['date_from'] ]] + [[ get_fiscalyear(data) or '' ]] + + [[ (data['form']['display_account']=='bal_all' and 'All') or (data['form']['display_account']=='bal_movement' and 'With movements') or 'With balance is not equal to 0']] + [[ get_filter(data)=='No Filter' and get_filter(data) or removeParentNode('para') ]] + [[ get_filter(data)=='Date' or removeParentNode('blockTable') ]] + + + Start Date + + + End Date + + + + + [[ get_start_date(data) ]] + + + [[ get_end_date(data) ]] + + + + [[ get_filter(data)=='Periods' or removeParentNode('blockTable') ]] + + + Start Period + + + End Period + + + + + [[ get_start_period(data) or removeParentNode('para') ]] + + + [[ get_end_period(data) or removeParentNode('para') ]] + + + - [[ data['form']['date_to'] ]] - - - [[ (data['form']['display_account']=='bal_all' and 'All') or (data['form']['display_account']=='bal_mouvement' and 'With movements') or 'With balance is not equal to 0']] - - - [[data['form']['periods'] and get_periods(data['form']) or '']] + [[ formatLang(time.strftime('%Y-%m-%d %H:%M:%S'), date_time = True)]] - - - - - - + + + + + + + Code Account @@ -224,5 +299,8 @@ [[ (a['level']>2 and setTag('para','para',{'fontName':"Helvetica"})) or removeParentNode('font') ]][[ a['type']=='view' and removeParentNode('font') ]][[ formatLang(a['balance']) ]][[ a['type']<>'view' and removeParentNode('font') ]] [[ formatLang(a['balance']) ]] + + + - + \ No newline at end of file diff --git a/addons/account/report/report_bs.py b/addons/account/report/account_balance_sheet.py similarity index 69% rename from addons/account/report/report_bs.py rename to addons/account/report/account_balance_sheet.py index 04fafd7ed30..08df077c779 100644 --- a/addons/account/report/report_bs.py +++ b/addons/account/report/account_balance_sheet.py @@ -1,6 +1,6 @@ # -*- encoding: utf-8 -*- ############################################################################## -# +# # OpenERP, Open Source Management Solution # Copyright (C) 2004-2009 Tiny SPRL (). # @@ -15,65 +15,76 @@ # GNU Affero General Public License for more details. # # You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . +# along with this program. If not, see . # ############################################################################## -import pooler import time -import mx.DateTime + +import pooler import rml_parse from report import report_sxw -from account.report import report_pl +from account.report import account_profit_loss +from common_report_header import common_report_header -class report_balancesheet_horizontal(rml_parse.rml_parse): - def __init__(self, cr, uid, name, context): - super(report_balancesheet_horizontal, self).__init__(cr, uid, name, context) - self.obj_pl=report_pl.report_pl_account_horizontal(cr, uid, name, context) - self.result_sum_dr=0.0 - self.result_sum_cr=0.0 +class report_balancesheet_horizontal(rml_parse.rml_parse, common_report_header): + def __init__(self, cr, uid, name, context=None): + super(report_balancesheet_horizontal, self).__init__(cr, uid, name, context=context) + self.obj_pl = account_profit_loss.report_pl_account_horizontal(cr, uid, name, context=context) + self.result_sum_dr = 0.0 + self.result_sum_cr = 0.0 self.result = {} - self.res_pl={} - self.result_temp=[] + self.res_bl = {} + self.result_temp = [] self.localcontext.update({ 'time': time, 'get_abs' : self.get_abs, 'get_lines' : self.get_lines, 'get_lines_another' : self.get_lines_another, - 'get_company': self.get_company, + 'get_company': self._get_company, 'get_currency': self._get_currency, 'sum_dr' : self.sum_dr, 'sum_cr' : self.sum_cr, 'get_data':self.get_data, 'get_pl_balance':self.get_pl_balance, - + 'get_fiscalyear': self._get_fiscalyear, + 'get_account': self._get_account, + 'get_start_period': self.get_start_period, + 'get_end_period': self.get_end_period, + 'get_sortby': self._get_sortby, + 'get_filter': self._get_filter, + 'get_journal': self._get_journal, + 'get_start_date':self._get_start_date, + 'get_end_date':self._get_end_date, + 'get_company':self._get_company, + }) self.context = context def get_abs(self,amount): return abs(amount) - + def sum_dr(self): - if self.res_pl['type'] == 'Net Profit': - self.result_sum_dr += self.res_pl['balance'] + if self.res_bl['type'] == 'Net Profit': + self.result_sum_dr += self.res_bl['balance'] return self.result_sum_dr or 0.0 - + def sum_cr(self): - if self.res_pl['type'] == 'Net Loss': - self.result_sum_cr += self.res_pl['balance'] + if self.res_bl['type'] == 'Net Loss': + self.result_sum_cr += self.res_bl['balance'] return self.result_sum_cr or 0.0 def get_pl_balance(self): - return self.res_pl or 0.0 - - def get_data(self,form): + return self.res_bl or 0.0 + + def get_data(self,data): cr, uid = self.cr, self.uid db_pool = pooler.get_pool(self.cr.dbname) - + #Getting Profit or Loss Balance from profit and Loss report - result_pl=self.obj_pl.get_data(form) - self.res_pl=self.obj_pl.final_result() - + result_pl=self.obj_pl.get_data(data) + self.res_bl = self.obj_pl.final_result() + type_pool = db_pool.get('account.account.type') account_pool = db_pool.get('account.account') year_pool = db_pool.get('account.fiscalyear') @@ -84,34 +95,31 @@ class report_balancesheet_horizontal(rml_parse.rml_parse): ] ctx = self.context.copy() - ctx['state'] = form['context'].get('state','all') - ctx['fiscalyear'] = form['fiscalyear'] - if form['state']=='byperiod' : - ctx['periods'] = form['periods'] - elif form['state']== 'bydate': - ctx['date_from'] = form['date_from'] - ctx['date_to'] = form['date_to'] - elif form['state'] == 'all' : - ctx['periods'] = form['periods'] - ctx['date_from'] = form['date_from'] - ctx['date_to'] = form['date_to'] +# ctx['state'] = form['context'].get('state','filter_no') + ctx['fiscalyear'] = data['form'].get('fiscalyear_id', False) - cal_list={} + if data['form']['filter'] == 'filter_period' : + ctx['periods'] = data['form'].get('periods', False) + elif data['form']['filter'] == 'filter_date': + ctx['date_from'] = data['form'].get('date_from', False) + ctx['date_to'] = data['form'].get('date_to', False) + + cal_list = {} pl_dict = {} account_dict = {} - account_id = [form['Account_list']] + account_id = data['form'].get('chart_account_id', False) account_ids = account_pool._get_children_and_consol(cr, uid, account_id, context=ctx) accounts = account_pool.browse(cr, uid, account_ids, context=ctx) - if self.res_pl['type'] == 'Net Profit C.F.B.L.': - self.res_pl['type'] = 'Net Profit' + if self.res_bl['type'] == 'Net Profit C.F.B.L.': + self.res_bl['type'] = 'Net Profit' else: - self.res_pl['type'] = 'Net Loss' + self.res_bl['type'] = 'Net Loss' pl_dict = { 'code' : False, - 'name' : self.res_pl['type'], + 'name' : self.res_bl['type'], 'level': False, - 'balance':self.res_pl['balance'], + 'balance':self.res_bl['balance'], } for typ in types: accounts_temp = [] @@ -128,23 +136,23 @@ class report_balancesheet_horizontal(rml_parse.rml_parse): self.result_sum_dr += abs(account.debit - account.credit) if typ == 'asset' and account.type <> 'view' and (account.debit <> account.credit): self.result_sum_cr += abs(account.debit - account.credit) - if form['display_account'] == 'bal_mouvement': + if data['form']['display_account'] == 'bal_movement': if account.credit > 0 or account.debit > 0 or account.balance > 0 : accounts_temp.append(account_dict) - elif form['display_account'] == 'bal_solde': - if account.balance != 0: + elif data['form']['display_account'] == 'bal_solde': + if account.balance != 0: accounts_temp.append(account_dict) else: accounts_temp.append(account_dict) - if account.id == form['reserve_account_id']: + if account.id == data['form']['reserve_account_id']: pl_dict['level'] = account['level'] + 1 accounts_temp.append(pl_dict) - + self.result[typ] = accounts_temp cal_list[typ]=self.result[typ] if cal_list: - temp={} + temp = {} for i in range(0,max(len(cal_list['liability']),len(cal_list['asset']))): if i < len(cal_list['liability']) and i < len(cal_list['asset']): temp={ @@ -171,7 +179,7 @@ class report_balancesheet_horizontal(rml_parse.rml_parse): 'balance1':cal_list['asset'][i]['balance'], } self.result_temp.append(temp) - if i < len(cal_list['liability']): + if i < len(cal_list['liability']): temp={ 'code' : cal_list['liability'][i]['code'], 'name' : cal_list['liability'][i]['name'], @@ -184,24 +192,19 @@ class report_balancesheet_horizontal(rml_parse.rml_parse): } self.result_temp.append(temp) return None - + def get_lines(self): return self.result_temp def get_lines_another(self, group): return self.result.get(group, []) - - def _get_currency(self, form): - return pooler.get_pool(self.cr.dbname).get('res.company').browse(self.cr, self.uid, form['company_id']).currency_id.code - - def get_company(self,form): - comp_obj=pooler.get_pool(self.cr.dbname).get('res.company').browse(self.cr,self.uid,form['company_id']) - return comp_obj.name report_sxw.report_sxw('report.account.balancesheet.horizontal', 'account.account', - 'addons/account/report/report_balance_sheet_horizontal.rml',parser=report_balancesheet_horizontal, - header=False) + 'addons/account/report/account_balance_sheet_horizontal.rml',parser=report_balancesheet_horizontal, + header='internal') report_sxw.report_sxw('report.account.balancesheet', 'account.account', - 'addons/account/report/report_balance_sheet.rml',parser=report_balancesheet_horizontal, - header=False) + 'addons/account/report/account_balance_sheet.rml',parser=report_balancesheet_horizontal, + header='internal') + +# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: \ No newline at end of file diff --git a/addons/account/report/report_balance_sheet.rml b/addons/account/report/account_balance_sheet.rml similarity index 70% rename from addons/account/report/report_balance_sheet.rml rename to addons/account/report/account_balance_sheet.rml index 20f52cdd2f2..5ab769d6625 100644 --- a/addons/account/report/report_balance_sheet.rml +++ b/addons/account/report/account_balance_sheet.rml @@ -1,6 +1,6 @@ -