Friday 8 September 2017

open form onclick button from form view

Add one button on form view like below code.

<div name="button_box" position="inside">
    <button class="oe_inline oe_stat_button" name="action_form_view"
            type="object" icon="fa-book">
        <field string="Examples" name="Examples_count" widget="statinfo"/>
    </button>
</div>

Add Examples_count field on py file.

Examples_count is field for display total number of record on button.

Add below code in py file

    @api.multi
    def action_form_view(self):
        Example_line_ids = self.env['Example.order.line'].search([('product_id','=',self.id)])
        Example_ids = []
        for line in Example_line_ids:
            if line.order_id:
                Example_ids.append(line.order_id.id)
       
        view_id = self.env.ref('product_Example.view_tree_tree').id
        form_view_id = self.env.ref('product_Example.view_Example_order_view').id
        context = self._context.copy()
        return {
            'name':'form_name',
            'view_type':'form',
            'view_mode':'tree',
            'res_model':'Example.order',
            'view_id':view_id,
            'views':[(view_id,'tree'),(form_view_id,'form')],
            'type':'ir.actions.act_window',
            'domain':[('id','in',Example_ids)],
            'target':'current',
            'context':context,
        }


    @api.multi
    def get_Example_count(self):
        Example_line_ids = self.env['Example.order.line'].search([('product_id','=',self.id)])
        Example_ids = []
        for line in Example_line_ids:
            if line.order_id:
                Example_ids.append(line.order_id.id)
        self.Examples_count = len(Example_ids) or 0


    Examples_count = fields.Float(compute='get_Example_count', string='Examples Count') 

No comments:

Post a Comment

Odoo 17 New Features

  Odoo 17 new Features 1) Duplicate  multiple records from List view. Please have look below screenshots first you need to select records th...