Skip to Content
Odoo Menu
  • Sign in
  • Try it free
  • Apps
    Finance
    • Accounting
    • Invoicing
    • Expenses
    • Spreadsheet (BI)
    • Documents
    • Sign
    Sales
    • CRM
    • Sales
    • POS Shop
    • POS Restaurant
    • Subscriptions
    • Rental
    Websites
    • Website Builder
    • eCommerce
    • Blog
    • Forum
    • Live Chat
    • eLearning
    Supply Chain
    • Inventory
    • Manufacturing
    • PLM
    • Purchase
    • Maintenance
    • Quality
    Human Resources
    • Employees
    • Recruitment
    • Time Off
    • Appraisals
    • Referrals
    • Fleet
    Marketing
    • Social Marketing
    • Email Marketing
    • SMS Marketing
    • Events
    • Marketing Automation
    • Surveys
    Services
    • Project
    • Timesheets
    • Field Service
    • Helpdesk
    • Planning
    • Appointments
    Productivity
    • Discuss
    • Approvals
    • IoT
    • VoIP
    • Knowledge
    • 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 Management
    • Gardening
    • Property Owner Association
    Consulting
    • Accounting Firm
    • Odoo Partner
    • Marketing Agency
    • Law firm
    • Talent Acquisition
    • Audit & Certification
    Manufacturing
    • Textile
    • Metal
    • Furnitures
    • Food
    • Brewery
    • Corporate Gifts
    Health & Fitness
    • Sports Club
    • Eyewear Store
    • Fitness Center
    • Wellness Practitioners
    • Pharmacy
    • Hair Salon
    Trades
    • Handyman
    • IT Hardware & 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
  • Community
    Learn
    • Tutorials
    • Documentation
    • Certifications
    • Training
    • Blog
    • Podcast
    Empower Education
    • Education Program
    • Scale Up! Business Game
    • Visit Odoo
    Get the Software
    • Download
    • Compare Editions
    • Releases
    Collaborate
    • Github
    • Forum
    • Events
    • Translations
    • Become a Partner
    • Services for Partners
    • Register your Accounting Firm
    Get Services
    • Find a Partner
    • Find an Accountant
    • Meet an advisor
    • Implementation Services
    • Customer References
    • Support
    • Upgrades
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Get a demo
  • Pricing
  • Help

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

  • CRM
  • e-Commerce
  • Accounting
  • Inventory
  • PoS
  • Project
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Tags (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Tags (View all)
odoo accounting v14 pos v15
About this forum
Help

create sequence with button to increment it

Subscribe

Get notified when there's activity on this post

This question has been flagged
sequencebutton
4 Replies
2756 Views
Avatar
Oliver

Hello all,

i am new in Odoo and i try my first steps to create a sequece and a button to increment it on button click.

I created my own module and added my files.

Here my files:

debit_card.py

from odoo import models, fields, api, _

class DebitCard(models.Model):
_name="debit.card"
_description="Debit Card"

debit_seq = fields.Char(
string="Debit Card Datev Sequence",
required=True,
copy=False,
readonly=True,
index=True,
default=lambda self: _("New"))

@api.model
def create(self, vals):
if vals.get('debit_seq', _('New')) == _('New'):
vals['debit_seq'] = self.env['ir.sequence'].next_by_code('debit.card.sequence.code') or _('New')
result = super(DebitCard, self).create(vals)
return result

debit_card_view.xml (can´t post correct code. don´t know why...)


        (record id="debit_card_form_view" model="ir.ui.view")
            (field name="name")debit.card.form.view(/field)
            (field name="model")debit.card(/field)
            (field name="arch")type="xml"(/field)
             (form string="Debit Card")
                    (div)Hello World! (/div)
                    (field name="debit_seq" style="font-size:22px;font-weight:bold;"/)
             (/form)
          (/field)
        (/record)
       
   

sequence.xml

(odoo)
(data noupdate="1")
(!-- Sequence for debit.card //--)
(record id="debit_card_datev_sequence" model="ir.sequence")
(field name="name")Debit Card Datev Sequence(/field)
(field name="code")debit.card.sequence.code(/field)
(field name="padding")7(/field)
(field name="number_next")62071(/field)
(field name="number_increment")1(/field)
(field name="company_id" eval="False"/)
(/record)
(/data)
(/odoo)


Now, if i call the debit card it shows me: "Hello World!"

But no sequence but "New"


I found many "examples" on web search but nothing helps me.


Where is the issue for not showing the sequence?

And how to implement a button to increment the sequence on click?

1
Avatar
Discard
Avatar
Mohamed Rizwan
Best Answer

Hi,

you can create a button like

def seq_increment(self):
​for rec in self:
​ ​rec.debit_seq = self.env['ir.sequence'].next_by_code('debit.card.sequence.code')

and xml would like

(record id="debit_card_form_view" model="ir.ui.view")
            (field name="name")debit.card.form.view(/field)
            (field name="model")debit.card(/field)
            (field name="arch")type="xml"(/field)
             (form string="Debit Card")
                    (header)
​ ​ ​ ​ ​(button name="seq_increment" type="object" string="Increment" class="oe_highlight" id="button_seq_increment"/)
​ ​ ​ ​(/header)
             (/form)
          (/field)
        (/record)


thanks

2
Avatar
Discard
Oliver
Author

Thank you very much. It works fine but it doesn`t use the next_number. I changed the field name next_number to next_number_actual because in Settings-Technical-Sequences the field name for the next number is: next_number_actual.
And if i call the "page" debit card first, it always shows "New". Is this because in the field declaration is the default value lambda self: _("New")? If yes, how may i show the current value of the sequence?

Avatar
Niyas Raphy (Walnut Software Solutions)
Best Answer

Hi,
If you already have a sequence record and if you need to increment the sequence value on a button click, inside the button function, you can add below line of code to get next number from the sequence.

Code: self.env['ir.sequence'].next_by_code('code_Value_of_Sequence')


Thanks

0
Avatar
Discard
Avatar
Oliver
Author Best Answer

The titel changed the value after clicking on the "increment button" and i don`t know why.

Can anyone explain me this behavior?

befor click:

after clicked.


0
Avatar
Discard
Mohamed Rizwan

by default, odoo is taking field 'name' as the record name, if your model doesnt have a field called 'name' it will shows as model_name,record_id, in your case it is debit.card,11.

if you need to show any other field as the record name, kindly provide that field in _rec_name after declaring the model name.

ie;
_name = 'debit.card'
_description = 'Debit Card Details'
_rec_name = 'seq_increment'

this will solve your issue.

thanks

Avatar
Cybrosys Techno Solutions Pvt.Ltd
Best Answer

Hi,


You should declare your sequence field in XML view to display it.

Like this, <field name="name"/>



Hope it helps

0
Avatar
Discard
Oliver
Author

The sequence field is declared in the xml view but it displayed always "New".
I need help for adding a button to increment the sequence and update the field output.

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

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

Sign up
Related Posts Replies Views Activity
Sequence Prefix
sequence
Avatar
0
Feb 23
6468
Opening new window with button in OpenERP Solved
button
Avatar
Avatar
1
Jan 24
15323
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
Oct 22
5218
Deleted a sequence
sequence
Avatar
0
Apr 22
3616
Community
  • Tutorials
  • Documentation
  • Forum
Open Source
  • Download
  • Github
  • Runbot
  • Translations
Services
  • Odoo.sh Hosting
  • Support
  • Upgrade
  • Custom Developments
  • Education
  • Find an Accountant
  • Find a Partner
  • Become a Partner
About us
  • Our company
  • Brand Assets
  • Contact us
  • Jobs
  • Events
  • Podcast
  • Blog
  • Customers
  • Legal • Privacy
  • Security
الْعَرَبيّة 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 is a suite of open source business apps that cover all your company needs: CRM, eCommerce, accounting, inventory, point of sale, project management, etc.

Odoo's unique value proposition is to be at the same time very easy to use and fully integrated.

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