odoo13新增Selection指定位置添加功能,以销售状态为例

在早前的odoo13或更早版本,一直有 select_add 方法,用于给 selection 增加值。但问题是不可以定义在什么位置,这时我们只能重新定义了。 但是由于 odoo 继承的特性,经常我们不知道哪个别的模块也新增加了一个 select。 在最新的版本中,增加了处理方法,来解决这种问题。

例:我们要在 销售订单中, 状态增加 处理。  销售报价发送前须【已审批】。 销售开票前须【已复核】,

以下是我们完整的销售审批模块,在 odoo 市场上可以找到, app_sale_approval

 

state = fields.Selection(selection_add=[
    ('to_approve', 'To Approve'),
    ('sent',),
    ('to_check', 'To Check'),
    ('done',),
])

同时,还对 selection 增加了 ondelete方法,配合selection_add,用于当模块卸载时处理数据。

 

:param ondelete: provides a fallback mechanism for any overridden
    field with a selection_add. It is a dict that maps every option
    from the selection_add to a fallback action.

    This fallback action will be applied to all records whose
    selection_add option maps to it.

    The actions can be any of the following:
        - 'set null' -- the default, all records with this option
          will have their selection value set to False.
        - 'cascade' -- all records with this option will be
          deleted along with the option itself.
        - 'set default' -- all records with this option will be
          set to the default of the field definition
        - <callable> -- a callable whose first and only argument will be
          the set of records containing the specified Selection option,
          for custom processing

 

Odoo 14全球排名第一的开源ERP新版本更新功能