تخطي للذهاب إلى المحتوى
القائمة
لقد تم الإبلاغ عن هذا السؤال
2 الردود
113 أدوات العرض

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?

الصورة الرمزية
إهمال

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/

أفضل إجابة

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

الصورة الرمزية
إهمال
الكاتب أفضل إجابة

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

الصورة الرمزية
إهمال

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

المنشورات ذات الصلة الردود أدوات العرض النشاط
0
أكتوبر 25
441
0
أكتوبر 25
396
2
أكتوبر 25
6076
2
أكتوبر 25
662
2
أكتوبر 25
1021