Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Keep backorders when splitting part of variant to new shipment with same SL #5670

Open
wants to merge 10 commits into
base: main
Choose a base branch
from

Commits on Mar 7, 2024

  1. Configuration menu
    Copy the full SHA
    319cb6e View commit details
    Browse the repository at this point in the history
  2. Move let statements inside context block

    These are already overridden in all other first-level context blocks
    so it makes sense to move them in the single block that relies on
    these values.
    spaghetticode committed Mar 7, 2024
    Configuration menu
    Copy the full SHA
    9062828 View commit details
    Browse the repository at this point in the history
  3. Extract shared examples

    Also, a couple of useless `let!` are removed (these records already
    exist).
    spaghetticode committed Mar 7, 2024
    Configuration menu
    Copy the full SHA
    57c62ab View commit details
    Browse the repository at this point in the history
  4. Reuse existing shared example

    The removed spec can be replaced by the shared example, which
    includes one further test so it slightly improves coverage.
    spaghetticode committed Mar 7, 2024
    Configuration menu
    Copy the full SHA
    2ff1bf4 View commit details
    Browse the repository at this point in the history
  5. Reuse existing let value

    This helps keeping things in sync just in the case that numbers
    change.
    spaghetticode committed Mar 7, 2024
    Configuration menu
    Copy the full SHA
    0d1e747 View commit details
    Browse the repository at this point in the history
  6. Extract shared example for later reuse

    These specs don't really require a specific first level scenario,
    so we're first extracting them to a shared example, and with the
    following commit we're going to use it in other existing scenarios.
    spaghetticode committed Mar 7, 2024
    Configuration menu
    Copy the full SHA
    0079208 View commit details
    Browse the repository at this point in the history
  7. Rework and reuse inventory units shared example

    The existing scenario is reworked in order to expose an issue
    when moving a few items of a variant (not all of them) to a
    shipment with same stock location as the original one.
    spaghetticode committed Mar 7, 2024
    Configuration menu
    Copy the full SHA
    67e609b View commit details
    Browse the repository at this point in the history
  8. Refactor Quantifier initialization

    This is propedeutic for the following commit.
    spaghetticode committed Mar 7, 2024
    Configuration menu
    Copy the full SHA
    0524dcd View commit details
    Browse the repository at this point in the history
  9. Add Quantifier#positive_stock method

    When the quantifier is initialized with a stock location or its ID,
    the new method returns the positive amount of stock on hand or zero,
    if the stock for the variant is negative. Otherwise, it returns nil.
    spaghetticode committed Mar 7, 2024
    Configuration menu
    Copy the full SHA
    2e17aeb View commit details
    Browse the repository at this point in the history
  10. Properly calculate inventory item quantities to be moved

    The backordered quantity count should differ depending on whether
    moving to the same or a different stock location. For this reason,
    the way we calculate `available_quantity` changes as follows:
    
    * when the stock location differs:
      the stock on hand at the new shipment stock location;
    * when the stock location is the same:
      the sum of the stock on hand at the shipment stock location
      plus the number of on_hand inventory items from the shipment
    
    The explicit `backordered_quantity` variable is introduced to track
    the number of backordered items for the target shipment. The value
    is calculated as follows:
    
    * when the stock location differs:
      the quantity to be moved minus the positive available quantity at
      the stock location;
    * when the stock location is the same:
      the shipment total quantity for the variant minus the positive
      available quantity at the stock location.
    
    Also, we start the process by moving backordered items first to
    to make sure no pending backordered item remains. If the backordered
    count decreased, we're going to leave a few to be later moved and
    transformed to on hand, while if the backordered count increased, we
    are going to move also some previously on hand items.
    spaghetticode committed Mar 7, 2024
    Configuration menu
    Copy the full SHA
    a1bb98e View commit details
    Browse the repository at this point in the history