Zum Inhalt springen
Menü
Sie müssen registriert sein, um mit der Community zu interagieren.
Diese Frage wurde gekennzeichnet
7 Antworten
9320 Ansichten

Any body please explain me about inheriting the computed field form old api to new api.

Avatar
Verwerfen

Can you please tell what exactly you are trying to do? You want to make some changes in that function or you want to use the same function for your custom field?

Autor

Hi Akhil, Thanks for replying, I need the result form the base method and with that result I need to perform more operation and update it.

Beste Antwort

It's not possible to inherit function from Old Api to New Api

If you want change the method called for a compute field. In the first time you should inherit of the model. And in this model you override the function field with your function

Old api

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

....

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
....
_columns = {
'name': fields.char('Account Type', required=True, translate=True),
......
'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),
'note': fields.text('Description'),
}

New api

Class account_account_type(models.Model):
_inherit = "account.account.type"
_description = "Account Type inherited"

....

@api.depends('field1')
def _your_function(self):
Your code here
....


    report_type': fields.Selection(compute='_your_function',string='Report' .... 
Avatar
Verwerfen

Hi John, its possible to inherit a function from old api to new api using the method decorator "@api.v7", but only in the case of compute field function, its not possible I think.

Yes it's right, It's possible to override function. In my example, I only speak for function field . Its my fault, I speak poorly.

Beste Antwort

You may redefine the same field and function in new api style by inheriting the class in your python file.

Avatar
Verwerfen
Beste Antwort

Hello Karthik,

I think this issue could be useful,

https://github.com/odoo/odoo/issues/9699

Avatar
Verwerfen
Verknüpfte Beiträge Antworten Ansichten Aktivität
2
Aug. 25
2893
1
Juli 25
1177
1
Aug. 25
1152
0
Mai 25
1631
2
Apr. 25
3812