首页 文章

如何使用Odoo 11上的服务器操作为扩展字段编写更新?

提问于
浏览
1

我正在学习Odoo 11并希望编写一个按钮,它将通过Server动作调用python方法 .

这是我的按钮代码:

<button name="enviarfactura" type="action" string="Homologar" attrs="{'invisible':['|',('sent','=',True), ('state', 'not in', ('open','paid'))]}"/>

这是我的action.server代码

<record model="ir.actions.server" id="x_nc_act_serv_fact">
  <field name="name">enviarfactura</field>
  <field name="model_id" ref="model_account_invoice"/>
  <field name="sequence">1</field>
  <field name="type">ir.actions.server</field>
  <field name="state">code</field>
  <field name="code">
            if records: 
               action = records.x_nc_met_fac()
  </field>
</record>

最后这是我的python方法 .

@api.multi
def x_nc_met_fac(self):
for rec in self:
    self.x_nc_fld_fact = True
    self.x_nc_fld_det_fact = 'my custom text'

现在的逻辑是,按钮将调用server.action,它将在我的python类上调用该方法 . 该方法将为模型account.invoice上的扩展字段设置新值 . 理论上这应该有效,但事实并非如此 .

丢弃可能的错误:

-tt 's might not be the python indentation. The python community on discord help me with it :P -It'不是server.action结构,因为当我上传包含此代码的模块时,它会创建server.action而没有任何问题 . - 当我点击按钮时,没有任何反应 . 所以我尝试将按钮的类型更改为 "type=object" 并告诉它我的方法的名称,它给出了错误 . Account.invoice没有属性"x_nc_met_fac"

任何帮助表示赞赏 . 提前致谢 .

1 回答

  • 0

    按钮的 name 必须是操作ID . 所以两个人认为必须做到:

    • 应在按钮之前定义您的操作 . 如果两者都在同一个xml中,那么很容易,如果没有检查模块清单中的顺序 . XML将按此顺序加载!

    • 将按钮 name 更改为"external ID substitution"

    <button name="%(x_nc_act_serv_fact)d" type="action" string="Homologar"
        attrs="{'invisible':['|',('sent','=',True), ('state', 'not in', ('open','paid'))]}"/>
    

相关问题