Added method get_account_currency

This commit is contained in:
Anand Doshi
2015-09-28 13:31:17 +05:30
parent b20baf894f
commit cd0989e051
10 changed files with 92 additions and 73 deletions

View File

@@ -207,3 +207,14 @@ def get_parent_account(doctype, txt, searchfield, start, page_len, filters):
and %s like %s order by name limit %s, %s""" % and %s like %s order by name limit %s, %s""" %
("%s", searchfield, "%s", "%s", "%s"), ("%s", searchfield, "%s", "%s", "%s"),
(filters["company"], "%%%s%%" % txt, start, page_len), as_list=1) (filters["company"], "%%%s%%" % txt, start, page_len), as_list=1)
def get_account_currency(account):
"""Helper function to get account currency"""
def generator():
account_currency, company = frappe.db.get_value("Account", account, ["account_currency", "company"])
if not account_currency:
account_currency = frappe.db.get_value("Company", company, "default_currency")
return account_currency
return frappe.local_cache("account_currency", account, generator)

View File

@@ -7,6 +7,7 @@ from frappe import _
from frappe.utils import flt, fmt_money, getdate, formatdate from frappe.utils import flt, fmt_money, getdate, formatdate
from frappe.model.document import Document from frappe.model.document import Document
from erpnext.accounts.party import get_party_account_currency from erpnext.accounts.party import get_party_account_currency
from erpnext.accounts.utils import get_account_currency
class CustomerFrozen(frappe.ValidationError): pass class CustomerFrozen(frappe.ValidationError): pass
class InvalidCurrency(frappe.ValidationError): pass class InvalidCurrency(frappe.ValidationError): pass
@@ -103,7 +104,7 @@ class GLEntry(Document):
def validate_currency(self): def validate_currency(self):
company_currency = frappe.db.get_value("Company", self.company, "default_currency") company_currency = frappe.db.get_value("Company", self.company, "default_currency")
account_currency = frappe.db.get_value("Account", self.account, "account_currency") or company_currency account_currency = get_account_currency(self.account)
if not self.account_currency: if not self.account_currency:
self.account_currency = company_currency self.account_currency = company_currency

View File

@@ -6,7 +6,7 @@ import frappe
from frappe.utils import cstr, flt, fmt_money, formatdate from frappe.utils import cstr, flt, fmt_money, formatdate
from frappe import msgprint, _, scrub from frappe import msgprint, _, scrub
from erpnext.controllers.accounts_controller import AccountsController from erpnext.controllers.accounts_controller import AccountsController
from erpnext.accounts.utils import get_balance_on from erpnext.accounts.utils import get_balance_on, get_account_currency
from erpnext.accounts.party import get_party_account_currency from erpnext.accounts.party import get_party_account_currency
from erpnext.setup.utils import get_company_currency from erpnext.setup.utils import get_company_currency
@@ -147,7 +147,7 @@ class JournalEntry(AccountsController):
self.reference_totals = {} self.reference_totals = {}
self.reference_types = {} self.reference_types = {}
self.reference_parties = {} self.reference_accounts = {}
for d in self.get("accounts"): for d in self.get("accounts"):
if not d.reference_type: if not d.reference_type:
@@ -170,8 +170,7 @@ class JournalEntry(AccountsController):
self.reference_totals[d.reference_name] = 0.0 self.reference_totals[d.reference_name] = 0.0
self.reference_totals[d.reference_name] += flt(d.get(dr_or_cr)) self.reference_totals[d.reference_name] += flt(d.get(dr_or_cr))
self.reference_types[d.reference_name] = d.reference_type self.reference_types[d.reference_name] = d.reference_type
if d.party_type and d.party: self.reference_accounts[d.reference_name] = d.account
self.reference_parties[d.reference_name] = [d.party_type, d.party]
against_voucher = frappe.db.get_value(d.reference_type, d.reference_name, against_voucher = frappe.db.get_value(d.reference_type, d.reference_name,
[scrub(dt) for dt in field_dict.get(d.reference_type)]) [scrub(dt) for dt in field_dict.get(d.reference_type)])
@@ -197,7 +196,7 @@ class JournalEntry(AccountsController):
"""Validate totals, stopped and docstatus for orders""" """Validate totals, stopped and docstatus for orders"""
for reference_name, total in self.reference_totals.iteritems(): for reference_name, total in self.reference_totals.iteritems():
reference_type = self.reference_types[reference_name] reference_type = self.reference_types[reference_name]
party_type, party = self.reference_parties.get(reference_name) account = self.reference_accounts[reference_name]
if reference_type in ("Sales Order", "Purchase Order"): if reference_type in ("Sales Order", "Purchase Order"):
order = frappe.db.get_value(reference_type, reference_name, order = frappe.db.get_value(reference_type, reference_name,
@@ -213,8 +212,8 @@ class JournalEntry(AccountsController):
if cstr(order.status) == "Stopped": if cstr(order.status) == "Stopped":
frappe.throw(_("{0} {1} is stopped").format(reference_type, reference_name)) frappe.throw(_("{0} {1} is stopped").format(reference_type, reference_name))
party_account_currency = get_party_account_currency(party_type, party, self.company) account_currency = get_account_currency(account)
if party_account_currency == self.company_currency: if account_currency == self.company_currency:
voucher_total = order.base_grand_total voucher_total = order.base_grand_total
else: else:
voucher_total = order.grand_total voucher_total = order.grand_total
@@ -611,7 +610,7 @@ def get_payment_entry_from_sales_order(sales_order):
jv.remark = 'Advance payment received against Sales Order {0}.'.format(so.name) jv.remark = 'Advance payment received against Sales Order {0}.'.format(so.name)
party_account = get_party_account("Customer", so.customer, so.company) party_account = get_party_account("Customer", so.customer, so.company)
party_account_currency = frappe.db.get_value("Account", party_account, "account_currency") party_account_currency = get_account_currency(party_account)
exchange_rate = get_exchange_rate(party_account, party_account_currency, so.company) exchange_rate = get_exchange_rate(party_account, party_account_currency, so.company)
@@ -662,7 +661,7 @@ def get_payment_entry_from_purchase_order(purchase_order):
jv.remark = 'Advance payment made against Purchase Order {0}.'.format(po.name) jv.remark = 'Advance payment made against Purchase Order {0}.'.format(po.name)
party_account = get_party_account("Supplier", po.supplier, po.company) party_account = get_party_account("Supplier", po.supplier, po.company)
party_account_currency = frappe.db.get_value("Account", party_account, "account_currency") party_account_currency = get_account_currency(party_account)
exchange_rate = get_exchange_rate(party_account, party_account_currency, po.company) exchange_rate = get_exchange_rate(party_account, party_account_currency, po.company)

View File

@@ -7,6 +7,7 @@ from frappe import _, scrub
from frappe.utils import flt from frappe.utils import flt
from frappe.model.document import Document from frappe.model.document import Document
import json import json
from erpnext.accounts.utils import get_account_currency
class PaymentTool(Document): class PaymentTool(Document):
def make_journal_entry(self): def make_journal_entry(self):
@@ -59,7 +60,7 @@ def get_outstanding_vouchers(args):
args = json.loads(args) args = json.loads(args)
party_account_currency = frappe.db.get_value("Account", args.get("party_account"), "account_currency") party_account_currency = get_account_currency(args.get("party_account"))
company_currency = frappe.db.get_value("Company", args.get("company"), "default_currency") company_currency = frappe.db.get_value("Company", args.get("company"), "default_currency")
if args.get("party_type") == "Customer" and args.get("received_or_paid") == "Received": if args.get("party_type") == "Customer" and args.get("received_or_paid") == "Received":
@@ -112,7 +113,7 @@ def get_orders_to_be_billed(party_type, party, party_account_currency, company_c
@frappe.whitelist() @frappe.whitelist()
def get_against_voucher_amount(against_voucher_type, against_voucher_no, party_account, company): def get_against_voucher_amount(against_voucher_type, against_voucher_no, party_account, company):
party_account_currency = frappe.db.get_value("Account", party_account, "account_currency") party_account_currency = get_account_currency(party_account)
company_currency = frappe.db.get_value("Company", company, "default_currency") company_currency = frappe.db.get_value("Company", company, "default_currency")
ref_field = "base_grand_total" if party_account_currency == company_currency else "grand_total" ref_field = "base_grand_total" if party_account_currency == company_currency else "grand_total"

View File

@@ -10,6 +10,7 @@ import frappe.defaults
from erpnext.controllers.buying_controller import BuyingController from erpnext.controllers.buying_controller import BuyingController
from erpnext.accounts.party import get_party_account, get_due_date from erpnext.accounts.party import get_party_account, get_due_date
from erpnext.accounts.utils import get_account_currency
form_grid_templates = { form_grid_templates = {
"items": "templates/form_grid/item_grid.html" "items": "templates/form_grid/item_grid.html"
@@ -272,7 +273,7 @@ class PurchaseInvoice(BuyingController):
valuation_tax = {} valuation_tax = {}
for tax in self.get("taxes"): for tax in self.get("taxes"):
if tax.category in ("Total", "Valuation and Total") and flt(tax.base_tax_amount_after_discount_amount): if tax.category in ("Total", "Valuation and Total") and flt(tax.base_tax_amount_after_discount_amount):
account_currency = frappe.db.get_value("Account", tax.account_head, "account_currency") account_currency = get_account_currency(tax.account_head)
dr_or_cr = "debit" if tax.add_deduct_tax == "Add" else "credit" dr_or_cr = "debit" if tax.add_deduct_tax == "Add" else "credit"
@@ -301,7 +302,7 @@ class PurchaseInvoice(BuyingController):
stock_items = self.get_stock_items() stock_items = self.get_stock_items()
for item in self.get("items"): for item in self.get("items"):
if flt(item.base_net_amount): if flt(item.base_net_amount):
account_currency = frappe.db.get_value("Account", item.expense_account, "account_currency") account_currency = get_account_currency(item.expense_account)
gl_entries.append( gl_entries.append(
self.get_gl_dict({ self.get_gl_dict({
"account": item.expense_account, "account": item.expense_account,
@@ -363,7 +364,7 @@ class PurchaseInvoice(BuyingController):
# writeoff account includes petty difference in the invoice amount # writeoff account includes petty difference in the invoice amount
# and the amount that is paid # and the amount that is paid
if self.write_off_account and flt(self.write_off_amount): if self.write_off_account and flt(self.write_off_amount):
write_off_account_currency = frappe.db.get_value("Account", self.write_off_account, "account_currency") write_off_account_currency = get_account_currency(self.write_off_account)
gl_entries.append( gl_entries.append(
self.get_gl_dict({ self.get_gl_dict({

View File

@@ -11,6 +11,7 @@ from erpnext.controllers.stock_controller import update_gl_entries_after
from frappe.model.mapper import get_mapped_doc from frappe.model.mapper import get_mapped_doc
from erpnext.controllers.selling_controller import SellingController from erpnext.controllers.selling_controller import SellingController
from erpnext.accounts.utils import get_account_currency
form_grid_templates = { form_grid_templates = {
"items": "templates/form_grid/item_grid.html" "items": "templates/form_grid/item_grid.html"
@@ -531,7 +532,7 @@ class SalesInvoice(SellingController):
def make_tax_gl_entries(self, gl_entries): def make_tax_gl_entries(self, gl_entries):
for tax in self.get("taxes"): for tax in self.get("taxes"):
if flt(tax.base_tax_amount_after_discount_amount): if flt(tax.base_tax_amount_after_discount_amount):
account_currency = frappe.db.get_value("Account", tax.account_head, "account_currency") account_currency = get_account_currency(tax.account_head)
gl_entries.append( gl_entries.append(
self.get_gl_dict({ self.get_gl_dict({
"account": tax.account_head, "account": tax.account_head,
@@ -547,7 +548,7 @@ class SalesInvoice(SellingController):
# income account gl entries # income account gl entries
for item in self.get("items"): for item in self.get("items"):
if flt(item.base_net_amount): if flt(item.base_net_amount):
account_currency = frappe.db.get_value("Account", item.income_account, "account_currency") account_currency = get_account_currency(item.income_account)
gl_entries.append( gl_entries.append(
self.get_gl_dict({ self.get_gl_dict({
"account": item.income_account, "account": item.income_account,
@@ -566,7 +567,7 @@ class SalesInvoice(SellingController):
def make_pos_gl_entries(self, gl_entries): def make_pos_gl_entries(self, gl_entries):
if cint(self.is_pos) and self.cash_bank_account and self.paid_amount: if cint(self.is_pos) and self.cash_bank_account and self.paid_amount:
bank_account_currency = frappe.db.get_value("Account", self.cash_bank_account, "account_currency") bank_account_currency = get_account_currency(self.cash_bank_account)
# POS, make payment entries # POS, make payment entries
gl_entries.append( gl_entries.append(
self.get_gl_dict({ self.get_gl_dict({
@@ -594,7 +595,7 @@ class SalesInvoice(SellingController):
def make_write_off_gl_entry(self, gl_entries): def make_write_off_gl_entry(self, gl_entries):
# write off entries, applicable if only pos # write off entries, applicable if only pos
if self.write_off_account and self.write_off_amount: if self.write_off_account and self.write_off_amount:
write_off_account_currency = frappe.db.get_value("Account", self.write_off_account, "account_currency") write_off_account_currency = get_account_currency(self.write_off_account)
gl_entries.append( gl_entries.append(
self.get_gl_dict({ self.get_gl_dict({

View File

@@ -5,6 +5,7 @@ from __future__ import unicode_literals
import frappe import frappe
from frappe.utils import flt, getdate, cstr from frappe.utils import flt, getdate, cstr
from frappe import _ from frappe import _
from erpnext.accounts.utils import get_account_currency
def execute(filters=None): def execute(filters=None):
account_details = {} account_details = {}
@@ -55,7 +56,7 @@ def set_account_currency(filters):
account_currency = None account_currency = None
if filters.get("account"): if filters.get("account"):
account_currency = frappe.db.get_value("Account", filters.account, "account_currency") account_currency = get_account_currency(filters.account)
elif filters.get("party"): elif filters.get("party"):
gle_currency = frappe.db.get_value("GL Entry", {"party_type": filters.party_type, gle_currency = frappe.db.get_value("GL Entry", {"party_type": filters.party_type,
"party": filters.party, "company": filters.company}, "account_currency") "party": filters.party, "company": filters.company}, "account_currency")

View File

@@ -9,6 +9,9 @@ from frappe import throw, _
from frappe.utils import formatdate from frappe.utils import formatdate
import frappe.desk.reportview import frappe.desk.reportview
# imported to enable erpnext.accounts.utils.get_account_currency
from erpnext.accounts.doctype.account.account import get_account_currency
class FiscalYearError(frappe.ValidationError): pass class FiscalYearError(frappe.ValidationError): pass
class BudgetError(frappe.ValidationError): pass class BudgetError(frappe.ValidationError): pass

View File

@@ -6,7 +6,7 @@ import frappe
from frappe import _, throw from frappe import _, throw
from frappe.utils import today, flt, cint from frappe.utils import today, flt, cint
from erpnext.setup.utils import get_company_currency, get_exchange_rate from erpnext.setup.utils import get_company_currency, get_exchange_rate
from erpnext.accounts.utils import get_fiscal_year, validate_fiscal_year from erpnext.accounts.utils import get_fiscal_year, validate_fiscal_year, get_account_currency
from erpnext.utilities.transaction_base import TransactionBase from erpnext.utilities.transaction_base import TransactionBase
from erpnext.controllers.recurring_document import convert_to_recurring, validate_recurring_document from erpnext.controllers.recurring_document import convert_to_recurring, validate_recurring_document
from erpnext.controllers.sales_and_purchase_return import validate_return from erpnext.controllers.sales_and_purchase_return import validate_return
@@ -221,7 +221,7 @@ class AccountsController(TransactionBase):
gl_dict.update(args) gl_dict.update(args)
if not account_currency: if not account_currency:
account_currency = frappe.db.get_value("Account", gl_dict.account, "account_currency") account_currency = get_account_currency(gl_dict.account)
if self.doctype != "Journal Entry": if self.doctype != "Journal Entry":
self.validate_account_currency(gl_dict.account, account_currency) self.validate_account_currency(gl_dict.account, account_currency)

View File

@@ -10,6 +10,7 @@ from frappe import _
import frappe.defaults import frappe.defaults
from erpnext.controllers.buying_controller import BuyingController from erpnext.controllers.buying_controller import BuyingController
from erpnext.accounts.utils import get_account_currency
form_grid_templates = { form_grid_templates = {
"items": "templates/form_grid/item_grid.html" "items": "templates/form_grid/item_grid.html"
@@ -319,7 +320,7 @@ class PurchaseReceipt(BuyingController):
}, warehouse_account[d.warehouse]["account_currency"])) }, warehouse_account[d.warehouse]["account_currency"]))
# stock received but not billed # stock received but not billed
stock_rbnb_currency = frappe.db.get_value("Account", stock_rbnb, "account_currency") stock_rbnb_currency = get_account_currency(stock_rbnb)
gl_entries.append(self.get_gl_dict({ gl_entries.append(self.get_gl_dict({
"account": stock_rbnb, "account": stock_rbnb,
"against": warehouse_account[d.warehouse]["name"], "against": warehouse_account[d.warehouse]["name"],