Skip ke Konten
Menu
Pertanyaan ini telah diberikan tanda
2 Replies
3050 Tampilan

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
Buang
Penulis Jawaban Terbai

Edit: to add detail to original question


Avatar
Buang
Jawaban Terbai

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
Buang
Post Terkait Replies Tampilan Aktivitas
0
Mar 23
1441
6
Des 24
19743
1
Mar 24
1456
4
Jun 23
3710
report odoo16 Diselesaikan
1
Feb 23
2678