Skip to Content
Menu
This question has been flagged
1 Reply
3531 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



Avatar
Discard
Author Best Answer

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

Avatar
Discard
Related Posts Replies Views Activity
2
Jun 23
970
1
Jun 20
33180
1
Nov 17
2126
2
Aug 15
4221
1
Aug 23
1961