From 73c8d23a79ec8b2def31d61d19855e8e3d0d7228 Mon Sep 17 00:00:00 2001 From: marination Date: Fri, 20 Mar 2020 17:49:59 +0530 Subject: [PATCH 1/9] fix: UOM fixes in Sales Order,Material Request & Production Plan --- .../doctype/production_plan/production_plan.py | 2 +- .../selling/doctype/sales_order/sales_order.py | 16 +++++----------- .../doctype/material_request/material_request.py | 2 +- 3 files changed, 7 insertions(+), 13 deletions(-) diff --git a/erpnext/manufacturing/doctype/production_plan/production_plan.py b/erpnext/manufacturing/doctype/production_plan/production_plan.py index a79ea0e14b..358a5429d9 100644 --- a/erpnext/manufacturing/doctype/production_plan/production_plan.py +++ b/erpnext/manufacturing/doctype/production_plan/production_plan.py @@ -144,7 +144,7 @@ class ProductionPlan(Document): item_condition = " and mr_item.item_code ={0}".format(frappe.db.escape(self.item_code)) items = frappe.db.sql("""select distinct parent, name, item_code, warehouse, description, - (qty - ordered_qty) as pending_qty + (qty - ordered_qty) * conversion_factor as pending_qty from `tabMaterial Request Item` mr_item where parent in (%s) and docstatus = 1 and qty > ordered_qty and exists (select name from `tabBOM` bom where bom.item=mr_item.item_code diff --git a/erpnext/selling/doctype/sales_order/sales_order.py b/erpnext/selling/doctype/sales_order/sales_order.py index 13d2b1519f..ef2d19ac54 100755 --- a/erpnext/selling/doctype/sales_order/sales_order.py +++ b/erpnext/selling/doctype/sales_order/sales_order.py @@ -496,7 +496,7 @@ def close_or_unclose_sales_orders(names, status): def get_requested_item_qty(sales_order): return frappe._dict(frappe.db.sql(""" - select sales_order_item, sum(stock_qty) + select sales_order_item, sum(qty) from `tabMaterial Request Item` where docstatus = 1 and sales_order = %s @@ -507,16 +507,12 @@ def get_requested_item_qty(sales_order): def make_material_request(source_name, target_doc=None): requested_item_qty = get_requested_item_qty(source_name) - def postprocess(source, doc): - doc.material_request_type = "Purchase" - def update_item(source, target, source_parent): # qty is for packed items, because packed items don't have stock_qty field - qty = source.get("stock_qty") or source.get("qty") + qty = source.get("qty") target.project = source_parent.project target.qty = qty - requested_item_qty.get(source.name, 0) - target.conversion_factor = 1 - target.stock_qty = qty - requested_item_qty.get(source.name, 0) + target.stock_qty = flt(target.qty) * flt(target.conversion_factor) doc = get_mapped_doc("Sales Order", source_name, { "Sales Order": { @@ -537,14 +533,12 @@ def make_material_request(source_name, target_doc=None): "doctype": "Material Request Item", "field_map": { "name": "sales_order_item", - "parent": "sales_order", - "stock_uom": "uom", - "stock_qty": "qty" + "parent": "sales_order" }, "condition": lambda doc: not frappe.db.exists('Product Bundle', doc.item_code) and doc.stock_qty > requested_item_qty.get(doc.name, 0), "postprocess": update_item } - }, target_doc, postprocess) + }, target_doc) return doc diff --git a/erpnext/stock/doctype/material_request/material_request.py b/erpnext/stock/doctype/material_request/material_request.py index 4542847016..285643d712 100644 --- a/erpnext/stock/doctype/material_request/material_request.py +++ b/erpnext/stock/doctype/material_request/material_request.py @@ -501,7 +501,7 @@ def raise_work_orders(material_request): wo_order = frappe.new_doc("Work Order") wo_order.update({ "production_item": d.item_code, - "qty": d.qty - d.ordered_qty, + "qty": d.stock_qty - d.ordered_qty, "fg_warehouse": d.warehouse, "wip_warehouse": default_wip_warehouse, "description": d.description, From 4464a591ef39d03d4441ee60fcbf36217f90e32f Mon Sep 17 00:00:00 2001 From: Rohan Date: Thu, 19 Mar 2020 18:02:35 +0530 Subject: [PATCH 2/9] fix: allow BOM to use same item as raw material --- erpnext/manufacturing/doctype/bom/bom.js | 3 +-- erpnext/manufacturing/doctype/bom/bom.py | 5 ----- 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/erpnext/manufacturing/doctype/bom/bom.js b/erpnext/manufacturing/doctype/bom/bom.js index 3acaee4ffb..70c4c608e7 100644 --- a/erpnext/manufacturing/doctype/bom/bom.js +++ b/erpnext/manufacturing/doctype/bom/bom.js @@ -43,8 +43,7 @@ frappe.ui.form.on("BOM", { frm.set_query("item_code", "items", function() { return { - query: "erpnext.controllers.queries.item_query", - filters: [["Item", "name", "!=", cur_frm.doc.item]] + query: "erpnext.controllers.queries.item_query" }; }); diff --git a/erpnext/manufacturing/doctype/bom/bom.py b/erpnext/manufacturing/doctype/bom/bom.py index f6cdb2e57c..b3e602bdfa 100644 --- a/erpnext/manufacturing/doctype/bom/bom.py +++ b/erpnext/manufacturing/doctype/bom/bom.py @@ -114,10 +114,6 @@ class BOM(WebsiteGenerator): child = self.append('operations', d) child.hour_rate = flt(d.hour_rate / self.conversion_rate, 2) - def validate_rm_item(self, item): - if (item[0]['name'] in [it.item_code for it in self.items]) and item[0]['name'] == self.item: - frappe.throw(_("BOM #{0}: Raw material cannot be same as main Item").format(self.name)) - def set_bom_material_details(self): for item in self.get("items"): self.validate_bom_currecny(item) @@ -147,7 +143,6 @@ class BOM(WebsiteGenerator): args = json.loads(args) item = self.get_item_det(args['item_code']) - self.validate_rm_item(item) args['bom_no'] = args['bom_no'] or item and cstr(item[0]['default_bom']) or '' args['transfer_for_manufacture'] = (cstr(args.get('include_item_in_manufacturing', '')) or From b7d84725e873877f13acd23ed45f19d134a3b1b1 Mon Sep 17 00:00:00 2001 From: Rohan Date: Thu, 19 Mar 2020 18:44:27 +0530 Subject: [PATCH 3/9] fix: add warehouse check for FG item --- erpnext/stock/doctype/stock_entry/stock_entry.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/erpnext/stock/doctype/stock_entry/stock_entry.py b/erpnext/stock/doctype/stock_entry/stock_entry.py index 8b072c66ee..d66a9fe9ce 100644 --- a/erpnext/stock/doctype/stock_entry/stock_entry.py +++ b/erpnext/stock/doctype/stock_entry/stock_entry.py @@ -234,7 +234,7 @@ class StockEntry(StockController): if self.purpose == "Manufacture" and self.work_order: production_item = frappe.get_value('Work Order', self.work_order, 'production_item') for item in self.items: - if item.item_code == production_item and item.qty != self.fg_completed_qty: + if item.item_code == production_item and item.t_warehouse and item.qty != self.fg_completed_qty: frappe.throw(_("Finished product quantity {0} and For Quantity {1} cannot be different") .format(item.qty, self.fg_completed_qty)) From ea182051d3bd63f104cc47de5b19eb43bf3f8b7e Mon Sep 17 00:00:00 2001 From: Rohan Date: Thu, 26 Mar 2020 15:26:47 +0530 Subject: [PATCH 4/9] fix: consumed qty values in work order --- .../doctype/work_order/work_order.py | 39 ++++++++++++------- 1 file changed, 24 insertions(+), 15 deletions(-) diff --git a/erpnext/manufacturing/doctype/work_order/work_order.py b/erpnext/manufacturing/doctype/work_order/work_order.py index 98149aedef..e50dc69b4b 100644 --- a/erpnext/manufacturing/doctype/work_order/work_order.py +++ b/erpnext/manufacturing/doctype/work_order/work_order.py @@ -552,24 +552,33 @@ class WorkOrder(Document): d.db_set('transferred_qty', flt(transferred_qty), update_modified = False) def update_consumed_qty_for_required_items(self): - '''update consumed qty from submitted stock entries for that item against - the work order''' + ''' + Update consumed qty from submitted stock entries + against a work order for each stock item + ''' - for d in self.required_items: - consumed_qty = frappe.db.sql('''select sum(qty) - from `tabStock Entry` entry, `tabStock Entry Detail` detail - where + for item in self.required_items: + consumed_qty = frappe.db.sql(''' + SELECT + SUM(qty) + FROM + `tabStock Entry` entry, + `tabStock Entry Detail` detail + WHERE entry.work_order = %(name)s - and (entry.purpose = "Material Consumption for Manufacture" - or entry.purpose = "Manufacture") - and entry.docstatus = 1 - and detail.parent = entry.name - and (detail.item_code = %(item)s or detail.original_item = %(item)s)''', { - 'name': self.name, - 'item': d.item_code - })[0][0] + AND (entry.purpose = "Material Consumption for Manufacture" + OR entry.purpose = "Manufacture") + AND entry.docstatus = 1 + AND detail.parent = entry.name + AND detail.s_warehouse IS NOT null + AND (detail.item_code = %(item)s + OR detail.original_item = %(item)s) + ''', { + 'name': self.name, + 'item': item.item_code + })[0][0] - d.db_set('consumed_qty', flt(consumed_qty), update_modified = False) + item.db_set('consumed_qty', flt(consumed_qty), update_modified=False) def make_bom(self): data = frappe.db.sql(""" select sed.item_code, sed.qty, sed.s_warehouse From 71fb8e8b57bef071b403cac420a854205e01e0fa Mon Sep 17 00:00:00 2001 From: Shivam Mishra Date: Fri, 27 Mar 2020 20:43:17 +0530 Subject: [PATCH 5/9] fix: use setup from Supplier Quotation Controller --- .../supplier_quotation/supplier_quotation.js | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/erpnext/buying/doctype/supplier_quotation/supplier_quotation.js b/erpnext/buying/doctype/supplier_quotation/supplier_quotation.js index 39042b8b06..16061c61ba 100644 --- a/erpnext/buying/doctype/supplier_quotation/supplier_quotation.js +++ b/erpnext/buying/doctype/supplier_quotation/supplier_quotation.js @@ -4,15 +4,17 @@ // attach required files {% include 'erpnext/public/js/controllers/buying.js' %}; -frappe.ui.form.on('Suppier Quotation', { - setup: function(frm) { - frm.custom_make_buttons = { - 'Purchase Order': 'Purchase Order' - } - } -}); - erpnext.buying.SupplierQuotationController = erpnext.buying.BuyingController.extend({ + setup: function() { + this.frm.custom_make_buttons = { + 'Purchase Order': 'Purchase Order', + 'Quotation': 'Quotation', + 'Subscription': 'Subscription' + } + + this._super(); + }, + refresh: function() { var me = this; this._super(); From e567563aa17a92b35f993e0fae3efac2692c1afe Mon Sep 17 00:00:00 2001 From: Saurabh Date: Wed, 4 Mar 2020 13:11:41 +0530 Subject: [PATCH 6/9] fix: if mandatory fields are missing do not create address against lead --- erpnext/crm/doctype/lead/lead.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/erpnext/crm/doctype/lead/lead.py b/erpnext/crm/doctype/lead/lead.py index 73ef79b894..cefe32c88b 100644 --- a/erpnext/crm/doctype/lead/lead.py +++ b/erpnext/crm/doctype/lead/lead.py @@ -135,10 +135,14 @@ class Lead(SellingController): # do not create an address if no fields are available, # skipping country since the system auto-sets it from system defaults - if not any([self.get(field) for field in address_fields if field != "country"]): + address = frappe.new_doc("Address") + + mandatory_fields = get_mandatory_fields(address) + + if not all([self.get(field) for field in mandatory_fields]): + frappe.msgprint(_('Missing mandatory fields in address.'), alert=True, indicator='yellow') return - address = frappe.new_doc("Address") address.update({addr_field: self.get(addr_field) for addr_field in address_fields}) address.update({info_field: self.get(info_field) for info_field in info_fields}) address.insert() @@ -370,3 +374,10 @@ def get_lead_with_phone_number(number): lead = leads[0].name if leads else None return lead + +def get_mandatory_fields(doc): + return [ + df.fieldname + for df in doc.meta.fields + if df.reqd + ] \ No newline at end of file From 6c8d63f3b92a11a36de2ec1a99e06a8909472baa Mon Sep 17 00:00:00 2001 From: Saurabh Date: Mon, 9 Mar 2020 11:57:47 +0530 Subject: [PATCH 7/9] fix: provision to setup new address from lead if address creation break due to mandatory exception --- erpnext/crm/doctype/lead/lead.py | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/erpnext/crm/doctype/lead/lead.py b/erpnext/crm/doctype/lead/lead.py index cefe32c88b..04f21ffb74 100644 --- a/erpnext/crm/doctype/lead/lead.py +++ b/erpnext/crm/doctype/lead/lead.py @@ -137,10 +137,13 @@ class Lead(SellingController): # skipping country since the system auto-sets it from system defaults address = frappe.new_doc("Address") - mandatory_fields = get_mandatory_fields(address) + mandatory_fields = [ df.fieldname for df in doc.meta.fields if df.reqd ] if not all([self.get(field) for field in mandatory_fields]): - frappe.msgprint(_('Missing mandatory fields in address.'), alert=True, indicator='yellow') + frappe.msgprint(_('Missing mandatory fields in address. \ + {0} to create address' ).format(" Click here "), + alert=True, indicator='yellow') return address.update({addr_field: self.get(addr_field) for addr_field in address_fields}) @@ -374,10 +377,3 @@ def get_lead_with_phone_number(number): lead = leads[0].name if leads else None return lead - -def get_mandatory_fields(doc): - return [ - df.fieldname - for df in doc.meta.fields - if df.reqd - ] \ No newline at end of file From 84b93414d0a61b4a8f535c3befcefa7b0061d4fa Mon Sep 17 00:00:00 2001 From: Saurabh Date: Tue, 31 Mar 2020 15:57:39 +0530 Subject: [PATCH 8/9] fix: typo --- erpnext/crm/doctype/lead/lead.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/erpnext/crm/doctype/lead/lead.py b/erpnext/crm/doctype/lead/lead.py index 04f21ffb74..eb9f86076c 100644 --- a/erpnext/crm/doctype/lead/lead.py +++ b/erpnext/crm/doctype/lead/lead.py @@ -137,7 +137,7 @@ class Lead(SellingController): # skipping country since the system auto-sets it from system defaults address = frappe.new_doc("Address") - mandatory_fields = [ df.fieldname for df in doc.meta.fields if df.reqd ] + mandatory_fields = [ df.fieldname for df in address.meta.fields if df.reqd ] if not all([self.get(field) for field in mandatory_fields]): frappe.msgprint(_('Missing mandatory fields in address. \ From 48aa2dd94bac306d634327d210558af3c455940f Mon Sep 17 00:00:00 2001 From: Poranut Chollavorn Date: Thu, 26 Mar 2020 13:46:36 +0000 Subject: [PATCH 9/9] fix(pos): fix pos display item instock --- .../page/point_of_sale/point_of_sale.py | 46 +++++++++++-------- 1 file changed, 28 insertions(+), 18 deletions(-) diff --git a/erpnext/selling/page/point_of_sale/point_of_sale.py b/erpnext/selling/page/point_of_sale/point_of_sale.py index 3425f8f2a5..17136e0472 100644 --- a/erpnext/selling/page/point_of_sale/point_of_sale.py +++ b/erpnext/selling/page/point_of_sale/point_of_sale.py @@ -64,30 +64,40 @@ def get_items(start, page_length, price_list, item_group, search_value="", pos_p for d in item_prices_data: item_prices[d.item_code] = d - + # prepare filter for bin query + bin_filters = {'item_code': ['in', items]} + if warehouse: + bin_filters['warehouse'] = warehouse if display_items_in_stock: - filters = {'actual_qty': [">", 0], 'item_code': ['in', items]} + bin_filters['actual_qty'] = [">", 0] - if warehouse: - filters['warehouse'] = warehouse + # query item bin + bin_data = frappe.get_all( + 'Bin', fields=['item_code', 'sum(actual_qty) as actual_qty'], + filters=bin_filters, group_by='item_code' + ) - bin_data = frappe._dict( - frappe.get_all("Bin", fields = ["item_code", "sum(actual_qty) as actual_qty"], - filters = filters, group_by = "item_code") - ) + # convert list of dict into dict as {item_code: actual_qty} + bin_dict = {} + for b in bin_data: + bin_dict[b.get('item_code')] = b.get('actual_qty') for item in items_data: - row = {} + item_code = item.item_code + item_price = item_prices.get(item_code) or {} + item_stock_qty = bin_dict.get(item_code) - row.update(item) - item_price = item_prices.get(item.item_code) or {} - row.update({ - 'price_list_rate': item_price.get('price_list_rate'), - 'currency': item_price.get('currency'), - 'actual_qty': bin_data.get('actual_qty') - }) - - result.append(row) + if display_items_in_stock and not item_stock_qty: + pass + else: + row = {} + row.update(item) + row.update({ + 'price_list_rate': item_price.get('price_list_rate'), + 'currency': item_price.get('currency'), + 'actual_qty': item_stock_qty, + }) + result.append(row) res = { 'items': result