From 265c1947e3b7d1944e271707556a2596553780b9 Mon Sep 17 00:00:00 2001 From: Rushabh Mehta Date: Tue, 26 Mar 2013 14:16:20 +0530 Subject: [PATCH 1/4] [form] [usability] change z-index only if in form --- selling/doctype/lead/lead.txt | 64 ++++++++++++++--------------------- 1 file changed, 26 insertions(+), 38 deletions(-) diff --git a/selling/doctype/lead/lead.txt b/selling/doctype/lead/lead.txt index ae8c6c4c155..e162551607e 100644 --- a/selling/doctype/lead/lead.txt +++ b/selling/doctype/lead/lead.txt @@ -2,7 +2,7 @@ { "creation": "2013-01-28 17:07:01", "docstatus": 0, - "modified": "2013-03-26 13:07:11", + "modified": "2013-03-26 14:05:01", "modified_by": "Administrator", "owner": "Administrator" }, @@ -117,6 +117,18 @@ "reqd": 0, "search_index": 0 }, + { + "depends_on": "eval:doc.source == 'Customer'", + "description": "Source of th", + "doctype": "DocField", + "fieldname": "customer", + "fieldtype": "Link", + "hidden": 0, + "label": "From Customer", + "oldfieldname": "customer", + "oldfieldtype": "Link", + "options": "Customer" + }, { "depends_on": "eval:doc.source == 'Campaign'", "description": "Enter campaign name if the source of lead is campaign.", @@ -145,37 +157,10 @@ }, { "doctype": "DocField", - "fieldname": "sb8", + "fieldname": "contact_info", "fieldtype": "Section Break", - "label": "Lead Details" - }, - { - "depends_on": "eval:doc.source == 'Existing Customer'", - "description": "Source of th", - "doctype": "DocField", - "fieldname": "customer", - "fieldtype": "Link", - "hidden": 0, - "label": "From Customer", - "oldfieldname": "customer", - "oldfieldtype": "Link", - "options": "Customer" - }, - { - "doctype": "DocField", - "fieldname": "column_break1", - "fieldtype": "Column Break", - "width": "50%" - }, - { - "doctype": "DocField", - "fieldname": "type", - "fieldtype": "Select", - "in_filter": 1, - "label": "Lead Type", - "oldfieldname": "type", - "oldfieldtype": "Select", - "options": "\nClient\nChannel Partner\nConsultant" + "label": "Contact Info", + "oldfieldtype": "Column Break" }, { "doctype": "DocField", @@ -185,13 +170,6 @@ "oldfieldname": "remark", "oldfieldtype": "Text" }, - { - "doctype": "DocField", - "fieldname": "contact_info", - "fieldtype": "Section Break", - "label": "Contact Info", - "oldfieldtype": "Column Break" - }, { "doctype": "DocField", "fieldname": "phone", @@ -307,6 +285,16 @@ "label": "More Info", "oldfieldtype": "Section Break" }, + { + "doctype": "DocField", + "fieldname": "type", + "fieldtype": "Select", + "in_filter": 1, + "label": "Lead Type", + "oldfieldname": "type", + "oldfieldtype": "Select", + "options": "\nClient\nChannel Partner\nConsultant" + }, { "default": "__user", "doctype": "DocField", From f5784e785a67b7fcd30e8330fbc7560046e42a39 Mon Sep 17 00:00:00 2001 From: Rushabh Mehta Date: Tue, 26 Mar 2013 14:41:09 +0530 Subject: [PATCH 2/4] [accounts] [fix] aganist_jv query error --- accounts/doctype/journal_voucher/journal_voucher.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/accounts/doctype/journal_voucher/journal_voucher.py b/accounts/doctype/journal_voucher/journal_voucher.py index 8b54f0fec2d..15976b851e4 100644 --- a/accounts/doctype/journal_voucher/journal_voucher.py +++ b/accounts/doctype/journal_voucher/journal_voucher.py @@ -375,7 +375,7 @@ def get_against_sales_invoice(doctype, txt, searchfield, start, page_len, filter (filters["account"], "%%%s%%" % txt, start, page_len)) def get_against_jv(doctype, txt, searchfield, start, page_len, filters): - return webnotes.conn.sql("""select name, posting_date, user_remark + return webnotes.conn.sql("""select jv.name, jv.posting_date, jv.user_remark from `tabJournal Voucher` jv, `tabJournal Voucher Detail` jv_detail where jv_detail.parent = jv.name and jv_detail.account = %s and docstatus = 1 and jv.%s like %s order by jv.name desc limit %s, %s""" % From 08c33bd6bcdc4d72dafe3e216cff4c7967ab3d9c Mon Sep 17 00:00:00 2001 From: Rushabh Mehta Date: Tue, 26 Mar 2013 14:43:41 +0530 Subject: [PATCH 3/4] [accounts] [fix] aganist_jv query error --- accounts/doctype/journal_voucher/journal_voucher.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/accounts/doctype/journal_voucher/journal_voucher.py b/accounts/doctype/journal_voucher/journal_voucher.py index 15976b851e4..9b1ca7a105b 100644 --- a/accounts/doctype/journal_voucher/journal_voucher.py +++ b/accounts/doctype/journal_voucher/journal_voucher.py @@ -377,7 +377,7 @@ def get_against_sales_invoice(doctype, txt, searchfield, start, page_len, filter def get_against_jv(doctype, txt, searchfield, start, page_len, filters): return webnotes.conn.sql("""select jv.name, jv.posting_date, jv.user_remark from `tabJournal Voucher` jv, `tabJournal Voucher Detail` jv_detail - where jv_detail.parent = jv.name and jv_detail.account = %s and docstatus = 1 + where jv_detail.parent = jv.name and jv_detail.account = %s and jv.docstatus = 1 and jv.%s like %s order by jv.name desc limit %s, %s""" % ("%s", searchfield, "%s", "%s", "%s"), (filters["account"], "%%%s%%" % txt, start, page_len)) \ No newline at end of file From 40dc9e83a5b6b5ee705cb16c03dd8db90d72ffb5 Mon Sep 17 00:00:00 2001 From: Anand Doshi Date: Tue, 26 Mar 2013 14:49:25 +0530 Subject: [PATCH 4/4] fixes in test cases and added fiscal year field to stock reco --- .../doctype/fiscal_year/test_fiscal_year.py | 5 +++ .../march_2013/p03_update_buying_amount.py | 4 +- .../march_2013/p07_update_valuation_rate.py | 2 +- patches/march_2013/p08_create_aii_accounts.py | 43 +++++++++++++++++-- stock/doctype/stock_entry/stock_entry.py | 3 +- stock/doctype/stock_entry/test_stock_entry.py | 7 +++ .../stock_ledger_entry/stock_ledger_entry.py | 22 +++++----- .../stock_reconciliation.py | 3 +- .../stock_reconciliation.txt | 23 +++++++--- .../test_stock_reconciliation.py | 15 ++++--- 10 files changed, 96 insertions(+), 31 deletions(-) diff --git a/accounts/doctype/fiscal_year/test_fiscal_year.py b/accounts/doctype/fiscal_year/test_fiscal_year.py index b209b39b965..456b15a89c0 100644 --- a/accounts/doctype/fiscal_year/test_fiscal_year.py +++ b/accounts/doctype/fiscal_year/test_fiscal_year.py @@ -1,6 +1,11 @@ from __future__ import unicode_literals test_records = [ + [{ + "doctype": "Fiscal Year", + "year": "_Test Fiscal Year 2012", + "year_start_date": "2012-01-01" + }], [{ "doctype": "Fiscal Year", "year": "_Test Fiscal Year 2013", diff --git a/patches/march_2013/p03_update_buying_amount.py b/patches/march_2013/p03_update_buying_amount.py index e45a3dbd1c1..ae0c5eab0b8 100644 --- a/patches/march_2013/p03_update_buying_amount.py +++ b/patches/march_2013/p03_update_buying_amount.py @@ -3,8 +3,8 @@ import webnotes def execute(): dn_list = webnotes.conn.sql("""select name from `tabDelivery Note` where docstatus < 2""") for dn in dn_list: - webnotes.bean("Delivery Note", dn[0]).set_buying_amount() + webnotes.bean("Delivery Note", dn[0]).run_method("set_buying_amount") si_list = webnotes.conn.sql("""select name from `tabSales Invoice` where docstatus < 2""") for si in si_list: - webnotes.bean("Sales Invoice", si[0]).set_buying_amount() \ No newline at end of file + webnotes.bean("Sales Invoice", si[0]).run_method("set_buying_amount") \ No newline at end of file diff --git a/patches/march_2013/p07_update_valuation_rate.py b/patches/march_2013/p07_update_valuation_rate.py index 0bce8a47eca..51e556b328b 100644 --- a/patches/march_2013/p07_update_valuation_rate.py +++ b/patches/march_2013/p07_update_valuation_rate.py @@ -1,7 +1,7 @@ import webnotes def execute(): - for purchase_invoice in webnotes.conn.sql("""select distinct parent + for purchase_invoice in webnotes.conn.sql_list("""select distinct parent from `tabPurchase Invoice Item` where docstatus = 1 and ifnull(valuation_rate, 0)=0"""): pi = webnotes.get_obj("Purchase Invoice", purchase_invoice) pi.calculate_taxes_and_totals() diff --git a/patches/march_2013/p08_create_aii_accounts.py b/patches/march_2013/p08_create_aii_accounts.py index c39c206c844..ff53d8b45af 100644 --- a/patches/march_2013/p08_create_aii_accounts.py +++ b/patches/march_2013/p08_create_aii_accounts.py @@ -1,24 +1,59 @@ import webnotes def execute(): + add_group_accounts() + add_ledger_accounts() + +def _check(parent_account, company): + def _get_root(is_pl_account, debit_or_credit): + res = webnotes.conn.sql("""select name from `tabAccount` + where company=%s and is_pl_account = %s and debit_or_credit = %s + and ifnull(parent_account, "") ="" """, (company, is_pl_account, debit_or_credit)) + return res and res[0][0] or None + + if not webnotes.conn.exists("Account", parent_account): + if parent_account.startswith("Current Assets"): + parent_account = _get_root("No", "Debit") + elif parent_account.startswith("Direct Expenses"): + parent_account = _get_root("Yes", "Debit") + elif parent_account.startswith("Current Liabilities"): + parent_account = _get_root("No", "Credit") + + return parent_account + + +def add_group_accounts(): accounts_to_add = [ ["Stock Assets", "Current Assets", "Group", ""], + ["Stock Expenses", "Direct Expenses", "Group", "Expense Account"], + ["Stock Liabilities", "Current Liabilities", "Group", ""], + ] + + add_accounts(accounts_to_add, _check) + + +def add_ledger_accounts(): + accounts_to_add = [ ["Stock In Hand", "Stock Assets", "Ledger", ""], ["Stock Debit But Not Billed", "Stock Assets", "Ledger", ""], - ["Stock Expenses", "Direct Expenses", "Group", "Expense Account"], ["Cost of Goods Sold", "Stock Expenses", "Ledger", "Expense Account"], ["Stock Adjustment", "Stock Expenses", "Ledger", "Expense Account"], ["Expenses Included In Valuation", "Stock Expenses", "Ledger", "Expense Account"], - ["Stock Liabilities", "Current Liabilities", "Group", ""], ["Stock Received But Not Billed", "Stock Liabilities", "Ledger", ""], ] + add_accounts(accounts_to_add) - for company, abbr in webnotes.conn.sql_list("""select name, abbr from `tabCompany`"""): + +def add_accounts(accounts_to_add, check_fn=None): + for company, abbr in webnotes.conn.sql("""select name, abbr from `tabCompany`"""): for account_name, parent_account_name, group_or_ledger, account_type in accounts_to_add: if not webnotes.conn.exists("Account", "%s - %s" % (account_name, abbr)): + parent_account = "%s - %s" % (parent_account_name, abbr) + if check_fn: + parent_account = check_fn(parent_account, company) account = webnotes.bean({ "doctype": "Account", "account_name": account_name, - "parent_account": "%s - %s" % (parent_account_name, abbr), + "parent_account": parent_account, "group_or_ledger": group_or_ledger, "account_type": account_type, "company": company diff --git a/stock/doctype/stock_entry/stock_entry.py b/stock/doctype/stock_entry/stock_entry.py index c437135ad63..a1761885462 100644 --- a/stock/doctype/stock_entry/stock_entry.py +++ b/stock/doctype/stock_entry/stock_entry.py @@ -610,7 +610,8 @@ class DocType(StockController): 'is_cancelled': (is_cancelled ==1) and 'Yes' or 'No', 'batch_no': cstr(d.batch_no).strip(), 'serial_no': cstr(d.serial_no).strip(), - "project": self.doc.project_name + "project": self.doc.project_name, + "fiscal_year": self.doc.fiscal_year, }) def get_cust_values(self): diff --git a/stock/doctype/stock_entry/test_stock_entry.py b/stock/doctype/stock_entry/test_stock_entry.py index 3f8012a7263..7c406f8e8cb 100644 --- a/stock/doctype/stock_entry/test_stock_entry.py +++ b/stock/doctype/stock_entry/test_stock_entry.py @@ -230,6 +230,7 @@ class TestStockEntry(unittest.TestCase): se.doc.purpose = "Sales Return" se.doc.sales_invoice_no = si.doc.name se.doc.posting_date = "2013-03-10" + se.doc.fiscal_year = "_Test Fiscal Year 2013" se.doclist[1].item_code = "_Test Item Home Desktop 200" se.doclist[1].qty = returned_qty se.doclist[1].transfer_qty = returned_qty @@ -241,6 +242,7 @@ class TestStockEntry(unittest.TestCase): se = webnotes.bean(copy=test_records[0]) se.doc.purpose = "Sales Return" se.doc.posting_date = "2013-03-10" + se.doc.fiscal_year = "_Test Fiscal Year 2013" se.doc.sales_invoice_no = si.doc.name se.doclist[1].qty = returned_qty se.doclist[1].transfer_qty = returned_qty @@ -300,6 +302,7 @@ class TestStockEntry(unittest.TestCase): se.doc.purpose = "Sales Return" se.doc.delivery_note_no = dn.doc.name se.doc.posting_date = "2013-03-10" + se.doc.fiscal_year = "_Test Fiscal Year 2013" se.doclist[1].qty = se.doclist[1].transfer_qty = returned_qty se.insert() @@ -399,6 +402,7 @@ class TestStockEntry(unittest.TestCase): se.doc.purpose = "Sales Return" se.doc.delivery_note_no = dn.doc.name se.doc.posting_date = "2013-03-10" + se.doc.fiscal_year = "_Test Fiscal Year 2013" se.doclist[1].qty = se.doclist[1].transfer_qty = returned_qty se.insert() @@ -449,6 +453,7 @@ class TestStockEntry(unittest.TestCase): se.doc.purpose = "Purchase Return" se.doc.purchase_receipt_no = pr.doc.name se.doc.posting_date = "2013-03-01" + se.doc.fiscal_year = "_Test Fiscal Year 2013" se.doclist[1].qty = se.doclist[1].transfer_qty = 5 se.doclist[1].s_warehouse = "_Test Warehouse" se.insert() @@ -471,6 +476,7 @@ class TestStockEntry(unittest.TestCase): se.doc.purpose = "Purchase Return" se.doc.purchase_receipt_no = pr_docname se.doc.posting_date = "2013-03-01" + se.doc.fiscal_year = "_Test Fiscal Year 2013" se.doclist[1].qty = se.doclist[1].transfer_qty = 6 se.doclist[1].s_warehouse = "_Test Warehouse" @@ -547,6 +553,7 @@ class TestStockEntry(unittest.TestCase): se.doc.purpose = "Purchase Return" se.doc.purchase_receipt_no = pr.doc.name se.doc.posting_date = "2013-03-01" + se.doc.fiscal_year = "_Test Fiscal Year 2013" se.doclist[1].qty = se.doclist[1].transfer_qty = 5 se.doclist[1].s_warehouse = "_Test Warehouse" se.insert() diff --git a/stock/doctype/stock_ledger_entry/stock_ledger_entry.py b/stock/doctype/stock_ledger_entry/stock_ledger_entry.py index 5ca7dd5bed1..42621130d5b 100644 --- a/stock/doctype/stock_ledger_entry/stock_ledger_entry.py +++ b/stock/doctype/stock_ledger_entry/stock_ledger_entry.py @@ -16,17 +16,13 @@ from __future__ import unicode_literals import webnotes -from webnotes import _ - +from webnotes import _, msgprint from webnotes.utils import cint, flt, getdate - -sql = webnotes.conn.sql -msgprint = webnotes.msgprint -from accounts.utils import get_fiscal_year +from webnotes.model.controller import DocListController class InvalidWarehouseCompany(Exception): pass -class DocType: +class DocType(DocListController): def __init__(self, doc, doclist=[]): self.doc = doc self.doclist = doclist @@ -39,12 +35,14 @@ class DocType: self.actual_amt_check() self.check_stock_frozen_date() self.scrub_posting_time() - self.doc.fiscal_year = get_fiscal_year(self.doc.posting_date)[0] + + from accounts.utils import validate_fiscal_year + validate_fiscal_year(self.doc.posting_date, self.doc.fiscal_year, self.meta.get_label("posting_date")) #check for item quantity available in stock def actual_amt_check(self): if self.doc.batch_no: - batch_bal = flt(sql("select sum(actual_qty) from `tabStock Ledger Entry` where warehouse = '%s' and item_code = '%s' and batch_no = '%s'"%(self.doc.warehouse,self.doc.item_code,self.doc.batch_no))[0][0]) + batch_bal = flt(webnotes.conn.sql("select sum(actual_qty) from `tabStock Ledger Entry` where warehouse = '%s' and item_code = '%s' and batch_no = '%s'"%(self.doc.warehouse,self.doc.item_code,self.doc.batch_no))[0][0]) self.doc.fields.update({'batch_bal': batch_bal}) if (batch_bal + self.doc.actual_qty) < 0: @@ -77,11 +75,11 @@ class DocType: if self.doc.fields.get(k)==None: msgprint("Stock Ledger Entry: '%s' is mandatory" % k, raise_exception = 1) elif k == 'warehouse': - if not sql("select name from tabWarehouse where name = '%s'" % self.doc.fields.get(k)): + if not webnotes.conn.sql("select name from tabWarehouse where name = '%s'" % self.doc.fields.get(k)): msgprint("Warehouse: '%s' does not exist in the system. Please check." % self.doc.fields.get(k), raise_exception = 1) def validate_item(self): - item_det = sql("""select name, has_batch_no, docstatus, + item_det = webnotes.conn.sql("""select name, has_batch_no, docstatus, ifnull(is_stock_item, 'No') from tabItem where name=%s""", self.doc.item_code) @@ -106,7 +104,7 @@ class DocType: raise Exception # check if batch belongs to item - if not sql("select name from `tabBatch` where item='%s' and name ='%s' and docstatus != 2" % (self.doc.item_code, self.doc.batch_no)): + if not webnotes.conn.sql("select name from `tabBatch` where item='%s' and name ='%s' and docstatus != 2" % (self.doc.item_code, self.doc.batch_no)): msgprint("'%s' is not a valid Batch Number for Item '%s'" % (self.doc.batch_no, self.doc.item_code), raise_exception = 1) # Nobody can do SL Entries where posting date is before freezing date except authorized person diff --git a/stock/doctype/stock_reconciliation/stock_reconciliation.py b/stock/doctype/stock_reconciliation/stock_reconciliation.py index 13c8ee48800..56041797d56 100644 --- a/stock/doctype/stock_reconciliation/stock_reconciliation.py +++ b/stock/doctype/stock_reconciliation/stock_reconciliation.py @@ -252,7 +252,8 @@ class DocType(StockController): "voucher_no": self.doc.name, "company": self.doc.company, "is_cancelled": "No", - "voucher_detail_no": row.voucher_detail_no + "voucher_detail_no": row.voucher_detail_no, + "fiscal_year": self.doc.fiscal_year, }) args.update(opts) # create stock ledger entry diff --git a/stock/doctype/stock_reconciliation/stock_reconciliation.txt b/stock/doctype/stock_reconciliation/stock_reconciliation.txt index 9137cae972c..760620bb734 100644 --- a/stock/doctype/stock_reconciliation/stock_reconciliation.txt +++ b/stock/doctype/stock_reconciliation/stock_reconciliation.txt @@ -1,8 +1,8 @@ [ { - "creation": "2013-01-22 16:50:41", + "creation": "2013-03-26 06:51:17", "docstatus": 0, - "modified": "2013-03-18 12:48:42", + "modified": "2013-03-26 08:32:03", "modified_by": "Administrator", "owner": "Administrator" }, @@ -30,7 +30,6 @@ "permlevel": 0 }, { - "amend": 1, "cancel": 1, "create": 1, "doctype": "DocPerm", @@ -41,7 +40,6 @@ "permlevel": 0, "read": 1, "report": 1, - "role": "Material Manager", "submit": 1, "write": 1 }, @@ -81,6 +79,15 @@ "print_hide": 1, "read_only": 1 }, + { + "doctype": "DocField", + "fieldname": "fiscal_year", + "fieldtype": "Select", + "label": "Fiscal Year", + "options": "link:Fiscal Year", + "print_hide": 1, + "reqd": 1 + }, { "doctype": "DocField", "fieldname": "company", @@ -145,6 +152,12 @@ "print_hide": 1 }, { - "doctype": "DocPerm" + "amend": 0, + "doctype": "DocPerm", + "role": "Material Manager" + }, + { + "doctype": "DocPerm", + "role": "System Manager" } ] \ No newline at end of file diff --git a/stock/doctype/stock_reconciliation/test_stock_reconciliation.py b/stock/doctype/stock_reconciliation/test_stock_reconciliation.py index cebc6ffc531..1e7e716f1bf 100644 --- a/stock/doctype/stock_reconciliation/test_stock_reconciliation.py +++ b/stock/doctype/stock_reconciliation/test_stock_reconciliation.py @@ -228,35 +228,40 @@ class TestStockReconciliation(unittest.TestCase): "voucher_type": "Stock Entry", "voucher_no": "TEST", "item_code": "_Test Item", "warehouse": "_Test Warehouse", "posting_date": "2012-12-12", "posting_time": "01:00", - "actual_qty": 20, "incoming_rate": 1000, "company": "_Test Company" + "actual_qty": 20, "incoming_rate": 1000, "company": "_Test Company", + "fiscal_year": "_Test Fiscal Year 2012", }, { "doctype": "Stock Ledger Entry", "__islocal": 1, "voucher_type": "Stock Entry", "voucher_no": "TEST", "item_code": "_Test Item", "warehouse": "_Test Warehouse", "posting_date": "2012-12-15", "posting_time": "02:00", - "actual_qty": 10, "incoming_rate": 700, "company": "_Test Company" + "actual_qty": 10, "incoming_rate": 700, "company": "_Test Company", + "fiscal_year": "_Test Fiscal Year 2012", }, { "doctype": "Stock Ledger Entry", "__islocal": 1, "voucher_type": "Stock Entry", "voucher_no": "TEST", "item_code": "_Test Item", "warehouse": "_Test Warehouse", "posting_date": "2012-12-25", "posting_time": "03:00", - "actual_qty": -15, "company": "_Test Company" + "actual_qty": -15, "company": "_Test Company", + "fiscal_year": "_Test Fiscal Year 2012", }, { "doctype": "Stock Ledger Entry", "__islocal": 1, "voucher_type": "Stock Entry", "voucher_no": "TEST", "item_code": "_Test Item", "warehouse": "_Test Warehouse", "posting_date": "2012-12-31", "posting_time": "08:00", - "actual_qty": -20, "company": "_Test Company" + "actual_qty": -20, "company": "_Test Company", + "fiscal_year": "_Test Fiscal Year 2012", }, { "doctype": "Stock Ledger Entry", "__islocal": 1, "voucher_type": "Stock Entry", "voucher_no": "TEST", "item_code": "_Test Item", "warehouse": "_Test Warehouse", "posting_date": "2013-01-05", "posting_time": "07:00", - "actual_qty": 15, "incoming_rate": 1200, "company": "_Test Company" + "actual_qty": 15, "incoming_rate": 1200, "company": "_Test Company", + "fiscal_year": "_Test Fiscal Year 2013", }, ]