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

[V8] Override old API default function

By
Aurélien Rivet
on 5/24/16, 8:58 AM 337 views

Hi all,

I would like to override an old api default function. Since I can't manage to put my cursor after the code formatting block you will find it at the end of my message. The question is what 'fields' parameter refers to ? How can i get it in new api if I when to call the old api function from the new one ?

 

def _get_default_base(self, cr, uid, fields, context=None):
     product_price_type_obj = self.pool.get('product.price.type')
     if fields.get('type') == 'purchase':
         product_price_type_ids = product_price_type_obj.search(cr, uid, [('field', '=', 'standard_price')], context=context)
      elif fields.get('type') == 'sale':
         product_price_type_ids = product_price_type_obj.search(cr, uid, [('field', '=', 'list_price')], context=context)
    else:
         return -1
     if not product_price_type_ids:
         return False
     else!
         pricetype = product_price_type_ids = product_price_type_obj.browse(cr, uid, product_price_type_ids, context=context)[0]
         return pricetype.id
0

Prakash Sharma

--Prakash Sharma--
815
| 2 1 4
Delhi, India
--Prakash Sharma--

I like to surround myself with brave, creative people.

My motivation for learning different technologies and algos drive me. I love challenges of a steep learning curve which I believe makes me a better learner. I have a strong desire to learn different technologies, which would enable me to become a full stack developer.

Prakash Sharma
On 5/24/16, 9:51 AM

put @api.model  decorator over the method like:

    @api.model
def _get_default_base(self, fields):
response = super(your_model_name, self)._get_default_base(self._cr,self.uid,fields,self._context)
#do your logic over response

return response


That works but I have to associate the function using the old api: _defaults = { base: _get_default_base } If I associate it using the new api (the 'default' kwarg in the field declaration) it does not work. Also, If i don't write the association my function is never called.

Aurélien Rivet
on 5/24/16, 10:05 AM

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: 5/24/16, 8:58 AM
Seen: 337 times
Last updated: 5/24/16, 9:51 AM