继承模型的必填字段 - Odoo v10 community
Mandatory field on inherited model - Odoo v10 community
我继承了res.partner
模型,现在,我想将vat
字段设为required
和unique
。
我知道如何正常执行此操作,例如在新模型上,但我希望原始字段具有这些属性。
我怎样才能做到这一点?
我认为它应该在视图中,但我不太确定,我不认为它可以通过 python.
以简单的方式完成
为了唯一性,我试过这样:
class ResPartner(models.Model):
_name = 'res.partner'
_inherit = 'res.partner'
fields...
methods...
_sql_constraints = [
('vat_company_uniq', 'unique(company_id, vat)', '¡ El RIF debe ser único por compañia !'),
]
但它不起作用,我的意思是,我没有看到,这个字段已经存在于原始对象中,所以如何 "modifiy" 它才能成为 unique
和 mandatory
?
删除 _name = 'res.partner' 并仅使用 _inherit = 'res.partner'.
之后,我们必须在 .py[=24= 中使用 required=True 属性重新声明 vat 字段]边。
_sql_constraints 不错。
重启Odoo服务器并升级你的模块。它会工作正常。
class ResPartner(models.Model):
_inherit = 'res.partner'
vat = fields...(required=True) //just specify the required attributes
# but here i don't think it will work because the framework will not be able
# to add this constrains because it has some duplicated value all ready like null
# in order to make this work you need to run a query to modify old values then restart the server than odoo should be able to add this constraint check log message to see if the constraint is added
_sql_constraints = [
('vat_company_uniq', 'unique(company_id, vat)', '¡ El RIF debe ser único por compañia !'),
]
我继承了res.partner
模型,现在,我想将vat
字段设为required
和unique
。
我知道如何正常执行此操作,例如在新模型上,但我希望原始字段具有这些属性。
我怎样才能做到这一点?
我认为它应该在视图中,但我不太确定,我不认为它可以通过 python.
以简单的方式完成为了唯一性,我试过这样:
class ResPartner(models.Model):
_name = 'res.partner'
_inherit = 'res.partner'
fields...
methods...
_sql_constraints = [
('vat_company_uniq', 'unique(company_id, vat)', '¡ El RIF debe ser único por compañia !'),
]
但它不起作用,我的意思是,我没有看到,这个字段已经存在于原始对象中,所以如何 "modifiy" 它才能成为 unique
和 mandatory
?
删除 _name = 'res.partner' 并仅使用 _inherit = 'res.partner'.
之后,我们必须在 .py[=24= 中使用 required=True 属性重新声明 vat 字段]边。
_sql_constraints 不错。
重启Odoo服务器并升级你的模块。它会工作正常。
class ResPartner(models.Model):
_inherit = 'res.partner'
vat = fields...(required=True) //just specify the required attributes
# but here i don't think it will work because the framework will not be able
# to add this constrains because it has some duplicated value all ready like null
# in order to make this work you need to run a query to modify old values then restart the server than odoo should be able to add this constraint check log message to see if the constraint is added
_sql_constraints = [
('vat_company_uniq', 'unique(company_id, vat)', '¡ El RIF debe ser único por compañia !'),
]