Get Value from Integer field on button click?

class WorkType( metaclass=PoolMeta):

    __name__ = ''

   treatment_input_qty = fields.Numeric("Input qty",states={

            'invisible': ~Eval('treatment_boolean', True),


    treatment_output_qty = fields.Numeric("Output qty",states={

            'invisible': ~Eval('treatment_boolean', True),


    treatment_loss = fields.Numeric("Loss",states={

            'invisible': ~Eval('treatment_boolean', True),


    treatment_lye_collected = fields.Numeric("Lye collected",states={

            'invisible': ~Eval('treatment_boolean', True),


     def __setup__(cls):
        super(WorkType, cls).__setup__()
            'validate_mb_treatment': {
                        'invisible': ~Eval('treatment_boolean', True),
                        'depends': ['treatment_boolean'],
   def validate_mb_treatment(self, name=None):

i tried the above code but self.treatment_output_qty returns Object instead of int value
apart from these how can i set another field when this button is clicked ?

If your button is a classmethod then self is not an instance but the class. So you should remove the decorator to get an instance button and add @fields.depends('treatment_output_quantity').



    def validate_mb_treatment(self,records):


        # sums = self.treatment_output_qty + self.treatment_loss + self.treatment_lye_collected     

        # print(sums)

Tried these but getting the following error
TypeError: wrapper() missing 1 required positional argument: 'records'

My bad the decorator for a button instance is @ModelView.button_change which replace the @fields.depends and the @ModelView.button.

Thanks a lot it worked for me but i was wondering how can i set another field when the button is clicked ?

Like for on on_change_* you can assign the value of the field to the instance.

i tried this but it didnt worked

     treatment_input_qty_percent= fields.Numeric("Input qty",states={
            'invisible': ~Eval('treatment_boolean', True),
     def on_change_with_treatment_input_qty_percent(self, name=None):
        return 2

    @ModelView.button_change('treatment_output_qty','treatment_input_qty', 'treatment_loss', 'treatment_lye_collected')

    def validate_mb_treatment(self):

        sums = self.treatment_output_qty + self.treatment_loss + self.treatment_lye_collected

        if self.treatment_input_qty == sums:


            raise UserError("Value Matched","All Value Matched")

        else :

            raise UserError("Failed","Value Does not Match")

The value in treatment_input_qty_percent is set when the form is saved

You must remove @fields.depends and add methods to @ModelView.button_change.

You must assign the value otherwise it does nothing. E.g:

self.treatment_input_qty_percent = self.on_change_with_treatment_input_qty_percent()

You can not raise exception on button_change (like you can not on on_change_*).

i tried this but methods is an unexpected argument for button_change

button_change() got an unexpected keyword argument 'methods'

You need a version with Issue 9871: Add methods to ModelView.button_change - Tryton issue tracker