Skip to Content
Menu
This question has been flagged
4 Replies
3177 Views


I have this model

class RawMaterialReport(models.Model):
    _name = 'raw.material.report'
    _description = 'Raw Material Report'

    product_id = fields.Many2one(
        'product.product', string='Product',
        required=False,
    )

    @api.multi
    def open_raw_materials(self):
        mrp_productions = self._context.get('active_ids')
        mrp_production = 
        self.env['mrp.production'].browse(mrp_productions)
        raw_products = 
        mrp_production.mapped('move_raw_ids.product_id')
        for p in raw_products:
            self.create({'product_id': p.id})

        view_id = self.env.ref('trk.raw_material_report_tree').id
        view = {
            'name': _('Details'),
            'view_type': 'form',
            'view_mode': 'tree, form',
            'res_model': 'raw.material.report',
            'views': [(view_id, 'form')],
            'type': 'ir.actions.act_window',
            # 'res_id': self.id,
        }
        return view

    <?xml version="1.0" encoding="utf-8"?>
    <openerp>
        <data>

    <record id="raw_material_report_tree" model="ir.ui.view">
        <field name="name">raw.material.report.tree</field>
        <field name="model">raw.material.report</field>
        <field name="priority">2</field>
        <field name="arch" type="xml">
            <tree string="Sales Orders" >
                <field name="product_id" />
            </tree>
        </field>
    </record>



     <record id="action_raw_material_report" 
            model="ir.actions.act_window">
            <field name="name">zzzzz</field>
            <field name="type">ir.actions.act_window</field>
            <field name="res_model">raw.material.report</field>
            <field name="view_type">form</field>
            <field name="view_mode">tree,kanban,form</field>
        </record>


        <record id="action_server_learn_skill" 
            model="ir.actions.server">
            <field name="name">test</field>
            <field name="type">ir.actions.server</field>
            <field name="model_id" ref="model_raw_material_report" />
            <field name="binding_model_id" 
            ref="mrp.model_mrp_production" />
            <field name="state">code</field>
            <field name="code">model.open_raw_materials()</field>
        </record>

        <menuitem id="menu_sale_order1"
            name="test"
            action="action_raw_material_report"
            parent="sale.sale_order_menu"
            sequence="2" />
    </data>
</openerp>

When I go to action and run my method everything goes good until that point where I try to return a view it just not redirecting me to my tree view. Nothing happens. But raw.material.report Records got created and I can check them if I go to my menu, it opens list view with them. So there is some kind of a problem with my return, can someone help on this? I actually tried to return an action like this

action = self.env.ref('trk.action_raw_material_report').read()[0]
return action

but get the same, it just not redirecting me to my tree view.


Avatar
Discard
Best Answer

Hi,

 Try this one

 return {
        'name': _('Details'),
        'view_type': 'form',
        'view_mode': 'tree, form',
        'res_model': 'raw.material.report',
        'views': [(view_id_tree[0].id, 'tree'),(False,'form')],
        'type': 'ir.actions.act_window',
        # 'res_id': self.id,
        'target': 'current',
    } 
Issue occurs because you may be passing wrong id in views [(view_id,'form')] instead of [(view_id,'tree')]
Avatar
Discard
Author Best Answer


The problem was that in action_server_learn_skill

I needed

<field name="code">action = model.open_raw_materials()</field>

instead of

<field name="code">model.open_raw_materials()</field>

because the method is not returning anything to action.


Avatar
Discard
Best Answer

 Hello Grf.​

 Please try this:

 @api.multi
 def your_function_name(self):
    tree_view_id = self.env.ref('trk.raw_material_report_tree').id
    return {
        'name': _('Details'),
        'type': 'ir.actions.act_window',
        'res_model': 'raw.material.report',
        'view_type':'form',
        'view_mode': 'tree',
        'view_id': tree_view_id,
        'res_id': False,
        'context': False,
        'target':'new'
    }

 You can refer below link:

 \https://www.odoo.com/forum/help-1/question/how-to-return-a-tree-view-from-a-python-function-119786           

 Make sure it will helpful.


 Thank you.

Avatar
Discard
Author

same result, nothng happens

Related Posts Replies Views Activity
1
Dec 24
529
3
Nov 23
15302
3
Nov 24
21044
1
Apr 23
4560
2
Dec 22
5494