odoo - 如何在 Odoo 12 中将值从字段传递给向导?

标签 odoo wizard

我下面有这个字段

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

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

@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。但还是没有达到我的预期。

对于按钮:

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

对于向导本身。我希望该值位于“Resi”字段中:

<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>

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

最佳答案

你可以试试这个方法

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',
}

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

'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 - 如何在 Odoo 12 中将值从字段传递给向导?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62529650/

相关文章:

python - 如何添加审批工作流程 OpenERP 7

python - 计算从一种模型到另一种模型的字段数量 - Odoo v8

inno-setup - 仅将 Inno Setup UI 用作自解压器 - 无需安装

asp.net-mvc-4 - 在 ASP.NET MVC 4 中创建具有友好 URL 的向导

Android:像带 fragment 的 Activity 一样的向导

visual-studio-2010 - 在项目模板中使用本地 IWizard 程序集作为 WizardExtension

java - 如何动态选择向导的下一页

python - Odoo 中从非 transient 模型到 transient 模型的 Many2One 或 One2Many 关系的解决方法

python - 来自未在 python 中使用 mako 呈现的变量的 Html 字符串

python - 一种方法有两个返回语句? Python