Search code examples
odooodoo-11erpodoo-view

active_id and actions in transientModel odoo


I am trying to get some values from (hr.payslip) model. Before that I need to add one more option in Action (dropdown list) where you can delete or export selected payslip. So when I select a payslip from treeView (checkbox in the image below) that new option should show up a wizard showing a table One2many having the selected payslip so I can Print or do some other action.

This is the scenario and i did not start any coding to do that.

I am new to odoo. I hope you can help me with some example.

enter image description here


Solution

  • you have to create new action and new object also create new object

    class NewObject(models.TransientModel):
        _name = 'new.object'
        _description = 'Description of new object'
        @api.multi
        def generate_report(self):
             payslip_ids = self._.get('active_ids',[])
             #payslip_ids this will be your selected payslip ids in list view.
    
    <act_window 
            name="Your Action string" 
            res_model="new.object"
            src_model="hr.payslip" 
            view_mode="form" 
            view_type="form"
            target="new" 
            multi="True" 
            key2="client_action_multi"
            id="id_of_act_window"
            view_id="view of new object"        
        />      
    

    then create view for new object

    <record id="id of new view" model="ir.ui.view">
            <field name="name">Name of view</field>
            <field name="model">model of new view</field>
            <field name="arch" type="xml">
                <form string="">
                    <button name="generate_report" string="Generate Report
                            type="object" class="oe_highlight" />
                </form>
            </field>
        </record>
    

    and here you can add your code you want like.