Fields condition


I am looking to retrieve the value of a Many2One field In order to put a constraint on another field.

class MaxPrice(ModelSQL, ModelView):
    __name__ = 'object.max.price'

    name = fields.Char('Nom')
    max_price = fields.Integer('Max')

class Object(ModelSQL, ModelView):
    __name__ = 'object.object'

    max = fields.Many2One('object.max.price', 'Maximum')

    min_price = fields.Integer('Prix min')

    max_price = fields.Integer('Prix max',
                """ I would like 'max.max_price' instead of 'max' """
                ('max_price', '<=', Eval('max')),()

“max” returns me the id of the selected data but I would like to have the value “max.max_price”
I can’t find how to do it.

can you help me ?

AFAIK you will need to create a functional field in the class ‘object.object’ which return the value of the max_price field of the ‘object.max.price’ class to be able to use it in the domain

I don’t know how to do what you suggest, or I didn’t understand.
Can you give me an example?

You must define a Function field like:

max_max_price = fields.Function(fields.Integer("Max"), 'on_change_with_max_max_price')

def on_change_with_max_max_price(self, name=None):
    if self.max:
        return self.max.max_price

Than you could use Eval('max_max_price') in the domain.

Thank you but I already tried and it’s not what I want.

I would like to test the “max_price” field in the same form where I fill in the “max” value.
The method you suggested requires us to save the entry before doing the verification.
Isn’t there a method to retrieve the “max.max_price” value dynamically?

This is what is done thanks to the on_change_with.

No it does not. But of course you need more code to manage the case of the user changing the Many2One which could make the value invalid etc.

Yes like in my example.

Sorry, I didn’t look at function name.
Thanks for helping

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.