Python 将旧的API Odoo函数字段转换为Odoo v9社区

Python 将旧的API Odoo函数字段转换为Odoo v9社区,python,openerp,Python,Openerp,因此,据我所知,函数字段在OdooV9上不受欢迎 举个例子: state = fields.function(_state_get, type="selection", copy=False, store={ stock.picking = (lambda self, cr, uid, ids, ctx: ids, ['move_type', 'launch_pack_operations'], 20), stock.move =

因此,据我所知,
函数
字段在OdooV9上不受欢迎

举个例子:

state = fields.function(_state_get, type="selection", copy=False,
        store={
            stock.picking = (lambda self, cr, uid, ids, ctx: ids, ['move_type', 'launch_pack_operations'], 20),
            stock.move = (_get_pickings, ['state', 'picking_id', 'partially_available'], 20)},
        selection=[
            ('draft', 'Draft'),
            ('cancel', 'Cancelled'),
            ('waiting', 'Waiting Another Operation'),
            ('confirmed', 'Waiting Availability'),
            ('partially_available', 'Partially Available'),
            ('assigned', 'Available'),
            ('done', 'Done'),
            ], string='Status', readonly=True, select=True, track_visibility='onchange',
        help="""
            * Draft: not confirmed yet and will not be scheduled until confirmed\n
            * Waiting Another Operation: waiting for another move to proceed before it becomes automatically available (e.g. in Make-To-Order flows)\n
            * Waiting Availability: still waiting for the availability of products\n
            * Partially Available: some products are available and reserved\n
            * Ready to Transfer: products reserved, simply waiting for confirmation.\n
            * Transferred: has been processed, can't be modified or cancelled anymore\n
            * Cancelled: has been cancelled, can't be confirmed anymore"""
    ),
这将调用两个函数
\u state\u get
\u get\u pickings


函数的工作方式与v9上的相同,但如何在新API中声明类似于此字段的内容?

您可以在新API中以这种方式声明字段

@api.depends('move_lines.state')
def _state_get(self)
    #your code
    pass

state = fields.Selection(compute=_state_get,store=True,copy=False,selection=[
            ('draft', 'Draft'),
            ('cancel', 'Cancelled'),
            ('waiting', 'Waiting Another Operation'),
            ('confirmed', 'Waiting Availability'),
            ('partially_available', 'Partially Available'),
            ('assigned', 'Available'),
            ('done', 'Done'),
            ], string='Status', readonly=True, select=True, track_visibility='onchange',
        help="""
            * Draft: not confirmed yet and will not be scheduled until confirmed\n
            * Waiting Another Operation: waiting for another move to proceed before it becomes automatically available (e.g. in Make-To-Order flows)\n
            * Waiting Availability: still waiting for the availability of products\n
            * Partially Available: some products are available and reserved\n
            * Ready to Transfer: products reserved, simply waiting for confirmation.\n
            * Transferred: has been processed, can't be modified or cancelled anymore\n
            * Cancelled: has been cancelled, can't be confirmed anymore"""
    )

超级棒!非常感谢。