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

How to determine field definition through a function?

By
philjun
on 4/8/15, 7:43 AM 446 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

Temur
on 4/8/15, 7:54 AM
0

Temur

--Temur--
2896
| 6 5 7
Tbilisi, Georgia
--Temur--
Programmer
Temur
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(
            _get_standard_price,
            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.

philjun
on 4/8/15, 8:20 AM

https://doc.odoo.com/6.0/developer/2_5_Objects_Fields_Methods/field_type/#functional-fields

Temur
on 4/8/15, 8:28 AM

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

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

Sorry, server is v7.

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: 4/8/15, 7:43 AM
Seen: 446 times
Last updated: 4/8/15, 8:42 AM