所以,据我所知,function
字段在Odoo v9上被弃用。
举个例子:
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 confirmedn
* 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 productsn
* Partially Available: some products are available and reservedn
* Ready to Transfer: products reserved, simply waiting for confirmation.n
* Transferred: has been processed, can't be modified or cancelled anymoren
* Cancelled: has been cancelled, can't be confirmed anymore"""
),
这将调用两个函数_state_get
和_get_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 confirmedn
* 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 productsn
* Partially Available: some products are available and reservedn
* Ready to Transfer: products reserved, simply waiting for confirmation.n
* Transferred: has been processed, can't be modified or cancelled anymoren
* Cancelled: has been cancelled, can't be confirmed anymore"""
)