From 19acce9fa1dc90769d81ab0d2b80cd13209fbfbe Mon Sep 17 00:00:00 2001 From: Anand Doshi Date: Fri, 29 Mar 2013 20:40:23 +0530 Subject: [PATCH] [aii] [patches] minor fixes --- accounts/doctype/cost_center/cost_center.py | 4 +++- .../sales_invoice_item/sales_invoice_item.txt | 6 +++--- .../march_2013/p03_update_buying_amount.py | 3 +++ .../march_2013/p07_update_valuation_rate.py | 2 ++ patches/march_2013/p08_create_aii_accounts.py | 21 ++++++++++++++++++- selling/doctype/sales_common/sales_common.py | 3 ++- stock/doctype/item/item.py | 4 ++-- stock/doctype/stock_entry/stock_entry.js | 3 ++- .../stock_entry_detail/stock_entry_detail.txt | 7 +++++-- 9 files changed, 42 insertions(+), 11 deletions(-) diff --git a/accounts/doctype/cost_center/cost_center.py b/accounts/doctype/cost_center/cost_center.py index 8340a8b39fc..e57b6a37582 100644 --- a/accounts/doctype/cost_center/cost_center.py +++ b/accounts/doctype/cost_center/cost_center.py @@ -17,7 +17,7 @@ from __future__ import unicode_literals import webnotes from webnotes.model.bean import getlist -from webnotes import msgprint +from webnotes import msgprint, _ from webnotes.utils.nestedset import DocTypeNestedSet @@ -37,6 +37,8 @@ class DocType(DocTypeNestedSet): if self.doc.cost_center_name != 'Root' and not self.doc.parent_cost_center: msgprint("Please enter parent cost center", raise_exception=1) + elif self.doc.cost_center_name == "Root" and self.doc.parent_cost_center: + msgprint(_("Root cannot have a parent cost center"), raise_exception=1) def convert_group_to_ledger(self): if self.check_if_child_exists(): diff --git a/accounts/doctype/sales_invoice_item/sales_invoice_item.txt b/accounts/doctype/sales_invoice_item/sales_invoice_item.txt index dee0e85d6e8..98962b5bbc2 100644 --- a/accounts/doctype/sales_invoice_item/sales_invoice_item.txt +++ b/accounts/doctype/sales_invoice_item/sales_invoice_item.txt @@ -1,8 +1,8 @@ [ { - "creation": "2013-03-26 11:03:08", + "creation": "2013-03-29 18:21:58", "docstatus": 0, - "modified": "2013-03-28 15:42:14", + "modified": "2013-03-29 19:32:32", "modified_by": "Administrator", "owner": "Administrator" }, @@ -223,7 +223,7 @@ "fieldname": "cost_center", "fieldtype": "Link", "in_filter": 1, - "label": "Sales Cost Center", + "label": "Cost Center", "oldfieldname": "cost_center", "oldfieldtype": "Link", "options": "Cost Center", diff --git a/patches/march_2013/p03_update_buying_amount.py b/patches/march_2013/p03_update_buying_amount.py index e4a3fcb10b2..0d96feba4af 100644 --- a/patches/march_2013/p03_update_buying_amount.py +++ b/patches/march_2013/p03_update_buying_amount.py @@ -2,6 +2,9 @@ import webnotes from webnotes.utils import now_datetime def execute(): + webnotes.reload_doc("stock", "doctype", "delivery_note_item") + webnotes.reload_doc("accounts", "doctype", "sales_invoice_item") + webnotes.conn.auto_commit_on_many_writes = True for company in webnotes.conn.sql("select name from `tabCompany`"): print company[0] diff --git a/patches/march_2013/p07_update_valuation_rate.py b/patches/march_2013/p07_update_valuation_rate.py index 7d11e42bda1..794baf3a41d 100644 --- a/patches/march_2013/p07_update_valuation_rate.py +++ b/patches/march_2013/p07_update_valuation_rate.py @@ -1,6 +1,8 @@ import webnotes def execute(): + webnotes.reload_doc("accounts", "doctype", "purchase_invoice_item") + for purchase_invoice in webnotes.conn.sql_list("""select distinct parent from `tabPurchase Invoice Item` pi_item where docstatus = 1 and ifnull(valuation_rate, 0)=0 and exists(select name from `tabPurchase Invoice` where name = pi_item.parent)"""): diff --git a/patches/march_2013/p08_create_aii_accounts.py b/patches/march_2013/p08_create_aii_accounts.py index f6e1e2dcfea..ec186b47ff6 100644 --- a/patches/march_2013/p08_create_aii_accounts.py +++ b/patches/march_2013/p08_create_aii_accounts.py @@ -1,8 +1,15 @@ import webnotes def execute(): + webnotes.reload_doc("setup", "doctype", "company") + add_group_accounts() add_ledger_accounts() add_aii_cost_center() + set_default_accounts() + +def set_default_accounts(): + for company in webnotes.conn.sql_list("select name from `tabCompany`"): + webnotes.get_obj("Company", company).set_default_accounts() def _check(parent_account, company): def _get_root(is_pl_account, debit_or_credit): @@ -45,6 +52,14 @@ def add_ledger_accounts(): def add_accounts(accounts_to_add, check_fn=None): for company, abbr in webnotes.conn.sql("""select name, abbr from `tabCompany`"""): + count = webnotes.conn.sql("""select count(name) from `tabAccount` + where company=%s and ifnull(parent_account, '')=''""", company)[0][0] + + if count > 4: + print "Company", company, \ + "has more than 4 root accounts. cannot apply patch to this company." + continue + 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) @@ -64,7 +79,11 @@ def add_aii_cost_center(): for company, abbr in webnotes.conn.sql("""select name, abbr from `tabCompany`"""): if not webnotes.conn.exists("Cost Center", "Auto Inventory Accounting - %s" % abbr): parent_cost_center = webnotes.conn.get_value("Cost Center", - {"parent_cost_center['']": '', "company_name": company}, 'name') + {"parent_cost_center['']": '', "company_name": company}) + + if not parent_cost_center: + print "Company", company, "does not have a root cost center" + continue cc = webnotes.bean({ "doctype": "Cost Center", diff --git a/selling/doctype/sales_common/sales_common.py b/selling/doctype/sales_common/sales_common.py index dde491994c1..b9f9af64d16 100644 --- a/selling/doctype/sales_common/sales_common.py +++ b/selling/doctype/sales_common/sales_common.py @@ -212,7 +212,8 @@ class DocType(TransactionBase): # ***************** Get Ref rate as entered in Item Master ******************** def get_ref_rate(self, item_code, price_list_name, price_list_currency, plc_conv_rate): - ref_rate = webnotes.conn.sql("select ref_rate from `tabItem Price` where parent = %s and price_list_name = %s and ref_currency = %s", (item_code, price_list_name, price_list_currency)) + ref_rate = webnotes.conn.sql("select ref_rate from `tabItem Price` where parent = %s and price_list_name = %s and ref_currency = %s and selling=1", + (item_code, price_list_name, price_list_currency)) base_ref_rate = ref_rate and flt(ref_rate[0][0]) * flt(plc_conv_rate) or 0 return base_ref_rate diff --git a/stock/doctype/item/item.py b/stock/doctype/item/item.py index 802771cce1c..b27d9f286e4 100644 --- a/stock/doctype/item/item.py +++ b/stock/doctype/item/item.py @@ -17,7 +17,7 @@ from __future__ import unicode_literals import webnotes -from webnotes.utils import cstr, flt +from webnotes.utils import cstr, flt, cint from webnotes.model.doc import addchild from webnotes.model.bean import getlist from webnotes import msgprint, _ @@ -119,7 +119,7 @@ class DocType(DocListController): def check_ref_rate_detail(self): check_list=[] for d in getlist(self.doclist,'ref_rate_details'): - if [cstr(d.price_list_name),cstr(d.ref_currency)] in check_list: + if [cstr(d.price_list_name),cstr(d.ref_currency),cint(d.selling),cint(d.buying)] in check_list: msgprint("Ref Rate is entered twice for Price List : '%s' and Currency : '%s'." % (d.price_list_name,d.ref_currency)) raise Exception else: diff --git a/stock/doctype/stock_entry/stock_entry.js b/stock/doctype/stock_entry/stock_entry.js index 464fdb5535b..1f4aafa9e51 100644 --- a/stock/doctype/stock_entry/stock_entry.js +++ b/stock/doctype/stock_entry/stock_entry.js @@ -360,7 +360,8 @@ cur_frm.cscript.uom = function(doc, cdt, cdn) { cur_frm.cscript.validate = function(doc, cdt, cdn) { cur_frm.cscript.validate_items(doc); - validated = cur_frm.cscript.get_doctype_docname() ? true : false; + if($.inArray(cur_frm.doc.purpose, ["Purchase Return", "Sales Return"])!==-1) + validated = cur_frm.cscript.get_doctype_docname() ? true : false; } cur_frm.cscript.validate_items = function(doc) { diff --git a/stock/doctype/stock_entry_detail/stock_entry_detail.txt b/stock/doctype/stock_entry_detail/stock_entry_detail.txt index 2c59dd702ed..8426ddca274 100644 --- a/stock/doctype/stock_entry_detail/stock_entry_detail.txt +++ b/stock/doctype/stock_entry_detail/stock_entry_detail.txt @@ -1,8 +1,8 @@ [ { - "creation": "2013-02-22 01:28:04", + "creation": "2013-03-29 18:22:12", "docstatus": 0, - "modified": "2013-03-07 07:03:32", + "modified": "2013-03-29 19:43:04", "modified_by": "Administrator", "owner": "Administrator" }, @@ -158,6 +158,7 @@ "label": "Conversion Factor", "oldfieldname": "conversion_factor", "oldfieldtype": "Currency", + "print_hide": 1, "read_only": 1, "reqd": 1 }, @@ -168,6 +169,7 @@ "label": "Qty as per Stock UOM", "oldfieldname": "transfer_qty", "oldfieldtype": "Currency", + "print_hide": 1, "read_only": 1, "reqd": 1 }, @@ -180,6 +182,7 @@ "oldfieldname": "stock_uom", "oldfieldtype": "Link", "options": "UOM", + "print_hide": 1, "read_only": 1, "reqd": 1, "search_index": 0