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

I don't want to skip sequence when deleting RFQ

Subscribe

Get notified when there's activity on this post

This question has been flagged
purchasesequencepurchase_ordersequencenumber
1 Reply
3266 Views
Avatar
Oyku Muhammed

I have made a customization that when confirming a sale order, an rfq or more to be created automatically, and when SO is cancelled, the RFQs to be deleted


but I don't want to skip the sequence, for example, if the deleted RFQs have P0004_P0005_P0006

I want the next number to be P0004, not P0007
so i tried to update the sequence next_number but didn't work
here is my code and i would appreciate help

def_action_cancel(self):

​res = super(SaleOrder, self)._action_cancel()

​​purchase_orders = self.env['purchase.order'].search([('source_sale_id',  '=', self.id)])

​sequence_code = 'purchase.order'# Update with the correct sequence code
for po in purchase_orders:

​​for order in po:

​ ​for inv in order.invoice_ids:

​ ​ ​ifinvandinv.state notin ('cancel', 'draft'):

​ ​ ​ ​raise UserError(_("Unable to cancel this sale order. You must first cancel the ""vendor bills related to the RFQs."))

​​po_name = po.name 

​po.write({'state': 'cancel', 'mail_reminder_confirmed': False})

​po.unlink()

​​​sequence = self.env['ir.sequence'].search([ ('code', '=', sequence_code), ('company_id', '=', self.env.company.id) ], limit=1)

​if sequence:

​ ​sequence_number = int(po_name.split('/')[-1])

​ ​next_sequence_number = sequence_number - 1

​ ​sequence.sudo().write({'number_next':

​ ​next_sequence_number})sequence.sudo().write({'number_next_actual': next_sequence_number})
return res



0
Avatar
Discard
Lars Aam

Why do you have such a requirement? Why not only cancel the RFQ's and not delete? keep the sequence without any gaps.
Btw. If you set up the MTO process for this, I think the RFQ's will be cancelled automatic, if you cancel the sales order.

Avatar
Niyas Raphy (Walnut Software Solutions)
Best Answer

Hi,

This wont be an easy customization, if you don't want a missing sequence better option is to prevent the deletion of RFQ and keep it in cancelled state. You can add necessary code logic for this.

If you go with what you are looking to achieve now,

Lets say we have a sequence values P0001, P0002 ....... P0005 and as per your code, on deleting a record, you are taking the sequence of the record and trying to update the ir.sequence next number value. Think what if you deleted multiple records from different positions ( 0002 0004) at the same ? The method wont be stable, as next number value will be either 0001 or 0003 in order of deletion.


If you need to really achieve this, try to modify and apply your logic in the place of sequence number assignation for the purchase, instead of calling a new sequence from the sequence record, find missing sequence in existing record and assign it for the new records, this will little heavy as you need to check for missing sequence in each creation.


Also in business perspective, if you share the RFQ with some one, and delete it from the system and later when you assign same sequence to different record, it will bring confusion, if later we look into the system with that reference number.


The ideal solution is to keep in cancelled state.


Additionally, you have option inside the ir.sequence called NO GAP in which if user delete the last record, the new number will be on last deleted sequence.


Update:

currently for the new purchase order the sequence is generated by calling this line of code:  vals['name'] = self_comp.env['ir.sequence'].next_by_code('purchase.order', sequence_date=seq_date) or '/'    from the create function.




So you have to rewrite this create method and instead of calling the next number from ir.sequence, check inside your records for missing numbers, if missing number is found, assign that value for newly created record, and only if the missing number is not found, you can get the next number from ir.sequence.


Thanks

1
Avatar
Discard
Oyku Muhammed
Author

Thank you for your answer.
I have already tried the no gap but it doesn't do the job,
but can you elaborate more on
"If you need to really achieve this, try to modify and apply your logic in the place of sequence number assignation for the purchase, instead of calling a new sequence from the sequence record, find missing sequence in existing record and assign it for the new records, this will little heavy as you need to check for missing sequence in each creation."

because I don't quite get it.
I am very aware that the requirement is not good in business but sometimes clients want what they want, and I already deployed the cancelling, but it wasn't what they need.

Niyas Raphy (Walnut Software Solutions)

see the updated answer

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
edit due date after creating partial purchase order
purchase purchase_order
Avatar
0
May 22
3391
How to change the Quotation, Order, Invoice sequence numbers ? Solved
sequence sequencenumber
Avatar
Avatar
Avatar
2
Dec 23
29949
Purchase prototype products; What´s your solution?
purchase purchase_order
Avatar
0
Jul 24
2452
How to enable Source Document (field label) Origin (field name) Solved
purchase purchase_order
Avatar
Avatar
1
Nov 20
5226
Configuring Purchase Order Form and Report Solved
purchase purchase_order
Avatar
Avatar
1
Oct 20
5736
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