Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
1 Trả lời
114 Lượt xem

Hello!

I'm taking over this already started project which has v18, I'm pretty new to Odoo and would love some help figuring out how to do what I have in mind:

We have a modified on field module which creates on site projects linked to a sales (one sale one project). It has the client, dates, etc, and then a tab component with a couple useful things like timesheets and notes. Among those tabs, we have one to file a report that the client can sign and where you can put details on what you've done and seen on site, and add pictures.

The issue is: we need to be able to file several reports, one for each day, for cases when the project lasts more than one day.

Right now, when you click on the tab, it directly shows a form which you can file and edit.

I thought of adding a button on top to create a new report if needed:

  • if there's only one, keep the current display
  • if there are multiples, display them in a list which you can toggle (date, who went, is the report signed or not) to avoid having a very long page

Another point is that we need to be able to print those individually, so having the option to choose which ones to print is needed.

Is this something I can do? If yes, how can I go about it?

I've read documentation about the in field module and have a good general understanding of the tool, and a web dev background.

Thanks a lot!

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

Hi,


In Odoo 18, your current setup allows only a single on-site report per project, which makes it hard to handle projects lasting multiple days. The clean solution is to create a dedicated Daily Report model and link it to your project with a one-to-many relation. This lets you add as many daily reports as needed, display them in a list if there are several, and still print each report individually.


The first step is to define a new model for daily reports. This model will store the project reference, date, technician, signed status, notes, and any attached photos:


class OnFieldReport(models.Model):

    _name = 'onfield.report'

    _description = 'On Field Daily Report'


    project_id = fields.Many2one('onfield.project', string="Project", required=True, ondelete='cascade')

    date = fields.Date(default=fields.Date.context_today, required=True)

    user_id = fields.Many2one('res.users', string="Technician", default=lambda self: self.env.user)

    signed = fields.Boolean("Signed by Client")

    notes = fields.Text("Report Notes")

    image_ids = fields.Many2many('ir.attachment', string="Photos")


Next, you extend your existing project model with a one-to-many field pointing to the reports:


class OnFieldProject(models.Model):

    _inherit = 'onfield.project'


    report_ids = fields.One2many('onfield.report', 'project_id', string="Daily Reports")



On the project form view, you add a new tab that displays the reports in both list and form view. This allows users to create new reports, quickly see existing ones, and open them individually:


<page string="Daily Reports">

    <field name="report_ids" context="{'default_project_id': active_id}">

        <tree editable="bottom">

            <field name="date"/>

            <field name="user_id"/>

            <field name="signed"/>

        </tree>

        <form>

            <sheet>

                <group>

                    <field name="date"/>

                    <field name="user_id"/>

                    <field name="signed"/>

                </group>

                <group>

                    <field name="notes"/>

                    <field name="image_ids" widget="many2many_binary"/>

                </group>

            </sheet>

        </form>

    </field>

</page>


Finally, you add a QWeb report definition so each daily report can be printed individually:


<report

    id="action_report_onfield_report"

    model="onfield.report"

    string="Daily Report"

    report_type="qweb-pdf"

    name="your_module.onfield_report_template"

    file="your_module.onfield_report_template"

/>



By moving the daily report into its own model and linking it to projects with a one-to-many relation, you can easily support multiple reports per project, keep the project form neat, and allow reports to be printed individually. This design scales well, stays user-friendly, and aligns with Odoo’s best practices for modularity and extensibility.


Hope it helps

Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
3
thg 5 25
943
2
thg 9 25
409
3
thg 8 25
1285
3
thg 7 25
793
2
thg 7 25
1267