Overslaan naar inhoud
Menu
Je moet geregistreerd zijn om te kunnen communiceren met de community.
Deze vraag is gerapporteerd
1 Beantwoorden
1048 Weergaven

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
Annuleer
Beste antwoord

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

Thanks

Avatar
Annuleer
Gerelateerde posts Antwoorden Weergaven Activiteit
0
okt. 16
4025
1
aug. 24
2884
1
jan. 25
2773
4
aug. 18
5985
2
aug. 25
123