Skip to Content
Menu
This question has been flagged
1 Reply
4129 Views

I have a function field 'balance' for a Report named BalanceSheet and all other accounts which lie under it,and also for other type of reports.

 

The field 'balance' is not store(because we are doing a dynamic calculation, balance and total fields are not stored anywhere in the database)

 

So, is it possible to get the value of above mentioned field in Graph?

Avatar
Discard
Best Answer

Yes it is possible... you can use it...

Avatar
Discard
Author

I am unable to get the value in the graph, can you explain how it is done?

Author

My file merlin_account_report.py ============================== class merlin_account_financial_report(osv.osv): _name = "merlin.account.financial.report" _description = "Merlin Account Report" def _get_total(self, cr, uid, ids, context=None): for i in ids: #get the id of the current function of the employee of identifier "i" sql_req= """ SELECT f.id AS func_id FROM merlin.account.financial.report c LEFT JOIN res_partner_function f ON (f.id = c.function) WHERE (c.parent_id = %d) """ % (i,) cr.execute(sql_req) sql_res = cr.dictfetchone() if sql_res: #The employee has one associated contract res[i] = sql_res['func_id'] else: #res[i] must be set to False and not to None because of XML:RPC # "cannot marshal None unless allow_none is enabled" res[i] = False return res def _get_level(self, cr, uid, ids, field_name, arg, context=None): '''Returns a dictionary with key=the ID of a record and value = the level of this record in the tree structure.''' res = {} for report in self.browse(cr, uid, ids, context=context): level = 0 if report.parent_id: level = report.parent_id.level + 1 res[report.id] = level return res def _get_children_by_order(self, cr, uid, ids, context=None): '''returns a dictionary with the key= the ID of a record and value = all its children, computed recursively, and sorted by sequence. Ready for the printing''' res = [] for id in ids: res.append(id) ids2 = self.search(cr, uid, [('parent_id', '=', id)], order='sequence ASC', context=context) res += self._get_children_by_order(cr, uid, ids2, context=context) return res def _get_balance(self, cr, uid, ids, field_names, args, context=None): '''returns a dictionary with key=the ID of a record and value=the balance amount computed for this record. If the record is of type : 'accounts' : it's the sum of the linked accounts 'account_type' : it's the sum of leaf accoutns with such an account_type 'account_report' : it's the amount of the related report 'sum' : it's the sum of the children of this record (aka a 'view' record)''' account_obj = self.pool.get('account.account') res = {} for report in self.browse(cr, uid, ids, context=context): if report.id in res: continue res[report.id] = dict((fn, 0.0) for fn in field_names) if report.type == 'accounts': # it's the sum of the linked accounts for a in report.account_ids: for field in field_names: res[report.id][field] += getattr(a, field) elif report.type == 'account_type': # it's the sum the leaf accounts with such an account type report_types = [x.id for x in report.account_type_ids] account_ids = account_obj.search(cr, uid, [('user_type','in', report_types), ('type','!=','view')], context=context) for a in account_obj.browse(cr, uid, account_ids, context=context): for field in field_names: res[report.id][field] += getattr(a, field) elif report.type == 'code': try: dic = {} list1 = re.findall('[a-zA-Z]+' , report.amount_python_compute) myobj = self.pool.get('merlin.account.financial.report') ids3 = myobj.search(cr, uid, [('code','in',list1)]) res2 = self._get_balance(cr, uid, ids3, field_names, False, context=context) for val in res2: dic[myobj.browse(cr,uid,val).code] = res2[val]['balance'] cal_bal = eval(report.amount_python_compute) res[report.id]['balance'] = cal_bal except: raise osv.except_osv(_('Error!'), _('Wrong python condition defined for financial Statement %s (%s).')% (report.name, report.code)) elif report.type == 'account_report' and report.account_report_id: # it's the amount of the linked report res2 = self._get_balance(cr, uid, [report.account_report_id.id], field_names, False, context=context) for key, value in res2.items(): for field in field_names: res[report.id][field] += value[field] elif report.type == 'sum': # it's the sum of the children of this account.report res2 = self._get_balance(cr, uid, [rec.id for rec in report.children_ids], field_names, False, context=context) for key, value in res2.items(): for field in field_names: res[report.id][field] += value[field] return res _columns = { 'name': fields.char('Report Name', size=128, required=True, translate=True), 'parent_id': fields.many2one('merlin.account.financial.report', 'Parent'), 'children_ids': fields.one2many('merlin.account.financial.report', 'parent_id', 'Account Report'), 'sequence': fields.integer('Sequence'), 'balance': fields.function(_get_balance, 'Balance', multi='balance'), 'debit': fields.function(_get_balance, 'Debit', multi='balance'), 'credit': fields.function(_get_balance, 'Credit', multi="balance"), 'cmp_balance' :fields.float('Compare Balance'), 'level': fields.function(_get_level, string='Level', store=True, type='integer'), 'type': fields.selection([ ('sum','View'), ('accounts','Accounts'), ('account_type','Account Type'), ('account_report','Report Value'), ('code','Python Code') ],'Type'), 'account_ids': fields.many2many('account.account', 'account_account_financial_report', 'report_line_id', 'account_id', 'Accounts'), 'account_report_id': fields.many2one('merlin.account.financial.report', 'Report Value'), 'account_type_ids': fields.many2many('account.account.type', 'account_account_financial_report_type', 'report_id', 'account_type_id', 'Account Types'), 'amount_python_compute':fields.text('Python Code'), 'code':fields.char('Code', size=64, required=True ,help="The code of financial statement can be used as reference in computation of other rules. In that case, it is case sensitive."), 'total':fields.boolean('Total'), 'sign': fields.selection([(-1, 'Reverse balance sign'), (1, 'Preserve balance sign')], 'Sign on Reports', required=True, help='For accounts that are typically more debited than credited and that you would like to print as negative amounts in your reports, you should reverse the sign of the balance; e.g.: Expense account. The same applies for accounts that are typically more credited than debited and that you would like to print as positive amounts in your reports; e.g.: Income account.'), } _defaults = { 'type': 'sum', 'sign': 1, } merlin_account_financial_report() # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: ---------------------------------------------------------------------------------------------------------- XML file =========== merlin.account.financial.report.form merlin.account.financial.report merlin.account.financial.report.tree merlin.account.financial.report merlin.account.financial.report.search merlin.account.financial.report Financial Reports ir.actions.act_window merlin.account.financial.report form tree,form merlin.account.financial.report.search merlin.account.financial.report merlin.account.report.hierarchy merlin.account.financial.report children_ids merlin.account.financial.report.graph merlin.account.financial.report graph Financial Reports Hierarchy merlin.account.financial.report tree tree,form,graph [('parent_id','=',False)] ------------------------------------------------------------------------------------ What changes are required to get the graph display the BAR chart representaion of fields 'balance' and 'total' ?

Author

WHOA , I am sorry for above code, I didn't know it just pastes the text like this if I copy from my module, It's the 1st time you know as I'm a Beginner cum Learner of OpenERP as well as this form(Odoo). Can you just explain how can i display the 'balance' and 'total' fields in the Graph?

sure, functional field can be added just like any other field... and also it will be shown in measures.... you can refer Invoice Analysis... in that functional fields are used....

Author

Okay I am going to refer Invoice Analysis, but maybe I've looked it up and in it, function fields are defined with property(parameter) STORE=TRUE, which means it is being stored somewhere in the database. In my case, we don't store 'balance' field, that's why it makes it to display in graph a TOUGH NUT TO CRACK. ANy more suggestions...!

Hmmmm... No idea which report you had check... Do check "account.invoice.report".. "user_currency_price_total" is a functional field which is not saved to db...

Author

above said field is not used in Graph in the said module, so not useful for me though.

Author

thanks for sharing related knowledge with a view to help.