【问题标题】:Odoo, how to override an action extending it's domain (not overriding)Odoo,如何覆盖扩展其域的操作(不覆盖)
【发布时间】:2020-12-22 11:39:58
【问题描述】:

在我不拥有的模块中是以下 act_window。

<record id="act_465" model="ir.actions.act_window">
    <field name="name">Act 465</field>
    <field name="res_model">stock.move</field>
    <field name="view_type">form</field>
    <field name="view_mode">tree,form</field>
    <field name="domain">[('available','=',True)]</field>
</record>

我想在我的单独模块中向域中添加以下 AND 条件:

('canceled', '!=', True)

我知道我可以通过[('available','=',True),('canceled', '!=', True)]覆盖 act_window 和 domain 的值。但是这样做会完全删除已经存在的('available','=',True)。这意味着如果基本模块的所有者更改了它的域,我无论如何都会覆盖他的更改。

问题

如何通过说“我想将('available','=',True) 添加到现有域”来扩展域?

【问题讨论】:

    标签: odoo odoo-9 odoo-12


    【解决方案1】:

    不能,action 域是 char 字段,没有属性来指定如何扩展特定的记录值。

    可以使用XML数据文件中的function标签来调用write方法并更新域,或者创建一个函数以给定的域列表作为参数来更新动作域。

    • 使用函数标记将域更新为字符串(我们假设域已设置,元组列表作为字符串提供)

      示例:

      <function model="ir.actions.act_window" name="write">
          <value eval="[ref('sale.action_quotations_with_onboarding')]"/>
          <value model="ir.actions.act_window" eval="{'domain':  obj().env['ir.actions.act_window'].browse(ref('sale.action_quotations_with_onboarding')).domain[:-1] + ', (\'invoice_status\', \'=\', \'to invoice\')]'}"/>
      </function>  
      
    • 创建一个函数以将域更新为列表,并将给定域作为参数

      示例:

      class IrActionsActWindow(models.Model):
          _inherit = 'ir.actions.act_window'
      
          def update_domain(self, new_domain=None):
              if new_domain:
                  self.write({'domain': safe_eval(self.domain) + new_domain})
      

      使用函数调用update_domain方法:

      <function model="ir.actions.act_window"
                name="update_domain"
                eval="[ref('sale.action_quotations_with_onboarding'), [('invoice_status', '=', 'to invoice')]]"/>
      

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-01-29
      • 2011-01-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-08-10
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多