This question has been flagged
1 Reply
11370 Views

I'm aiming to relate meetings to tasks in a m2o relationship.

I created event_ids o2m field in project.tasks, and corresponding task_id m2o in calendar.events. I added a project_id (m2o to account.analytic.account) to the calendar event: I didn't use a related field (task_id.project_id) since I would let the user to choose an analytic account even for Meetings created outside the task.

I added a m2o tree to task form view.

Now, in the Create task form, when I add a new event from the task form I'd like to have the event form pre-populated with data taken from the task, eg.: name, project_id, date_start, date_end, followers_ids.

I added a context to the event_ids, like this example:

<field name="event_ids" context="{'default_name': name, 'default_project_id': project_id, 'default_start_datetime': date_start, 'default_stop_datetime': date_end}" />

When the Meeting creation form opens, all fields get populated but project_id.

How should I proceed? Is there any module I can get inspiration from?

Should I use a button action to create a calendar.event instead of the "add new item" event of treeview?

Avatar
Discard
Author Best Answer

Two things here:

  1. I was mistakenly referring to task_id.project_id while I had to refer to task_id.project_id.account_analytic_id

  2. I thought I had solved by creating some compute, here the example of what i did for the analytic account analytic_account_id = fields.Many2one(comodel_name="account.analytic.account", compute='_compute_analytic_account_id' )

        analytic_account_id = fields.Many2one(comodel_name="account.analytic.account",  
    compute='_compute_analytic_account_id'
    )
        @api.one
    @api.depends('task_id')
    def _get_analytic_account(self):
    if self.task_id.id is not False:
    self.compute_analytic_account_id = self.task_id.project_id.analytic_account_id.id

Actually this doesn't solve, since if the user manually the values (eg. the analytic account), the compute clause overwrite them.

My working solution

For every field I created a related field, eg.

in the model project_task

compute_analytic_account_id = fields.Many2one(related="project_id.analytic_account_id")

in the view:

 <field name="event_ids" context="{
'default_name': name,
'default_start_datetime': date_start,
'default_stop_datetime': date_end,
'default_analytic_account_id': compute_analytic_account_id
}" />

Avatar
Discard