This question has been flagged
1 Reply
5190 Views

I've added a notes section in the project kanban view. The problem is when I click it I get an error

NameError: name 'active_id' is not defined

I've used this method to create smart buttons in project, contact, and product form views and it works well. When you click the smart button it will redirect to a pre-filtered notes page. I fear that since there's not really an "active" project open, that there will not be an active_id. If that's the case, how can I filter by the one I've clicked on?

Kanban view

<record id="view_project_notes_kanban" model="ir.ui.view">
<field name="name">triangle.project.note.kanban</field>
<field name="model">project.project</field>
<field name="inherit_id" ref="project.view_project_kanban"/>
<field name="arch" type="xml">
<data>
<xpath expr="//div[@class='o_project_kanban_boxes']" position="inside">
<div class="o_project_kanban_box">
<a name="%(note.action_note_note)d" type="action" context="{'search_default_project': active_id, 'default_project': active_id}">
<span class="o_value"><field name="note_count"/></span>
 <span class="o_label">Notes</span>
</a>
</div>
</xpath>
</data>
</field>
</record>

In addition to "active_id", I've also tried "record.id" and just "id". All come back with a NameError.

Form view (which works)

<record id="view_project_notes_form" model="ir.ui.view">  
<field name="name">triangle.project.note.form</field>
<field name="model">project.project</field>
<field name="inherit_id" ref="project.edit_project"/>
<field name="arch" type="xml">
<data>
<xpath expr="//div[@name='button_box']" position="inside">
<button class="oe_stat_button" type="action" name="%(note.action_note_note)d" icon="fa-sticky-note" context="{'search_default_project': active_id, 'default_project': active_id}">
<field string="Notes" name="note_count" widget="statinfo"/>
</button>
</xpath>
</data>
</field>
</record>
Avatar
Discard
Author Best Answer

Ok, I adjusted my method a little bit because the context should actually be on the note.note action and not the project.project view.

New Project Kanban:

<record id="view_project_notes_kanban" model="ir.ui.view">  
<field name="name">triangle.project.note.kanban</field>
<field name="model">project.project</field>
<field name="inherit_id" ref="project.view_project_kanban"/>
<field name="arch" type="xml">
<data>
<xpath expr="//div[@class='o_project_kanban_boxes']" position="inside">
<a name="%(triangle.act_project_2_note)d" type="action" class="o_project_kanban_box">
<span class="o_value"><field name="note_count"/></span>
<span class="o_label">Notes</span>
</a>
</xpath>
</data>
</field>
</record>

New Note Window Action:

<act_window id="act_project_2_note" 
name="Notes"
res_model="note.note"
view_mode="kanban,tree,form"
context="{'search_default_project': [active_id], 'default_project': active_id}"/>

This totally solved my problem!

Avatar
Discard