Reputation: 1
I have inherit product.product to get available products so:
'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
I want to display in field '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'
help please
Upvotes: 0
Views: 138
Reputation: 1232
You must use a fields.function instead of a fields.selection, like this :
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
And in '_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
You can keep the fields.selection and feel it by overriding the 'default_get' method.
Upvotes: 1