From 56a3165ac89132d497d2496bc9e978c957a19ed7 Mon Sep 17 00:00:00 2001 From: Anand Doshi Date: Fri, 29 Nov 2013 19:15:26 +0530 Subject: [PATCH 1/3] [minor] stock ledger report as script report Issue #1121 --- patches/patch_list.py | 1 + stock/page/stock_home/stock_home.js | 8 +-- stock/report/stock_ledger/stock_ledger.js | 58 ++++++++++++++++++++++ stock/report/stock_ledger/stock_ledger.py | 49 ++++++++++++++++++ stock/report/stock_ledger/stock_ledger.txt | 7 ++- stock/stock_ledger.py | 1 + 6 files changed, 114 insertions(+), 10 deletions(-) create mode 100644 stock/report/stock_ledger/stock_ledger.js create mode 100644 stock/report/stock_ledger/stock_ledger.py diff --git a/patches/patch_list.py b/patches/patch_list.py index 52277a8190..437f3227a7 100644 --- a/patches/patch_list.py +++ b/patches/patch_list.py @@ -255,4 +255,5 @@ patch_list = [ "patches.1311.p05_website_brand_html", "patches.1311.p06_fix_report_columns", "execute:webnotes.delete_doc('DocType', 'Documentation Tool')", + "execute:webnotes.delete_doc('Report', 'Stock Ledger') #2013-11-29", ] \ No newline at end of file diff --git a/stock/page/stock_home/stock_home.js b/stock/page/stock_home/stock_home.js index cbfc3fcf24..4be5a46601 100644 --- a/stock/page/stock_home/stock_home.js +++ b/stock/page/stock_home/stock_home.js @@ -138,7 +138,8 @@ wn.module_page["Stock"] = [ items: [ { "label":wn._("Stock Ledger"), - page: "stock-ledger" + doctype: "Delivery Note", + route: "query-report/Stock Ledger" }, { "label":wn._("Stock Balance"), @@ -170,11 +171,6 @@ wn.module_page["Stock"] = [ right: true, icon: "icon-list", items: [ - { - "label":wn._("Stock Ledger"), - route: "Report/Stock Ledger Entry/Stock Ledger", - doctype: "Stock Ledger Entry" - }, { "label":wn._("Ordered Items To Be Delivered"), route: "query-report/Ordered Items To Be Delivered", diff --git a/stock/report/stock_ledger/stock_ledger.js b/stock/report/stock_ledger/stock_ledger.js new file mode 100644 index 0000000000..0e323ebb61 --- /dev/null +++ b/stock/report/stock_ledger/stock_ledger.js @@ -0,0 +1,58 @@ +// Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors +// License: GNU General Public License v3. See license.txt + +wn.query_reports["Stock Ledger"] = { + "filters": [ + { + "fieldname":"company", + "label": wn._("Company"), + "fieldtype": "Link", + "options": "Company", + "default": wn.defaults.get_user_default("company"), + "reqd": 1 + }, + { + "fieldname":"from_date", + "label": wn._("From Date"), + "fieldtype": "Date", + "default": wn.defaults.get_user_default("year_start_date"), + "reqd": 1 + }, + { + "fieldname":"to_date", + "label": wn._("To Date"), + "fieldtype": "Date", + "default": wn.defaults.get_user_default("year_end_date"), + "reqd": 1 + }, + { + "fieldname":"warehouse", + "label": wn._("Warehouse"), + "fieldtype": "Link", + "options": "Warehouse" + }, + { + "fieldname":"item_code", + "label": wn._("Item"), + "fieldtype": "Link", + "options": "Item" + }, + { + "fieldname":"brand", + "label": wn._("Brand"), + "fieldtype": "Link", + "options": "Brand" + }, + { + "fieldname":"voucher_no", + "label": wn._("Voucher #"), + "fieldtype": "Data" + } + ] +} + +// $(function() { +// $(wrapper).bind("show", function() { +// wn.query_report.load(); +// }); +// }); \ No newline at end of file diff --git a/stock/report/stock_ledger/stock_ledger.py b/stock/report/stock_ledger/stock_ledger.py new file mode 100644 index 0000000000..3ae9135dca --- /dev/null +++ b/stock/report/stock_ledger/stock_ledger.py @@ -0,0 +1,49 @@ +# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors +# License: GNU General Public License v3. See license.txt + +from __future__ import unicode_literals +import webnotes + +def execute(filters=None): + columns = ["Date:Datetime:95", "Item:Link/Item:100", "Item Name::100", + "Item Group:Link/Item Group:100", "Brand:Link/Brand:100", + "Description::200", "Warehouse:Link/Warehouse:100", + "Stock UOM:Link/UOM:100", "Qty:Float:50", "Balance Qty:Float:80", + "Balance Value:Currency:100", "Voucher Type::100", "Voucher #::100", + "Batch:Link/Batch:100", "Serial #:Link/Serial No:100", "Company:Link/Company:100"] + + data = webnotes.conn.sql("""select concat_ws(" ", posting_date, posting_time), + item.name, item.item_name, item.item_group, brand, description, warehouse, sle.stock_uom, + actual_qty, qty_after_transaction, stock_value, voucher_type, voucher_no, + batch_no, serial_no, company + from `tabStock Ledger Entry` sle, + (select name, item_name, description, stock_uom, brand, item_group + from `tabItem` {item_conditions}) item + where item_code = item.name and + company = %(company)s and + posting_date between %(from_date)s and %(to_date)s + {sle_conditions} + order by posting_date desc, posting_time desc, sle.name desc"""\ + .format(item_conditions=get_item_conditions(filters), + sle_conditions=get_sle_conditions(filters)), + filters) + + return columns, data + +def get_item_conditions(filters): + conditions = [] + if filters.get("item_code"): + conditions.append("item_code=%(item_code)s") + if filters.get("brand"): + conditions.append("brand=%(brand)s") + + return "where {}".format(" and ".join(conditions)) if conditions else "" + +def get_sle_conditions(filters): + conditions = [] + if filters.get("warehouse"): + conditions.append("warehouse=%(warehouse)s") + if filters.get("voucher_no"): + conditions.append("voucher_no=%(voucher_no)s") + + return "and {}".format(" and ".join(conditions)) if conditions else "" \ No newline at end of file diff --git a/stock/report/stock_ledger/stock_ledger.txt b/stock/report/stock_ledger/stock_ledger.txt index a40be1de23..aadf32306f 100644 --- a/stock/report/stock_ledger/stock_ledger.txt +++ b/stock/report/stock_ledger/stock_ledger.txt @@ -1,19 +1,18 @@ [ { - "creation": "2013-01-14 15:26:21", + "creation": "2013-11-29 17:08:23", "docstatus": 0, - "modified": "2013-08-20 11:53:43", + "modified": "2013-11-29 17:28:15", "modified_by": "Administrator", "owner": "Administrator" }, { "doctype": "Report", "is_standard": "Yes", - "json": "{\"filters\":[],\"columns\":[[\"item_code\",\"Stock Ledger Entry\"],[\"warehouse\",\"Stock Ledger Entry\"],[\"posting_date\",\"Stock Ledger Entry\"],[\"posting_time\",\"Stock Ledger Entry\"],[\"actual_qty\",\"Stock Ledger Entry\"],[\"qty_after_transaction\",\"Stock Ledger Entry\"],[\"voucher_type\",\"Stock Ledger Entry\"],[\"voucher_no\",\"Stock Ledger Entry\"]],\"sort_by\":\"Stock Ledger Entry.posting_date\",\"sort_order\":\"desc\",\"sort_by_next\":\"Stock Ledger Entry.posting_time\",\"sort_order_next\":\"desc\"}", "name": "__common__", "ref_doctype": "Stock Ledger Entry", "report_name": "Stock Ledger", - "report_type": "Report Builder" + "report_type": "Script Report" }, { "doctype": "Report", diff --git a/stock/stock_ledger.py b/stock/stock_ledger.py index 469fa5329f..870274413f 100644 --- a/stock/stock_ledger.py +++ b/stock/stock_ledger.py @@ -1,5 +1,6 @@ # Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors # License: GNU General Public License v3. See license.txt +from __future__ import unicode_literals import webnotes from webnotes import msgprint From 5ff03e460b4df2fb744c7f5b3cdbeb26cbb83774 Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Mon, 2 Dec 2013 15:27:13 +0530 Subject: [PATCH 2/3] [fix] [minor] removed duplicate validation for sales bom --- selling/doctype/sales_bom/sales_bom.py | 38 -------------------------- 1 file changed, 38 deletions(-) diff --git a/selling/doctype/sales_bom/sales_bom.py b/selling/doctype/sales_bom/sales_bom.py index f2b00c6007..f6cfafa41d 100644 --- a/selling/doctype/sales_bom/sales_bom.py +++ b/selling/doctype/sales_bom/sales_bom.py @@ -3,8 +3,6 @@ from __future__ import unicode_literals import webnotes -from webnotes.utils import flt -from webnotes.model.utils import getlist class DocType: def __init__(self,d,dl): @@ -14,8 +12,6 @@ class DocType: self.doc.name = self.doc.new_item_code def validate(self): - # check for duplicate - self.check_duplicate() self.validate_main_item() from utilities.transaction_base import validate_uom_is_integer @@ -36,40 +32,6 @@ class DocType: 'uom': det and det[0][1] or '' } - def check_duplicate(self, finder=0): - il = getlist(self.doclist, "sales_bom_items") - if not il: - webnotes.msgprint("Add atleast one item") - return - - # get all Sales BOM that have the first item - sbl = webnotes.conn.sql("""select distinct parent from `tabSales BOM Item` where item_code=%s - and parent != %s and docstatus != 2""", (il[0].item_code, self.doc.name)) - - # check all siblings - sub_items = [[d.item_code, flt(d.qty)] for d in il] - - for s in sbl: - t = webnotes.conn.sql("""select item_code, qty from `tabSales BOM Item` where parent=%s and - docstatus != 2""", s[0]) - t = [[d[0], flt(d[1])] for d in t] - - if self.has_same_items(sub_items, t): - webnotes.msgprint("%s has the same Sales BOM details" % s[0]) - raise Exception - if finder: - webnotes.msgprint("There is no Sales BOM present with the following Combination.") - - def has_same_items(self, l1, l2): - if len(l1)!=len(l2): return 0 - for l in l2: - if l not in l1: - return 0 - for l in l1: - if l not in l2: - return 0 - return 1 - def get_new_item_code(doctype, txt, searchfield, start, page_len, filters): from controllers.queries import get_match_cond From 365c24173a75708a9bfca145fd51d533d176059c Mon Sep 17 00:00:00 2001 From: Anand Doshi Date: Mon, 2 Dec 2013 16:08:26 +0530 Subject: [PATCH 3/3] [minor] [fix] shopping cart cookies --- selling/utils/cart.py | 2 +- selling/utils/product.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/selling/utils/cart.py b/selling/utils/cart.py index c4c0b72616..3cd7b3c9f1 100644 --- a/selling/utils/cart.py +++ b/selling/utils/cart.py @@ -310,7 +310,7 @@ def set_price_list_and_rate(quotation, cart_settings, billing_territory): quotation.run_method("set_price_list_and_item_details") # set it in cookies for using in product page - webnotes.cookies[b"selling_price_list"] = quotation.doc.selling_price_list + webnotes.local._response.set_cookie("selling_price_list", quotation.doc.selling_price_list) def set_taxes(quotation, cart_settings, billing_territory): """set taxes based on billing territory""" diff --git a/selling/utils/product.py b/selling/utils/product.py index d218979b94..32ff85ad12 100644 --- a/selling/utils/product.py +++ b/selling/utils/product.py @@ -16,7 +16,7 @@ def get_product_info(item_code): cart_quotation = _get_cart_quotation() - price_list = webnotes.cookies.get("selling_price_list").value + price_list = webnotes.local.request.cookies.get("selling_price_list") warehouse = webnotes.conn.get_value("Item", item_code, "website_warehouse") if warehouse: