Přejít na obsah
Menu
You need to be registered to interact with the community.
This question has been flagged
2 Odpovědi
3378 Zobrazení

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.


Avatar
Zrušit
Autor Nejlepší odpověď

Edit: to add detail to original question


Avatar
Zrušit
Nejlepší odpověď

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.

Avatar
Zrušit
Related Posts Odpovědi Zobrazení Aktivita
0
bře 23
1524
6
pro 24
19962
1
bře 24
1565
4
čvn 23
3928
report odoo16 Vyřešeno
1
úno 23
2883