[Python] Custom date filter in Odoo Dashboard module

Discussão em 'Python' iniciado por Stack, Fevereiro 24, 2025.

  1. Stack

    Stack Membro Participativo

    Premise: I am a programmer, but not with Python. I worked only two times with Odoo.

    A client of mine uses Odoo (a choice I didn't recommend, because I don't understand it :) ), and asked me to try adding a custom filter in the Odoo dashboard (I think 17), I have access to Odoo.sh, JupyterLab and a test environment.

    From what I understand, by default The Board / Dashboard /Spreadsheets (I don't know the differences) offers the possibility to filter only by time periods like: 'last 30 days', by month, by year, etc.

    Actually, it's not a complete thing. In fact, I was asked to be able to add a filter by dates like, start date to end date period. I tried to do some research on the web and with AI, but I couldn't. If someone could help me, I would be grateful.

    I tried this:

    /src/odoo/addons/board/
    Edited: /models/board.py

    Added:
    line 12: date_start = fields.Date(string="Start Date")
    line 13: date_end = fields.Date(string="End Date")

    line 25: @api.model
    line 26: def get_dashboard_data(self, domain=None):
    line 27: if self.date_start and self.date_end:
    line 28: domain = domain or []
    line 29: domain.extend([('date', '>=', self.date_start), ('date', '<=', self.date_end)])
    line 30: return super(BoardBoard, self).get_dashboard_data(domain)


    Edited: /views/board_view.xml

    Added:
    line 10: <group>
    line 11: <field name="date_start"/>
    line 12: <field name="date_end"/>
    line 13: </group>


    [​IMG]

    Continue reading...

Compartilhe esta Página