This question has been flagged
1 Reply
3363 Views

Dear all,


I created a new module which adds fields to the project and task form view. However, once I install the module and get an instant warning message "The record has been modified, your changes will be discarded. Do you want to proceed?" when I open project settings or create a new task using the "Create" button. This does not occur when creating a from Kanban view.

I have no idea what could cause this behavior.


Please find my code below. I would be great if you could help me out.

models.py

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

color_gantt = fields.Char(string="Balkenfarbe", widget="colorpicker")

color_gantt_set = fields.Boolean(string="Zeige Ganttfarbe", default=True)

on_gantt = fields.Boolean(string="Bezeichnung in Gantt-Ansicht",
default=True)

tag_ids = fields.Many2many('project.tags',
string="Stichwörter")


class DescriptionTemplate(models.Model):
_inherit = 'project.task'

desc_template_id = fields.Many2one('project.task.description_template_texts',
string="Beschreibungsvorlagen")

content = fields.Html('Vorlagen',
related='desc_template_id.content',
store=False)

category = fields.Selection(
string="Projektkategorie",
related="project_id.x_category",
store=False)

@api.onchange('desc_template_id')
def _set_desc_template(self):
if not self.description:
self.description = self.content

@api.model
def default_get(self, vals):
task = super(DescriptionTemplate, self).default_get(vals)
project_id = self.env.context.get('default_project_id')
project = self.env['project.project'].browse(project_id)
project_tag_ids = project.tag_ids
ids_list = project_tag_ids.ids
task.update({
'color_gantt' : project.color_gantt,
'color_gantt_set' : project.color_gantt_set,
'on_gantt' : project.on_gantt,
'tag_ids' : [(6,0,ids_list)]
})
return task


class DescTempText(models.Model):
_name = 'project.task.description_template_texts'

name = fields.Char('Bezeichnung')

content = fields.Html('Vorlagen')


views.xml

<record model="ir.ui.view" id="edit_project_ganttaps_inherited">
<field name="name">project.project_form</field>
<field name="model">project.project</field>
<field name="inherit_id" ref="project_native.edit_project_ganttaps_inherited"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='detail_plan']" position='after'>
<field name="on_gantt"/>
<field name="color_gantt_set"/>
<field name="color_gantt" widget="colorpicker"/>
</xpath>
</field>
</record>

<record model="ir.ui.view" id="edit_project_inherited">
<field name="name">project.project_form</field>
<field name="model">project.project</field>
<field name="inherit_id" ref="project.edit_project"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='user_id']" position='after'>
<field name="tag_ids" widget="many2many_tags"/>
</xpath>
</field>
</record>

<record model="ir.ui.view" id="description_template_selector">
<field name="name">project.task.form</field>
<field name="model">project.task</field>
<field name="inherit_id" ref="project.view_task_form2"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='tag_ids']" position='after'>
<field name="desc_template_id"/>
<field name="content" invisible='1'/>
<field name="category" invisible='1'/>
</xpath>
</field>
</record>

<record model="ir.ui.view" id="description_template_kanban">
<field name="name">project.task.kanban</field>
<field name="model">project.task</field>
<field name="inherit_id" ref="project.view_task_kanban"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='tag_ids']" position='after'>
<field name="category" invisible='1'/>
</xpath>
</field>
</record>


<record model="ir.ui.view" id="project_kanban_tags">
<field name="name">project.project.kanban</field>
<field name="model">project.project</field>
<field name="inherit_id" ref="project.view_project_kanban"/>
<field name="arch" type="xml">
<xpath expr="//div[@class='o_primary']" position='after'>
<field name="tag_ids" widget="many2many_tags"/>
</xpath>
</field>
</record>

Avatar
Discard
Author Best Answer

Apparently some fields where contained unused parameters that cause this error to occurr. once those were fixed the issue went away.

Avatar
Discard

yes, you're right. there were some fields values didn't set and those fields have required. that's why this issue raises.