This question has been flagged
1 Reply
6974 Views

Hello everybody!!!

Can anyone help me know how to specify the domain in the action of a smart button when we want to view the employee informations from its payslip?

Thanks a lot in advane.

Best Regards.

Avatar
Discard
Best Answer

Hi Dress Far,

Create a smart button in your view file, you can refer the below code:

smart_button_view_file.xml

<div class="oe_button_box">
      <button  class="oe_stat_button" style="margin-left:150px;" 
name="%(smart_button)d" type="action" icon="fa-files-o">
             <field string="Smart Button" name="rec_count" 
widget="statinfo" />
      </button>
</div>
-> Will count the records on smart button.
rec_count = fields.Integer('Count', compute='count_func')
@api.model
def count_func(self):
     for rec in self:
           cnt = self.env['model.model'].search_count([('object_id', 
'=', rec.id)])
           rec.rec_count = cnt
-> create an action in the model view file where you want to pass domain.
object_model_view.xml
 <record id="smart_button" model="ir.actions.act_window">
        <field name="res_model">model.model</field>
        <field name="name">Model Name</field>
        <field name="view_type">form</field>
        <field name="view_mode">tree,form</field>
        <field name="domain">[('object_id', 'in', [object_id])]</field> 
#object id is M2O field.
        <field name="context">{'object_id':active_id}</field>
    </record>
    <record id="ir_economic_plan_open" model="ir.values">
        <field eval="'tree_but_open'" name="key2"/>
        <field eval="'model.model'" name="model"/>
        <field name="name">Model Name</field>
        <field eval="'ir.actions.act_window,'+str(smart_button)" 
name="value"/>
    </record>

The above code will fetch the records of a particular id.

You can apply your model names here.

Hope this will help you.

Thanks.

Avatar
Discard