Merge pull request #21065 from marination/bin-requested-qty
fix: Updated Bin Requested Qty logic
This commit is contained in:
commit
d313a239de
@ -661,4 +661,5 @@ erpnext.patches.v12_0.set_job_offer_applicant_email
|
||||
erpnext.patches.v12_0.create_irs_1099_field_united_states
|
||||
erpnext.patches.v12_0.move_bank_account_swift_number_to_bank
|
||||
erpnext.patches.v12_0.rename_bank_reconciliation_fields # 2020-01-22
|
||||
erpnext.patches.v12_0.set_received_qty_in_material_request_as_per_stock_uom
|
||||
erpnext.patches.v12_0.set_received_qty_in_material_request_as_per_stock_uom
|
||||
erpnext.patches.v12_0.recalculate_requested_qty_in_bin
|
||||
|
13
erpnext/patches/v12_0/recalculate_requested_qty_in_bin.py
Normal file
13
erpnext/patches/v12_0/recalculate_requested_qty_in_bin.py
Normal file
@ -0,0 +1,13 @@
|
||||
from __future__ import unicode_literals
|
||||
import frappe
|
||||
from erpnext.stock.stock_balance import update_bin_qty, get_indented_qty
|
||||
|
||||
def execute():
|
||||
bin_details = frappe.db.sql("""
|
||||
SELECT item_code, warehouse
|
||||
FROM `tabBin`""",as_dict=1)
|
||||
|
||||
for entry in bin_details:
|
||||
update_bin_qty(entry.get("item_code"), entry.get("warehouse"), {
|
||||
"indented_qty": get_indented_qty(entry.get("item_code"), entry.get("warehouse"))
|
||||
})
|
@ -276,8 +276,8 @@ class TestMaterialRequest(unittest.TestCase):
|
||||
current_requested_qty_item1 = self._get_requested_qty("_Test Item Home Desktop 100", "_Test Warehouse - _TC")
|
||||
current_requested_qty_item2 = self._get_requested_qty("_Test Item Home Desktop 200", "_Test Warehouse - _TC")
|
||||
|
||||
self.assertEqual(current_requested_qty_item1, existing_requested_qty_item1 + 54.0)
|
||||
self.assertEqual(current_requested_qty_item2, existing_requested_qty_item2 + 3.0)
|
||||
self.assertEqual(current_requested_qty_item1, existing_requested_qty_item1 - 54.0)
|
||||
self.assertEqual(current_requested_qty_item2, existing_requested_qty_item2 - 3.0)
|
||||
|
||||
from erpnext.stock.doctype.material_request.material_request import make_stock_entry
|
||||
|
||||
@ -331,8 +331,8 @@ class TestMaterialRequest(unittest.TestCase):
|
||||
current_requested_qty_item1 = self._get_requested_qty("_Test Item Home Desktop 100", "_Test Warehouse - _TC")
|
||||
current_requested_qty_item2 = self._get_requested_qty("_Test Item Home Desktop 200", "_Test Warehouse - _TC")
|
||||
|
||||
self.assertEqual(current_requested_qty_item1, existing_requested_qty_item1 + 27.0)
|
||||
self.assertEqual(current_requested_qty_item2, existing_requested_qty_item2 + 1.5)
|
||||
self.assertEqual(current_requested_qty_item1, existing_requested_qty_item1 - 27.0)
|
||||
self.assertEqual(current_requested_qty_item2, existing_requested_qty_item2 - 1.5)
|
||||
|
||||
# check if per complete is as expected for Stock Entry cancelled
|
||||
se.cancel()
|
||||
@ -344,8 +344,8 @@ class TestMaterialRequest(unittest.TestCase):
|
||||
current_requested_qty_item1 = self._get_requested_qty("_Test Item Home Desktop 100", "_Test Warehouse - _TC")
|
||||
current_requested_qty_item2 = self._get_requested_qty("_Test Item Home Desktop 200", "_Test Warehouse - _TC")
|
||||
|
||||
self.assertEqual(current_requested_qty_item1, existing_requested_qty_item1 + 54.0)
|
||||
self.assertEqual(current_requested_qty_item2, existing_requested_qty_item2 + 3.0)
|
||||
self.assertEqual(current_requested_qty_item1, existing_requested_qty_item1 - 54.0)
|
||||
self.assertEqual(current_requested_qty_item2, existing_requested_qty_item2 - 3.0)
|
||||
|
||||
def test_completed_qty_for_over_transfer(self):
|
||||
existing_requested_qty_item1 = self._get_requested_qty("_Test Item Home Desktop 100", "_Test Warehouse - _TC")
|
||||
@ -425,8 +425,8 @@ class TestMaterialRequest(unittest.TestCase):
|
||||
current_requested_qty_item1 = self._get_requested_qty("_Test Item Home Desktop 100", "_Test Warehouse - _TC")
|
||||
current_requested_qty_item2 = self._get_requested_qty("_Test Item Home Desktop 200", "_Test Warehouse - _TC")
|
||||
|
||||
self.assertEqual(current_requested_qty_item1, existing_requested_qty_item1 + 54.0)
|
||||
self.assertEqual(current_requested_qty_item2, existing_requested_qty_item2 + 3.0)
|
||||
self.assertEqual(current_requested_qty_item1, existing_requested_qty_item1 - 54.0)
|
||||
self.assertEqual(current_requested_qty_item2, existing_requested_qty_item2 - 3.0)
|
||||
|
||||
def test_incorrect_mapping_of_stock_entry(self):
|
||||
# submit material request of type Transfer
|
||||
@ -512,7 +512,7 @@ class TestMaterialRequest(unittest.TestCase):
|
||||
mr.submit()
|
||||
|
||||
#testing bin value after material request is submitted
|
||||
self.assertEqual(_get_requested_qty(), existing_requested_qty + 54.0)
|
||||
self.assertEqual(_get_requested_qty(), existing_requested_qty - 54.0)
|
||||
|
||||
# receive items to allow issue
|
||||
self._insert_stock_entry(60, 6, "_Test Warehouse - _TC")
|
||||
@ -609,6 +609,8 @@ class TestMaterialRequest(unittest.TestCase):
|
||||
def test_customer_provided_parts_mr(self):
|
||||
from erpnext.stock.doctype.material_request.material_request import make_stock_entry
|
||||
create_item('CUST-0987', is_customer_provided_item = 1, customer = '_Test Customer', is_purchase_item = 0)
|
||||
existing_requested_qty = self._get_requested_qty("_Test Customer", "_Test Warehouse - _TC")
|
||||
|
||||
mr = make_material_request(item_code='CUST-0987', material_request_type='Customer Provided')
|
||||
se = make_stock_entry(mr.name)
|
||||
se.insert()
|
||||
@ -617,7 +619,10 @@ class TestMaterialRequest(unittest.TestCase):
|
||||
self.assertEqual(se.get("items")[0].material_request, mr.name)
|
||||
mr = frappe.get_doc("Material Request", mr.name)
|
||||
mr.submit()
|
||||
current_requested_qty = self._get_requested_qty("_Test Customer", "_Test Warehouse - _TC")
|
||||
|
||||
self.assertEqual(mr.per_ordered, 100)
|
||||
self.assertEqual(existing_requested_qty, current_requested_qty)
|
||||
|
||||
def make_material_request(**args):
|
||||
args = frappe._dict(args)
|
||||
|
@ -113,13 +113,24 @@ def get_reserved_qty(item_code, warehouse):
|
||||
return flt(reserved_qty[0][0]) if reserved_qty else 0
|
||||
|
||||
def get_indented_qty(item_code, warehouse):
|
||||
indented_qty = frappe.db.sql("""select sum((mr_item.qty - mr_item.ordered_qty) * mr_item.conversion_factor)
|
||||
inward_qty = frappe.db.sql("""select sum((mr_item.qty - mr_item.ordered_qty) * mr_item.conversion_factor)
|
||||
from `tabMaterial Request Item` mr_item, `tabMaterial Request` mr
|
||||
where mr_item.item_code=%s and mr_item.warehouse=%s
|
||||
and mr.material_request_type in ('Purchase', 'Manufacture')
|
||||
and mr_item.qty > mr_item.ordered_qty and mr_item.parent=mr.name
|
||||
and mr.status!='Stopped' and mr.docstatus=1""", (item_code, warehouse))
|
||||
|
||||
outward_qty = frappe.db.sql("""select sum((mr_item.qty - mr_item.ordered_qty) * mr_item.conversion_factor)
|
||||
from `tabMaterial Request Item` mr_item, `tabMaterial Request` mr
|
||||
where mr_item.item_code=%s and mr_item.warehouse=%s
|
||||
and mr.material_request_type in ('Material Issue', 'Material Transfer')
|
||||
and mr_item.qty > mr_item.ordered_qty and mr_item.parent=mr.name
|
||||
and mr.status!='Stopped' and mr.docstatus=1""", (item_code, warehouse))
|
||||
|
||||
return flt(indented_qty[0][0]) if indented_qty else 0
|
||||
inward_qty, outward_qty = flt(inward_qty[0][0]) if inward_qty else 0, flt(outward_qty[0][0]) if outward_qty else 0
|
||||
indented_qty = inward_qty - outward_qty
|
||||
|
||||
return indented_qty
|
||||
|
||||
def get_ordered_qty(item_code, warehouse):
|
||||
ordered_qty = frappe.db.sql("""
|
||||
@ -145,9 +156,9 @@ def update_bin_qty(item_code, warehouse, qty_dict=None):
|
||||
from erpnext.stock.utils import get_bin
|
||||
bin = get_bin(item_code, warehouse)
|
||||
mismatch = False
|
||||
for fld, val in qty_dict.items():
|
||||
if flt(bin.get(fld)) != flt(val):
|
||||
bin.set(fld, flt(val))
|
||||
for field, value in qty_dict.items():
|
||||
if flt(bin.get(field)) != flt(value):
|
||||
bin.set(field, flt(value))
|
||||
mismatch = True
|
||||
|
||||
if mismatch:
|
||||
|
Loading…
Reference in New Issue
Block a user