Skip to Content
Menu
This question has been flagged

Hello there,

We are on Odoo 8.

The field 'report_type' of the class account_account_type is a functional field. His type is 'selection'. We want to add an option to this selection.


The original class :

class account_account_type(osv.osv):
_name = "account.account.type"
_description = "Account Type"

_columns = {

        'report_type': fields.function(_get_current_report_type, fnct_inv=_save_report_type, type='selection', string='P&L / BS Category', store=True,
selection= [('none','/'),
('income', _('Profit & Loss (Income account)')),
('expense', _('Profit & Loss (Expense account)')),
('asset', _('Balance Sheet (Asset account)')),
('liability', _('Balance Sheet (Liability account)'))], help="This field is used to generate legal reports: profit and loss, balance sheet.", required=True),
}


Our override code :

class account_account_type(osv.osv):    
    _inherit = "account.account.type"
    
    def __init__(self, cr, uid, name, context=None):
      super(account_account_type, self).__init__(cr, uid, name, context=context)
      option = ('personnal expense', _('Profit & Loss (Personnal expense account)'))
      type_selection = self._columns['report_type'].selection
      if option not in type_selection:
         type_selection.append(option)


We get this error :

TypeError: __init__() takes at least 4 arguments (3 given)


Is this the good way to add an option to the field 'report_type'? How could we fix our error?


Thanks to help




Avatar
Discard
Author Best Answer

Finally, I have completely overridden the field 'report_type' and its methods. It works well.

In my custom module :

class account_account_type(osv.osv):
 
_inherit = "account.account.type"

def _get_financial_report_ref(self, cr, uid, context=None):
obj_data = self.pool.get('ir.model.data')
obj_financial_report = self.pool.get('account.financial.report')
financial_report_ref = {}
for key, financial_report in [
('asset','account_financial_report_assets0'),
('liability','account_financial_report_liability0'),
('income','account_financial_report_income0'),
('expense','account_financial_report_expense0'),
('personnal expense', 'account_financial_report_personal_expense0'),
]:
try:
financial_report_ref[key] = obj_financial_report.browse(cr, uid,
obj_data.get_object_reference(cr, uid, 'account', financial_report)[1],
context=context)
except ValueError:
pass
return financial_report_ref
def _get_current_report_type(self, cr, uid, ids, name, arg, context=None):
res = {}
financial_report_ref = self._get_financial_report_ref(cr, uid, context=context)
for record in self.browse(cr, uid, ids, context=context):
res[record.id] = 'none'
for key, financial_report in financial_report_ref.items():
list_ids = [x.id for x in financial_report.account_type_ids]
if record.id in list_ids:
res[record.id] = key
return res
def _save_report_type(self, cr, uid, account_type_id, field_name, field_value, arg, context=None):
field_value = field_value or 'none'
obj_financial_report = self.pool.get('account.financial.report')
#unlink if it exists somewhere in the financial reports related to BS or PL
financial_report_ref = self._get_financial_report_ref(cr, uid, context=context)
for key, financial_report in financial_report_ref.items():
list_ids = [x.id for x in financial_report.account_type_ids]
if account_type_id in list_ids:
obj_financial_report.write(cr, uid, [financial_report.id], {'account_type_ids': [(3, account_type_id)]})
#write it in the good place
if field_value != 'none':
return obj_financial_report.write(cr, uid, [financial_report_ref[field_value].id], {'account_type_ids': [(4, account_type_id)]})
_columns = {
'report_type': fields.function(_get_current_report_type, fnct_inv=_save_report_type, type='selection', string='P&L / BS Category', store=True,
selection= [('none','/'),
('income', _('Profit & Loss (Income account)')),
('expense', _('Profit & Loss (Expense account)')),
('personnal expense', _('Profit & Loss (Personnal expense account)')),
('asset', _('Balance Sheet (Asset account)')),
('liability', _('Balance Sheet (Liability account)'))], help="This field is used to generate legal reports: profit and loss, balance sheet.", required=True),
}


Avatar
Discard
Related Posts Replies Views Activity
2
Dec 22
6559
0
Mar 15
2504
1
Mar 15
7429
3
Jan 18
4695
1
Dec 23
16413