Overslaan naar inhoud
Menu
Je moet geregistreerd zijn om te kunnen communiceren met de community.
Deze vraag is gerapporteerd
2 Antwoorden
400 Weergaven

Hello everyone,

I'm trying to get the "Last Update Status" variable in the Project to update automatically depending on the current date. I was thinking of doing this using a scheduled action. I've attached some screenshots.

I would like the bubble to change automatically where you can put if thebproject is to define, on risk, on track...

Here is the scheduled action I'm working on: 

fecha = datetime.date.today()


for proyecto in model.search([]):

    fecha = proyecto.x_studio_fecha_de_finalizacin

    if not fecha:

        estado = 'to_define'

    else:

        dias = (fecha - today).days

        if dias < 0:

            estado = 'off_track'

        elif dias <= 2:

            estado = 'at_risk'

        else:

            estado = 'on_track'

    proyecto.write({'x_studio_estado_personalizado': estado})


I appreciate your help — I've always programmed in Python, but I don't fully understand how to do it in Odoo.

Best regards,

Marcos

---------------------------------------------------------------------------------------------------


Buenas a todos, estoy intentando conseguir que se emmactualice la variable Last Update Satus de Proyecto dependiendo de la fecha en la que nos encontremos, he pensado en hacerlo con una acción planificada, os adjunto fotos:
Me gustaría cambiar la burbuja automáticamente

Aquí está la acción planificada que estoy elaborando:
fecha = datetime.date.today()


for proyecto in model.search([]):

    fecha = proyecto.x_studio_fecha_de_finalizacin

    if not fecha:

        estado = 'to_define'

    else:

        dias = (fecha - today).days

        if dias < 0:

            estado = 'off_track'

        elif dias <= 2:

            estado = 'at_risk'

        else:

            estado = 'on_track'

    proyecto.write({'x_studio_estado_personalizado': estado})



Agradezco vuestra ayuda, siempre he programado python pero no entiendo bien cómo hacerlo en odoo.

Un saludo,
Marcos

Avatar
Annuleer
Auteur Beste antwoord

I am in Odoo SaaS, I can´t to use import or other things becacuse an error appear on the screen:

forbidden opcode(s) in "from datetime import date as dt_date\r\n\r\ntoday = dt_date.today()\r\nfecha = datetime.date.today()\r\n\r\nfor proyecto in model.search([]):\r\n fecha = proyecto.x_studio_fecha_de_finalizacin\r\n if not fecha:\r\n estado = 'to_define'\r\n else:\r\n dias = (fecha - today).days\r\n if dias < 0:\r\n estado = 'off_track'\r\n elif dias <= 2:\r\n estado = 'at_risk'\r\n else:\r\n estado = 'on_track'\r\n proyecto.write({'x_studio_estado_personalizado': estado})": IMPORT_NAME, IMPORT_FROM


I don´t know what to do, if someone can help me, I appreciate this too much

Avatar
Annuleer
Beste antwoord

Hi,


To make your scheduled action update the custom status bubble based on the x_studio_completion_date, you just need to:


          -Fix variable naming (fecha is undefined, probably meant date)

          -Ensure correct logic for empty dates

          -Correct status vs state usage

          -Proper imports (datetime)

Try with the following code,


from datetime import date as dt_date


today = dt_date.today()


for project in model.search([]):

    completion_date = project.x_studio_completion_date


    if not completion_date:

        status = 'to_define'

    else:

        days = (completion_date - today).days


        if days < 0:

            status = 'off_track'

        elif days <= 2:

            status = 'at_risk'

        else:

            status = 'on_track'


    project.write({'x_studio_custom_status': status})



Hope it helps

Avatar
Annuleer