Skip to Content
Menu
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
To pytanie dostało ostrzeżenie
2 Odpowiedzi
3615 Widoki

I an needing a more complete version of project templates, I have had a look at the OCA module and they are only copying the tasks, I have tried using the below code:

def action_create_project_from_template(self):
template_id = self.signage_project_template_id
default ={}
default['name'] = self.name
#default['partner_id'] = self.partner_id
super(Project, template_id).copy(default)
return {
'view_mode': 'form',
'res_model': 'project.project',
'res_id': self.id,
'type': 'ir.actions.act_window',
'context': self._context
}

project.project.project.view.form.simplified.inherit
project.project


















Which I am calling from "project.project.view.form.simplified" which partly works, I do get the duplicate copy but because that form already created a project I end up with two projects.

Odoo self hosted v16

Is there a simple option to prevent the default action or a better approach altogether?

Edit:

project.project.view.form.simplified  is still calling the standard new project at the same time I am calling copy.

For clarity the main goal here is to be able to duplicate a project template whilst adding customer and name, all from the Kanban view.


Awatar
Odrzuć
Autor Najlepsza odpowiedź

Edit: to add detail to original question


Awatar
Odrzuć
Najlepsza odpowiedź

you can override the "copy" method of the project.project model and modify its behavior. Here's an example:
from odoo import models, fields, api

class Project(models.Model):
_inherit = 'project.project'

def copy(self, default=None):
if default is None:
default = {}
default.update({
'name': self.name,
# Add any other fields you want to copy from the template
})
return super().copy(default)

In the code above, we override the "copy" method of the project.project model and provide our custom implementation. We update the "default" dictionary with the desired field values from the template project. This will ensure that when the copy operation is performed, the new project will have the desired field values.

Make sure to restart the Odoo server after adding this code. Once implemented, you can remove the super(Project, template_id).copy(default) line from your "action_create_project_from_template" method.

Note: This approach assumes that the "signage_project_template_id" field on your model contains the ID of the template project you want to duplicate. Adjust the code accordingly if your implementation differs.

Awatar
Odrzuć
Powiązane posty Odpowiedzi Widoki Czynność
0
mar 23
1547
6
gru 24
20063
1
mar 24
1613
4
cze 23
3990
report odoo16 Rozwiązane
1
lut 23
2997