Skip to Content
Menu
This question has been flagged
1 Reply
1680 Views

Hi,

I'm trying to create a simple field that totals the Labour Cost and Material Cost fields shown on this screenshot. All fields are 'float', but no matter what I do, I keep getting error messages.

All Field names are shown within the XML view on the left.

In the example given, I would like the Total Cost field to show '7' (2+5), but without needing to manually input the number.

In an ideal world, I would also like these fields displayed as a monetary value.

Any ideas:



Avatar
Discard
Best Answer

Hi, 


you could create a field in your model and create a compute method to do this, but you need it in python:



class MyModel(models.Model):
    _name = 'my.model'

    field1 = fields.Float(string='Field 1')
    field2 = fields.Float(string='Field 2')
    computed_field = fields.Float(string='Computed Field', compute='_compute_computed_field')

    @api.depends('field1', 'field2')
    def _compute_computed_field(self):
        for record in self:
            record.computed_field = record.field1 + record.field2


I hope these code help to you

Bye

Avatar
Discard
Author

Hi, I don't have access to the Python code, as our server is hosted externally
Is there any way I can do this via Studio/XML?

As far as I know you can't make a compute field via XML. I don't know if it is possible via Studio. Sorry

Related Posts Replies Views Activity
0
Sep 23
1308
2
Aug 22
5337
1
Jul 25
1350
2
Mar 25
1616
0
Feb 25
1249