fix: incorrect logic for "Reserved Qty for Production" (#28880)

* fix: reservation for production incorrect

The query uses case to decide what fields to compute reservation on,
this case is outermost case hence the very first Work order's "Skip
transfer" is considered for ALL work orders.

Solution: move the case inside Sum.

Steps to reproduce:
1. Make work order for more than 1 qty (with | without skip transfer)
2. Create manufacture and transfer entries.
3. Keep checking reserved quantities during this process.

* test: use default warehouse for testing reservation
This commit is contained in:
Ankush Menat 2021-12-14 17:02:42 +05:30 committed by GitHub
parent 304aa44feb
commit 80f1a8c645
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 4 deletions

View File

@ -95,7 +95,7 @@ class TestWorkOrder(ERPNextTestCase):
def test_reserved_qty_for_partial_completion(self):
item = "_Test Item"
warehouse = create_warehouse("Test Warehouse for reserved_qty - _TC")
warehouse = "_Test Warehouse - _TC"
bin1_at_start = get_bin(item, warehouse)

View File

@ -43,9 +43,9 @@ class Bin(Document):
frappe.qb
.from_(wo)
.from_(wo_item)
.select(Case()
.when(wo.skip_transfer == 0, Sum(wo_item.required_qty - wo_item.transferred_qty))
.else_(Sum(wo_item.required_qty - wo_item.consumed_qty))
.select(Sum(Case()
.when(wo.skip_transfer == 0, wo_item.required_qty - wo_item.transferred_qty)
.else_(wo_item.required_qty - wo_item.consumed_qty))
)
.where(
(wo_item.item_code == self.item_code)