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

I have the following fields for my product:

NAME(char); MASS(int); PRICE(float); VALUE(float)

What I would like to do is to automatically calculate the total value of the product by multiplying the MASS with the PRICE ((MASS*PRICE)/100) in the VLAUE field. How and where do I place this function?

Thanks

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

@Dzingai what you need is to change the value field into a function field.  In new API (v8) you need to put the compute attribute in the field definition.  In both you need to develop a method in the said model to be used by the function.

You can find sample in the account.invoice modules which have quite a lot of function fields.

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

Thanks Salama. That is very helpful.

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

Try this  function just replace the attribut by the yours

this function should be in the class concerned


@api.depends('required_hours','completed_hours')

def presence_avarage_count(self):

for r in self:

r.presence_avarage = completed_hours / required_hours

Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
1
thg 7 25
369
0
thg 7 25
406
1
thg 5 25
898
0
thg 3 25
1034
0
thg 3 25
969