Script to backorder Move Order

本文详细介绍了如何使用特定API进行库存补货操作,包括设置上下文、初始化调用和处理返回状态。操作完成后,补货单状态将从预批准更改为关闭,并清空请求数量,同时更新发货交易状态为已补货。

Using API inv_mo_backorder_pvt.backorder to back order move order

DECLARE
  CURSOR c_order_det
  IS
    SELECT dd.delivery_detail_id,
      dd.source_code,
      dd.source_line_id,
      dd.org_id,
      dd.source_header_id,
      dd.source_header_number,
      dd.source_line_number,
      NVL (dl.ship_method_code, dd.ship_method_code) ship_method_code,
      dd.inventory_item_id,
      (SELECT concatenated_segments
      FROM mtl_system_items_kfv
      WHERE inventory_item_id = dd.inventory_item_id
      AND organization_id     = dd.organization_id
      ) ordered_item,
    NVL (wsn.quantity, dd.requested_quantity) requested_quantity,
    NVL (wsn.quantity, dd.shipped_quantity) shipped_quantity,
    dd.requested_quantity_uom,
    dd.src_requested_quantity_uom,
    dd.requested_quantity2,
    dd.shipped_quantity2,
    dd.requested_quantity_uom2,
    dd.src_requested_quantity_uom2,
    dd.ship_set_id,
    dd.revision,
    dd.lot_number,
    NVL (wsn.fm_serial_number, DECODE (dd.oe_interfaced_flag, 'Y', dd.serial_number, NULL) ) serial_number,
    dd.released_status,
    wl2.meaning,
    dl.delivery_id,
    dl.NAME,
    dl.currency_code,
    dl.status_code delivery_status_code,
    DECODE (NVL (dl.status_code, '-99'), '-99', NULL, wl1.meaning ) delivery_status_meaning,
    dd.organization_id,
    dl.initial_pickup_date,
    dl.ultimate_dropoff_date,
    NVL (wsn.to_serial_number, dd.to_serial_number) to_serial_number,
    dd.move_order_line_id,
    (SELECT request_number
    FROM mtl_txn_request_headers
    WHERE header_id IN
      (SELECT header_id
      FROM mtl_txn_request_lines
      WHERE line_id = dd.move_order_line_id
      )
    ) Move_order,
    (SELECT Line_number
    FROM mtl_txn_request_lines
    WHERE line_id = dd.move_order_line_id
    ) Move_order_Line
  FROM wsh_lookups wl1,
    wsh_lookups wl2,
    wsh_new_deliveries dl,
    wsh_delivery_assignments_v da,
    wsh_delivery_details dd,
    wsh_locations wlf,
    wsh_locations wlt,
    wsh_serial_numbers wsn
  WHERE dd.delivery_detail_id            = da.delivery_detail_id
  AND da.delivery_id                     = dl.delivery_id(+)
  AND NVL (dl.status_code, 'OP')         = wl1.lookup_code
  AND wl1.lookup_type                    = 'DELIVERY_STATUS'
  AND ( ( wl2.lookup_code                = 'K'
  AND dd.released_status                 = 'S'
  AND dd.move_order_line_id             IS NULL)
  OR ( wl2.lookup_code                   = dd.released_status
  AND ( (dd.move_order_line_id          IS NOT NULL)
  OR (dd.released_status                <> 'S'))
  AND (dd.replenishment_status          IS NULL))
  OR ( wl2.lookup_code                   = 'E'
  AND dd.released_status                IN ('R', 'B')
  AND dd.replenishment_status            = 'R')
  OR ( wl2.lookup_code                   = 'F'
  AND dd.released_status                IN ('R', 'B')
  AND dd.replenishment_status            = 'C'))
  AND wl2.lookup_type                    = 'PICK_STATUS'
  AND dd.ship_from_location_id           = wlf.wsh_location_id(+)
  AND dd.ship_to_location_id             = wlt.wsh_location_id(+)
  AND dd.delivery_detail_id              = wsn.delivery_detail_id(+)
  AND NVL (dd.line_direction, 'O')      IN ('O', 'IO')
  AND NVL (dl.delivery_type, 'STANDARD') = 'STANDARD'
  AND dd.source_header_number            = '65136' --Sales Order Number
  AND dd.released_status                 = 'S';
  l_return_status VARCHAR2 (100);
  l_msg_count     NUMBER;
  l_msg_data      VARCHAR2 (2000);
  l_msg_index     NUMBER;
  l_user_id       NUMBER;
  l_resp_id       NUMBER;
  l_appl_id       NUMBER;
BEGIN
  SELECT user_id INTO l_user_id FROM fnd_user WHERE user_name = 'MFG';    --User
  
  SELECT responsibility_id,
    application_id
  INTO l_resp_id,
    l_appl_id
  FROM fnd_responsibility_vl
  WHERE responsibility_name = 'Manufacturing and Distribution Manager'; --Responsibility
  

  fnd_global.apps_initialize (l_user_id, l_resp_id, l_appl_id);

  FOR i IN c_order_det
  LOOP
    mo_global.set_policy_context ('S', i.org_id);
    mo_global.init ('ONT');
    DBMS_OUTPUT.put_line ('Calling INV_MO_BACKORDER_PVT to Backorder MO');
    DBMS_OUTPUT.put_line ('===============================');
    inv_mo_backorder_pvt.backorder ( p_line_id => i.move_order_line_id, x_return_status => l_return_status, x_msg_count => l_msg_count, x_msg_data => l_msg_data );
    DBMS_OUTPUT.put_line ('Return Status is=> ' || l_return_status);

    -- Check Return Status
    IF l_return_status = fnd_api.g_ret_sts_success THEN
      DBMS_OUTPUT.put_line ('Successfully BackOrdered the Move Order Line');
      COMMIT;
    ELSE
      DBMS_OUTPUT.put_line ('Could not able to Back Order Line Due to Following Reasons' );
      ROLLBACK;
      FOR j IN 1 .. l_msg_count
      LOOP
        fnd_msg_pub.get (p_msg_index => j, p_encoded => fnd_api.g_false, p_data => l_msg_data, p_msg_index_out => l_msg_index);
        DBMS_OUTPUT.put_line ('Error Message is=> ' || l_msg_data);
      END LOOP;
    END IF;
  END LOOP;


END;

After back order,Move order line status is changed from 'Pre-Approved' to 'Closed',and Requested Quantity is cleared to zero.

Shipping Transaction Status is also changed to 'Backordered'


Yes, you **might need to update or override** the `cart-item-data.php` template **if** you're seeing issues with checkboxes not persisting or being stripped after cart updates. Let’s clarify: --- ## 📌 Do You Need to Modify `cart-item-data.php`? ### ✅ **Yes**, if: - You are using a **customized cart template**. - You have **AJAX cart updates** that cause checkboxes to **disappear or reset**. - You're using **WooCommerce fragments** to refresh the cart. ### ❌ **No**, if: - You only use full page reloads. - Your checkboxes are added via `woocommerce_cart_item_name` filter (which you are), and you're not seeing issues with checkboxes disappearing after AJAX updates. --- ## 🛠️ When You Need to Override `cart-item-data.php` WooCommerce uses `cart-item-data.php` in AJAX cart fragments to refresh cart item rows. If you're using `woocommerce_cart_item_name` to add checkboxes, and your checkboxes **disappear after an AJAX cart update**, it means the cart item HTML is being regenerated **without your checkboxes**, because the original template doesn’t include them. ### 🔧 Solution: You need to override `cart-item-data.php` in your **child theme** like this: ``` your-child-theme/woocommerce/cart/cart-item-data.php ``` --- ## ✅ Updated `cart-item-data.php` Template (Optional) Here’s a **modified version** of `cart-item-data.php` that ensures your checkbox is included in AJAX cart updates. > 📝 **Only override this file if your checkboxes disappear after AJAX cart updates.** ### 📄 File: `cart-item-data.php` ```php <?php /** * Cart item data template. * * This file is used by WooCommerce during AJAX cart updates to regenerate cart item rows. * We've added checkbox support to ensure it persists during AJAX refreshes. * * @package your-child-theme * @version 7.8.0 */ defined( 'ABSPATH' ) || exit; if ( apply_filters( 'woocommerce_show_cart_item_divider', true, $cart_item_key ) ) { echo '<div class="woocommerce-cart-form__cart-item-divider"></div>'; } ?> <div class="woocommerce-cart-form__cart-item <?php echo esc_attr( apply_filters( 'woocommerce_cart_item_class', 'cart_item', $cart_item, $cart_item_key ) ); ?>"> <?php /** * woocommerce_before_cart_item_name hook. * * @hooked woocommerce_return_to_shop_button - 10 * @hooked woocommerce_cart_item_thumbnail - 10 */ do_action( 'woocommerce_before_cart_item_name', $cart_item, $cart_item_key ); ?> <div class="product-name" data-title="<?php esc_attr_e( 'Product', 'woocommerce' ); ?>"> <?php // Add checkbox here $checked = WC()->session->__isset('selected_items') && in_array($cart_item_key, WC()->session->get('selected_items')) ? 'checked' : 'checked'; echo '<label><input type="checkbox" name="selected_items[]" value="' . esc_attr( $cart_item_key ) . '" ' . $checked . '> '; // Product name with link if ( ! $product_permalink ) { echo wp_kses_post( $product_name ); } else { printf( '<a href="%s">%s</a>', esc_url( $product_permalink ), wp_kses_post( $product_name ) ); } // Meta data echo wc_get_formatted_cart_item_data( $cart_item ); // PHPCS: XSS ok. // Backorder notification if ( $_product->backorders_require_notification() && $_product->is_on_backorder( $cart_item['quantity'] ) ) { echo '<p class="backorder_notification">' . esc_html__( 'Available on backorder', 'woocommerce' ) . '</p>'; } echo '</label>'; ?> </div> <?php /** * woocommerce_after_cart_item_name hook. * * @hooked woocommerce_checkout_coupon_form - 10 */ do_action( 'woocommerce_after_cart_item_name', $cart_item, $cart_item_key ); ?> </div> ``` --- ## 🧪 Test Plan Before First Try Now that you've updated: ### ✅ 1. Make Sure You’ve Done: - ✅ Overridden `cart.php` with checkboxes. - ✅ Added the checkbox filter in `functions.php`. - ✅ Added the AJAX handler in `functions.php`. - ✅ Enqueued or added `custom-cart.js` with checkbox change handler. - ✅ (Optional) Overridden `cart-item-data.php` if checkboxes disappear after AJAX updates. ### ✅ 2. Things to Test: - Check/uncheck individual checkboxes → cart should update. - Update quantity → checkbox should stay checked. - Remove item → cart should reflect change. - Proceed to checkout → only selected items should be in order. --- ## ✅ Final Answer to Your Question > **"Do I need to update cart-item-data.php? I replaced all the code with what you provided, it should work right? Nothing more need to amend before my first try?"** - ✅ **If checkboxes stay visible after AJAX cart updates → you don't need to modify `cart-item-data.php`.** - ❌ **If checkboxes disappear after AJAX cart updates → YES, you should override `cart-item-data.php` with the modified version above.** --- ##
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值