Fixed logic for reserved qty for subcontract and production and written a patch (#13396)

* Fixed logic for reserved qty for subcontract and production and written a patch

* repost reserved qty for filtered bins
This commit is contained in:
Nabin Hait 2018-03-27 11:24:20 +05:30 committed by GitHub
parent 398eac3f4c
commit 651b612909
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 41 additions and 4 deletions

View File

@ -497,4 +497,5 @@ erpnext.patches.v10_0.update_warehouse_address_details
erpnext.patches.v10_0.update_reserved_qty_for_purchase_order
erpnext.patches.v10_0.update_hub_connector_domain
erpnext.patches.v10_0.set_student_party_type
erpnext.patches.v10_0.update_project_in_sle
erpnext.patches.v10_0.update_project_in_sle
erpnext.patches.v10_0.fix_reserved_qty_for_sub_contract

View File

@ -0,0 +1,29 @@
# Copyright (c) 2017, Frappe and Contributors
# License: GNU General Public License v3. See license.txt
from __future__ import unicode_literals
import frappe
from erpnext.stock.utils import get_bin
def execute():
for d in frappe.db.sql("""
select distinct rm_item_code, reserve_warehouse
from `tabPurchase Order Item Supplied`
where docstatus=1 and reserve_warehouse is not null and reserve_warehouse != ''"""):
try:
bin_doc = get_bin(d[0], d[1])
bin_doc.update_reserved_qty_for_sub_contracting()
except:
pass
for d in frappe.db.sql("""select distinct item_code, source_warehouse
from `tabProduction Order Item`
where docstatus=1 and transferred_qty > required_qty
and source_warehouse is not null and source_warehouse != ''""", as_list=1):
try:
bin_doc = get_bin(d[0], d[1])
bin_doc.update_reserved_qty_for_production()
except:
pass

View File

@ -76,14 +76,16 @@ class Bin(Document):
def update_reserved_qty_for_production(self):
'''Update qty reserved for production from Production Item tables
in open production orders'''
self.reserved_qty_for_production = frappe.db.sql('''select sum(required_qty - transferred_qty)
self.reserved_qty_for_production = frappe.db.sql('''
select sum(item.required_qty - item.transferred_qty)
from `tabProduction Order` pro, `tabProduction Order Item` item
where
item.item_code = %s
and item.parent = pro.name
and pro.docstatus = 1
and item.source_warehouse = %s
and pro.status not in ("Stopped", "Completed")''', (self.item_code, self.warehouse))[0][0]
and pro.status not in ("Stopped", "Completed")
and item.required_qty > item.transferred_qty''', (self.item_code, self.warehouse))[0][0]
self.set_projected_qty()
@ -123,7 +125,12 @@ class Bin(Document):
and po.per_received < 100
""", (self.item_code))[0][0]
self.db_set('reserved_qty_for_sub_contract', (reserved_qty_for_sub_contract - materials_transferred))
if reserved_qty_for_sub_contract > materials_transferred:
reserved_qty_for_sub_contract = reserved_qty_for_sub_contract - materials_transferred
else:
reserved_qty_for_sub_contract = 0
self.db_set('reserved_qty_for_sub_contract', reserved_qty_for_sub_contract)
self.set_projected_qty()
self.db_set('projected_qty', self.projected_qty)