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

calculated field in form

By
TS
on 11/7/16, 3:26 PM 209 views

hello,


trivial question came to me, but - shame on me - I was not able to provide simple answer; considering I have two fields in form:


<group col="2">

<field name="x_po"/><newline/>

<field name="x_sz"/><newline/>

</group>


is there a simple way to add third field, which will show sum of above? something like "x_po+x_sz"?


regards

Tomasz



4

Hilar AK

--Hilar AK--
778
| 4 1 7
Italy
--Hilar AK--


Hilar AK
On 11/7/16, 11:52 PM

Make the third field as compute field

in your script just compute the total of two fields and return the value

if you need to display the total sum you just need to give sum="thirdfield" in your tree view

 @api.one
 def _get_total(self):
try:
         self.thirdfield = self.first + self.second

 thirdfield = fields.Float(compute='_get_total', string="")

don't forget to close try

Have an upvote

shameem@aχoncoms
on 11/8/16, 12:01 AM
2
Ameera PP
On 11/8/16, 12:01 AM

create a new field x_po_plus_x_sz



@api.onchange('x_po','x_sz')   

def getsum_x_po_x_sz(self):
        if self.x_po and self.x_sz:
            self.x_po_plus_x_sz=self.x_po + self.x_sz

0
TS
On 11/8/16, 10:52 AM

hello,

thank you for answers; I had hope it is to be done inside form view - but I guess code as above is to be added somewhere else, am I right? if yes - sorry for asking - where to insert code as above:

---

@api.one

def _get_total(self):

try:

self.thirdfield = self.first + self.second

thirdfield = fields.Float(compute='_get_total', string="")

---

regards

Tomasz

In your model, ie where you defined those fields or by inheriting the parent model,use the function

Hilar AK
on 11/9/16, 1:45 AM
0

Axel Mendoza

--Axel Mendoza--
10203
| 7 7 8
Camaguey, Cuba
--Axel Mendoza--

DevOps - Full stack - Software Architect - Developer - Technology Integrator

I could help you to develop anything and solve complex problems based on technologies, integrations and tricky stuffs mostly in Python with OpenERP/Odoo, Zato, Django and many others frameworks programming languages and technologies.

I offers consulting services to anyone with an unanswered questions or needs for customizations. Think about it, maybe it's better to have an expert to solve your issues and projects than having a full time employee trying to understand what to do an how

Reach me at aekroft@gmail.com

Axel Mendoza
On 11/8/16, 1:23 AM

Hi Tomasz

You need to add a calculated field that compute the calculation and if you wanna make it more dynamically you could add also an onchange for the source field for the sum to provide the result without the need of saving the form

Read more about it in the docs

https://www.odoo.com/documentation/10.0/reference/orm.html#fields

0
Faycel Gsouma
On 11/8/16, 5:57 AM

You need to make a compute field for the third one with an onchange annotationthirdfield = fields.Float(compute='_compute_sum', string="SUM")

@api.onchange('x_po','x_sz')

def _compute_sum(self): 

        self.thirdfield = self.x_po + self.x_sz

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: 11/7/16, 3:26 PM
Seen: 209 times
Last updated: 11/10/16, 6:20 AM