【问题标题】:Openerp comparing 2 field value and display result in another fieldOpenerp 比较 2 个字段值并在另一个字段中显示结果
【发布时间】:2014-06-16 11:21:02
【问题描述】:

我继承了 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'

请帮忙

【问题讨论】:

    标签: field openerp


    【解决方案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,
    ),
    

    您可以保留 fields.selection 并通过覆盖 'default_get' 方法来感受它。

    【讨论】:

      猜你喜欢
      • 2014-02-19
      • 1970-01-01
      • 2023-03-29
      • 1970-01-01
      • 2020-06-13
      • 1970-01-01
      • 2020-11-05
      • 2017-05-22
      • 1970-01-01
      相关资源
      最近更新 更多