Skip to Content
Odoo Menu
  • Log ind
  • Prøv gratis
  • apps
    Økonomi
    • Bogføring
    • Fakturering
    • Udgifter
    • Regneark (BI)
    • Dokumenter
    • e-Signatur
    Salg
    • CRM
    • Salg
    • POS Butik
    • POS Restaurant
    • Abonnementer
    • Udlejning
    Hjemmeside
    • Hjemmesidebygger
    • e-Handel
    • Blog
    • Forum
    • LiveChat
    • e-Læring
    Forsyningskæde
    • Lagerbeholdning
    • Produktion
    • PLM
    • Indkøb
    • Vedligeholdelse
    • Kvalitet
    HR
    • Medarbejdere
    • Rekruttering
    • Fravær
    • Medarbejdersamtaler
    • Anbefalinger
    • Flåde
    Marketing
    • Markedsføring på sociale medier
    • E-mailmarketing
    • SMS-marketing
    • Arrangementer
    • Automatiseret marketing
    • Spørgeundersøgelser
    Tjenester
    • Projekt
    • Timesedler
    • Udkørende Service
    • Kundeservice
    • Planlægning
    • Aftaler
    Produktivitet
    • Dialog
    • Godkendelser
    • IoT
    • VoIP
    • Vidensdeling
    • WhatsApp
    Tredjepartsapps Odoo Studio Odoo Cloud-platform
  • Brancher
    Detailhandel
    • Boghandel
    • Tøjforretning
    • Møbelforretning
    • Dagligvarebutik
    • Byggemarked
    • Legetøjsforretning
    Mad og værtsskab
    • Bar og pub
    • Restaurant
    • Fastfood
    • Gæstehus
    • Drikkevareforhandler
    • Hotel
    Ejendom
    • Ejendomsmægler
    • Arkitektfirma
    • Byggeri
    • Ejendomsadministration
    • Havearbejde
    • Boligejerforening
    Rådgivning
    • Regnskabsfirma
    • Odoo-partner
    • Marketingbureau
    • Advokatfirma
    • Rekruttering
    • Audit & certificering
    Produktion
    • Tekstil
    • Metal
    • Møbler
    • Fødevareproduktion
    • Bryggeri
    • Firmagave
    Heldbred & Fitness
    • Sportsklub
    • Optiker
    • Fitnesscenter
    • Kosmetolog
    • Apotek
    • Frisør
    Håndværk
    • Handyman
    • IT-hardware og support
    • Solenergisystemer
    • Skomager
    • Rengøringsservicer
    • VVS- og ventilationsservice
    Andet
    • Nonprofitorganisation
    • Miljøagentur
    • Udlejning af billboards
    • Fotografi
    • Cykeludlejning
    • Softwareforhandler
    Gennemse alle brancher
  • Community
    Få mere at vide
    • Tutorials
    • Dokumentation
    • Certificeringer
    • Oplæring
    • Blog
    • Podcast
    Bliv klogere
    • Udannelselsesprogram
    • Scale Up!-virksomhedsspillet
    • Besøg Odoo
    Få softwaren
    • Download
    • Sammenlign versioner
    • Udgaver
    Samarbejde
    • Github
    • Forum
    • Arrangementer
    • Oversættelser
    • Bliv partner
    • Tjenester til partnere
    • Registrér dit regnskabsfirma
    Modtag tjenester
    • Find en partner
    • Find en bogholder
    • Kontakt en rådgiver
    • Implementeringstjenester
    • Kundereferencer
    • Support
    • Opgraderinger
    Github Youtube Twitter LinkedIn Instagram Facebook Spotify
    +1 (650) 691-3277
    Få en demo
  • Prissætning
  • Hjælp

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

  • CRM
  • e-Commerce
  • Bogføring
  • Lager
  • PoS
  • Projekt
  • MRP
All apps
Du skal være registreret for at interagere med fællesskabet.
All Posts People Emblemer
Tags (View all)
odoo accounting v14 pos v15
Om dette forum
Du skal være registreret for at interagere med fællesskabet.
All Posts People Emblemer
Tags (View all)
odoo accounting v14 pos v15
Om dette forum
Hjælp

How do I create a field with a running count?

Tilmeld

Få besked, når der er aktivitet på dette indlæg

Dette spørgsmål er blevet anmeldt
3 Besvarelser
11645 Visninger
Avatar
philjun

In the product.product module, I wish to create a field (or edit an existing field) which displays an unique numeric value for each product. I want the module to automatically keep count and suggest the next number in the series. For instance, when I create a new product, I want the field to be automatically assigned the number '20000', and when I create the next product the number '20001' etc. Is there an easy way to handle this?

2
Avatar
Kassér
Yenthe Van Ginneken (Mainframe Monkey)

Thank you, Nimesh. Do you know if there is a guide to creating and assigning sequences?

Avatar
Anil Kesariya
Bedste svar

Hello philjun,

Here you go!

You need to follow these two steps.

Solution : 1 (In this solution your sequence field will be editable)

Step1 : Add sequence record in your module.


     <!-- Record for your seuqence type -->
        <record id="your_custom_sequence_type" model="ir.sequence.type">
            <field name="name">Label of your sequence code.</field>
            <field name="code">test.test.code</field>   <!-- Unique sequence code.-->
        </record>
        
    <!-- Record for Sequence-->
        <record id="student_reg_sequence" model="ir.sequence">
            <field name="name">Student Unique ID</field>
            <field name="code">test.test.code</field>  <!-- Apply the same you applied above-->
            <field name="prefix">%(year)s/</field> <!-- optional-->
            <field name="suffix">%(month)s/</field> <!-- optional-->
            <field name="number_next_actual">20000</field> <!-- optional, if you not add this field by default 1 will be starting no. -->
            <field name="padding">5</field> <!-- optional-->
            <field name="implementation">no_gap</field>
        </record>


Step 2: Add field in your model, in your case product is model

    _inherit = 'product.product'
    
    _columns = {
    'sequence':fields.char("Sequence")

    }

    _defaults = {
    'sequence':lambda self, cr, uid, context:self.pool.get('ir.sequence').get(cr, uid, 'test.test.code'),

    }


Solution : 2 (If you want to make your sequence field readonly than you can follow this solution.)


Step 1 : This is same as Solution 1.
 
Step 2 : # inherit model and addd field with readonly attribute

    _inherit = 'product.product'
    
    _columns = {
    'sequence':fields.char("Sequence", readonly=True)

    }


    def generate_sequence(self, cr, uid, ids, context=None):
            
        # This line will generate next sequence number from your seuqence.
        next_seq = self.pool.get('ir.sequence').get(cr, uid, 'test.test.code')

        self.write(cr, uid, ids, {'sequence':next_seq}, context=context)

        return True

Step 3: add button in product form


      <button name="generate_sequence" type="object" string="Generate Sequence"/>


There are many more option to create sequence these two solution will satisfied your needs.

Hope this will helps you.

Regards
Anil Kesariya

5
Avatar
Kassér
ABU K

The sequence incrementing 2 ,4 ,6,etc.. .I want to generate 1 ,2 ,3 etc..Then How to change this code

ABU K

Also one more problem is if I am not saving any record its incremented automatically to next id .

Anil Kesariya

check you have applied : no_gap

Anil Kesariya

Once the sequence is generated is will always move to next sequence, so choose the second option generate it on button click and hide the button once it is generated.

ABU K

Here What is the excecution and what is the use of this test.test.code

ABU K

Here What is the excecution flow and what is the use of test.test.code means

Anil Kesariya

it is sequence code, you can give any name here, make sure that code is unique not used for any other sequence.

Avatar
Nimesh
Bedste svar

You can create sequence starting with 20000 and assign to that field.

 

Thanks,

Nimesh.

2
Avatar
Kassér
Avatar
philjun
Forfatter Bedste svar

Thank you, Anil. I have done as specified in option 1, except that I have added the code to the existing product module rather than creating a new module. I have added the field and the default setting to the product.py file.

Regarding step 1, adding the sequence record to the module, I have created the file product_sequence.xml with the xml-code you specified, placed the file in the Product-module-folder, and added this file in the 'data' section of the __openerp__.py-file pertaining to the Product-module. Is it necessary to do something else to add the sequence record? In any case, my sequence is still not working.
 

0
Avatar
Kassér
Enjoying the discussion? Don't just read, join in!

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

Tilmeld dig
Community
  • Tutorials
  • Dokumentation
  • Forum
Open Source
  • Download
  • Github
  • Runbot
  • Oversættelser
Tjenester
  • Odoo.sh-hosting
  • Support
  • Opgradere
  • Individuelt tilpasset udvikling
  • Uddannelse
  • Find en bogholder
  • Find en partner
  • Bliv partner
Om os
  • Vores virksomhed
  • Brandaktiver
  • Kontakt os
  • Stillinger
  • Arrangementer
  • Podcast
  • Blog
  • Kunder
  • Juridiske dokumenter • Privatlivspolitik
  • Sikkerhedspolitik
الْعَرَبيّة 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 er en samling open source-forretningsapps, der dækker alle dine virksomhedsbehov – lige fra CRM, e-handel og bogføring til lagerstyring, POS, projektledelse og meget mere.

Det unikke ved Odoo er, at systemet både er brugervenligt og fuldt integreret.

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