【发布时间】:2020-01-23 14:44:57
【问题描述】:
我在 product.template 中添加了一个方法来计算与其他模型相关的一些自定义字段的产品名称表单字符串, 我在名称字段中添加了 store=True 以便我可以搜索它,但是当相关字段在其模型上更改时,文件名不会更改,因此我需要将服务器操作添加到名为“更新产品名称”的菜单项中在相关字段存在的cutome应用程序上,如果我按下此菜单项,它将运行命名方法并在产品名称上获取新的更新字段 我怎样才能做到这一点 这是代码
class autopart(models.Model):
_inherit = 'product.template'
@api.multi
@api.depends('item','dsc', 'drc', 'org','car','model', 'manf','year')
def naming(self):
for rec in self:
if rec.year:
rec.name = " ".join(
[rec.item and rec.item.name or "", rec.drc and rec.drc.name or "", rec.dsc and rec.dsc.name or "",
rec.org and rec.org.name or "", rec.manf and rec.manf.name or "", rec.car and rec.car.name or "",
rec.model and rec.model.name or "",rec.year and rec.year.name or ""
])
else:
rec.name = " ".join(
[rec.item and rec.item.name or "", rec.drc and rec.drc.name or "", rec.dsc and rec.dsc.name or "",
rec.org and rec.org.name or "", rec.manf and rec.manf.name or "", rec.car and rec.car.name or "",
rec.model and rec.model.name or "",
])
name = fields.Char(string="Name", compute=naming ,store=True , required=False,)
这里是菜单项
<menuitem id="update_products_menu" name="Update products" parent="master.menu_category_main" sequence="1" action="action_update_products"/>
服务器操作
<record id="action_update_products" model="ir.actions.server">
<field name="name">action_update_products</field>
<field name="type">ir.actions.server</field>
<field name="model_id" ref="model_updateproducts"/>
<field name="state">code</field>
<field name="code">how can i run naming methode from product.template here</field>
</record>
【问题讨论】:
标签: python python-3.x xml odoo call