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.

1

Buttons to compute values from two fields and show the result in third field.

By
Gopalakrishnan Kasilingam
on 12/29/14, 5:52 AM 522 views

i would like to create a calculator operation on odoo using buttons.. but i like to use third field to show the computed values of two other fields.. whenever i hit the button with operations like Addition,division,multipulication etc.. the third field should show the result of the resulting button operation.

Hi Anil Kesariya, Thanks for your code it helped me a lot for beginning with the button operations

Gopalakrishnan Kasilingam
on 12/29/14, 6:55 AM
4

Anil R. Kesariya

--Anil R. Kesariya--
4321
| 6 5 8
Gandhinagar, India
--Anil R. Kesariya--
ERP Consultant

Key Skill
-
Technical & Functional Expert
Anil R. Kesariya
On 12/29/14, 6:47 AM

@Gopalakrishan,

Here you go!

define realted methods in class which has been called from button as name value.

#your py field code

from openerp import models, fields, api

class your_class(models.Model)

    _name= 'your.model'

    f1 = fields.Integer("Field1")

    f2 = fields.Integer("Field2")

    result = fields.Iteger("Result")

#method defination those will trigger from button.

 @api.multi
    def add(self):

        self.result = self.f1 + self.f2

        return True

@api.multi
    def mul(self):

        self.result = self.f1  *  self.f2

        return True

@api.multi
    def div(self):

        self.result = self.f1 / self.f2

        return True

 

<!-- inside xml file. 

Here in xml field you will define button with type="object" and specific button call the related method from the class which is assigned as name in button.

-->

......

<header>

    <button name="add" string="Addition" type="object"/>

    <button name="mul" string="Multiplication" type="object"/>

    <button name="div" string="Division" type="object"/>

</header>

<field name="f1"/>

<field name="f2"/>

<field name="result"/>

 

.....

Hope this will work for you.

Regards,

Anil.
 

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: 12/29/14, 5:52 AM
Seen: 522 times
Last updated: 3/16/15, 8:10 AM