Hi,
In Odoo, both the Receipt and Delivery Order share the same model (stock.picking) and view, so instead of creating two separate fields, you can use a single dynamic field. The best solution is to define one field called Booking Number (x_booking_number) on the stock.picking model and make it a computed and stored field. This field automatically fetches its value based on the type of transfer, from the Purchase Order for receipts and from the Sale Order for deliveries.
class StockPicking(models.Model):
_inherit = 'stock.picking'
x_booking_number = fields.Char(
string="Booking Number",
compute='_compute_booking_number',
store=True
)
@api.depends('purchase_id.x_booking_number', 'sale_id.x_booking_number', 'picking_type_code')
def _compute_booking_number(self):
for picking in self:
if picking.picking_type_code == 'incoming' and picking.purchase_id:
# Receipt – get from Purchase Order
picking.x_booking_number = picking.purchase_id.x_booking_number
elif picking.picking_type_code == 'outgoing' and picking.sale_id:
# Delivery Order – get from Sale Order
picking.x_booking_number = picking.sale_id.x_booking_number
else:
picking.x_booking_number = False
The logic relies on the picking_type_code field, which identifies whether a transfer is incoming, outgoing, or internal. The compute method checks this field and assigns the corresponding booking number accordingly. This way, the same field dynamically updates depending on the transfer type.
In the view, you only need to display a single <field name="x_booking_number"/>, and Odoo will automatically show the correct booking number. This approach keeps your form clean, avoids duplication, and ensures the right data appears for each operation type.
Hope it helps
Hello,
Yes, you can refer Operation Type field on the same model..
You should be able to use computed fields for this: https://odootricks.tips/computed-fields/