Skip to Content
Menu
This question has been flagged
1 Reply
620 Views

Hello,

as the title mentions, I pass the a variable from purchase order form using a button:

<xpath expr="//button[@name='print_quotation']" position="after">

                <button name="%(dynamic_reporting.action_report_selection_wizard)d"

                    string="Print Custom Report"

                    class="btn-primary"

                    type="action"

                    context="{'default_model_id': active_model}"

                    />

            </xpath>

The value is passed with no problem(in my case I get default_model_id is: 'purchase.order'), but when I try to use that default_model_id to get to the ID of the model:

@api.model

    def _default_model_id(self):

        active_model = self.env.context.get('default_model_id', '')

        return self.env['ir.model'].search([('model', '=', active_model)], limit=1).id

    model_id = fields.Many2one('ir.model',

            'Modèle',

            domain="[('transient', '=', False)]",

            default=_default_model_id

            )

the field model_id always stay empty. I tried a bunch of stuff but it didn't amount to anything


any help would be appreciated

Avatar
Discard
Best Answer

In the button, you set the model_id as char() and then in the model it is Many2one which is confusing. By default, when you set the default_field_name, odoo will set the field name (without the prefix default_) to that value. If you want to pass the model id, simply set the default_model_id:active_model.id, or use another name for the context.

Avatar
Discard
Related Posts Replies Views Activity
1
May 25
39
0
May 25
198
1
May 25
396
1
May 25
451
0
Apr 25
2