From 9d9aec1ed4adc09c4a86b45da64d06e08a7c3115 Mon Sep 17 00:00:00 2001 From: Anand Doshi Date: Thu, 17 Jan 2013 15:44:57 +0530 Subject: [PATCH] shifted get_company_currency from transaction base to setup/utils.py --- accounts/doctype/gl_control/gl_control.py | 13 ++------- .../journal_voucher/journal_voucher.py | 9 +++--- .../purchase_invoice/purchase_invoice.py | 5 ++-- .../doctype/sales_invoice/sales_invoice.py | 5 ++-- .../doctype/purchase_order/purchase_order.py | 6 ++-- .../supplier_quotation/supplier_quotation.py | 4 +-- hr/doctype/salary_slip/salary_slip.py | 6 ++-- selling/doctype/quotation/quotation.py | 9 +++--- selling/doctype/sales_common/sales_common.py | 3 +- selling/doctype/sales_order/sales_order.py | 8 +++--- .../authorization_control.py | 6 ++-- setup/utils.py | 28 +++++++++++++++++++ stock/doctype/delivery_note/delivery_note.py | 6 ++-- .../purchase_receipt/purchase_receipt.py | 4 +-- utilities/transaction_base.py | 8 ------ 15 files changed, 65 insertions(+), 55 deletions(-) create mode 100644 setup/utils.py diff --git a/accounts/doctype/gl_control/gl_control.py b/accounts/doctype/gl_control/gl_control.py index 44cab1e7a8..7566de5a63 100644 --- a/accounts/doctype/gl_control/gl_control.py +++ b/accounts/doctype/gl_control/gl_control.py @@ -17,26 +17,17 @@ from __future__ import unicode_literals import webnotes -from webnotes.utils import cstr, flt, get_defaults, now, sendmail -from webnotes.model import db_exists +from webnotes.utils import cstr, flt, get_defaults from webnotes.model.doc import Document, addchild -from webnotes.model.wrapper import getlist, copy_doclist +from webnotes.model.wrapper import getlist from webnotes.model.code import get_obj from webnotes import msgprint -from webnotes.utils.email_lib import sendmail - - -from utilities.transaction_base import TransactionBase class DocType: def __init__(self,d,dl): self.doc, self.doclist = d, dl self.entries = [] - def get_company_currency(self,arg=''): - dcc = TransactionBase().get_company_currency(arg) - return dcc - def get_period_difference(self,arg, cost_center =''): # used in General Ledger Page Report # used for Budget where cost center passed as extra argument diff --git a/accounts/doctype/journal_voucher/journal_voucher.py b/accounts/doctype/journal_voucher/journal_voucher.py index 7c1dcfee8d..89114dd72e 100644 --- a/accounts/doctype/journal_voucher/journal_voucher.py +++ b/accounts/doctype/journal_voucher/journal_voucher.py @@ -18,15 +18,14 @@ from __future__ import unicode_literals import webnotes from webnotes.utils import cint, cstr, flt, fmt_money, formatdate, getdate -from webnotes.model import db_exists from webnotes.model.doc import addchild, make_autoname -from webnotes.model.wrapper import getlist, copy_doclist +from webnotes.model.wrapper import getlist from webnotes.model.code import get_obj -from webnotes import form, msgprint +from webnotes import msgprint +from setup.utils import get_company_currency sql = webnotes.conn.sql -from utilities.transaction_base import TransactionBase class DocType: def __init__(self,d,dl): @@ -238,7 +237,7 @@ class DocType: self.doc.pay_to_recd_from = webnotes.conn.get_value(master_type, ' - '.join(d.account.split(' - ')[:-1]), master_type == 'Customer' and 'customer_name' or 'supplier_name') if acc_type == 'Bank or Cash': - dcc = TransactionBase().get_company_currency(self.doc.company) + dcc = get_company_currency(self.doc.company) amt = cint(d.debit) and d.debit or d.credit self.doc.total_amount = dcc +' '+ cstr(amt) self.doc.total_amount_in_words = get_obj('Sales Common').get_total_in_words(dcc, cstr(amt)) diff --git a/accounts/doctype/purchase_invoice/purchase_invoice.py b/accounts/doctype/purchase_invoice/purchase_invoice.py index 105f6c2c6c..82261ed5ea 100644 --- a/accounts/doctype/purchase_invoice/purchase_invoice.py +++ b/accounts/doctype/purchase_invoice/purchase_invoice.py @@ -21,6 +21,7 @@ from webnotes.utils import add_days, cint, cstr, flt, formatdate, get_defaults from webnotes.model.wrapper import getlist from webnotes.model.code import get_obj from webnotes import msgprint +from setup.utils import get_company_currency sql = webnotes.conn.sql @@ -159,7 +160,7 @@ class DocType(BuyingController): # Check Conversion Rate # ---------------------- def check_conversion_rate(self): - default_currency = super(DocType, self).get_company_currency(self.doc.company) + default_currency = get_company_currency(self.doc.company) if not default_currency: msgprint('Message: Please enter default currency in Company Master') raise Exception @@ -370,7 +371,7 @@ class DocType(BuyingController): pc_obj = get_obj(dt='Purchase Common') # get total in words - dcc = super(DocType, self).get_company_currency(self.doc.company) + dcc = get_company_currency(self.doc.company) self.doc.in_words = pc_obj.get_total_in_words(dcc, self.doc.grand_total) self.doc.in_words_import = pc_obj.get_total_in_words(self.doc.currency, self.doc.grand_total_import) diff --git a/accounts/doctype/sales_invoice/sales_invoice.py b/accounts/doctype/sales_invoice/sales_invoice.py index 5042f5380b..2e48f91879 100644 --- a/accounts/doctype/sales_invoice/sales_invoice.py +++ b/accounts/doctype/sales_invoice/sales_invoice.py @@ -26,6 +26,7 @@ from webnotes.model.doc import make_autoname from webnotes.model.wrapper import getlist, copy_doclist from webnotes.model.code import get_obj from webnotes import session, form, msgprint +from setup.utils import get_company_currency session = webnotes.session @@ -412,7 +413,7 @@ class DocType(TransactionBase): def set_in_words(self): - dcc = TransactionBase().get_company_currency(self.doc.company) + dcc = get_company_currency(self.doc.company) self.doc.in_words = get_obj('Sales Common').get_total_in_words(dcc, self.doc.rounded_total) self.doc.in_words_export = get_obj('Sales Common').get_total_in_words(self.doc.currency, self.doc.rounded_total_export) @@ -503,7 +504,7 @@ class DocType(TransactionBase): d.actual_qty = bin and flt(bin[0]['actual_qty']) or 0 for d in getlist(self.doclist, 'packing_details'): - bin = sql("select actual_qty, projected_qty from `tabBin` where item_code = %s and warehouse = %s", (d.item_code, d.warehouse), as_dict = 1) + bin = webnotes.conn.sql("select actual_qty, projected_qty from `tabBin` where item_code = %s and warehouse = %s", (d.item_code, d.warehouse), as_dict = 1) d.actual_qty = bin and flt(bin[0]['actual_qty']) or 0 d.projected_qty = bin and flt(bin[0]['projected_qty']) or 0 diff --git a/buying/doctype/purchase_order/purchase_order.py b/buying/doctype/purchase_order/purchase_order.py index 52d2be6cce..be2833c789 100644 --- a/buying/doctype/purchase_order/purchase_order.py +++ b/buying/doctype/purchase_order/purchase_order.py @@ -23,6 +23,7 @@ from webnotes.model.wrapper import getlist from webnotes.model.code import get_obj from webnotes import msgprint from buying.utils import get_last_purchase_details +from setup.utils import get_company_currency sql = webnotes.conn.sql @@ -57,9 +58,6 @@ class DocType(BuyingController): # Step 4:=> validate for items pc_obj.validate_for_items(self) - # Step 5:=> validate conversion rate - pc_obj.validate_conversion_rate(self) - # Get po date pc_obj.get_prevdoc_date(self) @@ -70,7 +68,7 @@ class DocType(BuyingController): self.check_for_stopped_status(pc_obj) # get total in words - dcc = super(DocType, self).get_company_currency(self.doc.company) + dcc = get_company_currency(self.doc.company) self.doc.in_words = pc_obj.get_total_in_words(dcc, self.doc.grand_total) self.doc.in_words_import = pc_obj.get_total_in_words(self.doc.currency, self.doc.grand_total_import) diff --git a/buying/doctype/supplier_quotation/supplier_quotation.py b/buying/doctype/supplier_quotation/supplier_quotation.py index 0bc5f13172..4f28ecf59c 100644 --- a/buying/doctype/supplier_quotation/supplier_quotation.py +++ b/buying/doctype/supplier_quotation/supplier_quotation.py @@ -17,6 +17,7 @@ from __future__ import unicode_literals import webnotes from webnotes.model.code import get_obj +from setup.utils import get_company_currency from controllers.buying_controller import BuyingController class DocType(BuyingController): @@ -77,12 +78,11 @@ class DocType(BuyingController): pc = get_obj('Purchase Common') pc.validate_mandatory(self) pc.validate_for_items(self) - pc.validate_conversion_rate(self) pc.get_prevdoc_date(self) pc.validate_reference_value(self) def set_in_words(self): pc = get_obj('Purchase Common') - company_currency = super(DocType, self).get_company_currency(self.doc.company) + company_currency = get_company_currency(self.doc.company) self.doc.in_words = pc.get_total_in_words(company_currency, self.doc.grand_total) self.doc.in_words_import = pc.get_total_in_words(self.doc.currency, self.doc.grand_total_import) diff --git a/hr/doctype/salary_slip/salary_slip.py b/hr/doctype/salary_slip/salary_slip.py index 7886281ea4..651cc77776 100644 --- a/hr/doctype/salary_slip/salary_slip.py +++ b/hr/doctype/salary_slip/salary_slip.py @@ -18,11 +18,11 @@ from __future__ import unicode_literals import webnotes from webnotes.utils import add_days, cint, cstr, flt, getdate -from webnotes.model import db_exists from webnotes.model.doc import make_autoname -from webnotes.model.wrapper import getlist, copy_doclist +from webnotes.model.wrapper import getlist from webnotes.model.code import get_obj from webnotes import msgprint +from setup.utils import get_company_currency sql = webnotes.conn.sql @@ -137,7 +137,7 @@ class DocType(TransactionBase): def validate(self): self.check_existing() - dcc = TransactionBase().get_company_currency(self.doc.company) + dcc = get_company_currency(self.doc.company) self.doc.total_in_words = get_obj('Sales Common').get_total_in_words(dcc, self.doc.rounded_total) diff --git a/selling/doctype/quotation/quotation.py b/selling/doctype/quotation/quotation.py index ed09ab03f8..111b0b493b 100644 --- a/selling/doctype/quotation/quotation.py +++ b/selling/doctype/quotation/quotation.py @@ -17,12 +17,11 @@ from __future__ import unicode_literals import webnotes -from webnotes.utils import cstr, load_json -from webnotes.model import db_exists -from webnotes.model.doc import Document -from webnotes.model.wrapper import getlist, copy_doclist +from webnotes.utils import cstr, getdate +from webnotes.model.wrapper import getlist from webnotes.model.code import get_obj from webnotes import msgprint +from setup.utils import get_company_currency sql = webnotes.conn.sql @@ -194,7 +193,7 @@ class DocType(TransactionBase): sales_com_obj.check_conversion_rate(self) # Get total in words - dcc = TransactionBase().get_company_currency(self.doc.company) + dcc = get_company_currency(self.doc.company) self.doc.in_words = sales_com_obj.get_total_in_words(dcc, self.doc.rounded_total) self.doc.in_words_export = sales_com_obj.get_total_in_words(self.doc.currency, self.doc.rounded_total_export) diff --git a/selling/doctype/sales_common/sales_common.py b/selling/doctype/sales_common/sales_common.py index 03280e2804..b0b04bf68e 100644 --- a/selling/doctype/sales_common/sales_common.py +++ b/selling/doctype/sales_common/sales_common.py @@ -23,6 +23,7 @@ from webnotes.model.doc import addchild from webnotes.model.wrapper import getlist, copy_doclist from webnotes.model.code import get_obj from webnotes import form, msgprint, _ +from setup.utils import get_company_currency get_value = webnotes.conn.get_value @@ -351,7 +352,7 @@ class DocType(TransactionBase): # Check Conversion Rate (i.e. it will not allow conversion rate to be 1 for Currency other than default currency set in Global Defaults) # =========================================================================== def check_conversion_rate(self, obj): - default_currency = TransactionBase().get_company_currency(obj.doc.company) + default_currency = get_company_currency(obj.doc.company) if not default_currency: msgprint('Message: Please enter default currency in Company Master') raise Exception diff --git a/selling/doctype/sales_order/sales_order.py b/selling/doctype/sales_order/sales_order.py index 3e7b03dd83..f035cdc656 100644 --- a/selling/doctype/sales_order/sales_order.py +++ b/selling/doctype/sales_order/sales_order.py @@ -17,11 +17,11 @@ from __future__ import unicode_literals import webnotes -from webnotes.utils import cstr, date_diff, flt, getdate -from webnotes.model import db_exists -from webnotes.model.wrapper import getlist, copy_doclist +from webnotes.utils import cstr, flt, getdate +from webnotes.model.wrapper import getlist from webnotes.model.code import get_obj from webnotes import msgprint +from setup.utils import get_company_currency sql = webnotes.conn.sql @@ -222,7 +222,7 @@ class DocType(TransactionBase): self.doclist = sales_com_obj.make_packing_list(self,'sales_order_details') # get total in words - dcc = TransactionBase().get_company_currency(self.doc.company) + dcc = get_company_currency(self.doc.company) self.doc.in_words = sales_com_obj.get_total_in_words(dcc, self.doc.rounded_total) self.doc.in_words_export = sales_com_obj.get_total_in_words(self.doc.currency, self.doc.rounded_total_export) diff --git a/setup/doctype/authorization_control/authorization_control.py b/setup/doctype/authorization_control/authorization_control.py index 9455f8a874..8e02bdf617 100644 --- a/setup/doctype/authorization_control/authorization_control.py +++ b/setup/doctype/authorization_control/authorization_control.py @@ -18,9 +18,9 @@ from __future__ import unicode_literals import webnotes from webnotes.utils import cstr, flt, has_common, make_esc -from webnotes.model import db_exists -from webnotes.model.wrapper import getlist, copy_doclist +from webnotes.model.wrapper import getlist from webnotes import session, msgprint +from setup.utils import get_company_currency sql = webnotes.conn.sql @@ -52,7 +52,7 @@ class DocType(TransactionBase): if not has_common(appr_roles, webnotes.user.get_roles()) and not has_common(appr_users, [session['user']]): msg, add_msg = '','' if max_amount: - dcc = TransactionBase().get_company_currency(self.doc.company) + dcc = get_company_currency(self.doc.company) if based_on == 'Grand Total': msg = "since Grand Total exceeds %s. %s" % (dcc, flt(max_amount)) elif based_on == 'Itemwise Discount': msg = "since Discount exceeds %s for Item Code : %s" % (cstr(max_amount)+'%', item) elif based_on == 'Average Discount' or based_on == 'Customerwise Discount': msg = "since Discount exceeds %s" % (cstr(max_amount)+'%') diff --git a/setup/utils.py b/setup/utils.py new file mode 100644 index 0000000000..baa4d0ffd0 --- /dev/null +++ b/setup/utils.py @@ -0,0 +1,28 @@ +# ERPNext - web based ERP (http://erpnext.com) +# Copyright (C) 2012 Web Notes Technologies Pvt Ltd +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +from __future__ import unicode_literals +import webnotes + +def get_company_currency(company): + currency = webnotes.conn.get_value("Company", company, "default_currency") + if not currency: + currency = webnotes.conn.get_default("currency") + if not currency: + msgprint(_('Please specify Default Currency in Company Master \ + and Global Defaults'), raise_exception=True) + + return currency \ No newline at end of file diff --git a/stock/doctype/delivery_note/delivery_note.py b/stock/doctype/delivery_note/delivery_note.py index 411ce5c4c0..53f66c32de 100644 --- a/stock/doctype/delivery_note/delivery_note.py +++ b/stock/doctype/delivery_note/delivery_note.py @@ -18,10 +18,10 @@ from __future__ import unicode_literals import webnotes from webnotes.utils import cstr, flt, getdate -from webnotes.model import db_exists -from webnotes.model.wrapper import getlist, copy_doclist +from webnotes.model.wrapper import getlist from webnotes.model.code import get_obj from webnotes import msgprint +from setup.utils import get_company_currency sql = webnotes.conn.sql @@ -149,7 +149,7 @@ class DocType(TransactionBase): sales_com_obj.check_conversion_rate(self) # Get total in Words - dcc = TransactionBase().get_company_currency(self.doc.company) + dcc = get_company_currency(self.doc.company) self.doc.in_words = sales_com_obj.get_total_in_words(dcc, self.doc.rounded_total) self.doc.in_words_export = sales_com_obj.get_total_in_words(self.doc.currency, self.doc.rounded_total_export) diff --git a/stock/doctype/purchase_receipt/purchase_receipt.py b/stock/doctype/purchase_receipt/purchase_receipt.py index 3d45d1e2fb..0015048435 100644 --- a/stock/doctype/purchase_receipt/purchase_receipt.py +++ b/stock/doctype/purchase_receipt/purchase_receipt.py @@ -22,6 +22,7 @@ from webnotes.model.doc import addchild from webnotes.model.wrapper import getlist from webnotes.model.code import get_obj from webnotes import msgprint +from setup.utils import get_company_currency sql = webnotes.conn.sql @@ -131,13 +132,12 @@ class DocType(BuyingController): pc_obj = get_obj(dt='Purchase Common') pc_obj.validate_for_items(self) pc_obj.validate_mandatory(self) - pc_obj.validate_conversion_rate(self) pc_obj.get_prevdoc_date(self) pc_obj.validate_reference_value(self) self.check_for_stopped_status(pc_obj) # get total in words - dcc = super(DocType, self).get_company_currency(self.doc.company) + dcc = get_company_currency(self.doc.company) self.doc.in_words = pc_obj.get_total_in_words(dcc, self.doc.grand_total) self.doc.in_words_import = pc_obj.get_total_in_words(self.doc.currency, self.doc.grand_total_import) # update valuation rate diff --git a/utilities/transaction_base.py b/utilities/transaction_base.py index 2ff42af0c4..850204152c 100644 --- a/utilities/transaction_base.py +++ b/utilities/transaction_base.py @@ -229,14 +229,6 @@ class TransactionBase(DocListController): ch.incentives = d and flt(d[3]) or 0 ch.idx = idx idx += 1 - - # Get Company Specific Default Currency - # ------------------------------------- - def get_company_currency(self, name): - ret = webnotes.conn.sql("select default_currency from tabCompany where name = '%s'" %(name)) - dcc = ret and ret[0][0] or get_defaults()['currency'] - return dcc - def load_notification_message(self): dt = self.doc.doctype.lower().replace(" ", "_")