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

One2many relation empty!

By
José
on 12/17/14, 5:24 PM 618 views

Hello, I am developing a module in Odoo 8 and I have a very strange problem. I added a One2many field in product.pricelist.version model, and in account.voucher model I have the corresponding Many2one field.

class product_pricelist_version(models.Model):
    _inherit = 'product.pricelist.version'

    pays= fields.One2many('account.voucher', 'pricelist_version_id')

Then, I override the create method of product.pricelist.item model.

    def create(self, cr, uid, vals, context=None):

        id_pricelist = super(product_pricelist_item, self).create(cr, uid, vals, context)

        pricelist_item_obj = self.browse(cr, uid, id_pricelist, context)

        pricelist_version_obj = pricelist_item_obj.price_version_id

When I create a pricelist.version with one or more "pays", I do some logic. If I check the lenght with "len(pricelist_version_obj.pays)" I get 0! Why?! If I do "len(pricelist_item_obj.items_id)" I get the correct number of items...

1

Ivan

--Ivan--
3210
| 5 3 6
Jakarta, Indonesia
--Ivan--
Ivan
On 12/17/14, 5:46 PM

First, does account.voucher has pricelist_version_id?  If it is there, are there any account.voucher that has the that particular pricelist.version?

0
José
On 12/17/14, 6:14 PM

Yes and yes. I think that the problem is because Odoo first creates the product.pricelist.item and then the product.pricelist.version. So, when I access to product.pricelist.version.pay in create method of product.pricelist.item the object are still empty... Is it possible?
 

It is possible. However as long as the items are eventually connected to the version, it would calculate OK. Even in the create method like you have done (which is calling it after the super call). Check what is the value of pricelist_version_obj, is it referring to the correct product.pricelist.version (I would imagine so, because if it is empty, the len(pricelist_version_obj.pays) code would raise an exception).

Ivan
on 12/17/14, 8:44 PM

I think that Odoo calculates correctly the items lenght because the items are created yet, after the create method of product.pricelist.item. The pricelist is the correct, I check it with his attribute product.pricelist.name. I solved the problem doing the logic in the create method of product.pricelist.version, where the lenght of the "pays" attribute is the correct.

José
on 12/18/14, 6:35 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: 12/17/14, 5:24 PM
Seen: 618 times
Last updated: 3/16/15, 8:10 AM