Currently, the Backorder created takes the next Delivery Order number. But I want it to be numbered as the created Delivery Order number plus a "-1" behind (Same as OpenERP(Odoo) V7.
E.g. I'm validating the Delivery Order number D000903, and there's a backorder that need to be created. Once I click Create Backorder, I want the backorder number to be D000903-1, instead of the next delivery order number D000904.
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
This question has been flagged
you can override the default behavior by implementing a custom method. Here's an example of how you can achieve this:
from odoo import models, fields, api
class StockPicking(models.Model):
_inherit = 'stock.picking'
@api.model
def create_backorder(self):
"""Override create_backorder method to customize backorder numbering"""
res = super(StockPicking, self).create_backorder()
# Get the original delivery order
original_order = self.env['stock.picking'].browse(res['res_id'])
# Get the original delivery order number
original_order_number = original_order.name
# Split the number to extract the prefix and suffix
prefix, suffix = original_order_number.rsplit('-', 1) if '-' in original_order_number else (original_order_number, '')
# Increment the suffix by 1
new_suffix = int(suffix) + 1
# Create the new backorder number
backorder_number = f'{prefix}-{new_suffix}' if suffix else f'{original_order_number}-{new_suffix}'
# Update the backorder with the new number
backorder = self.env['stock.picking'].browse(res['context']['active_id'])
backorder.name = backorder_number
return res
In this code, we override the create_backorder method in the stock.picking model. We retrieve the original delivery order number and split it into the prefix and suffix parts. We increment the suffix by 1 and create the new backorder number by combining the prefix and the incremented suffix. Finally, we update the backorder record with the new number.
Enjoying the discussion? Don't just read, join in!
Create an account today to enjoy exclusive features and engage with our awesome community!
Sign upRelated Posts | Replies | Views | Activity | |
---|---|---|---|---|
|
2
Dec 24
|
5693 | ||
|
0
Jun 22
|
2126 | ||
|
2
Mar 22
|
3663 | ||
|
1
Feb 22
|
2426 | ||
|
2
Mar 21
|
3617 |