Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
1 Trả lời
1683 Lượt xem

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:



Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

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

Ảnh đại diện
Huỷ bỏ
Tác giả

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

Bài viết liên quan Trả lời Lượt xem Hoạt động
0
thg 9 23
1308
2
thg 8 22
5337
1
thg 7 25
1350
2
thg 3 25
1616
0
thg 2 25
1249