我已继承product.product以获取可用产品:
'qty_stock': fields.related('rented_product_id', 'qty_available', type='float', relation='product.product', string="En stosck", readonly=True),
'qty_1': fields.related('rented_product_id', 'incoming_qty', type='integer', relation='product.product', string="Résrver", readonly=True),
'qty_2': fields.related('rented_product_id', 'outgoing_qty', type='integer', relation='product.product', string="Sortant", readonly=True),
'qty_state': fields.selection([('libre','Libre'),('louee','Louée'),('reserver','Réservée')], 'Status', readonly=True
我想在字段'qty_state'中显示:
if 'qty_1' > 0 and 'qty_2 < 0 : display 'reserver'
if 'qty_1' > 0 and 'qty_2 = 0 : display 'louee'
if 'qty_1' = 0 and 'qty_2 = 0 : display 'libre'
请帮助
答案 0 :(得分:1)
您必须使用fields.function而不是fields.selection,如下所示:
def _get_qty_state(self, cr, uid, ids, field_name, args, context=None):
if context is None:
context = {}
res = {}
for product in self.browse(cr, uid, ids, context=context):
# Put 'libre' as default value
res[product.id] = 'libre'
if product.qty_1 > 0 and product.qty_2 < 0:
res[product.id] = 'reserver'
elif product.qty_1 > 0 and product.qty_2 == 0:
res[product.id] = 'louee'
return res
在'_columns'中:
'qty_state': fields.function(
_get_qty_state,
method=True,
type='selection',
selection=[('libre','Libre'),('louee','Louée'),('reserver','Réservée')],
string='Status',
readonly=True,
store=False,
),
OR
您可以保留fields.selection并通过覆盖'default_get'方法来感受它。