Skip to Content
Odoo Menu
  • Prihlásiť sa
  • Vyskúšajte zadarmo
  • Aplikácie
    Financie
    • Účtovníctvo
    • Fakturácia
    • Výdavky
    • Tabuľka (BI)
    • Dokumenty
    • Podpis
    Predaj
    • CRM
    • Predaj
    • POS Shop
    • POS Restaurant
    • Manažment odberu
    • Požičovňa
    Webstránky
    • Tvorca webstránok
    • eShop
    • Blog
    • Fórum
    • Živý chat
    • eLearning
    Supply Chain
    • Sklad
    • Výroba
    • Správa životného cyklu produktu
    • Nákup
    • Údržba
    • Manažment kvality
    Ľudské zdroje
    • Zamestnanci
    • Nábor zamestnancov
    • Voľné dni
    • Hodnotenia
    • Odporúčania
    • Vozový park
    Marketing
    • Marketing sociálnych sietí
    • Email marketing
    • SMS marketing
    • Eventy
    • Marketingová automatizácia
    • Prieskumy
    Služby
    • Projektové riadenie
    • Pracovné výkazy
    • Práca v teréne
    • Helpdesk
    • Plánovanie
    • Schôdzky
    Produktivita
    • Tímová komunikácia
    • Schvalovania
    • IoT
    • VoIP
    • Znalosti
    • WhatsApp
    Third party apps Odoo Studio Odoo Cloud Platform
  • Industries
    Retail
    • Book Store
    • Clothing Store
    • Furniture Store
    • Grocery Store
    • Hardware Store
    • Toy Store
    Food & Hospitality
    • Bar and Pub
    • Restaurant
    • Fast Food
    • Guest House
    • Beverage distributor
    • Hotel
    Real Estate
    • Real Estate Agency
    • Architecture Firm
    • Construction
    • Estate Managament
    • Gardening
    • Property Owner Association
    Consulting
    • Accounting Firm
    • Odoo Partner
    • Marketing Agency
    • Law firm
    • Talent Acquisition
    • Audit & Certification
    Výroba
    • Textile
    • Metal
    • Furnitures
    • Food
    • Brewery
    • Corporate Gifts
    Health & Fitness
    • Sports Club
    • Eyewear Store
    • Fitness Center
    • Wellness Practitioners
    • Pharmacy
    • Hair Salon
    Trades
    • Handyman
    • IT Hardware and Support
    • Solar Energy Systems
    • Shoe Maker
    • Cleaning Services
    • HVAC Services
    Others
    • Nonprofit Organization
    • Environmental Agency
    • Billboard Rental
    • Photography
    • Bike Leasing
    • Software Reseller
    Browse all Industries
  • Komunita
    Vzdelávanie
    • Tutoriály
    • Dokumentácia
    • Certifikácie
    • Školenie
    • Blog
    • Podcast
    Empower Education
    • Vzdelávací program
    • Scale Up! Business Game
    • Visit Odoo
    Softvér
    • Stiahnuť
    • Porovnanie Community a Enterprise vierzie
    • Releases
    Spolupráca
    • Github
    • Fórum
    • Eventy
    • Preklady
    • Staň sa partnerom
    • Services for Partners
    • Register your Accounting Firm
    Služby
    • Nájdite partnera
    • Nájdite účtovníka
    • Meet an advisor
    • Implementation Services
    • Zákaznícke referencie
    • Podpora
    • Upgrades
    ​Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Získajte demo
  • Cenník
  • Help

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

  • CRM
  • e-Commerce
  • Účtovníctvo
  • Sklady
  • PoS
  • Projektové riadenie
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Tagy (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Tagy (View all)
odoo accounting v14 pos v15
About this forum
Pomoc

How to fix a error with a field unique?

Odoberať

Get notified when there's activity on this post

This question has been flagged
sequenceuniqueres_partner
1 Odpoveď
13922 Zobrazenia
Avatar
Anabela Damas

Hi,

To create a list of clients and suppliers with a sequence number I made like this:

mymodule.py

...
class res_partner(osv.osv):
    _inherit = 'res.partner'
    _name = 'res.partner'

    _columns = {
        'n_client' : fields.char('Client Number', size=64, readonly=True),
        'n_supplier' : fields.char('Supplier Number', size=64, readonly=True),
    }
    _defaults = {
        'n_client': lambda obj, cr, uid, context: '/',
        'n_supplier': lambda obj, cr, uid, context: '/',        
    }
    _sql_constraints = [
        ('name_uniq_1', 'unique(n_client)', 'Number of client must be unique!'),
        ('n_supplier_uniq', 'unique(n_supplier)', 'Number of supplier must be unique!'),        
    ]

    def create(self, cr, uid, vals, context=None):
        if vals.get('n_client','/')=='/':
            vals['n_client'] = self.pool.get('ir.sequence').get(cr, uid, 'res.partner.customer') or '/'     
        if vals.get('n_supplier','/')=='/':
            vals['n_supplier'] = self.pool.get('ir.sequence').get(cr, uid, 'res.partner.supplier') or '/'
        return super(res_partner,self).create(cr, uid, vals, context=context)

    def copy(self, cr, uid, id, default=None, context=None):
        default.update({
            'n_client': self.pool.get('ir.sequence').get(cr, uid, 'res.partner.customer'),
            'n_supplier': self.pool.get('ir.sequence').get(cr, uid, 'res.partner.supplier')
        })
        return super(res_partner, self).copy(cr, uid, id, default, context)
res_partner()
...

mymoodule_sequence.xml

<?xml version="1.0" encoding="utf-8"?>
<openerp>
    <data noupdate="1">
            <record model="ir.sequence.type" id="seq_type_res_partner">
                <field name="name">number_client_sequence</field>
                <field name="code">res.partner.customer</field>
            </record>
            <record model="ir.sequence" id="seq_res_partner">
                <field name="name">number_client_sequence</field>
                <field name="code">res.partner.customer</field>
                <field name="prefix">C</field>
                <field name="padding">5</field>
            </record>
            <record model="ir.sequence.type" id="seq_type_res_supplier">
                <field name="name">number_supplier_sequence</field>
                <field name="code">res.partner.supplier</field>
            </record>
            <record model="ir.sequence" id="seq_res_supplier">
                <field name="name">number_supplier_sequence</field>
                <field name="code">res.partner.supplier</field>
                <field name="prefix">S</field>
                <field name="padding">5</field>
            </record>
    </data>
</openerp>

I get the numbering, but I have this error:

2013-04-15 12:41:07,379 4932 ERROR infinitechoice openerp.sql_db: bad query: ALTER TABLE "res_partner" ADD CONSTRAINT "res_partner_name_uniq_1" unique(n_client)
Traceback (most recent call last):
  File "/opt/openerp-7.0/openerp/sql_db.py", line 227, in execute
    res = self._obj.execute(query, params)
IntegrityError: could not create unique index "res_partner_name_uniq_1"
DETAIL:  Key (n_client)=(/) is duplicated.

2013-04-15 12:41:07,379 4932 WARNING infinitechoice openerp.osv.orm.schema: Table 'res_partner': unable to add 'unique(n_client)' constraint !
 If you want to have it, you should update the records and execute manually:
ALTER TABLE "res_partner" ADD CONSTRAINT "res_partner_name_uniq_1" unique(n_client)
2013-04-15 12:41:07,384 4932 ERROR infinitechoice openerp.sql_db: bad query: ALTER TABLE "res_partner" ADD CONSTRAINT "res_partner_n_supplier_uniq" unique(n_supplier)
Traceback (most recent call last):
  File "/opt/openerp-7.0/openerp/sql_db.py", line 227, in execute
    res = self._obj.execute(query, params)
IntegrityError: could not create unique index "res_partner_n_supplier_uniq"
DETAIL:  Key (n_supplier)=(/) is duplicated.

2013-04-15 12:41:07,384 4932 WARNING infinitechoice openerp.osv.orm.schema: Table 'res_partner': unable to add 'unique(n_supplier)' constraint !
 If you want to have it, you should update the records and execute manually:
ALTER TABLE "res_partner" ADD CONSTRAINT "res_partner_n_supplier_uniq" unique(n_supplier)

Problably I'm doing something wrong, do you know what it is ?

Thanks

0
Avatar
Zrušiť
Avatar
Gustavo
Best Answer

You already have data in the res_partner table, that's why you get the database error. Try removing the data or starting your sequence from a different number than 0

1
Avatar
Zrušiť
Anabela Damas
Autor

So is because of _defaults ? But without having the default value '/' I can get this to work...

Gustavo

check your data first, you already have data on your database. The error is a database error, not an OpenERP error

Anabela Damas
Autor

Yes I've "Your Company" and "Administrator", so I've to change the code to prevent the error... Do you how?

Gustavo

Yes, you need to modify the create and copy functions. When you assign the value to the vals variable, you need to add a constant value (such as 10) that represents the max value of the data already stored in your database

Anabela Damas
Autor

Sorry I didn't understand what you mean.

Anabela Damas
Autor

Thanks I alredy fix this

Enjoying the discussion? Don't just read, join in!

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

Registrácia
Related Posts Replies Zobrazenia Aktivita
how to set unique number?
sequence constraint unique
Avatar
Avatar
1
mar 15
8584
Sequence Prefix
sequence
Avatar
0
feb 23
6149
How to customize the invoice,bill and journal name sequence
sequence
Avatar
0
jan 23
95
What is the best (correct) way to create sequence ? py or xml? Solved
sequence
Avatar
Avatar
1
okt 22
5021
Deleted a sequence
sequence
Avatar
0
apr 22
3447
Komunita
  • Tutoriály
  • Dokumentácia
  • Fórum
Open Source
  • Stiahnuť
  • Github
  • Runbot
  • Preklady
Služby
  • Odoo.sh hosting
  • Podpora
  • Vyššia verzia
  • Custom Developments
  • Vzdelávanie
  • Nájdite účtovníka
  • Nájdite partnera
  • Staň sa partnerom
O nás
  • Naša spoločnosť
  • Majetok značky
  • Kontaktujte nás
  • Pracovné ponuky
  • Eventy
  • Podcast
  • Blog
  • Zákazníci
  • Právne dokumenty • Súkromie
  • Bezpečnosť
الْعَرَبيّة 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 je sada podnikových aplikácií s otvoreným zdrojovým kódom, ktoré pokrývajú všetky potreby vašej spoločnosti: CRM, e-shop, účtovníctvo, skladové hospodárstvo, miesto predaja, projektový manažment atď.

Odoo prináša vysokú pridanú hodnotu v jednoduchom použití a súčasne plne integrovanými biznis aplikáciami.

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