【问题标题】:Display dynamic Values in odoo View?在odoo视图中显示动态值?
【发布时间】:2018-09-07 06:50:08
【问题描述】:

我正在使用odoo9,我有一个确认弹出窗口,我想在这个弹出窗口中显示一些动态值?我怎样才能做到这一点?请看一下屏幕截图

我想用用户名替换当前联系人,这将是一些动态值。我怎样才能做到这一点? 下面是我的视图代码。

        <record id="view_dialog_temp_login_confirmation" model="ir.ui.view">
        <field name="name">Temp Login Confirmation</field>
        <field name="model">olims.message_dialog_box</field>
        <field name="arch" type="xml">
            <form string="Client User Confirmation">
                <p class="o_dialog_warning">
                   Current Contact user will be deleted.</p>
                <p>Do you really want to replace Contact User? </p>
                <field name="title" invisible="1"/>
                <footer>
                     <button name="create_temp_login" string="Yes" type="object" class="btn-primary"/>
                     <button string="No" class="btn-default" special="cancel"/>
                </footer>
            </form>
        </field>
    </record>

打开向导代码:

     @api.multi
     def open_temp_login_confirm_dialog(self, **kw):
    view_id = self.env['ir.ui.view'].search([('name', '=', 'Temp Login Confirmation')])

    return {
        'name': ('Confirmation'),
        'view_mode': 'form',
        'view_type': 'form',
        'res_model': 'olims.message_dialog_box',
        'view_id': [view_id.id],
        'target': 'new',
        'type': 'ir.actions.act_window',
        'context': context,
    }

【问题讨论】:

  • 如何打开该向导?请添加向导模型的代码以及打开它的位置。
  • @CZoellner 请看我的编辑。

标签: odoo odoo-9


【解决方案1】:

您可以在您的向导模型olims.message_dialog_box 上为关系res.partner 添加Many2one,然后使用默认值扩展该向导的open_ 方法,或者您只需在打开它之前创建一个向导记录。

partner_id = fields.Many2one(comodel_name="res.partner")

具有默认值的变体 1:

@api.multi
def open_temp_login_confirm_dialog(self):
    view_id = self.env['ir.ui.view'].search(
        [('name', '=', 'Temp Login Confirmation')])
    context = dict(self.env.context)
    context['default_partner_id'] = self.env.context.get('active_id')
    return {
        'name': ('Confirmation'),
        'view_mode': 'form',
        'view_type': 'form',
        'res_model': 'olims.message_dialog_box',
        'view_id': [view_id.id],
        'target': 'new',
        'type': 'ir.actions.act_window',
        'context': context,
    }

变体 2 创建一个向导并打开它

@api.multi
def open_temp_login_confirm_dialog(self):
    view_id = self.env['ir.ui.view'].search(
        [('name', '=', 'Temp Login Confirmation')])
    wizard = self.env['olims.message_dialog_box'].create({
        'partner_id': self.env.context.get('active_id')}) 
    return {
        'name': ('Confirmation'),
        'view_mode': 'form',
        'view_type': 'form',
        'res_model': 'olims.message_dialog_box',
        'view_id': [view_id.id],
        'target': 'new',
        'type': 'ir.actions.act_window',
        'res_id': wizard.id
    }

【讨论】:

  • 问题在视图中,如何在我的视图 xml 中获取它?意味着我应该如何在视图上打印?由 Qweb 提供?
  • 只要在你想要的地方用&lt;field name="partner_id" readonly="1" /&gt;扩展它。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-03-15
  • 2016-06-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多