Ir al contenido
Menú
Se marcó esta pregunta

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.

Avatar
Descartar
Mejor respuesta

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.

Avatar
Descartar
Publicaciones relacionadas Respuestas Vistas Actividad
2
dic 24
5696
0
jun 22
2127
2
mar 22
3663
1
feb 22
2426
2
mar 21
3617