Skip to Content
Меню
Вам необхідно зареєструватися, щоб взаємодіяти зі спільнотою.
Це запитання позначене
1 Відповісти
2190 Переглядів

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.

Аватар
Відмінити
Найкраща відповідь

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.

Аватар
Відмінити
Related Posts Відповіді Переглядів Дія
2
груд. 24
5698
0
черв. 22
2128
2
бер. 22
3665
1
лют. 22
2426
2
бер. 21
3617