使用字段作为键,每条记录必须唯一,才能使用它浏览 table (Openerp)
Use a field as key and it must be unique for each record to use it to browse the table (Openerp)
请在视图表单中使用一个字段作为键,并且每条记录都必须是唯一的才能使用它来浏览其他视图中的table,如何实现
class saisirsoum(osv.osv):
_name='saisir.soum'
_columns = {
'NumOffre' : fields.char('N° Offre'), # to be defined as key !!
'organisme_s' : fields.char('Organisme'),
'des_offre' : fields.char('Designation'),
'order_line' :fields.one2many('saisir.soumission.ligne','order_id','soumission_id'),
'observation_d' : fields.text('Observation'),
}
在您的情况下,您将通过设置 _sql_constraints
变量使 NumOffre
像这样独一无二。您还可以在其中定义要在用户尝试添加重复条目时显示的自定义消息。
class saisirsoum(osv.osv):
_name='saisir.soum'
_sql_constraints = [
('NumOffre', 'unique(NumOffre)', 'NumOffre already exists'),
]
_columns = {
'NumOffre' : fields.char('N° Offre'), # to be defined as key !!
'organisme_s' : fields.char('Organisme'),
'des_offre' : fields.char('Designation'),
'order_line' :fields.one2many('saisir.soumission.ligne','order_id','soumission_id'),
'observation_d' : fields.text('Observation'),
}
def create(self, cr, uid, vals, context=None): # when the record is about to created
NumOffre = vals.get('NumOffre') #get NumOffre from the form
if NumOffre:
pass # you can do something with it e.g searching
return super(saisirsoum, self).create(cr, uid, vals, context=context) # finally call the create method from the super class and create the record after you're done
您还可以以相同的方式覆盖其他 CRUD 方法,例如 write
和 unlink
请在视图表单中使用一个字段作为键,并且每条记录都必须是唯一的才能使用它来浏览其他视图中的table,如何实现
class saisirsoum(osv.osv):
_name='saisir.soum'
_columns = {
'NumOffre' : fields.char('N° Offre'), # to be defined as key !!
'organisme_s' : fields.char('Organisme'),
'des_offre' : fields.char('Designation'),
'order_line' :fields.one2many('saisir.soumission.ligne','order_id','soumission_id'),
'observation_d' : fields.text('Observation'),
}
在您的情况下,您将通过设置 _sql_constraints
变量使 NumOffre
像这样独一无二。您还可以在其中定义要在用户尝试添加重复条目时显示的自定义消息。
class saisirsoum(osv.osv):
_name='saisir.soum'
_sql_constraints = [
('NumOffre', 'unique(NumOffre)', 'NumOffre already exists'),
]
_columns = {
'NumOffre' : fields.char('N° Offre'), # to be defined as key !!
'organisme_s' : fields.char('Organisme'),
'des_offre' : fields.char('Designation'),
'order_line' :fields.one2many('saisir.soumission.ligne','order_id','soumission_id'),
'observation_d' : fields.text('Observation'),
}
def create(self, cr, uid, vals, context=None): # when the record is about to created
NumOffre = vals.get('NumOffre') #get NumOffre from the form
if NumOffre:
pass # you can do something with it e.g searching
return super(saisirsoum, self).create(cr, uid, vals, context=context) # finally call the create method from the super class and create the record after you're done
您还可以以相同的方式覆盖其他 CRUD 方法,例如 write
和 unlink