Skip to Content
Menu
This question has been flagged
2 Replies
187 Zobrazenia

I created a new field called Booking Number on the Receipt form.

This field is related to the Booking Number of the Purchase Order through the related field: purchase_id.x_booking_number.

After that, I wanted to create another Booking Number field on the Delivery Order form to link it with the Booking Number of the Sale Order.

However, I discovered that the Receipt and Delivery Order share the same view in Odoo.

I don’t want to have two separate Booking Number fields on this shared interface.

Is there a way to make the same Booking Number field dynamically receive the value from either the Purchase Order or the Sale Order, depending on the type of transfer?

Avatar
Zrušiť

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/

Best Answer

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

Avatar
Zrušiť
Autor Best Answer

can i try it by develovper mode or odoo studio, I am using the Odoo online version so I can't code

Avatar
Zrušiť

If you have installed the studio app then try to edit the action view.. I've not much knowledge about the studio customization.

Related Posts Replies Zobrazenia Aktivita
0
okt 25
452
0
okt 25
410
2
okt 25
6139
2
okt 25
679
2
okt 25
1069