İçereği Atla
Menü
Bu soru işaretlendi
1 Cevapla
743 Görünümler

Hello,

In Odoo 17 Studio

I like to do a calculation for the base field. But I am unable to write a computation code on the base field.

I have written a code in UI change the automation rule but that is also not working Can i get assistance for that?



Fields and name of the field:

x_studio_selection_field_5ir_1hhu4okhd = Rental Based (Selection field "Hourly","Daily","Weekly","Monthly")

x_studio_related_field_4io_1hhu53ucr=working Hours(integer Field)

price_unit= Unit Price(Base Field)

x_studio_duration= Duration in days (Integer Field)

price_subtotal = Total excluding tax(Base Field)



I have used the below code for calculation 

result=False

for record in self:

    if record.x_studio_selection_field_5ir_1hhu4okhd == "Hourly":

        result=record.x_studio_related_field_4io_1hhu53ucr*record.price_unit

    elif record.x_studio_selection_field_5ir_1hhu4okhd == "Daily":

        result=record.x_studio_duration*record.price_unit

    elif record.x_studio_selection_field_5ir_1hhu4okhd == "Weekly":

        result=(record.x_studio_duration/7)*record.price_unit

    else:

        result=(record.x_studio_duration/30)*record.price_unit

record['price_subtotal']=result


Avatar
Vazgeç
En İyi Yanıt

Hi,

1. Changed records to record in the loop.
2. The initialized result to 0 before the loop.
result = 0

for record in self:

    if record.x_studio_selection_field_5ir_1hhu4okhd == "Hourly":
        result = record.x_studio_related_field_4io_1hhu53ucr * record.price_unit

    elif record.x_studio_selection_field_5ir_1hhu4okhd == "Daily":
        result = record.x_studio_duration * record.price_unit

    elif record.x_studio_selection_field_5ir_1hhu4okhd == "Weekly":
        result = (record.x_studio_duration / 7) * record.price_unit

    else:
        result = (record.x_studio_duration / 30) * record.price_unit

    record['price_subtotal'] = result


Hope it helps

Avatar
Vazgeç
Üretici

Here, the problem is not with the coding but with the UI change option in automation rule. I have tried the code on Save option in Automation; it is working fine, but when I select the UI change, it is not working and does not pop up any errors

İlgili Gönderiler Cevaplar Görünümler Aktivite
4
May 25
2642
2
May 25
6057
1
Mar 25
1760
4
Mar 25
4630
3
Şub 25
5654