Community mailing list archives

community@mail.odoo.com

Re: Community

by
Martin Trigaux (mat)
- 04/26/2016 11:15:11
On 26/04/16 16:52, omar frikha wrote:
> I'm create a new python class:

Hello,

I have noticed several issues in your code that may me guess you lacked 
from understanding of some principles. Have you tried to follow the 
tutorial at https://www.odoo.com/documentation/9.0/howtos/backend.html ?


> class product_mod(models.Model):
>     _name="product.product.inherit"
>     _inherit="product.product"

You are using a prototype inheritance, are you sure you don't want to 
use class inheritance? prototype inheritance is used for very specific 
cases like mail.thread or mixins and I am not sure product is the type 
of model you would like to use this way.
https://www.odoo.com/documentation/9.0/howtos/backend.html#model-inheritance


>    produit=fields.Many2one("product.template")

again, if you _inherit from product.product (which inheritS from 
product.template), seems suspicious to add this many2one field

>     @api.depends('produit')

api.depends is used for computed fields, there is no computed field in 
the code you gave us
https://www.odoo.com/documentation/9.0/howtos/backend.html#dependencies

>    def move_line_get(self, cr):

the signature does not match the decorator. if you are going to write in 
new API, you will not need cr. I guess it's a copy/paste, check here how 
you can access the cursor in new API
https://www.odoo.com/documentation/9.0/howtos/backend.html#default-values

>         cr.execute('SELECT * FROM product_product;')

seems a bad idea in case you have hundred thousands of products (which 
is not uncommon). no need for ; in the queries

>         for t in cr.dictfetchall():
>             if (t.product_template_id==self.produit.id):
>                 res.append(id.name)

id.name will definitely not work and I don't get why you want to use 
SQL, you can probably be fine with the ORM, using search()
https://www.odoo.com/documentation/9.0/reference/orm.html#openerp.models.Model.search

Again, I think you lack of understanding some concepts and checking the 
tutorial should already give you some good basis. As we say, don't try 
to put the cart before the horse ;-)

-- 
Martin Trigaux
Odoo
https://odoo.com
https://github.com/mart-e