mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-26 00:14:50 +00:00
Added method get_account_currency
This commit is contained in:
@@ -50,20 +50,20 @@ class Account(Document):
|
|||||||
def set_root_and_report_type(self):
|
def set_root_and_report_type(self):
|
||||||
if self.parent_account:
|
if self.parent_account:
|
||||||
par = frappe.db.get_value("Account", self.parent_account, ["report_type", "root_type"], as_dict=1)
|
par = frappe.db.get_value("Account", self.parent_account, ["report_type", "root_type"], as_dict=1)
|
||||||
|
|
||||||
if par.report_type:
|
if par.report_type:
|
||||||
self.report_type = par.report_type
|
self.report_type = par.report_type
|
||||||
if par.root_type:
|
if par.root_type:
|
||||||
self.root_type = par.root_type
|
self.root_type = par.root_type
|
||||||
|
|
||||||
if self.is_group:
|
if self.is_group:
|
||||||
db_value = frappe.db.get_value("Account", self.name, ["report_type", "root_type"], as_dict=1)
|
db_value = frappe.db.get_value("Account", self.name, ["report_type", "root_type"], as_dict=1)
|
||||||
if db_value:
|
if db_value:
|
||||||
if self.report_type != db_value.report_type:
|
if self.report_type != db_value.report_type:
|
||||||
frappe.db.sql("update `tabAccount` set report_type=%s where lft > %s and rgt < %s",
|
frappe.db.sql("update `tabAccount` set report_type=%s where lft > %s and rgt < %s",
|
||||||
(self.report_type, self.lft, self.rgt))
|
(self.report_type, self.lft, self.rgt))
|
||||||
if self.root_type != db_value.root_type:
|
if self.root_type != db_value.root_type:
|
||||||
frappe.db.sql("update `tabAccount` set root_type=%s where lft > %s and rgt < %s",
|
frappe.db.sql("update `tabAccount` set root_type=%s where lft > %s and rgt < %s",
|
||||||
(self.root_type, self.lft, self.rgt))
|
(self.root_type, self.lft, self.rgt))
|
||||||
|
|
||||||
def validate_root_details(self):
|
def validate_root_details(self):
|
||||||
@@ -89,11 +89,11 @@ class Account(Document):
|
|||||||
frappe.throw(_("Account balance already in Debit, you are not allowed to set 'Balance Must Be' as 'Credit'"))
|
frappe.throw(_("Account balance already in Debit, you are not allowed to set 'Balance Must Be' as 'Credit'"))
|
||||||
elif account_balance < 0 and self.balance_must_be == "Debit":
|
elif account_balance < 0 and self.balance_must_be == "Debit":
|
||||||
frappe.throw(_("Account balance already in Credit, you are not allowed to set 'Balance Must Be' as 'Debit'"))
|
frappe.throw(_("Account balance already in Credit, you are not allowed to set 'Balance Must Be' as 'Debit'"))
|
||||||
|
|
||||||
def validate_account_currency(self):
|
def validate_account_currency(self):
|
||||||
if not self.account_currency:
|
if not self.account_currency:
|
||||||
self.account_currency = frappe.db.get_value("Company", self.company, "default_currency")
|
self.account_currency = frappe.db.get_value("Company", self.company, "default_currency")
|
||||||
|
|
||||||
elif self.account_currency != frappe.db.get_value("Account", self.name, "account_currency"):
|
elif self.account_currency != frappe.db.get_value("Account", self.name, "account_currency"):
|
||||||
if frappe.db.get_value("GL Entry", {"account": self.name}):
|
if frappe.db.get_value("GL Entry", {"account": self.name}):
|
||||||
frappe.throw(_("Currency can not be changed after making entries using some other currency"))
|
frappe.throw(_("Currency can not be changed after making entries using some other currency"))
|
||||||
@@ -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)
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
@@ -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)
|
||||||
|
|
||||||
|
|||||||
@@ -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"
|
||||||
|
|
||||||
|
|||||||
@@ -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({
|
||||||
|
|||||||
@@ -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({
|
||||||
|
|||||||
@@ -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 = {}
|
||||||
@@ -12,10 +13,10 @@ def execute(filters=None):
|
|||||||
account_details.setdefault(acc.name, acc)
|
account_details.setdefault(acc.name, acc)
|
||||||
|
|
||||||
validate_filters(filters, account_details)
|
validate_filters(filters, account_details)
|
||||||
|
|
||||||
validate_party(filters)
|
validate_party(filters)
|
||||||
|
|
||||||
filters = set_account_currency(filters)
|
filters = set_account_currency(filters)
|
||||||
|
|
||||||
columns = get_columns(filters)
|
columns = get_columns(filters)
|
||||||
|
|
||||||
@@ -46,49 +47,49 @@ def validate_party(filters):
|
|||||||
frappe.throw(_("To filter based on Party, select Party Type first"))
|
frappe.throw(_("To filter based on Party, select Party Type first"))
|
||||||
elif not frappe.db.exists(party_type, party):
|
elif not frappe.db.exists(party_type, party):
|
||||||
frappe.throw(_("Invalid {0}: {1}").format(party_type, party))
|
frappe.throw(_("Invalid {0}: {1}").format(party_type, party))
|
||||||
|
|
||||||
def set_account_currency(filters):
|
def set_account_currency(filters):
|
||||||
if not (filters.get("account") or filters.get("party")):
|
if not (filters.get("account") or filters.get("party")):
|
||||||
return filters
|
return filters
|
||||||
else:
|
else:
|
||||||
filters["company_currency"] = frappe.db.get_value("Company", filters.company, "default_currency")
|
filters["company_currency"] = frappe.db.get_value("Company", filters.company, "default_currency")
|
||||||
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")
|
||||||
if gle_currency:
|
if gle_currency:
|
||||||
account_currency = gle_currency
|
account_currency = gle_currency
|
||||||
else:
|
else:
|
||||||
account_currency = frappe.db.get_value(filters.party_type, filters.party, "default_currency")
|
account_currency = frappe.db.get_value(filters.party_type, filters.party, "default_currency")
|
||||||
|
|
||||||
filters["account_currency"] = account_currency or filters.company_currency
|
filters["account_currency"] = account_currency or filters.company_currency
|
||||||
|
|
||||||
if filters.account_currency != filters.company_currency:
|
if filters.account_currency != filters.company_currency:
|
||||||
filters["show_in_account_currency"] = 1
|
filters["show_in_account_currency"] = 1
|
||||||
|
|
||||||
return filters
|
return filters
|
||||||
|
|
||||||
def get_columns(filters):
|
def get_columns(filters):
|
||||||
columns = [
|
columns = [
|
||||||
_("Posting Date") + ":Date:90", _("Account") + ":Link/Account:200",
|
_("Posting Date") + ":Date:90", _("Account") + ":Link/Account:200",
|
||||||
_("Debit") + ":Float:100", _("Credit") + ":Float:100"
|
_("Debit") + ":Float:100", _("Credit") + ":Float:100"
|
||||||
]
|
]
|
||||||
|
|
||||||
if filters.get("show_in_account_currency"):
|
if filters.get("show_in_account_currency"):
|
||||||
columns += [
|
columns += [
|
||||||
_("Debit") + " (" + filters.account_currency + ")" + ":Float:100",
|
_("Debit") + " (" + filters.account_currency + ")" + ":Float:100",
|
||||||
_("Credit") + " (" + filters.account_currency + ")" + ":Float:100"
|
_("Credit") + " (" + filters.account_currency + ")" + ":Float:100"
|
||||||
]
|
]
|
||||||
|
|
||||||
columns += [
|
columns += [
|
||||||
_("Voucher Type") + "::120", _("Voucher No") + ":Dynamic Link/Voucher Type:160",
|
_("Voucher Type") + "::120", _("Voucher No") + ":Dynamic Link/Voucher Type:160",
|
||||||
_("Against Account") + "::120", _("Party Type") + "::80", _("Party") + "::150",
|
_("Against Account") + "::120", _("Party Type") + "::80", _("Party") + "::150",
|
||||||
_("Cost Center") + ":Link/Cost Center:100", _("Remarks") + "::400"
|
_("Cost Center") + ":Link/Cost Center:100", _("Remarks") + "::400"
|
||||||
]
|
]
|
||||||
|
|
||||||
return columns
|
return columns
|
||||||
|
|
||||||
def get_result(filters, account_details):
|
def get_result(filters, account_details):
|
||||||
@@ -101,21 +102,21 @@ def get_result(filters, account_details):
|
|||||||
return result
|
return result
|
||||||
|
|
||||||
def get_gl_entries(filters):
|
def get_gl_entries(filters):
|
||||||
select_fields = """, sum(ifnull(debit_in_account_currency, 0)) as debit_in_account_currency,
|
select_fields = """, sum(ifnull(debit_in_account_currency, 0)) as debit_in_account_currency,
|
||||||
sum(ifnull(credit_in_account_currency, 0)) as credit_in_account_currency""" \
|
sum(ifnull(credit_in_account_currency, 0)) as credit_in_account_currency""" \
|
||||||
if filters.get("show_in_account_currency") else ""
|
if filters.get("show_in_account_currency") else ""
|
||||||
|
|
||||||
group_by_condition = "group by voucher_type, voucher_no, account, cost_center" \
|
group_by_condition = "group by voucher_type, voucher_no, account, cost_center" \
|
||||||
if filters.get("group_by_voucher") else "group by name"
|
if filters.get("group_by_voucher") else "group by name"
|
||||||
|
|
||||||
gl_entries = frappe.db.sql("""select posting_date, account, party_type, party,
|
gl_entries = frappe.db.sql("""select posting_date, account, party_type, party,
|
||||||
sum(ifnull(debit, 0)) as debit, sum(ifnull(credit, 0)) as credit,
|
sum(ifnull(debit, 0)) as debit, sum(ifnull(credit, 0)) as credit,
|
||||||
voucher_type, voucher_no, cost_center, remarks, against, is_opening {select_fields}
|
voucher_type, voucher_no, cost_center, remarks, against, is_opening {select_fields}
|
||||||
from `tabGL Entry`
|
from `tabGL Entry`
|
||||||
where company=%(company)s {conditions}
|
where company=%(company)s {conditions}
|
||||||
{group_by_condition}
|
{group_by_condition}
|
||||||
order by posting_date, account"""\
|
order by posting_date, account"""\
|
||||||
.format(select_fields=select_fields, conditions=get_conditions(filters),
|
.format(select_fields=select_fields, conditions=get_conditions(filters),
|
||||||
group_by_condition=group_by_condition), filters, as_dict=1)
|
group_by_condition=group_by_condition), filters, as_dict=1)
|
||||||
|
|
||||||
return gl_entries
|
return gl_entries
|
||||||
@@ -135,7 +136,7 @@ def get_conditions(filters):
|
|||||||
|
|
||||||
if filters.get("party"):
|
if filters.get("party"):
|
||||||
conditions.append("party=%(party)s")
|
conditions.append("party=%(party)s")
|
||||||
|
|
||||||
if not (filters.get("account") or filters.get("party") or filters.get("group_by_account")):
|
if not (filters.get("account") or filters.get("party") or filters.get("group_by_account")):
|
||||||
conditions.append("posting_date >=%(from_date)s")
|
conditions.append("posting_date >=%(from_date)s")
|
||||||
|
|
||||||
@@ -160,7 +161,7 @@ def get_data_with_opening_closing(filters, account_details, gl_entries):
|
|||||||
if acc_dict.entries:
|
if acc_dict.entries:
|
||||||
# Opening for individual ledger, if grouped by account
|
# Opening for individual ledger, if grouped by account
|
||||||
if filters.get("group_by_account"):
|
if filters.get("group_by_account"):
|
||||||
data.append(get_balance_row(_("Opening"), acc_dict.opening,
|
data.append(get_balance_row(_("Opening"), acc_dict.opening,
|
||||||
acc_dict.opening_in_account_currency))
|
acc_dict.opening_in_account_currency))
|
||||||
|
|
||||||
data += acc_dict.entries
|
data += acc_dict.entries
|
||||||
@@ -170,7 +171,7 @@ def get_data_with_opening_closing(filters, account_details, gl_entries):
|
|||||||
account_closing = acc_dict.opening + acc_dict.total_debit - acc_dict.total_credit
|
account_closing = acc_dict.opening + acc_dict.total_debit - acc_dict.total_credit
|
||||||
account_closing_in_account_currency = acc_dict.opening_in_account_currency \
|
account_closing_in_account_currency = acc_dict.opening_in_account_currency \
|
||||||
+ acc_dict.total_debit_in_account_currency - acc_dict.total_credit_in_account_currency
|
+ acc_dict.total_debit_in_account_currency - acc_dict.total_credit_in_account_currency
|
||||||
|
|
||||||
data += [{"account": "'" + _("Totals") + "'", "debit": acc_dict.total_debit,
|
data += [{"account": "'" + _("Totals") + "'", "debit": acc_dict.total_debit,
|
||||||
"credit": acc_dict.total_credit},
|
"credit": acc_dict.total_credit},
|
||||||
get_balance_row(_("Closing (Opening + Totals)"),
|
get_balance_row(_("Closing (Opening + Totals)"),
|
||||||
@@ -179,10 +180,10 @@ def get_data_with_opening_closing(filters, account_details, gl_entries):
|
|||||||
# Total debit and credit between from and to date
|
# Total debit and credit between from and to date
|
||||||
if total_debit or total_credit:
|
if total_debit or total_credit:
|
||||||
data.append({
|
data.append({
|
||||||
"account": "'" + _("Totals") + "'",
|
"account": "'" + _("Totals") + "'",
|
||||||
"debit": total_debit,
|
"debit": total_debit,
|
||||||
"credit": total_credit,
|
"credit": total_credit,
|
||||||
"debit_in_account_currency": total_debit_in_account_currency,
|
"debit_in_account_currency": total_debit_in_account_currency,
|
||||||
"credit_in_account_currency": total_credit_in_account_currency
|
"credit_in_account_currency": total_credit_in_account_currency
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -191,7 +192,7 @@ def get_data_with_opening_closing(filters, account_details, gl_entries):
|
|||||||
closing = opening + total_debit - total_credit
|
closing = opening + total_debit - total_credit
|
||||||
closing_in_account_currency = opening_in_account_currency + \
|
closing_in_account_currency = opening_in_account_currency + \
|
||||||
total_debit_in_account_currency - total_credit_in_account_currency
|
total_debit_in_account_currency - total_credit_in_account_currency
|
||||||
|
|
||||||
data.append(get_balance_row(_("Closing (Opening + Totals)"),
|
data.append(get_balance_row(_("Closing (Opening + Totals)"),
|
||||||
closing, closing_in_account_currency))
|
closing, closing_in_account_currency))
|
||||||
|
|
||||||
@@ -216,38 +217,38 @@ def initialize_gle_map(gl_entries):
|
|||||||
def get_accountwise_gle(filters, gl_entries, gle_map):
|
def get_accountwise_gle(filters, gl_entries, gle_map):
|
||||||
opening, total_debit, total_credit = 0, 0, 0
|
opening, total_debit, total_credit = 0, 0, 0
|
||||||
opening_in_account_currency, total_debit_in_account_currency, total_credit_in_account_currency = 0, 0, 0
|
opening_in_account_currency, total_debit_in_account_currency, total_credit_in_account_currency = 0, 0, 0
|
||||||
|
|
||||||
from_date, to_date = getdate(filters.from_date), getdate(filters.to_date)
|
from_date, to_date = getdate(filters.from_date), getdate(filters.to_date)
|
||||||
for gle in gl_entries:
|
for gle in gl_entries:
|
||||||
amount = flt(gle.debit, 3) - flt(gle.credit, 3)
|
amount = flt(gle.debit, 3) - flt(gle.credit, 3)
|
||||||
amount_in_account_currency = flt(gle.debit_in_account_currency, 3) - flt(gle.credit_in_account_currency, 3)
|
amount_in_account_currency = flt(gle.debit_in_account_currency, 3) - flt(gle.credit_in_account_currency, 3)
|
||||||
|
|
||||||
if (filters.get("account") or filters.get("party") or filters.get("group_by_account")) \
|
if (filters.get("account") or filters.get("party") or filters.get("group_by_account")) \
|
||||||
and (gle.posting_date < from_date or cstr(gle.is_opening) == "Yes"):
|
and (gle.posting_date < from_date or cstr(gle.is_opening) == "Yes"):
|
||||||
|
|
||||||
gle_map[gle.account].opening += amount
|
gle_map[gle.account].opening += amount
|
||||||
if filters.get("show_in_account_currency"):
|
if filters.get("show_in_account_currency"):
|
||||||
gle_map[gle.account].opening_in_account_currency += amount_in_account_currency
|
gle_map[gle.account].opening_in_account_currency += amount_in_account_currency
|
||||||
|
|
||||||
if filters.get("account") or filters.get("party"):
|
if filters.get("account") or filters.get("party"):
|
||||||
opening += amount
|
opening += amount
|
||||||
if filters.get("show_in_account_currency"):
|
if filters.get("show_in_account_currency"):
|
||||||
opening_in_account_currency += amount_in_account_currency
|
opening_in_account_currency += amount_in_account_currency
|
||||||
|
|
||||||
elif gle.posting_date <= to_date:
|
elif gle.posting_date <= to_date:
|
||||||
gle_map[gle.account].entries.append(gle)
|
gle_map[gle.account].entries.append(gle)
|
||||||
gle_map[gle.account].total_debit += flt(gle.debit, 3)
|
gle_map[gle.account].total_debit += flt(gle.debit, 3)
|
||||||
gle_map[gle.account].total_credit += flt(gle.credit, 3)
|
gle_map[gle.account].total_credit += flt(gle.credit, 3)
|
||||||
|
|
||||||
total_debit += flt(gle.debit, 3)
|
total_debit += flt(gle.debit, 3)
|
||||||
total_credit += flt(gle.credit, 3)
|
total_credit += flt(gle.credit, 3)
|
||||||
|
|
||||||
if filters.get("show_in_account_currency"):
|
if filters.get("show_in_account_currency"):
|
||||||
gle_map[gle.account].total_debit_in_account_currency += flt(gle.debit_in_account_currency, 3)
|
gle_map[gle.account].total_debit_in_account_currency += flt(gle.debit_in_account_currency, 3)
|
||||||
gle_map[gle.account].total_credit_in_account_currency += flt(gle.credit_in_account_currency, 3)
|
gle_map[gle.account].total_credit_in_account_currency += flt(gle.credit_in_account_currency, 3)
|
||||||
|
|
||||||
total_debit_in_account_currency += flt(gle.debit_in_account_currency, 3)
|
total_debit_in_account_currency += flt(gle.debit_in_account_currency, 3)
|
||||||
total_credit_in_account_currency += flt(gle.credit_in_account_currency, 3)
|
total_credit_in_account_currency += flt(gle.credit_in_account_currency, 3)
|
||||||
|
|
||||||
return opening, total_debit, total_credit, opening_in_account_currency, \
|
return opening, total_debit, total_credit, opening_in_account_currency, \
|
||||||
total_debit_in_account_currency, total_credit_in_account_currency, gle_map
|
total_debit_in_account_currency, total_credit_in_account_currency, gle_map
|
||||||
@@ -258,27 +259,27 @@ def get_balance_row(label, balance, balance_in_account_currency=None):
|
|||||||
"debit": balance if balance > 0 else 0,
|
"debit": balance if balance > 0 else 0,
|
||||||
"credit": -1*balance if balance < 0 else 0
|
"credit": -1*balance if balance < 0 else 0
|
||||||
}
|
}
|
||||||
|
|
||||||
if balance_in_account_currency != None:
|
if balance_in_account_currency != None:
|
||||||
balance_row.update({
|
balance_row.update({
|
||||||
"debit_in_account_currency": balance_in_account_currency if balance_in_account_currency > 0 else 0,
|
"debit_in_account_currency": balance_in_account_currency if balance_in_account_currency > 0 else 0,
|
||||||
"credit_in_account_currency": -1*balance_in_account_currency if balance_in_account_currency < 0 else 0
|
"credit_in_account_currency": -1*balance_in_account_currency if balance_in_account_currency < 0 else 0
|
||||||
})
|
})
|
||||||
|
|
||||||
return balance_row
|
return balance_row
|
||||||
|
|
||||||
def get_result_as_list(data, filters):
|
def get_result_as_list(data, filters):
|
||||||
result = []
|
result = []
|
||||||
for d in data:
|
for d in data:
|
||||||
row = [d.get("posting_date"), d.get("account"), d.get("debit"), d.get("credit")]
|
row = [d.get("posting_date"), d.get("account"), d.get("debit"), d.get("credit")]
|
||||||
|
|
||||||
if filters.get("show_in_account_currency"):
|
if filters.get("show_in_account_currency"):
|
||||||
row += [d.get("debit_in_account_currency"), d.get("credit_in_account_currency")]
|
row += [d.get("debit_in_account_currency"), d.get("credit_in_account_currency")]
|
||||||
|
|
||||||
row += [d.get("voucher_type"), d.get("voucher_no"), d.get("against"),
|
row += [d.get("voucher_type"), d.get("voucher_no"), d.get("against"),
|
||||||
d.get("party_type"), d.get("party"), d.get("cost_center"), d.get("remarks")
|
d.get("party_type"), d.get("party"), d.get("cost_center"), d.get("remarks")
|
||||||
]
|
]
|
||||||
|
|
||||||
result.append(row)
|
result.append(row)
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|||||||
@@ -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
|
||||||
|
|
||||||
@@ -94,8 +97,8 @@ def get_balance_on(account=None, date=None, party_type=None, party=None, in_acco
|
|||||||
select name from `tabAccount` ac where ac.name = gle.account
|
select name from `tabAccount` ac where ac.name = gle.account
|
||||||
and ac.lft >= %s and ac.rgt <= %s
|
and ac.lft >= %s and ac.rgt <= %s
|
||||||
)""" % (acc.lft, acc.rgt))
|
)""" % (acc.lft, acc.rgt))
|
||||||
|
|
||||||
# If group and currency same as company,
|
# If group and currency same as company,
|
||||||
# always return balance based on debit and credit in company currency
|
# always return balance based on debit and credit in company currency
|
||||||
if acc.account_currency == frappe.db.get_value("Company", acc.company, "default_currency"):
|
if acc.account_currency == frappe.db.get_value("Company", acc.company, "default_currency"):
|
||||||
in_account_currency = False
|
in_account_currency = False
|
||||||
|
|||||||
@@ -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)
|
||||||
|
|||||||
@@ -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"
|
||||||
@@ -307,9 +308,9 @@ class PurchaseReceipt(BuyingController):
|
|||||||
val_rate_db_precision = 6 if cint(d.precision("valuation_rate")) <= 6 else 9
|
val_rate_db_precision = 6 if cint(d.precision("valuation_rate")) <= 6 else 9
|
||||||
|
|
||||||
# warehouse account
|
# warehouse account
|
||||||
stock_value_diff = flt(flt(d.valuation_rate, val_rate_db_precision) * flt(d.qty)
|
stock_value_diff = flt(flt(d.valuation_rate, val_rate_db_precision) * flt(d.qty)
|
||||||
* flt(d.conversion_factor), d.precision("base_net_amount"))
|
* flt(d.conversion_factor), d.precision("base_net_amount"))
|
||||||
|
|
||||||
gl_entries.append(self.get_gl_dict({
|
gl_entries.append(self.get_gl_dict({
|
||||||
"account": warehouse_account[d.warehouse]["name"],
|
"account": warehouse_account[d.warehouse]["name"],
|
||||||
"against": stock_rbnb,
|
"against": stock_rbnb,
|
||||||
@@ -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"],
|
||||||
|
|||||||
Reference in New Issue
Block a user