Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

How to override the get_lines method of the report_account_common class?

By
Pascal Tremblay
on 6/4/16, 4:40 PM 348 views

Hello there,

I'm trying to override the get_lines method of the report_account_common class.

It is really not easy to override this method.

What is the trick?


For the moment, I have this code in my custom module. I get no error, but override do nothing.

from openerp.addons.account.report.account_financial_report import report_account_common

class report_account_common_pt(report_account_common):

def __init__(self, cr, uid, name, context):

super(report_account_common_pt, self).__init__(cr, uid, name, context=context)

self.localcontext.update({

'report': 'report_account_common_pt',

})

def get_lines(self, data):

lines = []

account_obj = self.pool.get('account.account')

currency_obj = self.pool.get('res.currency')

ids2 = self.pool.get('account.financial.report')._get_children_by_order(self.cr, self.uid, [data['form']['account_report_id'][0]], context=data['form']['used_context'])

for report in self.pool.get('account.financial.report').browse(self.cr, self.uid, ids2, context=data['form']['used_context']):

vals = {

'name': report.name,

'balance': report.balance * report.sign or 0.0,

'type': 'report',

'level': bool(report.style_overwrite) and report.style_overwrite or report.level,

'account_type': report.type =='sum' and 'view' or False, #used to underline the financial report balances

}

if data['form']['debit_credit']:

vals['debit'] = report.debit

vals['credit'] = report.credit

if data['form']['enable_filter']:

vals['balance_cmp'] = self.pool.get('account.financial.report').browse(self.cr, self.uid, report.id, context=data['form']['comparison_context']).balance * report.sign or 0.0

lines.append(vals)

account_ids = []

if report.display_detail == 'no_detail':

#the rest of the loop is used to display the details of the financial report, so it's not needed here.

continue

if report.type == 'accounts' and report.account_ids:

account_ids = account_obj._get_children_and_consol(self.cr, self.uid, [x.id for x in report.account_ids])

elif report.type == 'account_type' and report.account_type_ids:

account_ids = account_obj.search(self.cr, self.uid, [('user_type','in', [x.id for x in report.account_type_ids])], order='code')

if account_ids:

for account in account_obj.browse(self.cr, self.uid, account_ids, context=data['form']['used_context']):

#if there are accounts to display, we add them to the lines with a level equals to their level in

#the COA + 1 (to avoid having them with a too low level that would conflicts with the level of data

#financial reports for Assets, liabilities...)

if report.display_detail == 'detail_flat' and account.type == 'view':

continue

flag = False

vals = {

'name': account.code + ' ' + account.name,

'balance': account.balance != 0 and account.balance * report.sign or account.balance,

'type': 'account',

'level': report.display_detail == 'detail_with_hierarchy' and min(account.level + 1,6) or 6, #account.level + 1

'account_type': account.type,

}

if data['form']['debit_credit']:

vals['debit'] = account.debit

vals['credit'] = account.credit

if not currency_obj.is_zero(self.cr, self.uid, account.company_id.currency_id, vals['balance']):

flag = True

if data['form']['enable_filter']:

vals['balance_cmp'] = account_obj.browse(self.cr, self.uid, account.id, context=data['form']['comparison_context']).balance * report.sign or 0.0

if not currency_obj.is_zero(self.cr, self.uid, account.company_id.currency_id, vals['balance_cmp']):

flag = True

if flag:

lines.append(vals)

return lines

class report_financial_pt(osv.AbstractModel):

_name = 'report.report_lapagept.report_financial_pt'

_inherit = 'report.abstract_report'

_template = 'account.report_financial'

_wrapped_report_class = report_account_common_pt



0

Pascal Tremblay

--Pascal Tremblay--
1312
| 5 2 7
Alma, Canada
--Pascal Tremblay--


Pascal Tremblay
On 6/4/16, 4:50 PM

Oh yeah! I got it!


from openerp.addons.account.report.account_financial_report import report_account_common

class report_account_common_pt(report_account_common):

def __init__(self, cr, uid, name, context):

super(report_account_common_pt, self).__init__(cr, uid, name, context=context)

self.localcontext.update({

'report': 'report_account_common_pt',

})

def get_lines(self, data):

lines = []

account_obj = self.pool.get('account.account')

currency_obj = self.pool.get('res.currency')

ids2 = self.pool.get('account.financial.report')._get_children_by_order(self.cr, self.uid, [data['form']['account_report_id'][0]], context=data['form']['used_context'])

for report in self.pool.get('account.financial.report').browse(self.cr, self.uid, ids2, context=data['form']['used_context']):

vals = {

'name': report.name,

'balance': report.balance * report.sign or 0.0,

'type': 'report',

'level': bool(report.style_overwrite) and report.style_overwrite or report.level,

'account_type': report.type =='sum' and 'view' or False, #used to underline the financial report balances

}

if data['form']['debit_credit']:

vals['debit'] = report.debit

vals['credit'] = report.credit

if data['form']['enable_filter']:

vals['balance_cmp'] = self.pool.get('account.financial.report').browse(self.cr, self.uid, report.id, context=data['form']['comparison_context']).balance * report.sign or 0.0

lines.append(vals)

account_ids = []

if report.display_detail == 'no_detail':

#the rest of the loop is used to display the details of the financial report, so it's not needed here.

continue

if report.type == 'accounts' and report.account_ids:

account_ids = account_obj._get_children_and_consol(self.cr, self.uid, [x.id for x in report.account_ids])

elif report.type == 'account_type' and report.account_type_ids:

account_ids = account_obj.search(self.cr, self.uid, [('user_type','in', [x.id for x in report.account_type_ids])], order='code')

if account_ids:

for account in account_obj.browse(self.cr, self.uid, account_ids, context=data['form']['used_context']):

#if there are accounts to display, we add them to the lines with a level equals to their level in

#the COA + 1 (to avoid having them with a too low level that would conflicts with the level of data

#financial reports for Assets, liabilities...)

if report.display_detail == 'detail_flat' and account.type == 'view':

continue

flag = False

vals = {

'name': account.code + ' ' + account.name,

'balance': account.balance != 0 and account.balance * report.sign or account.balance,

'type': 'account',

'level': report.display_detail == 'detail_with_hierarchy' and min(account.level + 1,6) or 6, #account.level + 1

'account_type': account.type,

}

if data['form']['debit_credit']:

vals['debit'] = account.debit

vals['credit'] = account.credit

if not currency_obj.is_zero(self.cr, self.uid, account.company_id.currency_id, vals['balance']):

flag = True

if data['form']['enable_filter']:

vals['balance_cmp'] = account_obj.browse(self.cr, self.uid, account.id, context=data['form']['comparison_context']).balance * report.sign or 0.0

if not currency_obj.is_zero(self.cr, self.uid, account.company_id.currency_id, vals['balance_cmp']):

flag = True

if flag:

lines.append(vals)

return lines

class report_financial_pt(osv.AbstractModel):

_name = 'report.account.report_financial'

_inherit = 'report.abstract_report'

_template = 'account.report_financial'

_wrapped_report_class = report_account_common_pt

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 6/4/16, 4:40 PM
Seen: 348 times
Last updated: 6/6/16, 4:55 AM