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 to get the next value of a sequence in an Odoo python model

Tilmeld

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

Dette spørgsmål er blevet anmeldt
sequencemodelsequencenumberir.sequence.type
3 Besvarelser
31785 Visninger
Avatar
E.M.

What should be done to get the next free value of a defined sequence inside an Odoo python model's method?

Is there any example somewhere?

I have seen next_by_id and next_by_code methods on ir_sequence.py but I am not sure on how to invoke them (not even sure that they are the right methods to invoke).

I assume that to get the right sequence I have to use: .

 seq_id = self.pool.get('ir.sequence').search(cr, uid, ['TESTSEQ'])

where TESTSEQ is the name of my defined sequence.

0
Avatar
Kassér
Avatar
Emipro Technologies Pvt. Ltd.
Bedste svar

Hi,

You can use both of the method. Please have a look on the below example.


if journal.sequence_id:
    next_number=sequence_obj.next_by_id(cr, uid, journal.sequence_id.id, context=context) # Case 1
else:
    next_number=sequence_obj.next_by_code(cr, uid, 'account.cash.statement', context=context) #Case 2

In above Case 1 : There is sequence is stored inside journal record. So, we can use next_by_id method by providing id of any sequence.

In above Case 2 : There is "next_by_code" method is called. So, inside that method we need to pass code of sequence. In that case "account.cash.statement" is code inside one of the sequence. 

Reference : You can find out about line of code inside point_of_sale => wizard => pos_open_statement.py file.

I think now you will know how to do it.

 

4
Avatar
Kassér
E.M.
Forfatter

Maybe I did not properly understand sequences. I want to create a sequence to generate consecutive numbers each time a product is generated (ultimate goal is to generate EAN13 codes for products, but I am just starting from the basics being able to print sequence numbers with PRINT). I have created a new sequence in the GUI (Configuration -> Sequences and IDs -> Sequences), -sure it has to be done via XML in the module, but just trying to understand the basics here-. Do I have to create both a sequence and a secuence code? What are they each of those ones used for? Also, as per below answer, it seems that cr and uid, do not apply in this case (it is api.model), how next_by_id and next_by_code should be used? Thanks,

E.M.
Forfatter

I finally found that what I was looking for was _next() method. I also found that I have to create both a sequence and a sequence type and search by sequence type identifier.

Avatar
E.M.
Forfatter Bedste svar

This is probably a quite basic question, but while trying to get the sequence ID:

seq_id = self.pool.get('ir.sequence').search(cr, uid, ['TESTSEQ'])

I get global name 'cr' not defined.

Is the search method properly invoked?


Complete code:

# -*- coding: utf-8 -*-

from openerp import models, fields, api

class EanAuto ( models.Model ):

        _inherit = 'product.product'

 

        @api.model

        def create(self, vals):

                print "DEBUG: CREATE 1"

                seq_id = self.pool.get('ir.sequence').search(cr, uid, ['TESTSEQ'])

                print seq_id

                seq_id._next

                new_product = super(EanAuto, self).create(vals)

                print "DEBUG: CREATE 2"

                return new_product

1
Avatar
Kassér
Emipro Technologies Pvt. Ltd.

You have used @api.model decorator. So, you do not need to pass cr, uid in search method. (Directly cr, uid is not available). You need to call search as like self.env['ir.sequence'].search([('code','=','TESTSEQ')]). I hope you can get this.

E.M.
Forfatter

That solution works, thanks.

Avatar
Sadok Abouda
Bedste svar

the latest sequence value is returned by using this:

last_seq = env['your_model'].search([], order='sequence ASC')[-1].sequence
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
Related Posts Besvarelser Visninger Aktivitet
How to change the Quotation, Order, Invoice sequence numbers ? Løst
sequence sequencenumber
Avatar
Avatar
Avatar
2
dec. 23
30005
Production Sequence error
manufacturing sequence sequencenumber
Avatar
Avatar
Avatar
2
okt. 25
486
Odoo Sequence Issue Across Multiple Companies
sequence sequencenumber sequences
Avatar
0
jan. 25
2129
How to correct wrong invoice sequence?
invoice sequence sequencenumber
Avatar
Avatar
3
jul. 23
6097
How to include Date in the journal sequence
sequence journals sequencenumber
Avatar
Avatar
1
okt. 22
4074
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