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

Prepopulate many2one field... what an adventure!

By
Mathieu Laflamme
on 1/13/16, 6:01 PM 521 views

I want to populate the product category field of product view when arriving from a view of my module.

Apparently not as streight forward as I thought :( Using default_categ_id in context require a database id and I want to use the XML id! The "ref" function cannot be use inside the context unfortunately...

So my solution is to put a computed field on the origin view which will grab the database id from the XML id so it will be available to pass... I now struggle to make this damn computed fields to work!!

Here is the code of the model

class PickAndPack(models.Model):
_name = "picking"
_inherit = ['complex.charges']
_description = "Picking & Packing item"

def _get_picking_categ_id(self):
return self.env.ref('complex_charges_picking.product_category_picking_fee').id

picking_categ_id = fields.Integer(compute='_compute_picking_categ_id')

@api.one
def _compute_picking_categ_id(self):
        print "test picking_categ_id: ", self._get_picking_categ_id()
self.picking_categ_id = self._get_picking_categ_id()


The view is fairly simple... 

I added the computed field like:

<field name="picking_categ_id"/>

The print "test picking_categ_id: " never trigger...  so picking_categ_id stay at 0.


What do I do wrong... I don't want to store this value in the record, that would be so stupid :(

0
Mathieu Laflamme
On 1/14/16, 12:09 PM

I removed @api.one and not it works!

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: 1/13/16, 6:01 PM
Seen: 521 times
Last updated: 1/14/16, 12:09 PM