Skip ke Konten
Menu
Pertanyaan ini telah diberikan tanda
2 Replies
208 Tampilan

Hola, buenas tardes.

Estoy trabajando en Odoo 17 y he desarrollado un botón personalizado en el modelo stock.picking. Al hacer clic en ese botón, se cambia el tipo de operación y se genera automáticamente una transferencia interna hacia una ubicación intermedia de tránsito, por ejemplo: Caracas/Tránsito.

Mi objetivo es que, al activar esta transferencia interna desde el botón personalizado, las cantidades reservadas del producto se reflejen directamente en esa ubicación de tránsito dentro del modelo stock.quant.

Es decir, si los productos originalmente estaban en Caracas/E, al generar esta transferencia interna y presionar el botón, quiero que esas cantidades (en tránsito) aparezcan visibles en stock.quant bajo la ubicación Caracas/Tránsito, como una forma de visualizar que los productos están "en camino" a otro lugar.

Ya tengo configuradas:

  • Las rutas
  • Las ubicaciones

Avatar
Buang
Jawaban Terbai

Hi,

Please refer to the code below:


def custom_button(self):

    """

    Trigger a custom internal transfer from the current location to a transit location.

    This method:

    - Creates an internal stock picking (transfer) for all move lines on the current record.

    - Confirms, assigns, and immediately validates the transfer so that quantities are

      updated in the destination (transit) location's stock.quants.

    Result:

    - Products are shown as "in transit" (i.e., moved to Caracas/Transit).

    - stock.quant reflects the quantities in the transit location.

    Assumptions:

    - `your_module.transit_location_id` and `stock.picking_type_internal` are valid XML IDs.

    - `self.move_ids` contains the stock moves to transfer.

    """

    transit_location = self.env.ref('your_module.transit_location_id')

    picking_type = self.env.ref('stock.picking_type_internal')

    picking = self.env['stock.picking'].create({

        'location_id': self.location_id.id,

        'location_dest_id': transit_location.id,

        'picking_type_id': picking_type.id,

        'move_ids_without_package': [(0, 0, {

            'name': self.name,

            'product_id': line.product_id.id,

            'product_uom_qty': line.product_uom_qty,

            'product_uom': line.product_id.uom_id.id,

            'location_id': self.location_id.id,

            'location_dest_id': transit_location.id,

        }) for line in self.move_ids]

    })

    picking.action_confirm()

    picking.action_assign()

    picking.button_validate()



Hope it helps.

Avatar
Buang
Jawaban Terbai

Está bien, ¿hay algo en lo que pueda ayudarte? ¿Tienes algún problema con tu módulo?

Avatar
Buang