2

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>

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>
lslaz
  • 85
  • 11

2 Answers2

2

Please try record.id instead of active_id, ie :-

    <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': record.id, 'default_project': record.id}">
          <span class="o_value"><field name="note_count"/></span>
          <span class="o_label">Notes</span>
        </a>
       </div>
      </xpath>
     </data>
    </field>
   </record>
Hilar AK
  • 1,655
  • 13
  • 25
  • 1
    This is definitely a good idea, however, it still comes back with an error. `NameError: name 'record' is not defined`. Really not sure how to debug this one! – lslaz Mar 15 '17 at 16:33
  • 1
    Just a little more info: The `record.field` method DOES work for me in a res.partner inherited view, but NOT in the project.project inherited view. – lslaz Mar 15 '17 at 16:48
  • Can you please specify which version are you working on – Hilar AK Mar 16 '17 at 04:33
  • In case of v9 if you are , then try to get the value of id with record ie, record.id.value – Hilar AK Mar 16 '17 at 04:36
  • 1
    Yes, it is v9. As stated above, I get a NameError on 'record'. Even if I tried 'record.id.value' it would still error on 'record'. – lslaz Mar 16 '17 at 13:54
0

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!

lslaz
  • 85
  • 11