コンテンツへスキップ
メニュー
この質問にフラグが付けられました
6 返信
17416 ビュー

I want to make a field Unique with combination of two fields and it does not show on form

class shipment_charge(osv.osv):
    _name = 'shipment.charge'
    _columns = {
        'type': fields.selection(list_type, 'Type', required=True, ),
        'mode': fields.selection(list_mode, 'Mode', required=True, help=""),
        'transit_time': fields.selection(list_transit_time, 'Transit Time', required=True, help=""),
        'charges_key':  fields.char('charges_key', size=64, help=""),
    }

    _sql_constraints = [
        ('charges_key_unique', 'unique (type, mode)', 'The Charges key is not Unique')
    ]
アバター
破棄
最善の回答

use this

def check_existance(self, cr, uid, ids, context=None):
        self_obj = self.browse(cr, uid, ids[0], context=context)
        field1 = self_obj.field1
        field2 = self_obj.field2
        search_ids = self.search(cr, uid, [('field1', '=', field1),('field2', '=' , field2)], context=context)
        res = True
        if len(search_ids) > 1:
            res = False
        return res

and add

_constraints = [(check_existance,'Combination already exist', ['field1'])]
アバター
破棄
著作者

still giving error ValueError: need more than 1 value to unpack

use

_constraints = [(check_existance,'Combination already exist', ['field1','field2'])]

最善の回答
_sql_constraints = [
        ('name_uniq', 'unique(type, mode)', 'The Charges Key is not Unique!'),
        ]

Please replace this instead of that

アバター
破棄
著作者

ERROR erp_dev openerp.netsvc: Constraint Error The Charges key is not Unique

its freezing the screen not rasing a error message

最善の回答

Below the code of a server action which concatenet 2 or more field into a new one

アバター
破棄
関連投稿 返信 ビュー 活動
4
6月 24
6791
2
12月 23
2498
4
3月 15
11925
2
3月 15
9130
1
3月 15
8404