Skip to Content
Meniu
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
Această întrebare a fost marcată
1 Răspunde
762 Vizualizări

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


Imagine profil
Abandonează
Cel mai bun răspuns

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

Imagine profil
Abandonează
Autor

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

Related Posts Răspunsuri Vizualizări Activitate
4
mai 25
2666
2
mai 25
6068
1
mar. 25
1782
4
mar. 25
4640
3
feb. 25
5676