我可以通过odoo中的服务器操作设置默认值吗
Can i set default value by server action in odoo
我想在 many2one
字段中设置默认值。但我想通过 python code
in server action
at on-creation
来设置它。问题是,我不知道在server action
中写python code
有什么规矩。有没有办法在服务器操作中设置 Many2one 字段的默认值。
例如:
通过自定义代码 Set default value of field depends on other field in odoo
也有同样的工作
我会非常感激...
您可以对此要求使用自动操作。只需在 Settings/Technical/Automation/Automated 个操作中创建一个。给它起个名字,你想要运行它的正确模型当然设置"When to run"到"On Creation"。
在第二个选项卡上添加一个新的服务器操作。按照服务器操作的简单代码片段(它用于 sale.order
,您需要一个具有给定外部 ID 的 ir.config_parameter
):
object.write({'client_order_ref': 'YourRef'})
if 'A' in object.partner_id.name:
object.write({'note': 'AAAAAAAAAA'})
else:
object.write({'note': env.ref('mymodule.mycool_ir_config_parameter').value})
该示例是为 Odoo V8+ 编写的。
我想在 many2one
字段中设置默认值。但我想通过 python code
in server action
at on-creation
来设置它。问题是,我不知道在server action
中写python code
有什么规矩。有没有办法在服务器操作中设置 Many2one 字段的默认值。
例如:
通过自定义代码 Set default value of field depends on other field in odoo
我会非常感激...
您可以对此要求使用自动操作。只需在 Settings/Technical/Automation/Automated 个操作中创建一个。给它起个名字,你想要运行它的正确模型当然设置"When to run"到"On Creation"。
在第二个选项卡上添加一个新的服务器操作。按照服务器操作的简单代码片段(它用于 sale.order
,您需要一个具有给定外部 ID 的 ir.config_parameter
):
object.write({'client_order_ref': 'YourRef'})
if 'A' in object.partner_id.name:
object.write({'note': 'AAAAAAAAAA'})
else:
object.write({'note': env.ref('mymodule.mycool_ir_config_parameter').value})
该示例是为 Odoo V8+ 编写的。