Přejít na obsah
Menu
You need to be registered to interact with the community.
This question has been flagged
1 Odpovědět
775 Zobrazení

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
Zrušit
Nejlepší odpověď

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
Zrušit
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 Odpovědi Zobrazení Aktivita
4
kvě 25
2689
2
kvě 25
6119
1
bře 25
1802
4
bře 25
4682
3
úno 25
5762