Skip to Content
Odoo Meniu
  • Autentificare
  • Try it free
  • Aplicații
    Finanțe
    • Contabilitate
    • Facturare
    • Cheltuieli
    • Spreadsheet (BI)
    • Documente
    • Semn
    Vânzări
    • CRM
    • Vânzări
    • POS Shop
    • POS Restaurant
    • Abonamente
    • Închiriere
    Site-uri web
    • Constructor de site-uri
    • eCommerce
    • Blog
    • Forum
    • Live Chat
    • eLearning
    Lanț Aprovizionare
    • Inventar
    • Producție
    • PLM
    • Achiziție
    • Maintenance
    • Calitate
    Resurse Umane
    • Angajați
    • Recrutare
    • Time Off
    • Evaluări
    • Referințe
    • Flotă
    Marketing
    • Social Marketing
    • Marketing prin email
    • SMS Marketing
    • Evenimente
    • Automatizare marketing
    • Sondaje
    Servicii
    • Proiect
    • Foi de pontaj
    • Servicii de teren
    • Centru de asistență
    • Planificare
    • Programări
    Productivitate
    • Discuss
    • Aprobări
    • IoT
    • VoIP
    • Knowledge
    • WhatsApp
    Aplicații Terțe Odoo Studio Platforma Odoo Cloud
  • Industrii
    Retail
    • Book Store
    • Magazin de îmbrăcăminte
    • Magazin de Mobilă
    • Magazin alimentar
    • Magazin de materiale de construcții
    • Magazin de jucării
    Food & Hospitality
    • Bar and Pub
    • Restaurant
    • Fast Food
    • Guest House
    • Distribuitor de băuturi
    • Hotel
    Proprietate imobiliara
    • Real Estate Agency
    • Firmă de Arhitectură
    • Construcție
    • Estate Managament
    • Grădinărit
    • Asociația Proprietarilor de Proprietăți
    Consultanta
    • Firma de Contabilitate
    • Partener Odoo
    • Agenție de marketing
    • Law firm
    • Atragere de talente
    • Audit & Certification
    Producție
    • Textil
    • Metal
    • Mobilier
    • Mâncare
    • Brewery
    • Cadouri corporate
    Health & Fitness
    • Club Sportiv
    • Magazin de ochelari
    • Centru de Fitness
    • Wellness Practitioners
    • Farmacie
    • Salon de coafură
    Trades
    • Handyman
    • IT Hardware and Support
    • Asigurare socială de stat
    • Cizmar
    • Servicii de curățenie
    • HVAC Services
    Altele
    • Organizație nonprofit
    • Agenție de Mediu
    • Închiriere panouri publicitare
    • Fotografie
    • Închiriere biciclete
    • Asigurare socială
    Browse all Industries
  • Comunitate
    Învăță
    • Tutorials
    • Documentație
    • Certificări
    • Instruire
    • Blog
    • Podcast
    Empower Education
    • Program Educațional
    • Scale Up! Business Game
    • Visit Odoo
    Obține Software-ul
    • Descărcare
    • Compară Edițiile
    • Lansări
    Colaborați
    • Github
    • Forum
    • Evenimente
    • Translations
    • Devino Partener
    • Services for Partners
    • Înregistrează-ți Firma de Contabilitate
    Obține Servicii
    • Găsește un Partener
    • Găsiți un contabil
    • Meet an advisor
    • Servicii de Implementare
    • Referințe ale clienților
    • Suport
    • Actualizări
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Obține un demo
  • Prețuri
  • Ajutor

Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:

  • CRM
  • e-Commerce
  • Contabilitate
  • Inventar
  • PoS
  • Proiect
  • MRP
All apps
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
All Posts Oameni Insigne
Etichete (View all)
odoo accounting v14 pos v15
Despre acest forum
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
All Posts Oameni Insigne
Etichete (View all)
odoo accounting v14 pos v15
Despre acest forum
Suport

_sql_constraints - how to check in Odoo 7.0(oldAPI) if name already exist - still not done

Abonare

Primiți o notificare când există activitate la acestă postare

Această întrebare a fost marcată
constraintsodoo
8 Răspunsuri
6971 Vizualizări
Imagine profil
Dr Obx

Hi guys,

I'm trying to check if there already is in database brand name ... but it won't work. Would you help me with?

======= c o d e =======

class product_brand(orm.Model):

_name = 'product.brand'

_sql_constraints = [('name_uniq','Check(1=1)','Brand name must be unique!'),]             # is this correct ?

_columns = {

'name': fields.char('Brand'),

'description': fields.text('Description', translate=True),

'partner_id': fields.many2one(

'res.partner',

'partner',

help='Select a partner for this brand if it exists.',

ondelete='restrict'),

'logo': fields.binary('Logo File'),

}

class product_template(orm.Model):

_inherit = 'product.template'

# or should it be placed here ?

_columns = {

'product_brand_id': fields.many2one(

'product.brand',

'Brand', help='Select a brand for this product.', ondelete='restrict'),

}

0
Imagine profil
Abandonează
Imagine profil
Solanki Shamji
Cel mai bun răspuns

May be this will useful to you

_sql_constraints = [

('brand_name_uniq', 'unique(field name)', 'Message you want to display')

]

And define after column definition.

Thanks.

Shamji 

1
Imagine profil
Abandonează
Dr Obx
Autor

Hi Solanki, so would you help me with this problem please ? Just bare in mind i need it for oldAPI. Already know how it works with new one but all my modules were built in old :( and I don't want rebuild whole system yet. Maybe in the future but I'm not ready to use new API :(

Dr Obx
Autor

Hi Solanki, so would you help me with this problem please ? Just bare in mind i need it for oldAPI. Already know how it works with new one but all my modules were built in old :( and I don't want rebuild whole system yet. Maybe in the future but I'm not ready to use new API :(

Imagine profil
Tarek Mohamed Ibrahim
Cel mai bun răspuns

I checked the word commented by Pawan "so first delete any duplicate named records" and tried to apply the constraint after deleting all the records in the table with no success, duplicates are still there. Finally I discovered that I have to DROP the table from the database and reinstall the module again so the constraint can go into the table definition. I added this reply for clarification

0
Imagine profil
Abandonează
Imagine profil
Pawan
Cel mai bun răspuns

Hi Robert,

you can create a sql constraint just using unique(name) as:

_sql_constraints = [('name_uniq', 'unique(name)', 'Brand name must be unique!')]

And keep in mind that there should be no duplicate name already existing in the particular master(table), if it exists then the sql contraint will not apply on that master, so first delete any duplicate named records, and then try updating database again.

Thanks
Pawan


0
Imagine profil
Abandonează
Dr Obx
Autor

I tried but still getting an error :(

Pawan

In your Post down, "unique(brand)" ,brand must be a column in your master, but i can see that in your column list.. Please add a column " brand: fields.char(string = 'Brand'), " and then try to restart ur server by updating module in order to update the database Or if you wan to add unique constraint on product_brand_id you can use: _sql_constraints = [('brand_uniq',unique('product_brand_id'),'Brand name must be unique!'),]

Imagine profil
Dr Obx
Autor Cel mai bun răspuns

So it should be like that:


class product_template(orm.Model):

_inherit = 'product.template'

_sql_constraints = [('brand_uniq',unique('brand'),'Brand name must be unique!'),] # is this correct ? 

_columns = {

'product_brand_id': fields.many2one(

'product.brand',

'Brand', help='Select a brand for this product.', ondelete='restrict'),

}

0
Imagine profil
Abandonează
Enjoying the discussion? Don't just read, join in!

Create an account today to enjoy exclusive features and engage with our awesome community!

Înscrie-te
Related Posts Răspunsuri Vizualizări Activitate
How do I go about this error? I am trying to uninstall a module
odoo
Imagine profil
0
nov. 25
3373
How to import product variants with my own external id when using dynamic creation mode Rezolvat
odoo
Imagine profil
Imagine profil
2
aug. 25
3956
How to import Bulk Image in Product your local database not any cloud, odoo.sh Rezolvat
odoo
Imagine profil
Imagine profil
1
iul. 25
1946
Odoo sh - Connect As
odoo
Imagine profil
1
aug. 25
1154
邮箱无法正常使用
odoo
Imagine profil
0
mai 25
2159
Comunitate
  • Tutorials
  • Documentație
  • Forum
Open Source
  • Descărcare
  • Github
  • Runbot
  • Translations
Servicii
  • Hosting Odoo.sh
  • Suport
  • Actualizare
  • Custom Developments
  • Educație
  • Găsiți un contabil
  • Găsește un Partener
  • Devino Partener
Despre Noi
  • Compania noastră
  • Active de marcă
  • Contactați-ne
  • Locuri de muncă
  • Evenimente
  • Podcast
  • Blog
  • Clienți
  • Aspecte juridice • Confidențialitate
  • Securitate
الْعَرَبيّة Català 简体中文 繁體中文 (台灣) Čeština Dansk Nederlands English Suomi Français Deutsch हिंदी Bahasa Indonesia Italiano 日本語 한국어 (KR) Lietuvių kalba Język polski Português (BR) română русский язык Slovenský jazyk slovenščina Español (América Latina) Español ภาษาไทย Türkçe українська Tiếng Việt

Odoo este o suită de aplicații de afaceri open source care acoperă toate nevoile companiei dvs.: CRM, comerț electronic, contabilitate, inventar, punct de vânzare, management de proiect etc.

Propunerea de valoare unică a Odoo este să fie în același timp foarte ușor de utilizat și complet integrat.

Website made with

Odoo Experience on YouTube

1. Use the live chat to ask your questions.
2. The operator answers within a few minutes.

Live support on Youtube
Watch now