Ir al contenido
Menú
Se marcó esta pregunta
1 Responder
1075 Vistas

Hello everyone,

I'm currently facing an issue where confirming a sale from the Point of Sale (POS) automatically generates an order picking (outgoing transfer). My requirement is to prevent the creation of the order picking while allowing the rest of the POS workflow to function as expected.


What I’ve Done So Far

To address this, I created a custom module that inherits the pos.order model and overrides the following methods:

  1. _create_order_picking
  2. _process_saved_order
  3. _process_order

Initially, I only overrode the _create_order_picking method. However, the issue persisted because other parts of the POS flow, like _process_saved_order and _process_order, still indirectly triggered the creation of the picking.

from odoo import models, api, _
import logging

class PosOrderInherit(models.Model):
    _inherit = 'pos.order'
    _logger = logging.getLogger(__name__)

    def _create_order_picking(self):
        """
        Avoid the creation of outgoing order pickings.
        """
        self.ensure_one()
        if self.config_id.picking_type_id:
            picking_type = self.config_id.picking_type_id
            self._logger.info(f"Picking type: {picking_type.code}")
            if picking_type.code == 'outgoing':
                self._logger.info("Picking type is outgoing, skipping picking creation.")
                return  # Do nothing, skip creation
        super(PosOrderInherit, self)._create_order_picking()

    def _process_saved_order(self, draft):
        """
        Skip saved order processing for outgoing picking types.
        """
        self.ensure_one()
        if self.config_id.picking_type_id:
            picking_type = self.config_id.picking_type_id
            self._logger.info(f"Processing saved order, picking type: {picking_type.code}")
            if picking_type.code == 'outgoing':
                self._logger.info("Skipping processing of saved order for outgoing type.")
                return self.id  # Return the current order ID
        return super(PosOrderInherit, self)._process_saved_order(draft).id

    @api.model
    def _process_order(self, order, draft, existing_order):
        """
        Skip processing if the picking type is outgoing.
        """
        pos_session = self.env['pos.session'].browse(order['data']['pos_session_id'])
        if pos_session.state in ('closing_control', 'closed'):
            order['data']['pos_session_id'] = self._get_valid_session(order['data']).id

        if order['data'].get('partner_id'):
            partner_id = self.env['res.partner'].browse(order['data']['partner_id'])
            if not partner_id.exists():
                order['data'].update({
                    "partner_id": False,
                    "to_invoice": False,
                })

        pos_order = existing_order or self.create(self._order_fields(order['data']))
        pos_order._link_combo_items(order['data'])
        pos_order = pos_order.with_company(pos_order.company_id)
        self = self.with_company(pos_order.company_id)
        self._process_payment_lines(order['data'], pos_order, pos_session, draft)

        pos_session._remove_capture_content(order['data'])

        if pos_order.config_id.picking_type_id.code == 'outgoing':
            self._logger.info("Order is outgoing. Skipping further processing.")
            return pos_order.id

        return pos_order._process_saved_order(draft).id

The Issue

  1. Despite these changes, the order picking is still being generated under certain conditions.
  2. I’ve confirmed that the overridden methods execute as intended (verified through logs), but the picking still appears.


Question

Is there another part of the POS workflow (or another method) that might be generating the order picking after _process_order and _process_saved_order?

Am I missing something in my approach, or is there a better way to completely skip the creation of the order picking while keeping the POS flow functional?

Any suggestions or insights will be greatly appreciated!

Avatar
Descartar
Mejor respuesta

Hi,
How about changing the product type to service ? will that solve your issue ?

Thanks

Avatar
Descartar
Publicaciones relacionadas Respuestas Vistas Actividad
0
oct 16
4073
1
ago 24
2922
1
ene 25
2785
4
ago 18
5990
1
ago 25
1704