Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
1 Trả lời
661 Lượt xem

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

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

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.

Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
1
thg 5 25
94
0
thg 5 25
254
1
thg 5 25
460
1
thg 5 25
547
0
thg 4 25
2