[英]Button of one2many form view in Odoo
I would like to ask about one2many field form view with action button. 我想问一下带操作按钮的one2many字段表单视图。
I have a model with one2many field. 我有一个one2many领域的模型。 I would like to add button in one2many form view, but, when I added that button in view, it only showed in readonly mode.
我想在one2many表单视图中添加按钮,但是,当我在视图中添加该按钮时,它仅以只读模式显示。 It did not know which model/object should be used, just I think, so how to add the model for that button.
我不知道应该使用哪个模型/对象,因此如何为该按钮添加模型。
My code like that: 我的代码是这样的:
class main_model(osv.osv):
_name = "main.model"
_columns = {
'other_model_ids':fields.one2many('other.model','main_id','Other'),
}
class other_model(osv.osv):
_name = "other.model"
_columns = {
'name':fields.char('Name'),
'code':fields.char('Code'),
'main_id':fields.many2one('main.model','Main'),
}
...
<field name="model">main.model</field>
<field name="type">form</field>
<field name="arch" type="xml">
<field name="other_model_ids">
<tree string="Other Model">
<field name="name"/>
<field name="code"/>
</tree>
<form string="Other Model">
<group>
<field name="name"/>
<button name="generate_code" string="Generate Code" type="object"/>
<field name="code"/>
</group>
</form>
</field>
</field>
...
I would like to add that button in one2many form view. 我想在one2many表单视图中添加该按钮。
button name="generate_code" string="Generate Code" type="object"...
but that button did not know which model belong this. 但是那个按钮不知道属于哪个型号。 If you know and have some time, please explain me.
如果您知道并有时间,请向我解释。 Thanks.
谢谢。
In my opinion: 在我看来:
1.You should define the function under the model: 1.您应该在模型下定义函数:
For example: 例如:
class other_model(osv.osv):
_name = "other.model"
_columns = {
'name':fields.char('Name'),
'code':fields.char('Code'),
'main_id':fields.many2one('main.model','Main'),
}
@api.one
def generate_code(self):
pass
2.You can try this: 2.您可以尝试以下方法:
<field name="model">main.model</field>
<field name="type">form</field>
<field name="arch" type="xml">
<form string="Main Model">
<notebook>
<page string="Other Models">
<field name="Other Model">
<tree>
<field name="name"/>
<field name="code"/>
<button name="generate_code" string="Generate Code" type="object"/>
</tree>
</field>
</page>
</notebook>
</form>
</field>
I wish this will help you. 希望对您有帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.