Community mailing list archives

Re: Community

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:


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 ?

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

>    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

>    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

>         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 (
>                 res.append( 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()

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