agritheory / beam

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

test: fix net qty and HU tests #117

Closed HKuz closed 1 month ago

HKuz commented 1 month ago

Addresses #98

After rebasing with staging, 4 other tests failed - this uncovered a few areas we needed to adjust either the test or add checks in the code.

Additionally, there was a timing issue on the Stock Entry doc event in hooks. The validate_items_with_handling_unit in validate was throwing errors for missing handlings units when they weren't created yet (that step is done in before_submit via generate_handling_units). I moved the validate function to run AFTER the handling units are generated, now both in the before_submit hook

Net Quantity

For net quantity, the underlying Stock Ledger entries use the transfer_qty field (from the Stock Entry Detail item row) when updating the handling unit's stock_qty. This field gets set and updated in the UI when the qty field changes, so in UI tests to transfer part of an HU, the stock ledger correctly shows net totals. Good news, most of the issue here was tied to fields not being set programmatically in the tests (it's done on a field change in the JS, not server-side), so the main "fix" was to explicitly set a few more fields in the tests.

The failing test had the following issues:

Overconsumption Updates (FOR DISCUSSION):

When the overconsumption code was turned on (uncommented in hooks.py, and tests not skipped), test_handling_units_overconsumption_in_material_transfer_stock_entry failed because it didn't raise the known error. The first issue was that the actual_qty field wasn't being set in the test, which is what the overconsumption check uses to compare to the HU stock_qty. The second issue was that the calc itself didn't catch when the test tried to use 8 units from a HU of 5 units.

Some changes:

Screen shot shows the values for the key fields we're using - when I changed the qty field and re-ran the console, it shows the qty and transfer_qty fields update, the actual_qty field remains the value that was set once the WH was added for the item. I also checked after adding a HU and after hitting save - same result.

Screenshot 2024-05-12 at 3 14 09 PM
HKuz commented 1 month ago

@agritheory sounds good - the ordering I put in here ended up not being necessary (I de-coupled the repack and net qty tests so they weren't interfering). We can safely change/redo the ordering when needed.