top of page
  • Writer's pictureTek Siong, Hock

Odoo - How to add the smart button

This is a tutorial to view the journal items of the customer (res.partner) in the contact module.

Call the window action to open the journal item view. You can find out the name (ref) of the journal item view by using developer tool in the tree view of the journal item (account.move.line).

<record id="view_partner_journal_x" model="ir.actions.act_window">
   <field name="name">Journal Items History</field>
   <field name="res_model">account.move.line</field>
   <field name="view_type">form</field>
   <field name="view_mode">kanban,tree,form,pivot,graph</field>
   <field name="view_id" ref="account.view_move_line_tree"/>
   <field name="domain">[('partner_id', '=', active_id)]</field>

Add the smart button in the res.partner form view, which will have action to go to the above view.

<record model="ir.ui.view" id="res_partner_x_view">
   <field name="name">Partner</field>
       <field name="model">res.partner</field>
       <field name="type">form</field>
   <field name="priority" eval="10"/>
   <field name="inherit_id" ref="base.view_partner_form"/>
   <field name="arch" type="xml">
      <button name="toggle_active" position="after">
         <button class="oe_stat_button" type="action" name="%(custom_module.view_partner_journal_x)d"
               attrs="{'invisible': [('is_company', '=', False)]}">
            <field string="Journal Items" name="journal_item_count" widget="statinfo"/>

In the inherited res.partner model, add the following codes to generate the count of the journal items.

journal_item_count = fields.Integer(compute='_compute_journal_item_count')

def _compute_journal_item_count(self):
    for partner in self:
        items = self.env['account.move.line'].search([
            ('partner_id', '=',,
        partner.journal_item_count = len(items)

373 views0 comments

Recent Posts

See All


bottom of page