Odoo Help


How to determine field definition through a function?

on 4/8/15, 7:43 AM 807 views

I want to let the definition of a field be dependant upon the value of another field. Concretely, I want the definition of the field product.standard_price to be dependant upon the value of the boolean field product.puchase_ok in such a way that standard_price is either equal to the value of another field or is defined in the standard way (as in the product-module). I am thinking that the definition of the standard_price field should be determined as a function operating like this (in pseudo-code): 

"If (purchase_ok): standard_price = standard defintion of the field

Else: standard_price = foo"

where "foo" is another field in the model.

Is my thinking correct and if so, how can such a function be implemented? (I know how to let a field be defined as a function -- I am more in doubt about the actual implementation of the function).

EDIT: The server is running v7.

your server is v7 or v8

on 4/8/15, 7:54 AM



| 6 5 7
Tbilisi, Georgia
On 4/8/15, 7:59 AM

in v8 maybe you'll find useful to override the "_set_standard_price" function of "product.template" model?

for v7 you can try to turn the "standard_price" field into the computed field but make sure you implement both fnct and fnct_inv (also store=True is recommended, it'll preserve old values if any)...

class product_template(osv.osv):
    _name = "product.template"
    _inherit = "product.template"
    def _set_standard_price(self, cr, uid, ids, field_name, field_value, arg, context):
        # set value of standard_price field
    def _get_standard_price(self, cr, uid, ids, field_name, arg, context):
        # get value of standard_price field
    _columns = {
        'standard_price': fields.function(
            fnct_inv = _set_standard_price,
            method = True,
            store = True, type = 'float',
            digits_compute = dp.get_precision('Product Price'),
            help = "same....", string = 'Cost',
            groups = "base.group_user"),

Thank you for your reply, but I am in doubt as to how to implement the function more concretely.

on 4/8/15, 8:20 AM


on 4/8/15, 8:28 AM

also don't forget to add "product" module to dependency list in __openerp__.py manifest

on 4/8/15, 8:36 AM
On 4/8/15, 7:58 AM

Sorry, server is v7.

About This Community

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


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

1 follower(s)


Asked: 4/8/15, 7:43 AM
Seen: 807 times
Last updated: 4/8/15, 8:42 AM