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.

4

How to inherit computed field from old Api to New Api ?

By
Karthik Arumugam
on 10/9/15, 3:43 AM 1,467 views

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

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?

Akhil P Sivan
on 10/9/15, 4:10 AM

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.

Karthik Arumugam
on 10/9/15, 5:52 AM
2
John Touba
On 10/9/15, 4:38 AM

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' .... 

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.

Akhil P Sivan
on 10/9/15, 4:51 AM

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.

John Touba
on 10/9/15, 4:59 AM
2

Akhil P Sivan

--Akhil P Sivan--
3423
| 5 3 6
Kochi, India
--Akhil P Sivan--

Interested in exploring Odoo both technically & functionality wise.

email-id : akhilpsivan01@gmail.com

Akhil P Sivan
On 10/9/15, 3:58 AM

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

0
Julio Serna
On 1/6/16, 12:00 PM

Hello Karthik,

I think this issue could be useful,

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

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

2 follower(s)

Stats

Asked: 10/9/15, 3:43 AM
Seen: 1467 times
Last updated: 1/9/16, 6:54 AM