如何将字段中的值传递给 Odoo 12 中的向导? [英] How to pass value from field to a wizard in Odoo 12?

查看:87
本文介绍了如何将字段中的值传递给 Odoo 12 中的向导?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在下面有这个字段

name = fields.Text("Input text here")

我想在单击按钮时将其值传递给向导.代码如下:

And I want to pass its value to the wizard when I click a button. Here's the code:

@api.multi
def open_wizard(self):
return {
'view_type': 'form',
'view_mode': 'form',
'res_model': 'customer.wizard',
'target': 'new',
'type': 'ir.actions.act_window',
'context': {'current_id': self.id}
 }

这是我的 XML.但它仍然没有像我预期的那样工作.

And here is my XML. But it still didn't work as I expected.

对于按钮:

<button name="open_wizard" string="Submit" type="object" class="oe_highlight" context="
{'name': name}"/>

对于向导本身.我希望该值位于Resi"字段中:

For the wizard itself. I want the value to be on the 'Resi' field:

<record id="view_test_report_wizard" model="ir.ui.view">
 <field name="name">Customer Wizard</field>
 <field name="model">customer.wizard</field>
 <field name="arch" type="xml">
 <form string="Choose The Details">
 <group>
 <tree>
 <group>
 <field string="Resi" name="name" context="{'name' : name}"/>
 <field name="tanggal"/>
 <field name="kotaasal"/>
 <field name="kotatujuan"/>
 <field name="id_customer"/>
 </group>
 </tree>
 </group>
 <footer>
 <button string="Back" class="oe_link" special="cancel"/>
 </footer>
</form>
</field>
</record>

你有什么解决办法吗?谢谢

Do you have any solution? Thank you

推荐答案

你可以试试这个方法

wiz = self.env['customer.wizard'].create({'name': self.name})

@api.multi
def open_wizard(self):
return {
'view_type': 'form',
'view_mode': 'form',
'res_model': 'customer.wizard',
'res_id': wiz.id,
'target': 'new',
'type': 'ir.actions.act_window',
}

或者你可以在上下文中传递值

or you can pass the value in the context

'context': {
   'default_name': self.name,'default_tanggal': self.tanggal
   'default_kotaasal': self.kotaasal,'default_kotatujuan': self.kotatujuan
   ,'default_id_customer': self.id_customer.id
}

这篇关于如何将字段中的值传递给 Odoo 12 中的向导?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆