agritheory / beam

General Purpose 2D barcode scanning for ERPNext
https://agritheory.com/documentation/beam/
Other
20 stars 9 forks source link

Handling Unit not tracking with certain material transfer-type stock entries #49

Closed HKuz closed 10 months ago

HKuz commented 11 months ago

Creating Stock Entries of type Material Transfer for Manufacture (off a work order) and a plain Material Transfer, the stock ledger entries didn't show the handling unit for any of the items moved. (Screen shot shows one example). Both stock entries moved quantities less than the full handling unit qty.

Expected behavior:

Screenshot 2023-07-17 at 6 12 41 PM
HKuz commented 11 months ago

@fproldan @agritheory - in testing my code changes for this issue, I made the following tweaks to the over-consumption validation code below. This checks that the doc's row qty is not larger than the qty in the HU, within "precision" decimal accuracy:

        if doc.doctype == "Stock Entry":
        # qty_field = "actual_qty"  # Changed to transfer_qty EDIT: actual_qty is total qty available for item in given WH (checks source WH, if not defined uses target WH)
        qty_field = "transfer_qty"
    else:
        qty_field = "stock_qty"

        # [...  other code in for loop]
                #  New error check:
                precision = int(frappe.get_precision(row.doctype, qty_field))
        if row.get(qty_field) - hu.stock_qty > 1 / (10**precision):
            frappe.throw(
                _(f"Row #{row.idx}: the Handling Unit for Item {row.item_code} has qty of {hu.stock_qty}.")
            )

Here's the example in inventory_tools that checks for float equality (within "precision" decimal accuracy). In this case, the precision was 3, so the absolute difference can't be more than 0.001.

precision = int(frappe.get_precision("Purchase Order Item", "stock_qty"))
diff = abs(items_fg_qty - subc_fg_qty)
if diff > (1 / (10**precision)):
    # ...

I'll add human-readable comment explanations in both areas.

agritheory commented 10 months ago

This problem is in scope of the larger net quantity issue. We will want a test that addresses this case specifically to make sure there's no regression.

agritheory commented 10 months ago

Resolved with #63