簡體   English   中英

繼承模型的必填字段-Odoo v10社區

[英]Mandatory field on inherited model - Odoo v10 community

我繼承了res.partner模型,現在,我想根據requiredunique來制作vat字段。

我知道如何正常工作,例如在新模型上,但是我希望原始字段具有這些屬性。

我該如何實現?

我認為應該在視圖上,但是我不太確定,我不認為可以通過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且具有mandatory

刪除_name ='res.partner'並僅使用_inherit ='res.partner'

之后,我們必須在.py端重新聲明具有required = True屬性的增值稅字段。

_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 !'),
    ]

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM