继承模型odoov10社区上的必填字段

2024-09-25 00:31:31 发布

您现在位置:Python中文网/ 问答频道 /正文

我继承了res.partner模型,现在,我想将vat字段设置为required和{}。在

我知道如何在正常情况下,例如在一个新模型上,但是我希望原始字段具有这些属性。在

我怎样才能做到这一点?在

我认为应该在视图中显示,但我不太确定,我不认为通过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 !'),
    ]

但它不起作用,我的意思是,我看不到的是,这个字段已经存在于原始对象中,所以如何“修改”它,使其成为unique和{}?在


Tags: 方法模型视图partnermodel属性modelsrequired
2条回答

删除\u name='res.合伙人'并且只使用inherit='res.合伙人'。在

然后,我们必须在.py侧重新声明vat字段,属性为required=True。在

\u sql\u 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 !'),
    ]

相关问题 更多 >