From 5708da5a9f0102c2f725caf189d7da2ed32ce4d2 Mon Sep 17 00:00:00 2001 From: Ravi Dey Date: Tue, 28 Jun 2011 19:01:02 +0530 Subject: [PATCH] Default currency for company fixed --- accounts/doctype/form_16a/form_16a.py | 9 +++++---- accounts/doctype/gl_control/gl_control.py | 8 ++++---- accounts/doctype/journal_voucher/journal_voucher.py | 12 +++++++----- .../doctype/receivable_voucher/receivable_voucher.py | 3 ++- accounts/page/accounts_browser/accounts_browser.js | 2 +- crm/doctype/quotation/quotation.py | 3 ++- crm/doctype/sales_order/sales_order.py | 3 ++- .../doctype/delivery_note/delivery_note.py | 3 ++- payroll/doctype/salary_slip/salary_slip.py | 7 ++++--- .../authorization_control/authorization_control.py | 7 ++++--- srm/doctype/purchase_order/purchase_order.py | 3 ++- utilities/transaction_base.py | 9 ++++++++- 12 files changed, 43 insertions(+), 26 deletions(-) diff --git a/accounts/doctype/form_16a/form_16a.py b/accounts/doctype/form_16a/form_16a.py index 66880ed21b..7d569b70d8 100644 --- a/accounts/doctype/form_16a/form_16a.py +++ b/accounts/doctype/form_16a/form_16a.py @@ -15,9 +15,9 @@ in_transaction = webnotes.conn.in_transaction convert_to_lists = webnotes.conn.convert_to_lists # ----------------------------------------------------------------------------------------- +from utilities.transaction_base import TransactionBase - -class DocType: +class DocType(TransactionBase): def __init__(self,d,dl): self.doc, self.doclist = d, dl @@ -97,5 +97,6 @@ class DocType: for d in getlist(self.doclist,'form_16A_tax_details'): tot=flt(tot)+flt(d.total_tax_deposited) - self.doc.total_amount = flt(tot) - self.doc.in_words = get_obj('Sales Common').get_total_in_words(get_defaults()['currency'], self.doc.total_amount) + dcc = TransactionBase().get_company_currency(self.doc.company) + self.doc.total_amount = flt(tot) + self.doc.in_words = get_obj('Sales Common').get_total_in_words(dcc, self.doc.total_amount) diff --git a/accounts/doctype/gl_control/gl_control.py b/accounts/doctype/gl_control/gl_control.py index 2a862edc5f..d88b6184e4 100644 --- a/accounts/doctype/gl_control/gl_control.py +++ b/accounts/doctype/gl_control/gl_control.py @@ -15,7 +15,7 @@ in_transaction = webnotes.conn.in_transaction convert_to_lists = webnotes.conn.convert_to_lists # ----------------------------------------------------------------------------------------- - +from utilities.transaction_base import TransactionBase class DocType: def __init__(self,d,dl): @@ -34,9 +34,9 @@ class DocType: # pl[r[0]] = flt(flt(inc) - flt(exp)) return {'cl':[r[0] for r in ret]}#, 'pl':pl} - def get_company_currency(self,arg=''): - ret = sql("select default_currency from tabCompany where name=%s and docstatus != 2", arg) - return ret[0] + def get_company_currency(self,arg=''): + dcc = TransactionBase().get_company_currency(arg) + return dcc # Get current balance # -------------------- diff --git a/accounts/doctype/journal_voucher/journal_voucher.py b/accounts/doctype/journal_voucher/journal_voucher.py index cb10555614..4f5e67a79b 100644 --- a/accounts/doctype/journal_voucher/journal_voucher.py +++ b/accounts/doctype/journal_voucher/journal_voucher.py @@ -15,7 +15,7 @@ in_transaction = webnotes.conn.in_transaction convert_to_lists = webnotes.conn.convert_to_lists # ----------------------------------------------------------------------------------------- - +from utilities.transaction_base import TransactionBase class DocType: def __init__(self,d,dl): @@ -238,7 +238,7 @@ class DocType: if self.doc.total_debit > 0: self.get_tds_category_account() if self.doc.supplier_account and self.doc.tds_category: - get_obj('TDS Control').get_tds_amount(self) + get_obj('TDS Control').get_tds_amount(self) #-------------------------------------------------------------------------------------------------------- @@ -333,6 +333,7 @@ class DocType: # ------------------------ def set_print_format_fields(self): for d in getlist(self.doclist, 'entries'): + #msgprint(self.doc.company) chk_type = sql("select master_type, account_type from `tabAccount` where name='%s'" % d.account) master_type, acc_type = chk_type and cstr(chk_type[0][0]) or '', chk_type and cstr(chk_type[0][1]) or '' if master_type in ['Supplier', 'Customer']: @@ -340,9 +341,10 @@ class DocType: self.doc.pay_to_recd_from = get_value(master_type, ' - '.join(d.account.split(' - ')[:-1]), master_type == 'Customer' and 'customer_name' or 'supplier_name') if acc_type == 'Bank or Cash': - amt = cint(d.debit) and d.debit or d.credit - self.doc.total_amount = get_defaults()['currency']+'. '+ cstr(amt) - self.doc.total_amount_in_words = get_obj('Sales Common').get_total_in_words(get_defaults()['currency'], cstr(amt)) + dcc = TransactionBase().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/receivable_voucher/receivable_voucher.py b/accounts/doctype/receivable_voucher/receivable_voucher.py index c12c3900aa..6fac40d277 100644 --- a/accounts/doctype/receivable_voucher/receivable_voucher.py +++ b/accounts/doctype/receivable_voucher/receivable_voucher.py @@ -311,7 +311,8 @@ class DocType(TransactionBase): # Set totals in words #-------------------- def set_in_words(self): - self.doc.in_words = get_obj('Sales Common').get_total_in_words(get_defaults()['currency'], self.doc.rounded_total) + dcc = TransactionBase().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) # Clear Advances diff --git a/accounts/page/accounts_browser/accounts_browser.js b/accounts/page/accounts_browser/accounts_browser.js index 1cca1e139c..38acfc9dc2 100644 --- a/accounts/page/accounts_browser/accounts_browser.js +++ b/accounts/page/accounts_browser/accounts_browser.js @@ -210,7 +210,7 @@ pscript.set_ac_head = function(parent_account, r,type) { } $c_obj('GL Control', 'get_company_currency', pscript.ab_company_sel.value, callback); - d.balance.innerHTML = (dcc ? dcc : sys_defaults.currency)+ ' ' + (r.balance ? fmt_money(r.balance) :'0.00'); + d.balance.innerHTML = (dcc)+ ' ' + (r.balance ? fmt_money(r.balance) :'0.00'); } //cost center group/ledger area else{ diff --git a/crm/doctype/quotation/quotation.py b/crm/doctype/quotation/quotation.py index caa0430e4d..aed868ef1d 100644 --- a/crm/doctype/quotation/quotation.py +++ b/crm/doctype/quotation/quotation.py @@ -207,7 +207,8 @@ class DocType(TransactionBase): sales_com_obj.check_conversion_rate(self) # Get total in words - self.doc.in_words = sales_com_obj.get_total_in_words(get_defaults()['currency'], self.doc.rounded_total) + dcc = TransactionBase().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) def on_update(self): diff --git a/crm/doctype/sales_order/sales_order.py b/crm/doctype/sales_order/sales_order.py index e1e15f18d3..11842fb079 100644 --- a/crm/doctype/sales_order/sales_order.py +++ b/crm/doctype/sales_order/sales_order.py @@ -305,7 +305,8 @@ class DocType(TransactionBase): sales_com_obj.make_packing_list(self,'sales_order_details') # get total in words - self.doc.in_words = sales_com_obj.get_total_in_words(get_defaults()['currency'], self.doc.rounded_total) + dcc = TransactionBase().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) # set SO status diff --git a/material_management/doctype/delivery_note/delivery_note.py b/material_management/doctype/delivery_note/delivery_note.py index b223da4eb5..74e6f8a97f 100644 --- a/material_management/doctype/delivery_note/delivery_note.py +++ b/material_management/doctype/delivery_note/delivery_note.py @@ -175,7 +175,8 @@ class DocType(TransactionBase): sales_com_obj.get_allocated_sum(self) # this is to verify that the allocated % of sales persons is 100% sales_com_obj.check_conversion_rate(self) # ::::::: Get total in Words :::::::: - self.doc.in_words = sales_com_obj.get_total_in_words(get_defaults()['currency'], self.doc.rounded_total) + dcc = TransactionBase().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) # ::::::: Set actual qty for each item in selected warehouse ::::::: diff --git a/payroll/doctype/salary_slip/salary_slip.py b/payroll/doctype/salary_slip/salary_slip.py index e952da2087..9c94885963 100644 --- a/payroll/doctype/salary_slip/salary_slip.py +++ b/payroll/doctype/salary_slip/salary_slip.py @@ -15,9 +15,9 @@ in_transaction = webnotes.conn.in_transaction convert_to_lists = webnotes.conn.convert_to_lists # ----------------------------------------------------------------------------------------- +from utilities.transaction_base import TransactionBase - -class DocType: +class DocType(TransactionBase): def __init__(self,doc,doclist=[]): self.doc = doc self.doclist = doclist @@ -118,7 +118,8 @@ class DocType: #======================================================= def validate(self): self.check_existing() - self.doc.total_in_words = get_obj('Sales Common').get_total_in_words(get_defaults()['currency'], self.doc.rounded_total) + dcc = TransactionBase().get_company_currency(self.doc.company) + self.doc.total_in_words = get_obj('Sales Common').get_total_in_words(dcc, self.doc.rounded_total) # ON SUBMIT #======================================================= diff --git a/settings/doctype/authorization_control/authorization_control.py b/settings/doctype/authorization_control/authorization_control.py index 9e8186b86b..4036ecf594 100644 --- a/settings/doctype/authorization_control/authorization_control.py +++ b/settings/doctype/authorization_control/authorization_control.py @@ -15,9 +15,9 @@ in_transaction = webnotes.conn.in_transaction convert_to_lists = webnotes.conn.convert_to_lists # ----------------------------------------------------------------------------------------- +from utilities.transaction_base import TransactionBase - -class DocType: +class DocType(TransactionBase): def __init__(self, d, dl): self.doc, self.doclist = d, dl @@ -42,7 +42,8 @@ class DocType: if not has_common(appr_roles, webnotes.user.get_roles()) and not has_common(appr_users, session['user']): msg, add_msg = '','' if max_amount: - if based_on == 'Grand Total': msg = "since Grand Total exceeds %s. %s" % (get_defaults()['currency'], flt(max_amount)) + dcc = TransactionBase().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/srm/doctype/purchase_order/purchase_order.py b/srm/doctype/purchase_order/purchase_order.py index 7c02e65c09..7d9e1da03b 100644 --- a/srm/doctype/purchase_order/purchase_order.py +++ b/srm/doctype/purchase_order/purchase_order.py @@ -133,7 +133,8 @@ class DocType(TransactionBase): # get total in words - self.doc.in_words = pc_obj.get_total_in_words(get_defaults().get('currency') and get_defaults()['currency'] or 'INR', self.doc.grand_total) + dcc = TransactionBase().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 bin diff --git a/utilities/transaction_base.py b/utilities/transaction_base.py index e1707004fb..332e201986 100644 --- a/utilities/transaction_base.py +++ b/utilities/transaction_base.py @@ -1,5 +1,5 @@ import webnotes -from webnotes.utils import load_json, cint, cstr, flt +from webnotes.utils import load_json, cint, cstr, flt, get_defaults from webnotes.model.doc import Document, addchild, removechild, getchildren from webnotes.model.doclist import getlist, copy_doclist from webnotes import msgprint @@ -202,3 +202,10 @@ class TransactionBase: 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 = sql("select default_currency from tabCompany where name = '%s'" %(name)) + dcc = ret and ret[0][0] or get_defaults()['currency'] + return dcc