Hello wold. Today i got inspiration from my comment's. He just started develop Odoo. You know, actually i am so appreciate that, maybe we feel difficult to learn something new, and we don't have person to help us, just world wide web. I know, because for first time I learn Odoo, i feel so disappointed for myself, I just think 'i can't do it'. But i keep learn Odoo, cause i am still work with company use Odoo aha. But huyaa for time by time i can learn the process Odoo, new syntax from python, qweb, or maybe js, css, etc cause my background its not from website. And you know, now i am realise that how's can develop Odoo is easy, i am so realise that. Just little bit share my misery. Lol
So just go ahead right? today i am gonna share about how to inherit function Odoo, for example in this post i will inherit function create. Just for note, function create is automatically create when we develop view form or tree. Aha you know function create in base Odoo, it always have the name 'create'. And usually have one parameter is self or two parameter is self, vals (variable that we have). For example in Odoo base, we have create like this.
As you can see create have two variable, self and vals. And now i want to inherit that. see my code.
@api.model def create(self, vals): . . . . return A
As you can see create have two variable, self and vals. And now i want to inherit that. see my code.
class AddFieldProduct (models.Model): _inherit = "product.template" info = fields.Char('Info') @api.model def create(self, vals): if self.info : self.info = 'is a field info' return super(AddFieldProduct, self).create(vals)
as you can see, the requirement is :
1. We need to create file something like me, i create file inherit_function.py and then we need to create class like 'class inherit_function (models.Model)' and type class 'model'.
2. Declaration class with _inherit = "product.template", it mean we want to inherit model product.product.
3. Write name and parameter, similar with function, see def create(self, vals) and add @api.model above the function.
4. Add what you what you want need. Like this one i just want to set field info is 'is a field info'. if self.info : self.info = 0
5. And last add return with super like this one, return super(inherit_function, self).create(vals). inherit_function is a my class, see on the top.
7. When we inherit create like that, we put there condition on the function, field info will save 'is a field info' in database. trust me.
6. That's it, easy right?
So the conclusion is Semangat!! like my boss always say to me, when i got problem with my code. Lol
keep it up dude, i have also written same article on my blog just check it please: Override Odoo Functions
ReplyDeleteThanks for sharing the great information Odoo CRM | Odoo eCommerce
ReplyDeleteNice blog! This is useful for those who is looking for the Odoo Software Dubai. Keep Sharing such information blog.
ReplyDelete