Siirry sisältöön
Menu
Sinun on rekisteröidyttävä, jotta voit olla vuorovaikutuksessa yhteisön kanssa.
Tämä kysymys on merkitty
2 Vastaukset
998 Näkymät

BE: Odoo 16.

FE: React Native


My model:

class Tenant(models.Model):    

​_name = "pma.tenant"   

​ _inherit = ["mail.thread", "mail.activity.mixin", "pm.softdelete"]   

​ _description = "Manager Tenant"    

​_order = "create_date desc"​

​name = fields.Char(string="Tenant Name", required=True)    

​owner = fields.Many2one("res.users", string="Owner", required=True, ​default=lambda self: self.env.user    )
    ​phone = fields.Char(string="Phone Number", required=True)

 

I have sql sentence:     

​ _sql_constraints = [( "phone_uniq",  # unique_key"unique (phone, owner)",            ​"You can not have two tenant with the same phone number !")]

to check: 1 owner -> 1 tenant (not allow the same phone number).


ex: Owner A has Tenant [A (0111222333), B, C, .... ] - Owner B has Tenant [A(0111222333), B, C .....]



In Odoo, it work.

In my app, I want to show  ValidationError, but now it show ( duplicate key value violates unique constraint \"pma_tenant_phone_uniq\" )



Please help me ~~~

Avatar
Hylkää
Tekijä

Thanks. I used but it's not working. I want to show ValidationError in my app. Now, it show: <duplicate key value violates unique constraint "pma_tenant_phone_uniq">.
Just my app, in odoo it's working as expected

Tekijä

In my app, when create Tenant B same phone number with Tenant A, I want to show message (You cannot have two tenants with the same phone number for the same owner!). But now, it just show (<duplicate key value violates unique constraint "pma_tenant_phone_uniq">.). Please helpme

Paras vastaus

Hi
Please check the code below,

_sql_constraints = [
        (
            "phone_owner_uniq",
            "unique (phone, owner)",
            "You cannot have two tenants with the same phone number for the same owner!",
        )
    ]


Hope it helps

Avatar
Hylkää
Tekijä Paras vastaus

Please help me ~~~~

Avatar
Hylkää
Aiheeseen liittyviä artikkeleita Vastaukset Näkymät Toimenpide
0
lokak. 24
1449
0
syysk. 23
2029
1
marrask. 22
5664
1
marrask. 21
2079
1
lokak. 21
3313