From f56d73c9bc17663b1ab0918a4164d663af70e0fc Mon Sep 17 00:00:00 2001 From: Rushabh Mehta Date: Thu, 10 Oct 2013 16:35:09 +0530 Subject: [PATCH] [minor] removed get_rate --- .../purchase_invoice/purchase_invoice.py | 8 -------- .../purchase_taxes_and_charges_master.js | 16 ++------------- .../purchase_taxes_and_charges_master.py | 7 +------ .../doctype/sales_invoice/sales_invoice.py | 8 +------- .../sales_taxes_and_charges_master.js | 18 +++-------------- .../sales_taxes_and_charges_master.py | 6 +----- .../purchase_common/purchase_common.js | 1 + .../purchase_common/purchase_common.py | 15 -------------- .../doctype/purchase_order/purchase_order.py | 7 ------- controllers/accounts_controller.py | 4 ++++ controllers/buying_controller.py | 5 ++++- public/js/controllers/accounts.js | 18 +++++++++++++++++ selling/doctype/quotation/quotation.py | 6 ------ selling/doctype/sales_common/sales_common.js | 1 + selling/doctype/sales_common/sales_common.py | 20 ------------------- selling/doctype/sales_order/sales_order.py | 3 --- stock/doctype/delivery_note/delivery_note.py | 3 --- .../material_request/material_request.py | 4 ---- .../purchase_receipt/purchase_receipt.py | 8 -------- 19 files changed, 36 insertions(+), 122 deletions(-) create mode 100644 public/js/controllers/accounts.js diff --git a/accounts/doctype/purchase_invoice/purchase_invoice.py b/accounts/doctype/purchase_invoice/purchase_invoice.py index c79bfd6648..a562c67a38 100644 --- a/accounts/doctype/purchase_invoice/purchase_invoice.py +++ b/accounts/doctype/purchase_invoice/purchase_invoice.py @@ -88,14 +88,6 @@ class DocType(BuyingController): super(DocType, self).get_advances(self.doc.credit_to, "Purchase Invoice Advance", "advance_allocation_details", "debit") - def get_rate(self,arg): - return get_obj('Purchase Common').get_rate(arg,self) - - def get_rate1(self,acc): - rate = webnotes.conn.sql("select tax_rate from `tabAccount` where name='%s'"%(acc)) - ret={'add_tax_rate' :rate and flt(rate[0][0]) or 0 } - return ret - def check_active_purchase_items(self): for d in getlist(self.doclist, 'entries'): if d.item_code: # extra condn coz item_code is not mandatory in PV diff --git a/accounts/doctype/purchase_taxes_and_charges_master/purchase_taxes_and_charges_master.js b/accounts/doctype/purchase_taxes_and_charges_master/purchase_taxes_and_charges_master.js index 423c4e49b9..3368773601 100644 --- a/accounts/doctype/purchase_taxes_and_charges_master/purchase_taxes_and_charges_master.js +++ b/accounts/doctype/purchase_taxes_and_charges_master/purchase_taxes_and_charges_master.js @@ -4,6 +4,8 @@ // //--------- ONLOAD ------------- +wn.require("app/js/controllers/accounts.js"); + cur_frm.cscript.onload = function(doc, cdt, cdn) { } @@ -134,20 +136,6 @@ cur_frm.fields_dict['purchase_tax_details'].grid.get_field("cost_center").get_qu } } -cur_frm.cscript.account_head = function(doc, cdt, cdn) { - var d = locals[cdt][cdn]; - if(!d.charge_type && d.account_head){ - alert("Please select Charge Type first"); - validated = false; - d.account_head = ''; - } - else if(d.account_head && d.charge_type) { - arg = "{'charge_type' : '" + d.charge_type + "', 'account_head' : '" + d.account_head + "'}"; - return get_server_fields('get_rate', arg, 'purchase_tax_details', doc, cdt, cdn, 1); - } - refresh_field('account_head',d.name,'purchase_tax_details'); -} - cur_frm.cscript.rate = function(doc, cdt, cdn) { var d = locals[cdt][cdn]; if(!d.charge_type && d.rate) { diff --git a/accounts/doctype/purchase_taxes_and_charges_master/purchase_taxes_and_charges_master.py b/accounts/doctype/purchase_taxes_and_charges_master/purchase_taxes_and_charges_master.py index 0a32fb972d..3d003f6e93 100644 --- a/accounts/doctype/purchase_taxes_and_charges_master/purchase_taxes_and_charges_master.py +++ b/accounts/doctype/purchase_taxes_and_charges_master/purchase_taxes_and_charges_master.py @@ -14,9 +14,4 @@ from webnotes.model.code import get_obj class DocType: def __init__(self, doc, doclist=[]): self.doc = doc - self.doclist = doclist - - # Get Tax Rate if account type is Tax - # =================================================================== - def get_rate(self, arg): - return get_obj('Purchase Common').get_rate(arg, self) \ No newline at end of file + self.doclist = doclist \ No newline at end of file diff --git a/accounts/doctype/sales_invoice/sales_invoice.py b/accounts/doctype/sales_invoice/sales_invoice.py index 5c7597c403..92c168008a 100644 --- a/accounts/doctype/sales_invoice/sales_invoice.py +++ b/accounts/doctype/sales_invoice/sales_invoice.py @@ -264,13 +264,7 @@ class DocType(SellingController): def get_adj_percent(self, arg=''): """Fetch ref rate from item master as per selected price list""" - get_obj('Sales Common').get_adj_percent(self) - - - def get_rate(self,arg): - """Get tax rate if account type is tax""" - get_obj('Sales Common').get_rate(arg) - + get_obj('Sales Common').get_adj_percent(self) def get_comm_rate(self, sales_partner): """Get Commission rate of Sales Partner""" diff --git a/accounts/doctype/sales_taxes_and_charges_master/sales_taxes_and_charges_master.js b/accounts/doctype/sales_taxes_and_charges_master/sales_taxes_and_charges_master.js index f1a602738b..d8f55fdd50 100644 --- a/accounts/doctype/sales_taxes_and_charges_master/sales_taxes_and_charges_master.js +++ b/accounts/doctype/sales_taxes_and_charges_master/sales_taxes_and_charges_master.js @@ -2,6 +2,9 @@ // License: GNU General Public License v3. See license.txt //--------- ONLOAD ------------- + +wn.require("app/js/controllers/accounts.js"); + cur_frm.cscript.onload = function(doc, cdt, cdn) { if(doc.doctype === "Sales Taxes and Charges Master") erpnext.add_for_territory(); @@ -142,21 +145,6 @@ cur_frm.fields_dict['other_charges'].grid.get_field("cost_center").get_query = f } } - -cur_frm.cscript.account_head = function(doc, cdt, cdn) { - var d = locals[cdt][cdn]; - if(!d.charge_type && d.account_head){ - alert("Please select Charge Type first"); - validated = false; - d.account_head = ''; - } - else if(d.account_head && d.charge_type) { - arg = "{'charge_type' : '" + d.charge_type +"', 'account_head' : '" + d.account_head + "'}"; - return get_server_fields('get_rate', arg, 'other_charges', doc, cdt, cdn, 1); - } - refresh_field('account_head',d.name,'other_charges'); -} - cur_frm.cscript.rate = function(doc, cdt, cdn) { var d = locals[cdt][cdn]; if(!d.charge_type && d.rate) { diff --git a/accounts/doctype/sales_taxes_and_charges_master/sales_taxes_and_charges_master.py b/accounts/doctype/sales_taxes_and_charges_master/sales_taxes_and_charges_master.py index 019edcb31b..67ba9cb8ad 100644 --- a/accounts/doctype/sales_taxes_and_charges_master/sales_taxes_and_charges_master.py +++ b/accounts/doctype/sales_taxes_and_charges_master/sales_taxes_and_charges_master.py @@ -6,11 +6,7 @@ import webnotes from webnotes.utils import cint from webnotes.model.controller import DocListController -class DocType(DocListController): - def get_rate(self, arg): - from webnotes.model.code import get_obj - return get_obj('Sales Common').get_rate(arg) - +class DocType(DocListController): def validate(self): if self.doc.is_default == 1: webnotes.conn.sql("""update `tabSales Taxes and Charges Master` set is_default = 0 diff --git a/buying/doctype/purchase_common/purchase_common.js b/buying/doctype/purchase_common/purchase_common.js index 433a76fba7..023c7f3a63 100644 --- a/buying/doctype/purchase_common/purchase_common.js +++ b/buying/doctype/purchase_common/purchase_common.js @@ -8,6 +8,7 @@ wn.provide("erpnext.buying"); wn.require("app/js/transaction.js"); +wn.require("app/js/controllers/accounts.js"); erpnext.buying.BuyingController = erpnext.TransactionController.extend({ onload: function() { diff --git a/buying/doctype/purchase_common/purchase_common.py b/buying/doctype/purchase_common/purchase_common.py index c05aba4883..1d57f88910 100644 --- a/buying/doctype/purchase_common/purchase_common.py +++ b/buying/doctype/purchase_common/purchase_common.py @@ -36,13 +36,6 @@ class DocType(BuyingController): msgprint("Supplier : %s does not exists" % (name)) raise Exception - # Get Available Qty at Warehouse - def get_bin_details( self, arg = ''): - arg = eval(arg) - bin = webnotes.conn.sql("select projected_qty from `tabBin` where item_code = %s and warehouse = %s", (arg['item_code'], arg['warehouse']), as_dict=1) - ret = { 'projected_qty' : bin and flt(bin[0]['projected_qty']) or 0 } - return ret - def update_last_purchase_rate(self, obj, is_submit): """updates last_purchase_rate in item table for each item""" @@ -197,14 +190,6 @@ class DocType(BuyingController): msgprint(cstr(doctype) + ": " + cstr(submitted[0][0]) + _(" not submitted"), raise_exception=1) - def get_rate(self, arg, obj): - arg = eval(arg) - rate = webnotes.conn.sql("select account_type, tax_rate from `tabAccount` where name = %s" - , (arg['account_head']), as_dict=1) - - return {'rate': rate and (rate[0]['account_type'] == 'Tax' \ - and not arg['charge_type'] == 'Actual') and flt(rate[0]['tax_rate']) or 0 } - def get_prevdoc_date(self, obj): for d in getlist(obj.doclist, obj.fname): if d.prevdoc_doctype and d.prevdoc_docname: diff --git a/buying/doctype/purchase_order/purchase_order.py b/buying/doctype/purchase_order/purchase_order.py index 3389f7419a..dc75466a4b 100644 --- a/buying/doctype/purchase_order/purchase_order.py +++ b/buying/doctype/purchase_order/purchase_order.py @@ -65,10 +65,6 @@ class DocType(BuyingController): } }) - # get available qty at warehouse - def get_bin_details(self, arg = ''): - return get_obj(dt='Purchase Common').get_bin_details(arg) - def get_schedule_dates(self): for d in getlist(self.doclist, 'po_details'): if d.prevdoc_detail_docname and not d.schedule_date: @@ -185,9 +181,6 @@ class DocType(BuyingController): def on_update(self): pass - def get_rate(self,arg): - return get_obj('Purchase Common').get_rate(arg,self) - @webnotes.whitelist() def make_purchase_receipt(source_name, target_doclist=None): from webnotes.model.mapper import get_mapped_doclist diff --git a/controllers/accounts_controller.py b/controllers/accounts_controller.py index 927b24980f..f290d4d747 100644 --- a/controllers/accounts_controller.py +++ b/controllers/accounts_controller.py @@ -423,3 +423,7 @@ class AccountsController(TransactionBase): self._abbr = webnotes.conn.get_value("Company", self.doc.company, "abbr") return self._abbr + +@webnotes.whitelist() +def get_tax_rate(account_head): + return webnotes.conn.get_value("Account", account_head, "tax_rate") diff --git a/controllers/buying_controller.py b/controllers/buying_controller.py index 25d76aa66d..3de550c4c2 100644 --- a/controllers/buying_controller.py +++ b/controllers/buying_controller.py @@ -2,7 +2,7 @@ # License: GNU General Public License v3. See license.txt from __future__ import unicode_literals -import webnotes +import webnotes, json from webnotes import _, msgprint from webnotes.utils import flt, _round @@ -280,3 +280,6 @@ class BuyingController(StockController): (", ".join((["%s"]*len(item_codes))),), item_codes)] return self._purchase_items + + def get_bin_details(self, arg): + return {"projected_qty": webnotes.conn.get_value("Bin", json.loads(arg), "projected_qty") or 0 } diff --git a/public/js/controllers/accounts.js b/public/js/controllers/accounts.js new file mode 100644 index 0000000000..201c47e2bb --- /dev/null +++ b/public/js/controllers/accounts.js @@ -0,0 +1,18 @@ + +// get tax rate +cur_frm.cscript.account_head = function(doc, cdt, cdn) { + var d = locals[cdt][cdn]; + if(!d.charge_type && d.account_head){ + msgprint("Please select Charge Type first"); + wn.model.set_value(cdt, cdn, "account_head", ""); + } else if(d.account_head && d.charge_type!=="Actual") { + wn.call({ + type:"GET", + method: "controllers.accounts_controller.get_tax_rate", + args: {"account_head":d.account_head}, + callback: function(r) { + wn.model.set_value(cdt, cdn, "rate", r.message || 0); + } + }) + } +} diff --git a/selling/doctype/quotation/quotation.py b/selling/doctype/quotation/quotation.py index b6bc45d772..78afb97404 100644 --- a/selling/doctype/quotation/quotation.py +++ b/selling/doctype/quotation/quotation.py @@ -56,13 +56,7 @@ class DocType(SellingController): # -------------------------------------------------------------- def get_adj_percent(self, arg=''): get_obj('Sales Common').get_adj_percent(self) - - # Get Tax rate if account type is TAX - # ----------------------------------- - def get_rate(self,arg): - return get_obj('Sales Common').get_rate(arg) - # Does not allow same item code to be entered twice # ------------------------------------------------- def validate_for_items(self): diff --git a/selling/doctype/sales_common/sales_common.js b/selling/doctype/sales_common/sales_common.js index c87e823dba..f744faa32a 100644 --- a/selling/doctype/sales_common/sales_common.js +++ b/selling/doctype/sales_common/sales_common.js @@ -10,6 +10,7 @@ wn.provide("erpnext.selling"); wn.require("app/js/transaction.js"); +wn.require("app/js/controllers/accounts.js"); erpnext.selling.SellingController = erpnext.TransactionController.extend({ onload: function() { diff --git a/selling/doctype/sales_common/sales_common.py b/selling/doctype/sales_common/sales_common.py index df7f151149..634ea2a370 100644 --- a/selling/doctype/sales_common/sales_common.py +++ b/selling/doctype/sales_common/sales_common.py @@ -86,26 +86,6 @@ class DocType(TransactionBase): if (obj.doc.price_list_currency == default_currency and flt(obj.doc.plc_conversion_rate) != 1.00) or not obj.doc.plc_conversion_rate or (obj.doc.price_list_currency != default_currency and flt(obj.doc.plc_conversion_rate) == 1.00): msgprint("Please Enter Appropriate Conversion Rate for Price List Currency to Base Currency (%s --> %s)" % (obj.doc.price_list_currency, default_currency), raise_exception = 1) - - - - # Get Tax rate if account type is TAX - # ========================================================================= - def get_rate(self, arg): - arg = eval(arg) - rate = webnotes.conn.sql("select account_type, tax_rate from `tabAccount` where name = '%s' and docstatus != 2" %(arg['account_head']), as_dict=1) - ret = {'rate' : 0} - if arg['charge_type'] == 'Actual' and rate[0]['account_type'] == 'Tax': - msgprint("You cannot select ACCOUNT HEAD of type TAX as your CHARGE TYPE is 'ACTUAL'") - ret = { - 'account_head' : '' - } - elif rate[0]['account_type'] in ['Tax', 'Chargeable'] and not arg['charge_type'] == 'Actual': - ret = { - 'rate' : rate and flt(rate[0]['tax_rate']) or 0 - } - return ret - def get_item_list(self, obj, is_stopped=0): """get item list""" diff --git a/selling/doctype/sales_order/sales_order.py b/selling/doctype/sales_order/sales_order.py index 0cdca58ce9..1c22c08a3b 100644 --- a/selling/doctype/sales_order/sales_order.py +++ b/selling/doctype/sales_order/sales_order.py @@ -38,9 +38,6 @@ class DocType(SellingController): def get_available_qty(self,args): return get_obj('Sales Common').get_available_qty(eval(args)) - def get_rate(self,arg): - return get_obj('Sales Common').get_rate(arg) - def validate_mandatory(self): # validate transaction date v/s delivery date if self.doc.delivery_date: diff --git a/stock/doctype/delivery_note/delivery_note.py b/stock/doctype/delivery_note/delivery_note.py index b20e790af7..281908598f 100644 --- a/stock/doctype/delivery_note/delivery_note.py +++ b/stock/doctype/delivery_note/delivery_note.py @@ -66,9 +66,6 @@ class DocType(SellingController): """Re-calculates Basic Rate & amount based on Price List Selected""" get_obj('Sales Common').get_adj_percent(self) - def get_rate(self,arg): - return get_obj('Sales Common').get_rate(arg) - def so_required(self): """check in manage account if sales order required or not""" if webnotes.conn.get_value("Selling Settings", None, 'so_required') == 'Yes': diff --git a/stock/doctype/material_request/material_request.py b/stock/doctype/material_request/material_request.py index d1672ba12c..7aea3364e4 100644 --- a/stock/doctype/material_request/material_request.py +++ b/stock/doctype/material_request/material_request.py @@ -20,10 +20,6 @@ class DocType(BuyingController): self.tname = 'Material Request Item' self.fname = 'indent_details' - # get available qty at warehouse - def get_bin_details(self, arg = ''): - return get_obj(dt='Purchase Common').get_bin_details(arg) - def check_if_already_pulled(self): pass#if self.[d.sales_order_no for d in getlist(self.doclist, 'indent_details')] diff --git a/stock/doctype/purchase_receipt/purchase_receipt.py b/stock/doctype/purchase_receipt/purchase_receipt.py index 6169b1d916..1e1f1eaf86 100644 --- a/stock/doctype/purchase_receipt/purchase_receipt.py +++ b/stock/doctype/purchase_receipt/purchase_receipt.py @@ -38,10 +38,6 @@ class DocType(BuyingController): total_qty = sum((item.qty for item in self.doclist.get({"parentfield": "purchase_receipt_details"}))) self.doc.fields["__billing_complete"] = billed_qty[0][0] == total_qty - # get available qty at warehouse - def get_bin_details(self, arg = ''): - return get_obj(dt='Purchase Common').get_bin_details(arg) - def validate(self): super(DocType, self).validate() @@ -290,10 +286,6 @@ class DocType(BuyingController): bin = webnotes.conn.sql("select actual_qty from `tabBin` where item_code = %s and warehouse = %s", (d.rm_item_code, self.doc.supplier_warehouse), as_dict = 1) d.current_stock = bin and flt(bin[0]['actual_qty']) or 0 - - def get_rate(self,arg): - return get_obj('Purchase Common').get_rate(arg,self) - def get_gl_entries_for_stock(self, warehouse_account=None): against_stock_account = self.get_company_default("stock_received_but_not_billed")