Merge pull request #15150 from rohitwaghchaure/fix_consolidated_balance_sheet_report
[Fix] Consolidated balance sheet report
diff --git a/README.md b/README.md
index 279ba22..4294842 100644
--- a/README.md
+++ b/README.md
@@ -46,7 +46,7 @@
## Contributing
1. [Issue Guidelines](https://github.com/frappe/erpnext/wiki/Issue-Guidelines)
-1. [Report Security Vulnerabilities](https://erpnext.com/reporting-security-vulnerabilities)
+1. [Report Security Vulnerabilities](https://erpnext.com/report)
1. [Pull Request Requirements](https://github.com/frappe/erpnext/wiki/Contribution-Guidelines)
1. [Translations](https://translate.erpnext.com)
1. [Chart of Accounts](https://charts.erpnext.com)
diff --git a/erpnext/__init__.py b/erpnext/__init__.py
index 47f5c73..e0a37e9 100644
--- a/erpnext/__init__.py
+++ b/erpnext/__init__.py
@@ -5,7 +5,7 @@
from erpnext.hooks import regional_overrides
from frappe.utils import getdate
-__version__ = '10.1.46'
+__version__ = '10.1.48'
def get_default_company(user=None):
'''Get default company for user'''
@@ -27,7 +27,7 @@
'''Returns the currency of the default company'''
company = get_default_company()
if company:
- return frappe.db.get_value('Company', company, 'default_currency')
+ return frappe.get_cached_value('Company', company, 'default_currency')
def get_default_cost_center(company):
'''Returns the default cost center of the company'''
@@ -37,7 +37,7 @@
if not frappe.flags.company_cost_center:
frappe.flags.company_cost_center = {}
if not company in frappe.flags.company_cost_center:
- frappe.flags.company_cost_center[company] = frappe.db.get_value('Company', company, 'cost_center')
+ frappe.flags.company_cost_center[company] = frappe.get_cached_value('Company', company, 'cost_center')
return frappe.flags.company_cost_center[company]
def get_company_currency(company):
@@ -45,7 +45,7 @@
if not frappe.flags.company_currency:
frappe.flags.company_currency = {}
if not company in frappe.flags.company_currency:
- frappe.flags.company_currency[company] = frappe.db.get_value('Company', company, 'default_currency')
+ frappe.flags.company_currency[company] = frappe.db.get_value('Company', company, 'default_currency', cache=True)
return frappe.flags.company_currency[company]
def set_perpetual_inventory(enable=1, company=None):
@@ -58,7 +58,7 @@
def encode_company_abbr(name, company):
'''Returns name encoded with company abbreviation'''
- company_abbr = frappe.db.get_value("Company", company, "abbr")
+ company_abbr = frappe.get_cached_value('Company', company, "abbr")
parts = name.rsplit(" - ", 1)
if parts[-1].lower() != company_abbr.lower():
@@ -74,8 +74,8 @@
frappe.local.enable_perpetual_inventory = {}
if not company in frappe.local.enable_perpetual_inventory:
- frappe.local.enable_perpetual_inventory[company] = frappe.db.get_value("Company",
- company, "enable_perpetual_inventory") or 0
+ frappe.local.enable_perpetual_inventory[company] = frappe.get_cached_value('Company',
+ company, "enable_perpetual_inventory") or 0
return frappe.local.enable_perpetual_inventory[company]
@@ -87,8 +87,8 @@
frappe.local.default_finance_book = {}
if not company in frappe.local.default_finance_book:
- frappe.local.default_finance_book[company] = frappe.db.get_value("Company",
- company, "default_finance_book")
+ frappe.local.default_finance_book[company] = frappe.get_cached_value('Company',
+ company, "default_finance_book")
return frappe.local.default_finance_book[company]
@@ -108,8 +108,8 @@
You can also set global company flag in `frappe.flags.company`
'''
if company or frappe.flags.company:
- return frappe.db.get_value('Company',
- company or frappe.flags.company, 'country')
+ return frappe.get_cached_value('Company',
+ company or frappe.flags.company, 'country')
elif frappe.flags.country:
return frappe.flags.country
else:
diff --git a/erpnext/accounts/doctype/account/account.py b/erpnext/accounts/doctype/account/account.py
index 5ea8358..566baa5 100644
--- a/erpnext/accounts/doctype/account/account.py
+++ b/erpnext/accounts/doctype/account/account.py
@@ -119,7 +119,7 @@
def validate_account_currency(self):
if not self.account_currency:
- self.account_currency = frappe.db.get_value("Company", self.company, "default_currency")
+ self.account_currency = frappe.get_cached_value('Company', self.company, "default_currency")
elif self.account_currency != frappe.db.get_value("Account", self.name, "account_currency"):
if frappe.db.get_value("GL Entry", {"account": self.name}):
@@ -179,9 +179,9 @@
if not account:
return
def generator():
- account_currency, company = frappe.db.get_value("Account", account, ["account_currency", "company"])
+ account_currency, company = frappe.get_cached_value("Account", account, ["account_currency", "company"])
if not account_currency:
- account_currency = frappe.db.get_value("Company", company, "default_currency")
+ account_currency = frappe.get_cached_value('Company', company, "default_currency")
return account_currency
@@ -192,7 +192,7 @@
def get_account_autoname(account_number, account_name, company):
# first validate if company exists
- company = frappe.db.get_value("Company", company, ["abbr", "name"], as_dict=True)
+ company = frappe.get_cached_value('Company', company, ["abbr", "name"], as_dict=True)
if not company:
frappe.throw(_('Company {0} does not exist').format(company))
diff --git a/erpnext/accounts/doctype/account/chart_of_accounts/chart_of_accounts.py b/erpnext/accounts/doctype/account/chart_of_accounts/chart_of_accounts.py
index 3f639cf..f4cf6fa 100644
--- a/erpnext/accounts/doctype/account/chart_of_accounts/chart_of_accounts.py
+++ b/erpnext/accounts/doctype/account/chart_of_accounts/chart_of_accounts.py
@@ -38,7 +38,7 @@
"report_type": report_type,
"account_number": account_number,
"account_type": child.get("account_type"),
- "account_currency": frappe.db.get_value("Company", company, "default_currency"),
+ "account_currency": frappe.db.get_value('Company', company, "default_currency"),
"tax_rate": child.get("tax_rate")
})
diff --git a/erpnext/accounts/doctype/accounting_period/accounting_period.py b/erpnext/accounts/doctype/accounting_period/accounting_period.py
index 32441db..f7190b7 100644
--- a/erpnext/accounts/doctype/accounting_period/accounting_period.py
+++ b/erpnext/accounts/doctype/accounting_period/accounting_period.py
@@ -14,7 +14,7 @@
self.bootstrap_doctypes_for_closing()
def autoname(self):
- company_abbr = frappe.db.get_value("Company", self.company, "abbr")
+ company_abbr = frappe.get_cached_value('Company', self.company, "abbr")
self.name = " - ".join([self.period_name, company_abbr])
def validate_overlap(self):
diff --git a/erpnext/accounts/doctype/budget/budget.py b/erpnext/accounts/doctype/budget/budget.py
index 771ec8d..cce4d48 100644
--- a/erpnext/accounts/doctype/budget/budget.py
+++ b/erpnext/accounts/doctype/budget/budget.py
@@ -81,8 +81,8 @@
if args.get('company') and not args.fiscal_year:
args.fiscal_year = get_fiscal_year(args.get('posting_date'), company=args.get('company'))[0]
- frappe.flags.exception_approver_role = frappe.db.get_value('Company',
- args.get('company'), 'exception_budget_approver_role')
+ frappe.flags.exception_approver_role = frappe.get_cached_value('Company',
+ args.get('company'), 'exception_budget_approver_role')
if not args.account:
args.account = args.get("expense_account")
@@ -155,7 +155,7 @@
actual_expense = amount or get_actual_expense(args)
if actual_expense > budget_amount:
diff = actual_expense - budget_amount
- currency = frappe.db.get_value('Company', args.company, 'default_currency')
+ currency = frappe.get_cached_value('Company', args.company, 'default_currency')
msg = _("{0} Budget for Account {1} against {2} {3} is {4}. It will exceed by {5}").format(
_(action_for), frappe.bold(args.account), args.budget_against_field,
diff --git a/erpnext/accounts/doctype/exchange_rate_revaluation/exchange_rate_revaluation.py b/erpnext/accounts/doctype/exchange_rate_revaluation/exchange_rate_revaluation.py
index aa19a9e..ae77516 100644
--- a/erpnext/accounts/doctype/exchange_rate_revaluation/exchange_rate_revaluation.py
+++ b/erpnext/accounts/doctype/exchange_rate_revaluation/exchange_rate_revaluation.py
@@ -85,7 +85,7 @@
if self.total_gain_loss == 0:
return
- unrealized_exchange_gain_loss_account = frappe.db.get_value("Company", self.company,
+ unrealized_exchange_gain_loss_account = frappe.get_cached_value('Company', self.company,
"unrealized_exchange_gain_loss_account")
if not unrealized_exchange_gain_loss_account:
frappe.throw(_("Please set Unrealized Exchange Gain/Loss Account in Company {0}")
diff --git a/erpnext/accounts/doctype/journal_entry/journal_entry.py b/erpnext/accounts/doctype/journal_entry/journal_entry.py
index ba13ea4..f93c75a 100644
--- a/erpnext/accounts/doctype/journal_entry/journal_entry.py
+++ b/erpnext/accounts/doctype/journal_entry/journal_entry.py
@@ -69,8 +69,8 @@
def validate_inter_company_accounts(self):
if self.voucher_type == "Inter Company Journal Entry" and self.inter_company_journal_entry_reference:
doc = frappe.get_doc("Journal Entry", self.inter_company_journal_entry_reference)
- account_currency = frappe.db.get_value("Company", self.company, "default_currency")
- previous_account_currency = frappe.db.get_value("Company", doc.company, "default_currency")
+ account_currency = frappe.get_cached_value('Company', self.company, "default_currency")
+ previous_account_currency = frappe.get_cached_value('Company', doc.company, "default_currency")
if account_currency == previous_account_currency:
if self.total_credit != doc.total_debit or self.total_debit != doc.total_credit:
frappe.throw(_("Total Credit/ Debit Amount should be same as linked Journal Entry"))
@@ -611,7 +611,7 @@
account (of that type), otherwise return empty dict.
'''
if account_type=="Bank":
- account = frappe.db.get_value("Company", company, "default_bank_account")
+ account = frappe.get_cached_value('Company', company, "default_bank_account")
if not account:
account_list = frappe.get_all("Account", filters = {"company": company,
"account_type": "Bank", "is_group": 0})
@@ -619,7 +619,7 @@
account = account_list[0].name
elif account_type=="Cash":
- account = frappe.db.get_value("Company", company, "default_cash_account")
+ account = frappe.get_cached_value('Company', company, "default_cash_account")
if not account:
account_list = frappe.get_all("Account", filters = {"company": company,
"account_type": "Cash", "is_group": 0})
@@ -711,7 +711,7 @@
def get_payment_entry(ref_doc, args):
- cost_center = frappe.db.get_value("Company", ref_doc.company, "cost_center")
+ cost_center = frappe.get_cached_value('Company', ref_doc.company, "cost_center")
exchange_rate = 1
if args.get("party_account"):
# Modified to include the posting date for which the exchange rate is required.
diff --git a/erpnext/accounts/doctype/opening_invoice_creation_tool/opening_invoice_creation_tool.py b/erpnext/accounts/doctype/opening_invoice_creation_tool/opening_invoice_creation_tool.py
index 679750d..cde8e8c 100644
--- a/erpnext/accounts/doctype/opening_invoice_creation_tool/opening_invoice_creation_tool.py
+++ b/erpnext/accounts/doctype/opening_invoice_creation_tool/opening_invoice_creation_tool.py
@@ -133,7 +133,7 @@
def get_invoice_dict(self, row=None):
def get_item_dict():
default_uom = frappe.db.get_single_value("Stock Settings", "stock_uom") or _("Nos")
- cost_center = frappe.db.get_value("Company", self.company, "cost_center")
+ cost_center = frappe.get_cached_value('Company', self.company, "cost_center")
if not cost_center:
frappe.throw(
_("Please set the Default Cost Center in {0} company.").format(frappe.bold(self.company))
@@ -171,7 +171,7 @@
"posting_date": row.posting_date,
frappe.scrub(party_type): row.party,
"doctype": "Sales Invoice" if self.invoice_type == "Sales" else "Purchase Invoice",
- "currency": frappe.db.get_value("Company", self.company, "default_currency")
+ "currency": frappe.get_cached_value('Company', self.company, "default_currency")
})
if self.invoice_type == "Sales":
diff --git a/erpnext/accounts/doctype/payment_entry/payment_entry.py b/erpnext/accounts/doctype/payment_entry/payment_entry.py
index 456acba..9ce7ecb 100644
--- a/erpnext/accounts/doctype/payment_entry/payment_entry.py
+++ b/erpnext/accounts/doctype/payment_entry/payment_entry.py
@@ -515,7 +515,7 @@
def calculate_deductions(self, tax_details):
return {
"account": tax_details['tax']['account_head'],
- "cost_center": frappe.db.get_value("Company", self.company, "cost_center"),
+ "cost_center": frappe.get_cached_value('Company', self.company, "cost_center"),
"amount": self.total_allocated_amount * (tax_details['tax']['rate'] / 100)
}
@@ -535,7 +535,7 @@
return []
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.get_cached_value('Company', args.get("company"), "default_currency")
# Get negative outstanding sales /purchase invoices
negative_outstanding_invoices = []
@@ -686,7 +686,7 @@
@frappe.whitelist()
def get_company_defaults(company):
fields = ["write_off_account", "exchange_gain_loss_account", "cost_center"]
- ret = frappe.db.get_value("Company", company, fields, as_dict=1)
+ ret = frappe.get_cached_value('Company', company, fields, as_dict=1)
for fieldname in fields:
if not ret[fieldname]:
diff --git a/erpnext/accounts/doctype/payment_entry/test_payment_entry.py b/erpnext/accounts/doctype/payment_entry/test_payment_entry.py
index 57516a1..2408235 100644
--- a/erpnext/accounts/doctype/payment_entry/test_payment_entry.py
+++ b/erpnext/accounts/doctype/payment_entry/test_payment_entry.py
@@ -151,7 +151,7 @@
def test_payment_entry_against_ec(self):
- payable = frappe.db.get_value('Company', "_Test Company", 'default_payable_account')
+ payable = frappe.get_cached_value('Company', "_Test Company", 'default_payable_account')
ec = make_expense_claim(payable, 300, 300, "_Test Company", "Travel Expenses - _TC")
pe = get_payment_entry("Expense Claim", ec.name, bank_account="_Test Bank USD - _TC", bank_amount=300)
pe.reference_no = "1"
diff --git a/erpnext/accounts/doctype/period_closing_voucher/period_closing_voucher.py b/erpnext/accounts/doctype/period_closing_voucher/period_closing_voucher.py
index 03d0918..86023aa 100644
--- a/erpnext/accounts/doctype/period_closing_voucher/period_closing_voucher.py
+++ b/erpnext/accounts/doctype/period_closing_voucher/period_closing_voucher.py
@@ -28,7 +28,7 @@
.format(self.closing_account_head))
account_currency = get_account_currency(self.closing_account_head)
- company_currency = frappe.db.get_value("Company", self.company, "default_currency")
+ company_currency = frappe.get_cached_value('Company', self.company, "default_currency")
if account_currency != company_currency:
frappe.throw(_("Currency of the Closing Account must be {0}").format(company_currency))
diff --git a/erpnext/accounts/doctype/pos_profile/pos_profile.py b/erpnext/accounts/doctype/pos_profile/pos_profile.py
index fd41106..bf2e20c 100644
--- a/erpnext/accounts/doctype/pos_profile/pos_profile.py
+++ b/erpnext/accounts/doctype/pos_profile/pos_profile.py
@@ -102,7 +102,7 @@
def get_item_groups(pos_profile):
item_groups = []
- pos_profile = frappe.get_doc('POS Profile', pos_profile)
+ pos_profile = frappe.get_cached_doc('POS Profile', pos_profile)
if pos_profile.get('item_groups'):
# Get items based on the item groups defined in the POS profile
diff --git a/erpnext/accounts/doctype/pricing_rule/pricing_rule.py b/erpnext/accounts/doctype/pricing_rule/pricing_rule.py
index 6c2ae7a..a44ac00 100644
--- a/erpnext/accounts/doctype/pricing_rule/pricing_rule.py
+++ b/erpnext/accounts/doctype/pricing_rule/pricing_rule.py
@@ -70,13 +70,13 @@
def validate_max_discount(self):
if self.rate_or_discount == "Discount Percentage" and self.item_code:
- max_discount = frappe.db.get_value("Item", self.item_code, "max_discount")
+ max_discount = frappe.get_cached_value("Item", self.item_code, "max_discount")
if max_discount and flt(self.discount_percentage) > flt(max_discount):
throw(_("Max discount allowed for item: {0} is {1}%").format(self.item_code, max_discount))
def validate_price_list_with_currency(self):
if self.currency and self.for_price_list:
- price_list_currency = frappe.db.get_value("Price List", self.for_price_list, "currency")
+ price_list_currency = frappe.db.get_value("Price List", self.for_price_list, "currency", True)
if not self.currency == price_list_currency:
throw(_("Currency should be same as Price List Currency: {0}").format(price_list_currency))
@@ -158,7 +158,7 @@
if not (args.item_group and args.brand):
try:
- args.item_group, args.brand = frappe.db.get_value("Item", args.item_code, ["item_group", "brand"])
+ args.item_group, args.brand = frappe.get_cached_value("Item", args.item_code, ["item_group", "brand"])
except TypeError:
# invalid item_code
return item_details
@@ -167,14 +167,14 @@
if args.transaction_type=="selling":
if args.customer and not (args.customer_group and args.territory):
- customer = frappe.db.get_value("Customer", args.customer, ["customer_group", "territory"])
+ customer = frappe.get_cached_value("Customer", args.customer, ["customer_group", "territory"])
if customer:
args.customer_group, args.territory = customer
args.supplier = args.supplier_group = None
elif args.supplier and not args.supplier_group:
- args.supplier_group = frappe.db.get_value("Supplier", args.supplier, "supplier_group")
+ args.supplier_group = frappe.get_cached_value("Supplier", args.supplier, "supplier_group")
args.customer = args.customer_group = args.territory = None
pricing_rules = get_pricing_rules(args)
@@ -209,7 +209,7 @@
return item_details
def remove_pricing_rule_for_item(pricing_rule, item_details):
- pricing_rule = frappe.db.get_value('Pricing Rule', pricing_rule,
+ pricing_rule = frappe.get_cached_value('Pricing Rule', pricing_rule,
['price_or_discount', 'margin_type'], as_dict=1)
if pricing_rule and pricing_rule.price_or_discount == 'Discount Percentage':
item_details.discount_percentage = 0.0
@@ -239,6 +239,12 @@
field = frappe.scrub(parenttype)
condition = ""
if args.get(field):
+ if not frappe.flags.tree_conditions:
+ frappe.flags.tree_conditions = {}
+ key = (parenttype, args[field], )
+ if key in frappe.flags.tree_conditions:
+ return frappe.flags.tree_conditions[key]
+
try:
lft, rgt = frappe.db.get_value(parenttype, args[field], ["lft", "rgt"])
except TypeError:
@@ -251,6 +257,8 @@
if allow_blank: parent_groups.append('')
condition = " ifnull("+field+", '') in ('" + \
"', '".join([frappe.db.escape(d) for d in parent_groups])+"')"
+ frappe.flags.tree_conditions[key] = condition
+
return condition
@@ -284,7 +292,7 @@
# load variant of if not defined
if "variant_of" not in args:
- args.variant_of = frappe.db.get_value("Item", args.item_code, "variant_of")
+ args.variant_of = frappe.get_cached_value("Item", args.item_code, "variant_of")
if args.variant_of:
item_variant_condition = ' or item_code=%(variant_of)s '
diff --git a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py
index f343165..2660490 100644
--- a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py
+++ b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py
@@ -220,7 +220,7 @@
item.expense_account = warehouse_account[item.warehouse]["account"]
else:
item.expense_account = stock_not_billed_account
-
+
elif not item.expense_account and for_validate:
throw(_("Expense account is mandatory for item {0}").format(item.item_code or item.item_name))
@@ -486,7 +486,6 @@
asset_amount = flt(item.net_amount) + flt(item.item_tax_amount/self.conversion_rate)
base_asset_amount = flt(item.base_net_amount + item.item_tax_amount)
- item.expense_account = item.expense_account
if (not item.expense_account or frappe.db.get_value('Account',
item.expense_account, 'account_type') != 'Asset Received But Not Billed'):
diff --git a/erpnext/accounts/doctype/purchase_taxes_and_charges_template/purchase_taxes_and_charges_template.py b/erpnext/accounts/doctype/purchase_taxes_and_charges_template/purchase_taxes_and_charges_template.py
index bd66aa5..efcef46 100644
--- a/erpnext/accounts/doctype/purchase_taxes_and_charges_template/purchase_taxes_and_charges_template.py
+++ b/erpnext/accounts/doctype/purchase_taxes_and_charges_template/purchase_taxes_and_charges_template.py
@@ -14,5 +14,5 @@
def autoname(self):
if self.company and self.title:
- abbr = frappe.db.get_value('Company', self.company, 'abbr')
+ abbr = frappe.get_cached_value('Company', self.company, 'abbr')
self.name = '{0} - {1}'.format(self.title, abbr)
diff --git a/erpnext/accounts/doctype/sales_invoice/pos.py b/erpnext/accounts/doctype/sales_invoice/pos.py
index b67b61c..a14c234 100755
--- a/erpnext/accounts/doctype/sales_invoice/pos.py
+++ b/erpnext/accounts/doctype/sales_invoice/pos.py
@@ -495,7 +495,7 @@
address = frappe.get_doc('Address', name)
else:
address = frappe.new_doc('Address')
- address.country = frappe.db.get_value('Company', args.get('company'), 'country')
+ address.country = frappe.get_cached_value('Company', args.get('company'), 'country')
address.append('links', {
'link_doctype': 'Customer',
'link_name': customer
diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py
index f559fc0..d1ef3a6 100644
--- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py
+++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py
@@ -161,7 +161,7 @@
self.update_project()
update_linked_invoice(self.doctype, self.name, self.inter_company_invoice_reference)
- # create the loyalty point ledger entry if the customer is enrolled in any loyalty program
+ # create the loyalty point ledger entry if the customer is enrolled in any loyalty program
if not self.is_return and self.loyalty_program:
self.make_loyalty_point_entry()
elif self.is_return and self.return_against and self.loyalty_program:
@@ -259,7 +259,7 @@
from erpnext.selling.doctype.customer.customer import check_credit_limit
validate_against_credit_limit = False
- bypass_credit_limit_check_at_sales_order = cint(frappe.db.get_value("Customer", self.customer,
+ bypass_credit_limit_check_at_sales_order = cint(frappe.get_cached_value("Customer", self.customer,
"bypass_credit_limit_check_at_sales_order"))
if bypass_credit_limit_check_at_sales_order:
validate_against_credit_limit = True
@@ -345,7 +345,7 @@
update_multi_mode_option(self, pos)
if not self.account_for_change_amount:
- self.account_for_change_amount = frappe.db.get_value('Company', self.company, 'default_cash_account')
+ self.account_for_change_amount = frappe.get_cached_value('Company', self.company, 'default_cash_account')
if pos:
self.allow_print_before_pay = pos.allow_print_before_pay
@@ -388,7 +388,7 @@
return frappe.db.sql("select abbr from tabCompany where name=%s", self.company)[0][0]
def validate_debit_to_acc(self):
- account = frappe.db.get_value("Account", self.debit_to,
+ account = frappe.get_cached_value("Account", self.debit_to,
["account_type", "report_type", "account_currency"], as_dict=True)
if not account:
@@ -460,9 +460,9 @@
"""check in manage account if sales order / delivery note required or not."""
dic = {'Sales Order':['so_required', 'is_pos'],'Delivery Note':['dn_required', 'update_stock']}
for i in dic:
- if frappe.db.get_value('Selling Settings', None, dic[i][0]) == 'Yes':
+ if frappe.db.get_single_value('Selling Settings', dic[i][0]) == 'Yes':
for d in self.get('items'):
- if frappe.db.get_value('Item', d.item_code, 'is_stock_item') == 1 \
+ if frappe.get_cached_value('Item', d.item_code, 'is_stock_item') == 1 \
and not d.get(i.lower().replace(' ','_')) and not self.get(dic[i][1]):
msgprint(_("{0} is mandatory for Item {1}").format(i,d.item_code), raise_exception=1)
@@ -491,7 +491,7 @@
super(SalesInvoice, self).validate_warehouse()
for d in self.get_item_list():
- if not d.warehouse and frappe.db.get_value("Item", d.item_code, "is_stock_item"):
+ if not d.warehouse and frappe.get_cached_value("Item", d.item_code, "is_stock_item"):
frappe.throw(_("Warehouse required for stock Item {0}").format(d.item_code))
def validate_delivery_note(self):
@@ -501,7 +501,7 @@
def validate_write_off_account(self):
if flt(self.write_off_amount) and not self.write_off_account:
- self.write_off_account = frappe.db.get_value('Company', self.company, 'write_off_account')
+ self.write_off_account = frappe.get_cached_value('Company', self.company, 'write_off_account')
if flt(self.write_off_amount) and not self.write_off_account:
msgprint(_("Please enter Write Off Account"), raise_exception=1)
@@ -830,7 +830,7 @@
# write off entries, applicable if only pos
if self.write_off_account and self.write_off_amount:
write_off_account_currency = get_account_currency(self.write_off_account)
- default_cost_center = frappe.db.get_value('Company', self.company, 'cost_center')
+ default_cost_center = frappe.get_cached_value('Company', self.company, 'cost_center')
gl_entries.append(
self.get_gl_dict({
@@ -865,7 +865,7 @@
self.get_gl_dict({
"account": round_off_account,
"against": self.customer,
- "credit_in_account_currency": self.rounding_adjustment,
+ "credit_in_account_currency": self.base_rounding_adjustment,
"credit": self.base_rounding_adjustment,
"cost_center": round_off_cost_center,
}
@@ -1006,7 +1006,7 @@
where redeem_against=%s''', (lp_entry.name), as_dict=1)
if against_lp_entry:
invoice_list = ", ".join([d.sales_invoice for d in against_lp_entry])
- frappe.throw(_('''Sales Invoice can't be cancelled since the Loyalty Points earned has been redeemed.
+ frappe.throw(_('''Sales Invoice can't be cancelled since the Loyalty Points earned has been redeemed.
First cancel the Sales Invoice No {0}''').format(invoice_list))
else:
frappe.db.sql('''delete from `tabLoyalty Point Entry` where sales_invoice=%s''', (self.name))
@@ -1153,7 +1153,7 @@
ref_party = doc.supplier if doctype == "Sales Invoice" else doc.customer
if not frappe.db.get_value(partytype, {"represents_company": doc.company}, "name") == party:
frappe.throw(_("Invalid {0} for Inter Company Invoice.").format(partytype))
- if not frappe.db.get_value(ref_partytype, {"name": ref_party}, "represents_company") == company:
+ if not frappe.get_cached_value(ref_partytype, ref_party, "represents_company") == company:
frappe.throw(_("Invalid Company for Inter Company Invoice."))
elif frappe.db.get_value(partytype, {"name": party, internal: 1}, "name") == party:
@@ -1260,10 +1260,10 @@
def get_inter_company_details(doc, doctype):
if doctype == "Sales Invoice":
party = frappe.db.get_value("Supplier", {"disabled": 0, "is_internal_supplier": 1, "represents_company": doc.company}, "name")
- company = frappe.db.get_value("Customer", {"name": doc.customer}, "represents_company")
+ company = frappe.get_cached_value("Customer", doc.customer, "represents_company")
else:
party = frappe.db.get_value("Customer", {"disabled": 0, "is_internal_customer": 1, "represents_company": doc.company}, "name")
- company = frappe.db.get_value("Supplier", {"name": doc.supplier}, "represents_company")
+ company = frappe.get_cached_value("Supplier", doc.supplier, "represents_company")
return {
"party": party,
@@ -1285,7 +1285,7 @@
frappe.throw(_("No {0} found for Inter Company Transactions.").format(partytype))
company = details.get("company")
- default_currency = frappe.db.get_value("Company", company, "default_currency")
+ default_currency = frappe.get_cached_value('Company', company, "default_currency")
if default_currency != doc.currency:
frappe.throw(_("Company currencies of both the companies should match for Inter Company Transactions."))
diff --git a/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py b/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py
index 3e8881c..468ed9f 100644
--- a/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py
+++ b/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py
@@ -1324,14 +1324,14 @@
return si
def test_company_monthly_sales(self):
- existing_current_month_sales = frappe.db.get_value("Company", "_Test Company", "total_monthly_sales")
+ existing_current_month_sales = frappe.get_cached_value('Company', "_Test Company", "total_monthly_sales")
si = create_sales_invoice()
- current_month_sales = frappe.db.get_value("Company", "_Test Company", "total_monthly_sales")
+ current_month_sales = frappe.get_cached_value('Company', "_Test Company", "total_monthly_sales")
self.assertEqual(current_month_sales, existing_current_month_sales + si.base_grand_total)
si.cancel()
- current_month_sales = frappe.db.get_value("Company", "_Test Company", "total_monthly_sales")
+ current_month_sales = frappe.get_cached_value('Company', "_Test Company", "total_monthly_sales")
self.assertEqual(current_month_sales, existing_current_month_sales)
def test_rounding_adjustment(self):
diff --git a/erpnext/accounts/doctype/sales_taxes_and_charges_template/sales_taxes_and_charges_template.py b/erpnext/accounts/doctype/sales_taxes_and_charges_template/sales_taxes_and_charges_template.py
index 9dee1f9..b46de6c 100644
--- a/erpnext/accounts/doctype/sales_taxes_and_charges_template/sales_taxes_and_charges_template.py
+++ b/erpnext/accounts/doctype/sales_taxes_and_charges_template/sales_taxes_and_charges_template.py
@@ -14,7 +14,7 @@
def autoname(self):
if self.company and self.title:
- abbr = frappe.db.get_value('Company', self.company, 'abbr')
+ abbr = frappe.get_cached_value('Company', self.company, 'abbr')
self.name = '{0} - {1}'.format(self.title, abbr)
def set_missing_values(self):
diff --git a/erpnext/accounts/general_ledger.py b/erpnext/accounts/general_ledger.py
index 0199e7d..a661c03 100644
--- a/erpnext/accounts/general_ledger.py
+++ b/erpnext/accounts/general_ledger.py
@@ -66,7 +66,7 @@
# filter zero debit and credit entries
merged_gl_map = filter(lambda x: flt(x.debit, 9)!=0 or flt(x.credit, 9)!=0, merged_gl_map)
merged_gl_map = list(merged_gl_map)
-
+
return merged_gl_map
def check_if_in_list(gle, gl_map):
@@ -83,12 +83,12 @@
def save_entries(gl_map, adv_adj, update_outstanding, from_repost=False):
if not from_repost:
validate_account_for_perpetual_inventory(gl_map)
-
+
round_off_debit_credit(gl_map)
for entry in gl_map:
make_entry(entry, adv_adj, update_outstanding, from_repost)
-
+
# check against budget
if not from_repost:
validate_expense_against_budget(entry)
@@ -115,7 +115,7 @@
def round_off_debit_credit(gl_map):
precision = get_field_precision(frappe.get_meta("GL Entry").get_field("debit"),
- currency=frappe.db.get_value("Company", gl_map[0].company, "default_currency", cache=True))
+ currency=frappe.get_cached_value('Company', gl_map[0].company, "default_currency"))
debit_credit_diff = 0.0
for entry in gl_map:
@@ -124,12 +124,12 @@
debit_credit_diff += entry.debit - entry.credit
debit_credit_diff = flt(debit_credit_diff, precision)
-
+
if gl_map[0]["voucher_type"] in ("Journal Entry", "Payment Entry"):
allowance = 5.0 / (10**precision)
else:
allowance = .5
-
+
if abs(debit_credit_diff) >= allowance:
frappe.throw(_("Debit and Credit not equal for {0} #{1}. Difference is {2}.")
.format(gl_map[0].voucher_type, gl_map[0].voucher_no, debit_credit_diff))
@@ -139,11 +139,21 @@
def make_round_off_gle(gl_map, debit_credit_diff):
round_off_account, round_off_cost_center = get_round_off_account_and_cost_center(gl_map[0].company)
-
+ round_off_account_exists = False
round_off_gle = frappe._dict()
- for k in ["voucher_type", "voucher_no", "company",
- "posting_date", "remarks", "is_opening"]:
- round_off_gle[k] = gl_map[0][k]
+ for d in gl_map:
+ if d.account == round_off_account:
+ round_off_gle = d
+ if d.debit_in_account_currency:
+ debit_credit_diff -= flt(d.debit_in_account_currency)
+ else:
+ debit_credit_diff += flt(d.credit_in_account_currency)
+ round_off_account_exists = True
+
+ if not round_off_gle:
+ for k in ["voucher_type", "voucher_no", "company",
+ "posting_date", "remarks", "is_opening"]:
+ round_off_gle[k] = gl_map[0][k]
round_off_gle.update({
"account": round_off_account,
@@ -158,10 +168,11 @@
"against_voucher": None
})
- gl_map.append(round_off_gle)
+ if not round_off_account_exists:
+ gl_map.append(round_off_gle)
def get_round_off_account_and_cost_center(company):
- round_off_account, round_off_cost_center = frappe.db.get_value("Company", company,
+ round_off_account, round_off_cost_center = frappe.get_cached_value('Company', company,
["round_off_account", "round_off_cost_center"]) or [None, None]
if not round_off_account:
frappe.throw(_("Please mention Round Off Account in Company"))
@@ -195,7 +206,7 @@
validate_balance_type(entry["account"], adv_adj)
if not adv_adj:
validate_expense_against_budget(entry)
-
+
if entry.get("against_voucher") and update_outstanding == 'Yes' and not adv_adj:
update_outstanding_amt(entry["account"], entry.get("party_type"), entry.get("party"), entry.get("against_voucher_type"),
entry.get("against_voucher"), on_cancel=True)
diff --git a/erpnext/accounts/party.py b/erpnext/accounts/party.py
index cc90c74..454c52b 100644
--- a/erpnext/accounts/party.py
+++ b/erpnext/accounts/party.py
@@ -142,7 +142,7 @@
return party.default_price_list
if party.doctype == "Customer":
- price_list = frappe.db.get_value("Customer Group",
+ price_list = frappe.get_cached_value("Customer Group",
party.customer_group, "default_price_list")
if price_list:
return price_list
@@ -162,7 +162,7 @@
price_list = get_default_price_list(party) or given_price_list
if price_list:
- out.price_list_currency = frappe.db.get_value("Price List", price_list, "currency")
+ out.price_list_currency = frappe.db.get_value("Price List", price_list, "currency", cache=True)
out["selling_price_list" if party.doctype=="Customer" else "buying_price_list"] = price_list
@@ -203,19 +203,19 @@
if not account and party_type in ['Customer', 'Supplier']:
party_group_doctype = "Customer Group" if party_type=="Customer" else "Supplier Group"
- group = frappe.db.get_value(party_type, party, scrub(party_group_doctype))
+ group = frappe.get_cached_value(party_type, party, scrub(party_group_doctype))
account = frappe.db.get_value("Party Account",
{"parenttype": party_group_doctype, "parent": group, "company": company}, "account")
if not account and party_type in ['Customer', 'Supplier']:
default_account_name = "default_receivable_account" \
if party_type=="Customer" else "default_payable_account"
- account = frappe.db.get_value("Company", company, default_account_name)
+ account = frappe.get_cached_value('Company', company, default_account_name)
existing_gle_currency = get_party_gle_currency(party_type, party, company)
if existing_gle_currency:
if account:
- account_currency = frappe.db.get_value("Account", account, "account_currency")
+ account_currency = frappe.db.get_value("Account", account, "account_currency", cache=True)
if (account and account_currency != existing_gle_currency) or not account:
account = get_party_gle_account(party_type, party, company)
@@ -224,7 +224,7 @@
def get_party_account_currency(party_type, party, company):
def generator():
party_account = get_party_account(party_type, party, company)
- return frappe.db.get_value("Account", party_account, "account_currency")
+ return frappe.db.get_value("Account", party_account, "account_currency", cache=True)
return frappe.local_cache("party_account_currency", (party_type, party, company), generator)
@@ -271,10 +271,10 @@
else:
companies.append(account.company)
- party_account_currency = frappe.db.get_value("Account", account.account, "account_currency")
+ party_account_currency = frappe.db.get_value("Account", account.account, "account_currency", cache=True)
existing_gle_currency = get_party_gle_currency(doc.doctype, doc.name, account.company)
- company_default_currency = frappe.db.get_value("Company",
- frappe.db.get_default("Company"), "default_currency", cache=True)
+ company_default_currency = frappe.get_cached_value('Company',
+ frappe.db.get_default("Company"), "default_currency")
if existing_gle_currency and party_account_currency != existing_gle_currency:
frappe.throw(_("Accounting entries have already been made in currency {0} for company {1}. Please select a receivable or payable account with currency {0}.").format(existing_gle_currency, account.company))
@@ -296,8 +296,8 @@
due_date = get_due_date_from_template(template_name, posting_date, bill_date).strftime("%Y-%m-%d")
else:
if party_type == "Supplier":
- supplier_group = frappe.db.get_value(party_type, party, fieldname="supplier_group")
- template_name = frappe.db.get_value("Supplier Group", supplier_group, fieldname="payment_terms")
+ supplier_group = frappe.get_cached_value(party_type, party, "supplier_group")
+ template_name = frappe.get_cached_value("Supplier Group", supplier_group, "payment_terms")
if template_name:
due_date = get_due_date_from_template(template_name, posting_date, bill_date).strftime("%Y-%m-%d")
# If due date is calculated from bill_date, check this condition
@@ -387,32 +387,32 @@
return
template = None
if party_type == 'Customer':
- customer = frappe.db.get_value("Customer", party_name,
+ customer = frappe.get_cached_value("Customer", party_name,
fieldname=['payment_terms', "customer_group"], as_dict=1)
template = customer.payment_terms
if not template and customer.customer_group:
- template = frappe.db.get_value("Customer Group",
- customer.customer_group, fieldname='payment_terms')
+ template = frappe.get_cached_value("Customer Group",
+ customer.customer_group, 'payment_terms')
else:
- supplier = frappe.db.get_value("Supplier", party_name,
+ supplier = frappe.get_cached_value("Supplier", party_name,
fieldname=['payment_terms', "supplier_group"], as_dict=1)
template = supplier.payment_terms
if not template and supplier.supplier_group:
- template = frappe.db.get_value("Supplier Group", supplier.supplier_group, fieldname='payment_terms')
+ template = frappe.get_cached_value("Supplier Group", supplier.supplier_group, 'payment_terms')
if not template and company:
- template = frappe.db.get_value("Company", company, fieldname='payment_terms')
+ template = frappe.get_cached_value('Company', company, fieldname='payment_terms')
return template
def validate_party_frozen_disabled(party_type, party_name):
if party_type and party_name:
if party_type in ("Customer", "Supplier"):
- party = frappe.db.get_value(party_type, party_name, ["is_frozen", "disabled"], as_dict=True)
+ party = frappe.get_cached_value(party_type, party_name, ["is_frozen", "disabled"], as_dict=True)
if party.disabled:
frappe.throw(_("{0} {1} is disabled").format(party_type, party_name), PartyDisabled)
elif party.get("is_frozen"):
- frozen_accounts_modifier = frappe.db.get_value( 'Accounts Settings', None,'frozen_accounts_modifier')
+ frozen_accounts_modifier = frappe.db.get_single_value( 'Accounts Settings', 'frozen_accounts_modifier')
if not frozen_accounts_modifier in frappe.get_roles():
frappe.throw(_("{0} {1} is frozen").format(party_type, party_name), PartyFrozen)
@@ -454,7 +454,7 @@
company = frappe.db.get_default("company") or frappe.get_all("Company")[0].name
party_account_currency = get_party_account_currency(party_type, party, company)
company_default_currency = get_default_currency() \
- or frappe.db.get_value('Company', company, 'default_currency')
+ or frappe.get_cached_value('Company', company, 'default_currency')
if party_account_currency==company_default_currency:
total_field = "base_grand_total"
diff --git a/erpnext/accounts/report/accounts_receivable/accounts_receivable.html b/erpnext/accounts/report/accounts_receivable/accounts_receivable.html
index 9fefc037..09f3cc2 100644
--- a/erpnext/accounts/report/accounts_receivable/accounts_receivable.html
+++ b/erpnext/accounts/report/accounts_receivable/accounts_receivable.html
@@ -34,7 +34,7 @@
<h5 class="text-center">
{%= __(filters.ageing_based_on) %}
{%= __("Until") %}
- {%= dateutil.str_to_user(filters.report_date) %}
+ {%= frappe.datetime.str_to_user(filters.report_date) %}
</h5>
<hr>
{% if(filters.show_pdc_in_print) { %}
@@ -138,7 +138,7 @@
<tr>
{% if(report.report_name === "Accounts Receivable" || report.report_name === "Accounts Payable") { %}
{% if(data[i][__("Customer")] || data[i][__("Supplier")]) { %}
- <td>{%= dateutil.str_to_user(data[i]["posting_date"]) %}</td>
+ <td>{%= frappe.datetime.str_to_user(data[i]["posting_date"]) %}</td>
<td>
{% if(!filters.show_pdc_in_print) { %}
{%= data[i]["voucher_type"] %}
@@ -220,7 +220,7 @@
<br> {%= data[i][__("Customer Name")] %}
{% } else if(data[i][__("Supplier Name")] != data[i][__("Supplier")]) { %}
<br> {%= data[i][__("Supplier Name")] %}
- {% } %}
+ {% } %}
{% } %}
<br>{%= __("Remarks") %}:
{%= data[i][__("Remarks")] %}
@@ -238,4 +238,4 @@
{% } %}
</tbody>
</table>
-<p class="text-right text-muted">{{ __("Printed On ") }}{%= dateutil.str_to_user(dateutil.get_datetime_as_string()) %}</p>
\ No newline at end of file
+<p class="text-right text-muted">{{ __("Printed On ") }}{%= frappe.datetime.str_to_user(frappe.datetime.get_datetime_as_string()) %}</p>
\ No newline at end of file
diff --git a/erpnext/accounts/report/accounts_receivable/accounts_receivable.py b/erpnext/accounts/report/accounts_receivable/accounts_receivable.py
index 2b3e824..28543b5 100644
--- a/erpnext/accounts/report/accounts_receivable/accounts_receivable.py
+++ b/erpnext/accounts/report/accounts_receivable/accounts_receivable.py
@@ -132,7 +132,7 @@
if not self.filters.get("company"):
self.filters["company"] = frappe.db.get_single_value('Global Defaults', 'default_company')
- company_currency = frappe.db.get_value("Company", self.filters.get("company"), "default_currency")
+ company_currency = frappe.get_cached_value('Company', self.filters.get("company"), "default_currency")
return_entries = self.get_return_entries(args.get("party_type"))
diff --git a/erpnext/accounts/report/balance_sheet/balance_sheet.py b/erpnext/accounts/report/balance_sheet/balance_sheet.py
index 204eceb..7d9acf2 100644
--- a/erpnext/accounts/report/balance_sheet/balance_sheet.py
+++ b/erpnext/accounts/report/balance_sheet/balance_sheet.py
@@ -11,7 +11,7 @@
period_list = get_period_list(filters.from_fiscal_year, filters.to_fiscal_year,
filters.periodicity, company=filters.company)
- currency = filters.presentation_currency or frappe.db.get_value("Company", filters.company, "default_currency")
+ currency = filters.presentation_currency or frappe.get_cached_value('Company', filters.company, "default_currency")
asset = get_data(filters.company, "Asset", "Debit", period_list,
only_current_fiscal_year=False, filters=filters,
@@ -65,7 +65,7 @@
total_row = {}
if asset and (liability or equity):
total = total_row_total=0
- currency = currency or frappe.db.get_value("Company", company, "default_currency")
+ currency = currency or frappe.get_cached_value('Company', company, "default_currency")
total_row = {
"account_name": "'" + _("Total (Credit)") + "'",
"account": "'" + _("Total (Credit)") + "'",
diff --git a/erpnext/accounts/report/bank_reconciliation_statement/bank_reconciliation_statement.html b/erpnext/accounts/report/bank_reconciliation_statement/bank_reconciliation_statement.html
index 23d2a31..eaabc90 100644
--- a/erpnext/accounts/report/bank_reconciliation_statement/bank_reconciliation_statement.html
+++ b/erpnext/accounts/report/bank_reconciliation_statement/bank_reconciliation_statement.html
@@ -18,17 +18,17 @@
{% for(var i=0, l=data.length; i<l; i++) { %}
{% if (data[i]["posting_date"]) { %}
<tr>
- <td>{%= dateutil.str_to_user(data[i]["posting_date"]) %}</td>
+ <td>{%= frappe.datetime.str_to_user(data[i]["posting_date"]) %}</td>
<td>{%= data[i]["payment_entry"] %}</td>
<td>{%= __("Against") %}: {%= data[i]["against_account"] %}
{% if (data[i]["reference_no"]) { %}
<br>{%= __("Reference") %}: {%= data[i]["reference_no"] %}
{% if (data[i]["ref_date"]) { %}
- <br>{%= __("Reference Date") %}: {%= dateutil.str_to_user(data[i]["ref_date"]) %}
+ <br>{%= __("Reference Date") %}: {%= frappe.datetime.str_to_user(data[i]["ref_date"]) %}
{% } %}
{% } %}
{% if (data[i]["clearance_date"]) { %}
- <br>{%= __("Clearance Date") %}: {%= dateutil.str_to_user(data[i]["clearance_date"]) %}
+ <br>{%= __("Clearance Date") %}: {%= frappe.datetime.str_to_user(data[i]["clearance_date"]) %}
{% } %}
</td>
<td style="text-align: right">{%= format_currency(data[i]["debit"]) %}</td>
@@ -46,4 +46,4 @@
{% } %}
</tbody>
</table>
-<p class="text-right text-muted">Printed On {%= dateutil.str_to_user(dateutil.get_datetime_as_string()) %}</p>
+<p class="text-right text-muted">Printed On {%= frappe.datetime.str_to_user(frappe.datetime.get_datetime_as_string()) %}</p>
diff --git a/erpnext/accounts/report/cash_flow/cash_flow.py b/erpnext/accounts/report/cash_flow/cash_flow.py
index 56de941..9eda21e 100644
--- a/erpnext/accounts/report/cash_flow/cash_flow.py
+++ b/erpnext/accounts/report/cash_flow/cash_flow.py
@@ -29,7 +29,7 @@
net_profit_loss = get_net_profit_loss(income, expense, period_list, filters.company)
data = []
- company_currency = frappe.db.get_value("Company", filters.company, "default_currency")
+ company_currency = frappe.get_cached_value('Company', filters.company, "default_currency")
for cash_flow_account in cash_flow_accounts:
section_data = []
diff --git a/erpnext/accounts/report/cash_flow/custom_cash_flow.py b/erpnext/accounts/report/cash_flow/custom_cash_flow.py
index ee0f38c..d0b283a 100644
--- a/erpnext/accounts/report/cash_flow/custom_cash_flow.py
+++ b/erpnext/accounts/report/cash_flow/custom_cash_flow.py
@@ -358,7 +358,7 @@
net_profit_loss = get_net_profit_loss(income, expense, period_list, filters.company)
- company_currency = frappe.db.get_value("Company", filters.company, "default_currency")
+ company_currency = frappe.get_cached_value('Company', filters.company, "default_currency")
data = compute_data(filters, company_currency, net_profit_loss, period_list, mappers, cash_flow_accounts)
diff --git a/erpnext/accounts/report/consolidated_financial_statement/consolidated_financial_statement.py b/erpnext/accounts/report/consolidated_financial_statement/consolidated_financial_statement.py
index f473073..d517a56 100644
--- a/erpnext/accounts/report/consolidated_financial_statement/consolidated_financial_statement.py
+++ b/erpnext/accounts/report/consolidated_financial_statement/consolidated_financial_statement.py
@@ -59,7 +59,7 @@
"account_name": "'" + _("Unclosed Fiscal Years Profit / Loss (Credit)") + "'",
"account": "'" + _("Unclosed Fiscal Years Profit / Loss (Credit)") + "'",
"warn_if_negative": True,
- "currency": frappe.db.get_value("Company", filters.company, "default_currency")
+ "currency": frappe.get_cached_value('Company', filters.company, "default_currency")
}
for company in companies:
unclosed[company] = opening_balance
@@ -92,7 +92,7 @@
return data, None, chart
def get_income_expense_data(companies, fiscal_year, filters):
- company_currency = frappe.db.get_value("Company", filters.company, "default_currency")
+ company_currency = frappe.get_cached_value('Company', filters.company, "default_currency")
income = get_data(companies, "Income", "Credit", fiscal_year, filters, True)
expense = get_data(companies, "Expense", "Debit", fiscal_year, filters, True)
@@ -107,7 +107,7 @@
income, expense, net_profit_loss = get_income_expense_data(companies, fiscal_year, filters)
data = []
- company_currency = frappe.db.get_value("Company", filters.company, "default_currency")
+ company_currency = frappe.get_cached_value('Company', filters.company, "default_currency")
for cash_flow_account in cash_flow_accounts:
section_data = []
@@ -216,7 +216,7 @@
return out
def get_company_currency(filters=None):
- return frappe.db.get_value("Company", filters.get('company'), "default_currency")
+ return frappe.get_cached_value('Company', filters.get('company'), "default_currency")
def calculate_values(accounts_by_name, gl_entries_by_account, companies, fiscal_year, filters):
for entries in gl_entries_by_account.values():
@@ -268,8 +268,8 @@
return all_companies, companies
def get_subsidiary_companies(company):
- lft, rgt = frappe.db.get_value('Company',
- company, ["lft", "rgt"])
+ lft, rgt = frappe.get_cached_value('Company',
+ company, ["lft", "rgt"])
return frappe.db.sql_list("""select name from `tabCompany`
where lft >= {0} and rgt <= {1} order by lft, rgt""".format(lft, rgt))
@@ -322,8 +322,8 @@
accounts_by_name, ignore_closing_entries=False):
"""Returns a dict like { "account": [gl entries], ... }"""
- company_lft, company_rgt = frappe.db.get_value('Company',
- filters.get('company'), ["lft", "rgt"])
+ company_lft, company_rgt = frappe.get_cached_value('Company',
+ filters.get('company'), ["lft", "rgt"])
additional_conditions = get_additional_conditions(from_date, ignore_closing_entries, filters)
diff --git a/erpnext/accounts/report/financial_statements.html b/erpnext/accounts/report/financial_statements.html
index e475a1c..4b3b5f2 100644
--- a/erpnext/accounts/report/financial_statements.html
+++ b/erpnext/accounts/report/financial_statements.html
@@ -51,7 +51,7 @@
</td>
{% for(var i=2, l=report_columns.length; i<l; i++) { %}
<td class="text-right">
- {% var fieldname = report_columns[i].field || report_columns[i].fieldname; %}
+ {% var fieldname = report_columns[i].fieldname; %}
{% if (!is_null(row[fieldname])) { %}
{%= format_currency(row[fieldname], filters.presentation_currency) %}
{% } %}
diff --git a/erpnext/accounts/report/financial_statements.py b/erpnext/accounts/report/financial_statements.py
index 1ede508..3ac2eee 100644
--- a/erpnext/accounts/report/financial_statements.py
+++ b/erpnext/accounts/report/financial_statements.py
@@ -162,7 +162,7 @@
if filters and filters.get("presentation_currency"):
return filters["presentation_currency"]
else:
- return frappe.db.get_value("Company", company, "default_currency")
+ return frappe.get_cached_value('Company', company, "default_currency")
def calculate_values(
diff --git a/erpnext/accounts/report/general_ledger/general_ledger.py b/erpnext/accounts/report/general_ledger/general_ledger.py
index 804e3fe..7e579ac 100644
--- a/erpnext/accounts/report/general_ledger/general_ledger.py
+++ b/erpnext/accounts/report/general_ledger/general_ledger.py
@@ -72,7 +72,7 @@
def set_account_currency(filters):
if filters.get("account") or (filters.get('party') and len(filters.party) == 1):
- filters["company_currency"] = frappe.db.get_value("Company", filters.company, "default_currency")
+ filters["company_currency"] = frappe.get_cached_value('Company', filters.company, "default_currency")
account_currency = None
if filters.get("account"):
@@ -89,12 +89,11 @@
account_currency = gle_currency
else:
account_currency = (None if filters.party_type in ["Employee", "Student", "Shareholder", "Member"] else
- frappe.db.get_value(filters.party_type, filters.party, "default_currency"))
+ frappe.db.get_value(filters.party_type, filters.party[0], "default_currency"))
filters["account_currency"] = account_currency or filters.company_currency
-
if filters.account_currency != filters.company_currency:
- filters["show_in_account_currency"] = 1
+ filters.presentation_currency = filters.account_currency
return filters
@@ -294,15 +293,6 @@
balance = get_balance(d, balance, 'debit', 'credit')
d['balance'] = balance
- if filters.get("show_in_account_currency"):
- balance_in_account_currency = get_balance(d, balance_in_account_currency,
- 'debit_in_account_currency', 'credit_in_account_currency')
- d['balance_in_account_currency'] = balance_in_account_currency
- else:
- d['debit_in_account_currency'] = d.get('debit', 0)
- d['credit_in_account_currency'] = d.get('credit', 0)
- d['balance_in_account_currency'] = d.get('balance')
-
d['account_currency'] = filters.account_currency
d['bill_no'] = inv_details.get(d.get('against_voucher'), '')
diff --git a/erpnext/accounts/report/gross_profit/gross_profit.py b/erpnext/accounts/report/gross_profit/gross_profit.py
index 2b0d5e7..19075d3 100644
--- a/erpnext/accounts/report/gross_profit/gross_profit.py
+++ b/erpnext/accounts/report/gross_profit/gross_profit.py
@@ -11,7 +11,7 @@
def execute(filters=None):
if not filters: filters = frappe._dict()
- filters.currency = frappe.db.get_value("Company", filters.company, "default_currency")
+ filters.currency = frappe.get_cached_value('Company', filters.company, "default_currency")
gross_profit_data = GrossProfitGenerator(filters)
diff --git a/erpnext/accounts/report/profit_and_loss_statement/profit_and_loss_statement.py b/erpnext/accounts/report/profit_and_loss_statement/profit_and_loss_statement.py
index 8687dce..48d7361 100644
--- a/erpnext/accounts/report/profit_and_loss_statement/profit_and_loss_statement.py
+++ b/erpnext/accounts/report/profit_and_loss_statement/profit_and_loss_statement.py
@@ -39,7 +39,7 @@
"account_name": "'" + _("Profit for the year") + "'",
"account": "'" + _("Profit for the year") + "'",
"warn_if_negative": True,
- "currency": currency or frappe.db.get_value("Company", company, "default_currency")
+ "currency": currency or frappe.get_cached_value('Company', company, "default_currency")
}
has_value = False
diff --git a/erpnext/accounts/report/profitability_analysis/profitability_analysis.py b/erpnext/accounts/report/profitability_analysis/profitability_analysis.py
index 8bc1954..39706ac 100644
--- a/erpnext/accounts/report/profitability_analysis/profitability_analysis.py
+++ b/erpnext/accounts/report/profitability_analysis/profitability_analysis.py
@@ -96,7 +96,7 @@
def prepare_data(accounts, filters, total_row, parent_children_map, based_on):
data = []
- company_currency = frappe.db.get_value("Company", filters.get("company"), "default_currency")
+ company_currency = frappe.get_cached_value('Company', filters.get("company"), "default_currency")
for d in accounts:
has_value = False
diff --git a/erpnext/accounts/report/purchase_register/purchase_register.py b/erpnext/accounts/report/purchase_register/purchase_register.py
index 7a298b3..5d24096 100644
--- a/erpnext/accounts/report/purchase_register/purchase_register.py
+++ b/erpnext/accounts/report/purchase_register/purchase_register.py
@@ -26,7 +26,7 @@
suppliers = list(set([d.supplier for d in invoice_list]))
supplier_details = get_supplier_details(suppliers)
- company_currency = frappe.db.get_value("Company", filters.company, "default_currency")
+ company_currency = frappe.get_cached_value('Company', filters.company, "default_currency")
data = []
for inv in invoice_list:
diff --git a/erpnext/accounts/report/sales_register/sales_register.py b/erpnext/accounts/report/sales_register/sales_register.py
index a318751..dd92c92 100644
--- a/erpnext/accounts/report/sales_register/sales_register.py
+++ b/erpnext/accounts/report/sales_register/sales_register.py
@@ -25,7 +25,7 @@
#Cost Center & Warehouse Map
invoice_cc_wh_map = get_invoice_cc_wh_map(invoice_list)
invoice_so_dn_map = get_invoice_so_dn_map(invoice_list)
- company_currency = frappe.db.get_value("Company", filters.get("company"), "default_currency")
+ company_currency = frappe.get_cached_value('Company', filters.get("company"), "default_currency")
mode_of_payments = get_mode_of_payments([inv.name for inv in invoice_list])
data = []
diff --git a/erpnext/accounts/report/trial_balance_for_party/trial_balance_for_party.py b/erpnext/accounts/report/trial_balance_for_party/trial_balance_for_party.py
index 8be63a0..2508a1f 100644
--- a/erpnext/accounts/report/trial_balance_for_party/trial_balance_for_party.py
+++ b/erpnext/accounts/report/trial_balance_for_party/trial_balance_for_party.py
@@ -25,7 +25,7 @@
party_filters = {"name": filters.get("party")} if filters.get("party") else {}
parties = frappe.get_all(filters.get("party_type"), fields = ["name", party_name_field],
filters = party_filters, order_by="name")
- company_currency = frappe.db.get_value("Company", filters.company, "default_currency")
+ company_currency = frappe.get_cached_value('Company', filters.company, "default_currency")
opening_balances = get_opening_balances(filters)
balances_within_period = get_balances_within_period(filters)
diff --git a/erpnext/accounts/report/utils.py b/erpnext/accounts/report/utils.py
index d1995d2..e33bd83 100644
--- a/erpnext/accounts/report/utils.py
+++ b/erpnext/accounts/report/utils.py
@@ -2,7 +2,7 @@
from erpnext import get_company_currency, get_default_company
from erpnext.setup.utils import get_exchange_rate
from erpnext.accounts.doctype.fiscal_year.fiscal_year import get_from_and_to_date
-from frappe.utils import cint, get_datetime_str, formatdate
+from frappe.utils import cint, get_datetime_str, formatdate, flt
__exchange_rates = {}
P_OR_L_ACCOUNTS = list(
@@ -49,7 +49,7 @@
:return: Result of converting `value`
"""
rate = get_rate_as_at(date, from_, to)
- converted_value = value / (rate or 1)
+ converted_value = flt(value) / (rate or 1)
return converted_value
@@ -97,17 +97,16 @@
for entry in gl_entries:
account = entry['account']
- debit = cint(entry['debit'])
- credit = cint(entry['credit'])
- debit_in_account_currency = cint(entry['debit_in_account_currency'])
- credit_in_account_currency = cint(entry['credit_in_account_currency'])
+ debit = flt(entry['debit'])
+ credit = flt(entry['credit'])
+ debit_in_account_currency = flt(entry['debit_in_account_currency'])
+ credit_in_account_currency = flt(entry['credit_in_account_currency'])
account_currency = entry['account_currency']
if account_currency != presentation_currency or (account_currency == presentation_currency and not is_p_or_l_account(account)):
value = debit or credit
date = currency_info['report_date'] if not is_p_or_l_account(account) else entry['posting_date']
-
converted_value = convert(value, presentation_currency, company_currency, date)
if entry.get('debit'):
diff --git a/erpnext/accounts/utils.py b/erpnext/accounts/utils.py
index 421a4fd..ae128a7 100644
--- a/erpnext/accounts/utils.py
+++ b/erpnext/accounts/utils.py
@@ -133,7 +133,7 @@
# If group and currency same as company,
# 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.get_cached_value('Company', acc.company, "default_currency"):
in_account_currency = False
else:
cond.append("""gle.account = "%s" """ % (frappe.db.escape(account, percent=False), ))
@@ -275,7 +275,7 @@
if args.parent_cost_center == args.company:
args.parent_cost_center = "{0} - {1}".format(args.parent_cost_center,
- frappe.db.get_value('Company', args.company, 'abbr'))
+ frappe.get_cached_value('Company', args.company, 'abbr'))
cc = frappe.new_doc("Cost Center")
cc.update(args)
@@ -498,7 +498,7 @@
@frappe.whitelist()
def get_company_default(company, fieldname):
- value = frappe.db.get_value("Company", company, fieldname)
+ value = frappe.get_cached_value('Company', company, fieldname)
if not value:
throw(_("Please set default {0} in Company {1}")
@@ -570,7 +570,7 @@
stock_rbnb = flt(pr_valuation_amount, 2) - flt(pi_valuation_amount, 2)
# Balance as per system
- stock_rbnb_account = "Stock Received But Not Billed - " + frappe.db.get_value("Company", company, "abbr")
+ stock_rbnb_account = "Stock Received But Not Billed - " + frappe.get_cached_value('Company', company, "abbr")
sys_bal = get_balance_on(stock_rbnb_account, posting_date, in_account_currency=False)
# Amount should be credited
@@ -707,7 +707,7 @@
if doctype == 'Account':
sort_accounts(acc, is_root, key="value")
- company_currency = frappe.db.get_value("Company", company, "default_currency")
+ company_currency = frappe.get_cached_value('Company', company, "default_currency")
for each in acc:
each["company_currency"] = company_currency
each["balance"] = flt(get_balance_on(each.get("value"), in_account_currency=False))
@@ -809,7 +809,7 @@
name_split=name.split("-")
parts = [doc_title.strip(), name_split[len(name_split)-1].strip()]
else:
- abbr = frappe.db.get_value("Company", company, ["abbr"], as_dict=True)
+ abbr = frappe.get_cached_value('Company', company, ["abbr"], as_dict=True)
parts = [doc_title.strip(), abbr.abbr]
if cstr(number_value).strip():
parts.insert(0, cstr(number_value).strip())
diff --git a/erpnext/assets/doctype/asset/asset.py b/erpnext/assets/doctype/asset/asset.py
index e475a5e..04fa8dc 100644
--- a/erpnext/assets/doctype/asset/asset.py
+++ b/erpnext/assets/doctype/asset/asset.py
@@ -44,7 +44,7 @@
self.db_set('booked_fixed_asset', 0)
def validate_item(self):
- item = frappe.db.get_value("Item", self.item_code,
+ item = frappe.get_cached_value("Item", self.item_code,
["is_fixed_asset", "is_stock_item", "disabled"], as_dict=1)
if not item:
frappe.throw(_("Item {0} does not exist").format(self.item_code))
@@ -61,7 +61,7 @@
def set_missing_values(self):
if not self.asset_category:
- self.asset_category = frappe.db.get_value("Item", self.item_code, "asset_category")
+ self.asset_category = frappe.get_cached_value("Item", self.item_code, "asset_category")
if self.item_code and not self.get('finance_books'):
finance_books = get_item_details(self.item_code, self.asset_category)
@@ -410,7 +410,7 @@
def make_purchase_invoice(asset, item_code, gross_purchase_amount, company, posting_date):
pi = frappe.new_doc("Purchase Invoice")
pi.company = company
- pi.currency = frappe.db.get_value("Company", company, "default_currency")
+ pi.currency = frappe.get_cached_value('Company', company, "default_currency")
pi.set_posting_time = 1
pi.posting_date = posting_date
pi.append("items", {
@@ -429,7 +429,7 @@
def make_sales_invoice(asset, item_code, company, serial_no=None):
si = frappe.new_doc("Sales Invoice")
si.company = company
- si.currency = frappe.db.get_value("Company", company, "default_currency")
+ si.currency = frappe.get_cached_value('Company', company, "default_currency")
disposal_account, depreciation_cost_center = get_disposal_account_and_cost_center(company)
si.append("items", {
"item_code": item_code,
@@ -504,7 +504,7 @@
asset_category = asset_category, company = company)
if not account:
- account = frappe.db.get_value('Company', company, account_name)
+ account = frappe.get_cached_value('Company', company, account_name)
if not account:
frappe.throw(_("Set {0} in asset category {1} or company {2}")
diff --git a/erpnext/assets/doctype/asset/depreciation.py b/erpnext/assets/doctype/asset/depreciation.py
index 446066c..1a96579 100644
--- a/erpnext/assets/doctype/asset/depreciation.py
+++ b/erpnext/assets/doctype/asset/depreciation.py
@@ -35,7 +35,7 @@
fixed_asset_account, accumulated_depreciation_account, depreciation_expense_account = \
get_depreciation_accounts(asset)
- depreciation_cost_center, depreciation_series = frappe.db.get_value("Company", asset.company,
+ depreciation_cost_center, depreciation_series = frappe.get_cached_value('Company', asset.company,
["depreciation_cost_center", "series_for_depreciation_entry"])
depreciation_cost_center = asset.cost_center or depreciation_cost_center
@@ -93,7 +93,7 @@
depreciation_expense_account = accounts.depreciation_expense_account
if not accumulated_depreciation_account or not depreciation_expense_account:
- accounts = frappe.db.get_value("Company", asset.company,
+ accounts = frappe.get_cached_value('Company', asset.company,
["accumulated_depreciation_account", "depreciation_expense_account"])
if not accumulated_depreciation_account:
@@ -116,7 +116,7 @@
elif asset.status in ("Cancelled", "Sold", "Scrapped"):
frappe.throw(_("Asset {0} cannot be scrapped, as it is already {1}").format(asset.name, asset.status))
- depreciation_series = frappe.db.get_value("Company", asset.company, "series_for_depreciation_entry")
+ depreciation_series = frappe.get_cached_value('Company', asset.company, "series_for_depreciation_entry")
je = frappe.new_doc("Journal Entry")
je.voucher_type = "Journal Entry"
@@ -189,7 +189,7 @@
@frappe.whitelist()
def get_disposal_account_and_cost_center(company):
- disposal_account, depreciation_cost_center = frappe.db.get_value("Company", company,
+ disposal_account, depreciation_cost_center = frappe.get_cached_value('Company', company,
["disposal_account", "depreciation_cost_center"])
if not disposal_account:
diff --git a/erpnext/assets/doctype/asset_value_adjustment/asset_value_adjustment.py b/erpnext/assets/doctype/asset_value_adjustment/asset_value_adjustment.py
index d248803..ac3c350 100644
--- a/erpnext/assets/doctype/asset_value_adjustment/asset_value_adjustment.py
+++ b/erpnext/assets/doctype/asset_value_adjustment/asset_value_adjustment.py
@@ -36,7 +36,7 @@
fixed_asset_account, accumulated_depreciation_account, depreciation_expense_account = \
get_depreciation_accounts(asset)
- depreciation_cost_center, depreciation_series = frappe.db.get_value("Company", asset.company,
+ depreciation_cost_center, depreciation_series = frappe.get_cached_value('Company', asset.company,
["depreciation_cost_center", "series_for_depreciation_entry"])
je = frappe.new_doc("Journal Entry")
diff --git a/erpnext/buying/doctype/purchase_order/purchase_order.py b/erpnext/buying/doctype/purchase_order/purchase_order.py
index b63c256..a543c20 100644
--- a/erpnext/buying/doctype/purchase_order/purchase_order.py
+++ b/erpnext/buying/doctype/purchase_order/purchase_order.py
@@ -134,7 +134,7 @@
d.last_purchase_rate = d.rate
else:
- item_last_purchase_rate = frappe.db.get_value("Item", d.item_code, "last_purchase_rate")
+ item_last_purchase_rate = frappe.get_cached_value("Item", d.item_code, "last_purchase_rate")
if item_last_purchase_rate:
d.base_price_list_rate = d.base_rate = d.price_list_rate \
= d.rate = d.last_purchase_rate = item_last_purchase_rate
@@ -168,7 +168,7 @@
for d in self.get("items"):
if (not po_item_rows or d.name in po_item_rows) \
and [d.item_code, d.warehouse] not in item_wh_list \
- and frappe.db.get_value("Item", d.item_code, "is_stock_item") \
+ and frappe.get_cached_value("Item", d.item_code, "is_stock_item") \
and d.warehouse and not d.delivered_by_supplier:
item_wh_list.append([d.item_code, d.warehouse])
for item_code, warehouse in item_wh_list:
@@ -286,7 +286,7 @@
if d.rm_item_code:
stock_bin = get_bin(d.rm_item_code, d.reserve_warehouse)
stock_bin.update_reserved_qty_for_sub_contracting()
-
+
def update_receiving_percentage(self):
total_qty, received_qty = 0.0, 0.0
for item in self.items:
@@ -304,7 +304,7 @@
last_purchase_rate = (last_purchase_details['base_rate'] * (flt(conversion_factor) or 1.0)) / conversion_rate
return last_purchase_rate
else:
- item_last_purchase_rate = frappe.db.get_value("Item", item_code, "last_purchase_rate")
+ item_last_purchase_rate = frappe.get_cached_value("Item", item_code, "last_purchase_rate")
if item_last_purchase_rate:
return item_last_purchase_rate
diff --git a/erpnext/buying/doctype/purchase_order/test_purchase_order.py b/erpnext/buying/doctype/purchase_order/test_purchase_order.py
index c67d4e5..f150736 100644
--- a/erpnext/buying/doctype/purchase_order/test_purchase_order.py
+++ b/erpnext/buying/doctype/purchase_order/test_purchase_order.py
@@ -183,7 +183,7 @@
"supplier" : "_Test Supplier",
"is_subcontracted" : "No",
"schedule_date": add_days(nowdate(), 1),
- "currency" : frappe.db.get_value("Company", "_Test Company", "default_currency"),
+ "currency" : frappe.get_cached_value('Company', "_Test Company", "default_currency"),
"conversion_factor" : 1,
"items" : get_same_items(),
"group_same_items": 1
@@ -520,7 +520,7 @@
po.company = args.company or "_Test Company"
po.supplier = args.customer or "_Test Supplier"
po.is_subcontracted = args.is_subcontracted or "No"
- po.currency = args.currency or frappe.db.get_value("Company", po.company, "default_currency")
+ po.currency = args.currency or frappe.get_cached_value('Company', po.company, "default_currency")
po.conversion_factor = args.conversion_factor or 1
po.supplier_warehouse = args.supplier_warehouse or None
diff --git a/erpnext/buying/report/quoted_item_comparison/quoted_item_comparison.html b/erpnext/buying/report/quoted_item_comparison/quoted_item_comparison.html
index e26636e..098214d 100644
--- a/erpnext/buying/report/quoted_item_comparison/quoted_item_comparison.html
+++ b/erpnext/buying/report/quoted_item_comparison/quoted_item_comparison.html
@@ -1,10 +1,10 @@
<head>
-
-
+
+
<link href="/assets/frappe/css/c3.min.css" rel="stylesheet" type="text/css">
-
-
+
+
<script type="text/javascript" src="/assets/frappe/js/lib/d3.min.js"></script>
<script type="text/javascript" src="/assets/frappe/js/lib/c3.min.js"></script>
<script type="text/javascript">
@@ -13,12 +13,12 @@
var chartData = [];
{% var q = 0; %}
{% for(var j=0, m=data.length+1; j<m; j++) { %}
-
+
var tempData{%=j%} = [];
-
+
{% for(var i=1, l=report.columns.length; i<l; i++) { %}
{% if(__(report.columns[i].label) != __("Quotation")) { %}
-
+
{% if(j == 0) { %}
{% if(i == 1) { %}
tempData{%=j%}[{%=i%}-1] = \"x\";
@@ -28,14 +28,14 @@
{% } %}
{% } else { %}
{% if(i == 1) { %}
- tempData{%=j%}[{%=i%}-1] = \"{%= data[j-1][report.columns[i].field] %} \";
+ tempData{%=j%}[{%=i%}-1] = \"{%= data[j-1][report.columns[i].fieldname] %} \";
{% } else { %}
- tempData{%=j%}[{%=i%}-1] = {% if(data[j-1][report.columns[i].field] == "") { if (i > 2) { %}
- tempData{%=j%}[{%=i%}-2]
- {% } else { %}
- 0
- {% } } else { %}
- {%= data[j-1][report.columns[i].field] %}
+ tempData{%=j%}[{%=i%}-1] = {% if(data[j-1][report.columns[i].fieldname] == "") { if (i > 2) { %}
+ tempData{%=j%}[{%=i%}-2]
+ {% } else { %}
+ 0
+ {% } } else { %}
+ {%= data[j-1][report.columns[i].fieldname] %}
{% } %};
{% } %};
{% } %}
@@ -52,12 +52,12 @@
{% } %}
{% } %}
-
+
{% } %}
chartData[{%=j%}] = tempData{%=j%};
{% } %}
console.log(chartData);
-
+
hold = {
bindto: "#chart_div" ,data: {
x: "x",
@@ -81,7 +81,7 @@
console.log(hold);
var chart = c3.generate(hold);
});
-
+
function onReady(selector, callback) {
var intervalID = window.setInterval(function() {
if (document.querySelector(selector) !== undefined) {
@@ -89,8 +89,8 @@
callback.call(this);
}
}, 500);}
-
-
+
+
</script>
</head>
@@ -114,9 +114,9 @@
{% for(var i=0, l=data.length; i<l; i++) { %}
<tr>
-
+
{% for(var j=0,m=report.columns.length; j<m; j++) { %}
- <td style="width: 15%">{%= data[i][report.columns[j].field] %}</td>
+ <td style="width: 15%">{%= data[i][report.columns[j].fieldname] %}</td>
{% } %}
</tr>
@@ -128,5 +128,5 @@
<div id="chart_div"></div>
-
-<p class="text-right text-muted">Printed On {%= dateutil.str_to_user(dateutil.get_datetime_as_string()) %}</p>
\ No newline at end of file
+
+<p class="text-right text-muted">Printed On {%= frappe.datetime.str_to_user(frappe.datetime.get_datetime_as_string()) %}</p>
\ No newline at end of file
diff --git a/erpnext/controllers/accounts_controller.py b/erpnext/controllers/accounts_controller.py
index 5175395..f6f9e4d 100644
--- a/erpnext/controllers/accounts_controller.py
+++ b/erpnext/controllers/accounts_controller.py
@@ -400,7 +400,7 @@
else:
allocated_amount = min(self.grand_total - advance_allocated, d.amount)
advance_allocated += flt(allocated_amount)
-
+
self.append("advances", {
"doctype": self.doctype + " Advance",
"reference_type": d.reference_type,
@@ -606,7 +606,7 @@
@property
def company_abbr(self):
if not hasattr(self, "_abbr"):
- self._abbr = frappe.db.get_value("Company", self.company, "abbr")
+ self._abbr = frappe.db.get_value('Company', self.company, "abbr")
return self._abbr
@@ -841,7 +841,7 @@
def validate_conversion_rate(currency, conversion_rate, conversion_rate_label, company):
"""common validation for currency and price list currency"""
- company_currency = frappe.db.get_value("Company", company, "default_currency", cache=True)
+ company_currency = frappe.get_cached_value('Company', company, "default_currency")
if not conversion_rate:
throw(_("{0} is mandatory. Maybe Currency Exchange record is not created for {1} to {2}.").format(
diff --git a/erpnext/controllers/print_settings.py b/erpnext/controllers/print_settings.py
index cb73159..c41db25 100644
--- a/erpnext/controllers/print_settings.py
+++ b/erpnext/controllers/print_settings.py
@@ -12,7 +12,7 @@
}
doc.hide_in_print_layout = ["uom", "stock_uom"]
- doc.flags.compact_item_print = cint(frappe.db.get_value("Print Settings", None, "compact_item_print"))
+ doc.flags.compact_item_print = cint(frappe.db.get_single_value("Print Settings", "compact_item_print"))
if doc.flags.compact_item_print:
doc.print_templates["description"] = "templates/print_formats/includes/item_table_description.html"
diff --git a/erpnext/controllers/selling_controller.py b/erpnext/controllers/selling_controller.py
index 748fe59..419afe1 100644
--- a/erpnext/controllers/selling_controller.py
+++ b/erpnext/controllers/selling_controller.py
@@ -8,6 +8,7 @@
from erpnext.stock.get_item_details import get_bin_details
from erpnext.stock.utils import get_incoming_rate
from erpnext.stock.get_item_details import get_conversion_factor
+from erpnext.stock.doctype.item.item import get_item_defaults, set_item_default
from erpnext.controllers.stock_controller import StockController
@@ -40,7 +41,7 @@
self.validate_selling_price()
self.set_qty_as_per_stock_uom()
self.set_po_nos()
- check_active_sales_items(self)
+ set_default_income_account_for_item(self)
def set_missing_values(self, for_validate=False):
super(SellingController, self).set_missing_values(for_validate)
@@ -138,10 +139,11 @@
def validate_max_discount(self):
for d in self.get("items"):
- discount = flt(frappe.db.get_value("Item", d.item_code, "max_discount"))
+ if d.item_code:
+ discount = flt(frappe.get_cached_value("Item", d.item_code, "max_discount"))
- if discount and flt(d.discount_percentage) > discount:
- frappe.throw(_("Maximum discount for Item {0} is {1}%").format(d.item_code, discount))
+ if discount and flt(d.discount_percentage) > discount:
+ frappe.throw(_("Maximum discount for Item {0} is {1}%").format(d.item_code, discount))
def set_qty_as_per_stock_uom(self):
for d in self.get("items"):
@@ -165,7 +167,7 @@
if not it.item_code:
continue
- last_purchase_rate, is_stock_item = frappe.db.get_value("Item", it.item_code, ["last_purchase_rate", "is_stock_item"])
+ last_purchase_rate, is_stock_item = frappe.get_cached_value("Item", it.item_code, ["last_purchase_rate", "is_stock_item"])
last_purchase_rate_in_sales_uom = last_purchase_rate / (it.conversion_factor or 1)
if flt(it.base_rate) < flt(last_purchase_rate_in_sales_uom):
throw_message(it.item_name, last_purchase_rate_in_sales_uom, "last purchase rate")
@@ -282,7 +284,7 @@
sl_entries = []
for d in self.get_item_list():
- if frappe.db.get_value("Item", d.item_code, "is_stock_item") == 1 and flt(d.qty):
+ if frappe.get_cached_value("Item", d.item_code, "is_stock_item") == 1 and flt(d.qty):
if flt(d.conversion_factor)==0.0:
d.conversion_factor = get_conversion_factor(d.item_code, d.uom).get("conversion_factor") or 1.0
return_rate = 0
@@ -349,24 +351,8 @@
from erpnext.controllers.buying_controller import validate_item_type
validate_item_type(self, "is_sales_item", "sales")
-def check_active_sales_items(obj):
+def set_default_income_account_for_item(obj):
for d in obj.get("items"):
if d.item_code:
- item = frappe.db.sql("""select i.docstatus, id.income_account
- from `tabItem` i, `tabItem Default` id
- where i.name=%s and id.parent=i.name and id.company=%s""",
- (d.item_code, obj.company), as_dict=True)
-
if getattr(d, "income_account", None):
- doc = frappe.get_doc("Item", d.item_code)
- if item and not item[0].income_account:
- for default in doc.item_defaults:
- if default.company == obj.company:
- default.income_account = d.income_account
- break
- elif not item:
- doc.append("item_defaults", {
- "company": obj.company,
- "income_account": d.income_account
- })
- doc.save(ignore_permissions=True)
+ set_item_default(d.item_code, obj.company, 'income_account', d.income_account)
diff --git a/erpnext/crm/doctype/opportunity/opportunity.py b/erpnext/crm/doctype/opportunity/opportunity.py
index 5c203d9..e8da4e6 100644
--- a/erpnext/crm/doctype/opportunity/opportunity.py
+++ b/erpnext/crm/doctype/opportunity/opportunity.py
@@ -217,7 +217,7 @@
from erpnext.controllers.accounts_controller import get_default_taxes_and_charges
quotation = frappe.get_doc(target)
- company_currency = frappe.db.get_value("Company", quotation.company, "default_currency")
+ company_currency = frappe.get_cached_value('Company', quotation.company, "default_currency")
party_account_currency = get_party_account_currency("Customer", quotation.customer,
quotation.company) if quotation.customer else company_currency
diff --git a/erpnext/demo/setup/setup_data.py b/erpnext/demo/setup/setup_data.py
index 41f24e1..911d418 100644
--- a/erpnext/demo/setup/setup_data.py
+++ b/erpnext/demo/setup/setup_data.py
@@ -14,7 +14,7 @@
setup_fiscal_year()
setup_holiday_list()
setup_user()
- setup_employee()
+ #setup_employee()
setup_user_roles()
setup_role_permissions()
@@ -293,7 +293,7 @@
}).insert()
def setup_mode_of_payment():
- company_abbr = frappe.db.get_value("Company", erpnext.get_default_company(), "abbr")
+ company_abbr = frappe.get_cached_value('Company', erpnext.get_default_company(), "abbr")
account_dict = {'Cash': 'Cash - '+ company_abbr , 'Bank': 'National Bank - '+ company_abbr}
for payment_mode in frappe.get_all('Mode of Payment', fields = ["name", "type"]):
if payment_mode.type:
@@ -317,7 +317,7 @@
frappe.flags.in_import = False
def setup_account_to_expense_type():
- company_abbr = frappe.db.get_value("Company", erpnext.get_default_company(), "abbr")
+ company_abbr = frappe.get_cached_value('Company', erpnext.get_default_company(), "abbr")
expense_types = [{'name': _('Calls'), "account": "Sales Expenses - "+ company_abbr},
{'name': _('Food'), "account": "Entertainment Expenses - "+ company_abbr},
{'name': _('Medical'), "account": "Utility Expenses - "+ company_abbr},
@@ -354,7 +354,7 @@
budget.submit()
def setup_pos_profile():
- company_abbr = frappe.db.get_value("Company", erpnext.get_default_company(), "abbr")
+ company_abbr = frappe.get_cached_value('Company', erpnext.get_default_company(), "abbr")
pos = frappe.new_doc('POS Profile')
pos.user = frappe.db.get_global('demo_accounts_user')
pos.pos_profile_name = "Demo POS Profile"
diff --git a/erpnext/demo/user/accounts.py b/erpnext/demo/user/accounts.py
index 1a41482..a12933b 100644
--- a/erpnext/demo/user/accounts.py
+++ b/erpnext/demo/user/accounts.py
@@ -28,7 +28,7 @@
si.posting_date = frappe.flags.current_date
for d in si.get("items"):
if not d.income_account:
- d.income_account = "Sales - {}".format(frappe.db.get_value('Company', si.company, 'abbr'))
+ d.income_account = "Sales - {}".format(frappe.get_cached_value('Company', si.company, 'abbr'))
si.insert()
si.submit()
frappe.db.commit()
@@ -106,7 +106,7 @@
si.posting_date = frappe.flags.current_date
for d in si.get("items"):
if not d.income_account:
- d.income_account = "Sales - {}".format(frappe.db.get_value('Company', si.company, 'abbr'))
+ d.income_account = "Sales - {}".format(frappe.get_cached_value('Company', si.company, 'abbr'))
si.set_missing_values()
make_payment_entries_for_pos_invoice(si)
si.insert()
diff --git a/erpnext/demo/user/manufacturing.py b/erpnext/demo/user/manufacturing.py
index a3f631c..0231eda9 100644
--- a/erpnext/demo/user/manufacturing.py
+++ b/erpnext/demo/user/manufacturing.py
@@ -78,7 +78,7 @@
st.posting_date = frappe.flags.current_date
st.fiscal_year = str(frappe.flags.current_date.year)
for d in st.get("items"):
- d.cost_center = "Main - " + frappe.db.get_value('Company', st.company, 'abbr')
+ d.cost_center = "Main - " + frappe.get_cached_value('Company', st.company, 'abbr')
st.insert()
frappe.db.commit()
st.submit()
diff --git a/erpnext/demo/user/purchase.py b/erpnext/demo/user/purchase.py
index 327f617..ad99de9 100644
--- a/erpnext/demo/user/purchase.py
+++ b/erpnext/demo/user/purchase.py
@@ -51,7 +51,7 @@
# get supplier details
supplier = get_random("Supplier")
- company_currency = frappe.db.get_value("Company", "Wind Power LLC", "default_currency")
+ company_currency = frappe.get_cached_value('Company', "Wind Power LLC", "default_currency")
party_account_currency = get_party_account_currency("Supplier", supplier, "Wind Power LLC")
if company_currency == party_account_currency:
exchange_rate = 1
diff --git a/erpnext/demo/user/sales.py b/erpnext/demo/user/sales.py
index 02e1d42..65d7f55 100644
--- a/erpnext/demo/user/sales.py
+++ b/erpnext/demo/user/sales.py
@@ -84,7 +84,7 @@
# get customer, currency and exchange_rate
customer = get_random("Customer")
- company_currency = frappe.db.get_value("Company", "Wind Power LLC", "default_currency")
+ company_currency = frappe.get_cached_value('Company', "Wind Power LLC", "default_currency")
party_account_currency = get_party_account_currency("Customer", customer, "Wind Power LLC")
if company_currency == party_account_currency:
exchange_rate = 1
diff --git a/erpnext/demo/user/stock.py b/erpnext/demo/user/stock.py
index f5ec4f9..a6b0e00 100644
--- a/erpnext/demo/user/stock.py
+++ b/erpnext/demo/user/stock.py
@@ -55,7 +55,7 @@
for d in dn.get("items"):
if not d.expense_account:
d.expense_account = ("Cost of Goods Sold - {0}".format(
- frappe.db.get_value('Company', dn.company, 'abbr')))
+ frappe.get_cached_value('Company', dn.company, 'abbr')))
dn.insert()
try:
dn.submit()
diff --git a/erpnext/education/report/course_wise_assessment_report/course_wise_assessment_report.html b/erpnext/education/report/course_wise_assessment_report/course_wise_assessment_report.html
index e2df273..33e725f 100644
--- a/erpnext/education/report/course_wise_assessment_report/course_wise_assessment_report.html
+++ b/erpnext/education/report/course_wise_assessment_report/course_wise_assessment_report.html
@@ -36,7 +36,7 @@
<tr>
{% for(var i=1, l=report_columns.length; i<l; i++) { %}
<td class="text-center">
- {% var fieldname = report_columns[i].field; %}
+ {% var fieldname = report_columns[i].fieldname; %}
{% if (!is_null(row[fieldname])) { %}
{%= row[fieldname] %}
{% } %}
@@ -47,4 +47,4 @@
</tbody>
</table>
-<p class="text-right text-muted">Printed On {%= dateutil.str_to_user(dateutil.get_datetime_as_string()) %}</p>
+<p class="text-right text-muted">Printed On {%= frappe.datetime.str_to_user(frappe.datetime.get_datetime_as_string()) %}</p>
diff --git a/erpnext/healthcare/doctype/clinical_procedure/clinical_procedure.py b/erpnext/healthcare/doctype/clinical_procedure/clinical_procedure.py
index 6346f1f..97d8a02 100644
--- a/erpnext/healthcare/doctype/clinical_procedure/clinical_procedure.py
+++ b/erpnext/healthcare/doctype/clinical_procedure/clinical_procedure.py
@@ -86,7 +86,7 @@
# in stock uom
se_child.transfer_qty = flt(item.transfer_qty)
se_child.conversion_factor = flt(item.conversion_factor)
- cost_center = frappe.db.get_value('Company', self.company, 'cost_center')
+ cost_center = frappe.get_cached_value('Company', self.company, 'cost_center')
se_child.cost_center = cost_center
se_child.expense_account = expense_account
return stock_entry.as_dict()
@@ -146,7 +146,7 @@
expense_account = get_account(None, "expense_account", "Healthcare Settings", doc.company)
for item_line in stock_entry.items:
- cost_center = frappe.db.get_value('Company', doc.company, 'cost_center')
+ cost_center = frappe.get_cached_value('Company', doc.company, 'cost_center')
#item_line.s_warehouse = warehouse #deaful source warehouse set, stock entry to copy to lines
item_line.cost_center = cost_center
#if not expense_account:
diff --git a/erpnext/healthcare/doctype/healthcare_settings/healthcare_settings.py b/erpnext/healthcare/doctype/healthcare_settings/healthcare_settings.py
index 3a142f5..8c3cdfe 100644
--- a/erpnext/healthcare/doctype/healthcare_settings/healthcare_settings.py
+++ b/erpnext/healthcare/doctype/healthcare_settings/healthcare_settings.py
@@ -48,7 +48,7 @@
receivable_account = get_account(None, "receivable_account", "Healthcare Settings", company)
if receivable_account:
return receivable_account
- return frappe.db.get_value("Company", company, "default_receivable_account")
+ return frappe.get_cached_value('Company', company, "default_receivable_account")
def get_income_account(practitioner, company):
if(practitioner):
@@ -58,7 +58,7 @@
income_account = get_account(None, "income_account", "Healthcare Settings", company)
if income_account:
return income_account
- return frappe.db.get_value("Company", company, "default_income_account")
+ return frappe.get_cached_value('Company', company, "default_income_account")
def get_account(parent_type, parent_field, parent, company):
if(parent_type):
diff --git a/erpnext/healthcare/page/medical_record/medical_record_row.html b/erpnext/healthcare/page/medical_record/medical_record_row.html
index 6b79146..9a670c9 100644
--- a/erpnext/healthcare/page/medical_record/medical_record_row.html
+++ b/erpnext/healthcare/page/medical_record/medical_record_row.html
@@ -5,7 +5,7 @@
<div class="col-xs-9 medical_record-message"
data-doctype="{%= reference_doctype %}"
data-docname="{%= reference_name %}"
- title="{%= by %} / {%= dateutil.str_to_user(creation) %}">
+ title="{%= by %} / {%= frappe.datetime.str_to_user(creation) %}">
<span class="avatar avatar-small">
<div class="avatar-frame" style="background-image: url({{ imgsrc }});"></div>
<!-- <img src="{%= imgsrc %}"> -->
diff --git a/erpnext/hooks.py b/erpnext/hooks.py
index 999ece9..7bf948e 100644
--- a/erpnext/hooks.py
+++ b/erpnext/hooks.py
@@ -21,7 +21,7 @@
app_include_js = "assets/js/erpnext.min.js"
app_include_css = "assets/css/erpnext.css"
web_include_js = "assets/js/erpnext-web.min.js"
-web_include_css = "assets/erpnext/css/website.css"
+web_include_css = "assets/css/erpnext-web.css"
doctype_js = {
"Communication": "public/js/communication.js",
diff --git a/erpnext/hr/doctype/department/department.js b/erpnext/hr/doctype/department/department.js
index a945312..76bc932 100644
--- a/erpnext/hr/doctype/department/department.js
+++ b/erpnext/hr/doctype/department/department.js
@@ -5,8 +5,8 @@
refresh: function(frm) {
// read-only for root department
if(!frm.doc.parent_department) {
- cur_frm.set_read_only();
- cur_frm.set_intro(__("This is a root customer group and cannot be edited."));
+ frm.set_read_only();
+ frm.set_intro(__("This is a root department and cannot be edited."));
}
},
validate: function(frm) {
diff --git a/erpnext/hr/doctype/department/department.py b/erpnext/hr/doctype/department/department.py
index 8c6a764..9b2b581 100644
--- a/erpnext/hr/doctype/department/department.py
+++ b/erpnext/hr/doctype/department/department.py
@@ -25,7 +25,7 @@
def before_rename(self, old, new, merge=False):
# renaming consistency with abbreviation
- if not frappe.db.get_value('Company', self.company, 'abbr') in new:
+ if not frappe.get_cached_value('Company', self.company, 'abbr') in new:
new = get_abbreviated_name(new, self.company)
return new
@@ -41,7 +41,7 @@
frappe.db.add_index("Department", ["lft", "rgt"])
def get_abbreviated_name(name, company):
- abbr = frappe.db.get_value('Company', company, 'abbr')
+ abbr = frappe.get_cached_value('Company', company, 'abbr')
new_name = '{0} - {1}'.format(name, abbr)
return new_name
diff --git a/erpnext/hr/doctype/employee/employee.py b/erpnext/hr/doctype/employee/employee.py
index a2de336..7285e04 100755
--- a/erpnext/hr/doctype/employee/employee.py
+++ b/erpnext/hr/doctype/employee/employee.py
@@ -253,7 +253,7 @@
company=frappe.db.get_value("Global Defaults", None, "default_company")
if not holiday_list:
- holiday_list = frappe.db.get_value("Company", company, "default_holiday_list")
+ holiday_list = frappe.get_cached_value('Company', company, "default_holiday_list")
if not holiday_list and raise_exception:
frappe.throw(_('Please set a default Holiday List for Employee {0} or Company {1}').format(employee, company))
diff --git a/erpnext/hr/doctype/employee_loan/employee_loan.js b/erpnext/hr/doctype/employee_loan/employee_loan.js
new file mode 100644
index 0000000..e089e29
--- /dev/null
+++ b/erpnext/hr/doctype/employee_loan/employee_loan.js
@@ -0,0 +1,121 @@
+// Copyright (c) 2016, Frappe Technologies Pvt. Ltd. and contributors
+// For license information, please see license.txt
+
+frappe.ui.form.on('Employee Loan', {
+ onload: function (frm) {
+ frm.set_query("employee_loan_application", function () {
+ return {
+ "filters": {
+ "employee": frm.doc.employee,
+ "docstatus": 1,
+ "status": "Approved"
+ }
+ };
+ });
+
+ frm.set_query("interest_income_account", function () {
+ return {
+ "filters": {
+ "company": frm.doc.company,
+ "root_type": "Income",
+ "is_group": 0
+ }
+ };
+ });
+
+ frm.set_query("employee", function() {
+ return {
+ "filters": {
+ "company": frm.doc.company,
+ }
+ };
+ });
+
+ $.each(["payment_account", "employee_loan_account"], function (i, field) {
+ frm.set_query(field, function () {
+ return {
+ "filters": {
+ "company": frm.doc.company,
+ "root_type": "Asset",
+ "is_group": 0
+ }
+ };
+ });
+ })
+ },
+
+ refresh: function (frm) {
+ if (frm.doc.docstatus == 1 && (frm.doc.status == "Sanctioned" || frm.doc.status == "Partially Disbursed")) {
+ frm.add_custom_button(__('Make Disbursement Entry'), function () {
+ frm.trigger("make_jv");
+ })
+ }
+ frm.trigger("toggle_fields");
+ },
+
+ make_jv: function (frm) {
+ frappe.call({
+ args: {
+ "employee_loan": frm.doc.name,
+ "company": frm.doc.company,
+ "employee_loan_account": frm.doc.employee_loan_account,
+ "employee": frm.doc.employee,
+ "loan_amount": frm.doc.loan_amount,
+ "payment_account": frm.doc.payment_account
+ },
+ method: "erpnext.hr.doctype.employee_loan.employee_loan.make_jv_entry",
+ callback: function (r) {
+ if (r.message)
+ var doc = frappe.model.sync(r.message)[0];
+ frappe.set_route("Form", doc.doctype, doc.name);
+ }
+ })
+ },
+
+ mode_of_payment: function (frm) {
+ if (frm.doc.mode_of_payment && frm.doc.company) {
+ frappe.call({
+ method: "erpnext.accounts.doctype.sales_invoice.sales_invoice.get_bank_cash_account",
+ args: {
+ "mode_of_payment": frm.doc.mode_of_payment,
+ "company": frm.doc.company
+ },
+ callback: function (r, rt) {
+ if (r.message) {
+ frm.set_value("payment_account", r.message.account);
+ }
+ }
+ });
+ }
+ },
+
+ employee_loan_application: function (frm) {
+ if(frm.doc.employee_loan_application){
+ return frappe.call({
+ method: "erpnext.hr.doctype.employee_loan.employee_loan.get_employee_loan_application",
+ args: {
+ "employee_loan_application": frm.doc.employee_loan_application
+ },
+ callback: function (r) {
+ if (!r.exc && r.message) {
+ frm.set_value("loan_type", r.message.loan_type);
+ frm.set_value("loan_amount", r.message.loan_amount);
+ frm.set_value("repayment_method", r.message.repayment_method);
+ frm.set_value("monthly_repayment_amount", r.message.repayment_amount);
+ frm.set_value("repayment_periods", r.message.repayment_periods);
+ frm.set_value("rate_of_interest", r.message.rate_of_interest);
+ }
+ }
+ });
+ }
+ },
+
+ repayment_method: function (frm) {
+ frm.trigger("toggle_fields")
+ },
+
+ toggle_fields: function (frm) {
+ frm.toggle_enable("monthly_repayment_amount", frm.doc.repayment_method == "Repay Fixed Amount per Period")
+ frm.toggle_enable("repayment_periods", frm.doc.repayment_method == "Repay Over Number of Periods")
+ }
+});
diff --git a/erpnext/hr/doctype/employee_loan_application/employee_loan_application.py b/erpnext/hr/doctype/employee_loan_application/employee_loan_application.py
new file mode 100644
index 0000000..b6c6502
--- /dev/null
+++ b/erpnext/hr/doctype/employee_loan_application/employee_loan_application.py
@@ -0,0 +1,69 @@
+# -*- coding: utf-8 -*-
+# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and contributors
+# For license information, please see license.txt
+
+from __future__ import unicode_literals
+import frappe, math
+from frappe import _
+from frappe.utils import flt, rounded
+from frappe.model.mapper import get_mapped_doc
+from frappe.model.document import Document
+
+from erpnext.hr.doctype.employee_loan.employee_loan import get_monthly_repayment_amount, check_repayment_method
+
+class EmployeeLoanApplication(Document):
+ def validate(self):
+ check_repayment_method(self.repayment_method, self.loan_amount, self.repayment_amount, self.repayment_periods)
+ self.validate_loan_amount()
+ self.get_repayment_details()
+
+ def validate_loan_amount(self):
+ maximum_loan_limit = frappe.db.get_value('Loan Type', self.loan_type, 'maximum_loan_amount')
+ if maximum_loan_limit and self.loan_amount > maximum_loan_limit:
+ frappe.throw(_("Loan Amount cannot exceed Maximum Loan Amount of {0}").format(maximum_loan_limit))
+
+ def get_repayment_details(self):
+ if self.repayment_method == "Repay Over Number of Periods":
+ self.repayment_amount = get_monthly_repayment_amount(self.repayment_method, self.loan_amount, self.rate_of_interest, self.repayment_periods)
+
+ if self.repayment_method == "Repay Fixed Amount per Period":
+ monthly_interest_rate = flt(self.rate_of_interest) / (12 *100)
+ if monthly_interest_rate:
+ monthly_interest_amount = self.loan_amount * monthly_interest_rate
+ if monthly_interest_amount >= self.repayment_amount:
+ frappe.throw(_("Repayment amount {} should be greater than monthly interest amount {}").
+ format(self.repayment_amount, monthly_interest_amount))
+
+ self.repayment_periods = math.ceil((math.log(self.repayment_amount) -
+ math.log(self.repayment_amount - (monthly_interest_amount))) /
+ (math.log(1 + monthly_interest_rate)))
+ else:
+ self.repayment_periods = self.loan_amount / self.repayment_amount
+
+ self.calculate_payable_amount()
+
+ def calculate_payable_amount(self):
+ balance_amount = self.loan_amount
+ self.total_payable_amount = 0
+ self.total_payable_interest = 0
+
+ while(balance_amount > 0):
+ interest_amount = rounded(balance_amount * flt(self.rate_of_interest) / (12*100))
+ balance_amount = rounded(balance_amount + interest_amount - self.repayment_amount)
+
+ self.total_payable_interest += interest_amount
+
+ self.total_payable_amount = self.loan_amount + self.total_payable_interest
+
+@frappe.whitelist()
+def make_employee_loan(source_name, target_doc = None):
+ doclist = get_mapped_doc("Employee Loan Application", source_name, {
+ "Employee Loan Application": {
+ "doctype": "Employee Loan",
+ "validation": {
+ "docstatus": ["=", 1]
+ }
+ }
+ }, target_doc)
+
+ return doclist
\ No newline at end of file
diff --git a/erpnext/hr/doctype/expense_claim/expense_claim.py b/erpnext/hr/doctype/expense_claim/expense_claim.py
index e5dfe6f..fff18cd 100644
--- a/erpnext/hr/doctype/expense_claim/expense_claim.py
+++ b/erpnext/hr/doctype/expense_claim/expense_claim.py
@@ -53,11 +53,11 @@
def set_payable_account(self):
if not self.payable_account and not self.is_paid:
- self.payable_account = frappe.db.get_value("Company", self.company, "default_payable_account")
+ self.payable_account = frappe.get_cached_value('Company', self.company, "default_payable_account")
def set_cost_center(self):
if not self.cost_center:
- self.cost_center = frappe.db.get_value('Company', self.company, 'cost_center')
+ self.cost_center = frappe.get_cached_value('Company', self.company, 'cost_center')
def on_submit(self):
if self.approval_status=="Draft":
@@ -311,8 +311,8 @@
@frappe.whitelist()
def get_expense_claim(
employee_name, company, employee_advance_name, posting_date, paid_amount, claimed_amount):
- default_payable_account = frappe.db.get_value("Company", company, "default_payable_account")
- default_cost_center = frappe.db.get_value('Company', company, 'cost_center')
+ default_payable_account = frappe.get_cached_value('Company', company, "default_payable_account")
+ default_cost_center = frappe.get_cached_value('Company', company, 'cost_center')
expense_claim = frappe.new_doc('Expense Claim')
expense_claim.company = company
diff --git a/erpnext/hr/doctype/expense_claim/test_expense_claim.py b/erpnext/hr/doctype/expense_claim/test_expense_claim.py
index 3e031c9..075bc63 100644
--- a/erpnext/hr/doctype/expense_claim/test_expense_claim.py
+++ b/erpnext/hr/doctype/expense_claim/test_expense_claim.py
@@ -100,7 +100,7 @@
self.assertEquals(len(gl_entry), 0)
def get_payable_account(company):
- return frappe.db.get_value('Company', company, 'default_payable_account')
+ return frappe.get_cached_value('Company', company, 'default_payable_account')
def make_expense_claim(payable_account,claim_amount, sanctioned_amount, company, account, project=None, task_name=None):
expense_claim = frappe.get_doc({
diff --git a/erpnext/hr/doctype/job_opening/job_opening.py b/erpnext/hr/doctype/job_opening/job_opening.py
index 226080f..4fc2ac1 100644
--- a/erpnext/hr/doctype/job_opening/job_opening.py
+++ b/erpnext/hr/doctype/job_opening/job_opening.py
@@ -37,7 +37,7 @@
if self.staffing_plan and self.planned_vacancies:
staffing_plan_company = frappe.db.get_value("Staffing Plan", self.staffing_plan, "company")
- lft, rgt = frappe.db.get_value("Company", staffing_plan_company, ["lft", "rgt"])
+ lft, rgt = frappe.get_cached_value('Company', staffing_plan_company, ["lft", "rgt"])
designation_counts = get_designation_counts(self.designation, self.company)
current_count = designation_counts['employee_count'] + designation_counts['job_openings']
diff --git a/erpnext/hr/doctype/payroll_entry/payroll_entry.py b/erpnext/hr/doctype/payroll_entry/payroll_entry.py
index 8f54697..e097cc2 100644
--- a/erpnext/hr/doctype/payroll_entry/payroll_entry.py
+++ b/erpnext/hr/doctype/payroll_entry/payroll_entry.py
@@ -196,8 +196,8 @@
return account_dict
def get_default_payroll_payable_account(self):
- payroll_payable_account = frappe.db.get_value("Company",
- {"company_name": self.company}, "default_payroll_payable_account")
+ payroll_payable_account = frappe.get_cached_value('Company',
+ {"company_name": self.company}, "default_payroll_payable_account")
if not payroll_payable_account:
frappe.throw(_("Please set Default Payroll Payable Account in Company {0}")
diff --git a/erpnext/hr/doctype/salary_slip/test_salary_slip.py b/erpnext/hr/doctype/salary_slip/test_salary_slip.py
index 0b23238..144022b 100644
--- a/erpnext/hr/doctype/salary_slip/test_salary_slip.py
+++ b/erpnext/hr/doctype/salary_slip/test_salary_slip.py
@@ -330,12 +330,12 @@
sal_comp.save()
def create_account(company):
- salary_account = frappe.db.get_value("Account", "Salary - " + frappe.db.get_value('Company', company, 'abbr'))
+ salary_account = frappe.db.get_value("Account", "Salary - " + frappe.get_cached_value('Company', company, 'abbr'))
if not salary_account:
frappe.get_doc({
"doctype": "Account",
"account_name": "Salary",
- "parent_account": "Indirect Expenses - " + frappe.db.get_value('Company', company, 'abbr'),
+ "parent_account": "Indirect Expenses - " + frappe.get_cached_value('Company', company, 'abbr'),
"company": company
}).insert()
return salary_account
diff --git a/erpnext/hr/doctype/shift_assignment/shift_assignment.py b/erpnext/hr/doctype/shift_assignment/shift_assignment.py
index ace9cb8..48d4e57 100644
--- a/erpnext/hr/doctype/shift_assignment/shift_assignment.py
+++ b/erpnext/hr/doctype/shift_assignment/shift_assignment.py
@@ -38,7 +38,7 @@
def throw_overlap_error(self, d):
msg = _("Employee {0} has already applied for {1} on {2} : ").format(self.employee,
d['shift_type'], formatdate(d['date'])) \
- + """ <b><a href="#Form/Shift Request/{0}">{0}</a></b>""".format(d["name"])
+ + """ <b><a href="#Form/Shift Assignment/{0}">{0}</a></b>""".format(d["name"])
frappe.throw(msg, OverlapError)
@frappe.whitelist()
@@ -77,4 +77,4 @@
"docstatus": d.docstatus
}
if e not in events:
- events.append(e)
\ No newline at end of file
+ events.append(e)
diff --git a/erpnext/hr/doctype/staffing_plan/staffing_plan.py b/erpnext/hr/doctype/staffing_plan/staffing_plan.py
index ac3f25f..70e185c 100644
--- a/erpnext/hr/doctype/staffing_plan/staffing_plan.py
+++ b/erpnext/hr/doctype/staffing_plan/staffing_plan.py
@@ -52,7 +52,7 @@
.format(overlap[0][0], staffing_plan_detail.designation)))
def validate_with_parent_plan(self, staffing_plan_detail):
- if not frappe.db.get_value("Company", self.company, "parent_company"):
+ if not frappe.get_cached_value('Company', self.company, "parent_company"):
return # No parent, nothing to validate
# Get staffing plan applicable for the company (Parent Company)
@@ -74,7 +74,7 @@
parent_company)), ParentCompanyError)
#Get vacanices already planned for all companies down the hierarchy of Parent Company
- lft, rgt = frappe.db.get_value("Company", parent_company, ["lft", "rgt"])
+ lft, rgt = frappe.get_cached_value('Company', parent_company, ["lft", "rgt"])
all_sibling_details = frappe.db.sql("""select sum(spd.vacancies) as vacancies,
sum(spd.total_estimated_cost) as total_estimated_cost
from `tabStaffing Plan Detail` spd join `tabStaffing Plan` sp on spd.parent=sp.name
@@ -123,7 +123,7 @@
return False
employee_counts_dict = {}
- lft, rgt = frappe.db.get_value("Company", company, ["lft", "rgt"])
+ lft, rgt = frappe.get_cached_value('Company', company, ["lft", "rgt"])
employee_counts_dict["employee_count"] = frappe.db.sql("""select count(*) from `tabEmployee`
where designation = %s and status='Active'
and company in (select name from tabCompany where lft>=%s and rgt<=%s)
@@ -148,7 +148,7 @@
and to_date >= %s and from_date <= %s """, (company, designation, from_date, to_date), as_dict = 1)
if not staffing_plan:
- parent_company = frappe.db.get_value("Company", company, "parent_company")
+ parent_company = frappe.get_cached_value('Company', company, "parent_company")
if parent_company:
staffing_plan = get_active_staffing_plan_details(parent_company,
designation, from_date, to_date)
diff --git a/erpnext/hr/page/team_updates/team_update_row.html b/erpnext/hr/page/team_updates/team_update_row.html
index e3adcb8..4f36754 100644
--- a/erpnext/hr/page/team_updates/team_update_row.html
+++ b/erpnext/hr/page/team_updates/team_update_row.html
@@ -2,7 +2,7 @@
<div class="col-xs-3 text-right activity-date"><span class="{%= date_class %}">
{%= date_sep || "" %}</span></div>
<div class="col-xs-9 activity-message"
- title="{%= by %} / {%= dateutil.str_to_user(creation) %}">
+ title="{%= by %} / {%= frappe.datetime.str_to_user(creation) %}">
<div class="row">
<div class="col-xs-2 col-sm-1">
{{ avatar }}
diff --git a/erpnext/hr/report/monthly_attendance_sheet/monthly_attendance_sheet.py b/erpnext/hr/report/monthly_attendance_sheet/monthly_attendance_sheet.py
index 0c338e0..e9c7029 100644
--- a/erpnext/hr/report/monthly_attendance_sheet/monthly_attendance_sheet.py
+++ b/erpnext/hr/report/monthly_attendance_sheet/monthly_attendance_sheet.py
@@ -16,7 +16,7 @@
emp_map = get_employee_details()
holiday_list = [emp_map[d]["holiday_list"] for d in emp_map if emp_map[d]["holiday_list"]]
- default_holiday_list = frappe.db.get_value("Company", filters.get("company"), "default_holiday_list")
+ default_holiday_list = frappe.get_cached_value('Company', filters.get("company"), "default_holiday_list")
holiday_list.append(default_holiday_list)
holiday_list = list(set(holiday_list))
holiday_map = get_holiday(holiday_list, filters["month"])
diff --git a/erpnext/hr/report/salary_register/salary_register.html b/erpnext/hr/report/salary_register/salary_register.html
index a322bd4..3abc3a0 100644
--- a/erpnext/hr/report/salary_register/salary_register.html
+++ b/erpnext/hr/report/salary_register/salary_register.html
@@ -2,7 +2,7 @@
var report_columns = report.get_columns_for_print();
%}
<div style="margin-bottom: 7px;" class="text-center">
- {%= frappe.boot.letter_heads[filters.letter_head || frappe.defaults.get_default("letter_head")] %}
+ {%= frappe.boot.letter_heads[filters.letter_head || frappe.defaults.get_default("letter_head")].header %}
</div>
<h2 class="text-center">{%= __(report.report_name) %}</h2>
<h5 class="text-center">{{ __("From") }} {%= filters.from_date %} {{ __("to") }} {%= filters.to_date %}</h5>
@@ -23,7 +23,7 @@
<tr>
{% for(var i=1, l=report_columns.length; i<l; i++) { %}
<td class="text-right">
- {% var fieldname = report_columns[i].field; %}
+ {% var fieldname = report_columns[i].fieldname; %}
{% if (report_columns[i].fieldtype=='Currency' && !isNaN(row[fieldname])) { %}
{%= format_currency(row[fieldname]) %}
{% } else { %}
@@ -37,4 +37,4 @@
{% } %}
</tbody>
</table>
-<p class="text-right text-muted">{{ __("Printed On") }} {%= dateutil.str_to_user(dateutil.get_datetime_as_string()) %}</p>
+<p class="text-right text-muted">{{ __("Printed On") }} {%= frappe.datetime.str_to_user(frappe.datetime.get_datetime_as_string()) %}</p>
diff --git a/erpnext/maintenance/doctype/maintenance_schedule/maintenance_schedule.py b/erpnext/maintenance/doctype/maintenance_schedule/maintenance_schedule.py
index 6015bd6..3a64e1a 100644
--- a/erpnext/maintenance/doctype/maintenance_schedule/maintenance_schedule.py
+++ b/erpnext/maintenance/doctype/maintenance_schedule/maintenance_schedule.py
@@ -105,7 +105,7 @@
if employee:
holiday_list = get_holiday_list_for_employee(employee)
else:
- holiday_list = frappe.db.get_value("Company", self.company, "default_holiday_list")
+ holiday_list = frappe.get_cached_value('Company', self.company, "default_holiday_list")
holidays = frappe.db.sql_list('''select holiday_date from `tabHoliday` where parent=%s''', holiday_list)
diff --git a/erpnext/manufacturing/doctype/bom/bom.py b/erpnext/manufacturing/doctype/bom/bom.py
index 84252a0..e5a62f2 100644
--- a/erpnext/manufacturing/doctype/bom/bom.py
+++ b/erpnext/manufacturing/doctype/bom/bom.py
@@ -592,7 +592,7 @@
["Cost Center", "cost_center", "cost_center"], ["Warehouse", "default_warehouse", ""]]:
company_in_record = frappe.db.get_value(d[0], item_details.get(d[1]), "company")
if not item_details.get(d[1]) or (company_in_record and company != company_in_record):
- item_dict[item][d[1]] = frappe.db.get_value("Company", company, d[2]) if d[2] else None
+ item_dict[item][d[1]] = frappe.get_cached_value('Company', company, d[2]) if d[2] else None
return item_dict
diff --git a/erpnext/manufacturing/doctype/workstation/workstation.py b/erpnext/manufacturing/doctype/workstation/workstation.py
index dd1c9f2..f6ab72a 100644
--- a/erpnext/manufacturing/doctype/workstation/workstation.py
+++ b/erpnext/manufacturing/doctype/workstation/workstation.py
@@ -45,7 +45,7 @@
@frappe.whitelist()
def get_default_holiday_list():
- return frappe.db.get_value("Company", frappe.defaults.get_user_default("Company"), "default_holiday_list")
+ return frappe.get_cached_value('Company', frappe.defaults.get_user_default("Company"), "default_holiday_list")
def check_if_within_operating_hours(workstation, operation, from_datetime, to_datetime):
if from_datetime and to_datetime:
diff --git a/erpnext/patches/v10_0/set_currency_in_pricing_rule.py b/erpnext/patches/v10_0/set_currency_in_pricing_rule.py
index c01b2af..c413931 100644
--- a/erpnext/patches/v10_0/set_currency_in_pricing_rule.py
+++ b/erpnext/patches/v10_0/set_currency_in_pricing_rule.py
@@ -7,6 +7,6 @@
currency = frappe.db.get_default("currency")
for doc in frappe.get_all('Pricing Rule', fields = ["company", "name"]):
if doc.company:
- currency = frappe.db.get_value("Company", doc.company, "default_currency")
+ currency = frappe.get_cached_value('Company', doc.company, "default_currency")
frappe.db.sql("""update `tabPricing Rule` set currency = %s where name = %s""",(currency, doc.name))
diff --git a/erpnext/patches/v10_0/update_address_template_for_india.py b/erpnext/patches/v10_0/update_address_template_for_india.py
index 5897b43..145ed45 100644
--- a/erpnext/patches/v10_0/update_address_template_for_india.py
+++ b/erpnext/patches/v10_0/update_address_template_for_india.py
@@ -6,7 +6,7 @@
from erpnext.regional.india.setup import update_address_template
def execute():
- if frappe.db.get_value('Company', {'country': 'India'}, 'name'):
+ if frappe.db.get_value('Company', {'country': 'India'}, 'name'):
address_template = frappe.db.get_value('Address Template', 'India', 'template')
if not address_template or "gstin" not in address_template:
update_address_template()
diff --git a/erpnext/patches/v4_2/party_model.py b/erpnext/patches/v4_2/party_model.py
index 6f93352..46d7fff 100644
--- a/erpnext/patches/v4_2/party_model.py
+++ b/erpnext/patches/v4_2/party_model.py
@@ -56,7 +56,7 @@
parent_account = None
if "receivables_group" in frappe.db.get_table_columns("Company"):
- parent_account = frappe.db.get_value("Company", company,
+ parent_account = frappe.get_cached_value('Company', company,
"receivables_group" if master_type=="Customer" else "payables_group")
if not parent_account:
parent_account = frappe.db.get_value("Account", {"company": company,
diff --git a/erpnext/patches/v7_0/create_warehouse_nestedset.py b/erpnext/patches/v7_0/create_warehouse_nestedset.py
index ca47ac5..1c9fc32 100644
--- a/erpnext/patches/v7_0/create_warehouse_nestedset.py
+++ b/erpnext/patches/v7_0/create_warehouse_nestedset.py
@@ -31,7 +31,7 @@
sle_against_companies = frappe.db.sql_list("""select distinct company from `tabStock Ledger Entry`""")
if len(sle_against_companies) == 1:
- company = frappe.db.get_value("Company", sle_against_companies[0],
+ company = frappe.get_cached_value('Company', sle_against_companies[0],
fieldname=["name", "abbr"], as_dict=1)
set_company_to_warehouse(company.name)
make_warehouse_nestedset(company)
diff --git a/erpnext/projects/doctype/project/project.py b/erpnext/projects/doctype/project/project.py
index 2383804..94436a8 100644
--- a/erpnext/projects/doctype/project/project.py
+++ b/erpnext/projects/doctype/project/project.py
@@ -55,7 +55,14 @@
if self.name is None:
return {}
else:
- return frappe.get_all("Task", "*", {"project": self.name}, order_by="exp_start_date asc")
+ filters = {"project": self.name}
+
+ if self.get("deleted_task_list"):
+ filters.update({
+ 'name': ("not in", self.deleted_task_list)
+ })
+
+ return frappe.get_all("Task", "*", filters, order_by="exp_start_date asc")
def validate(self):
self.validate_project_name()
@@ -86,12 +93,26 @@
def sync_tasks(self):
"""sync tasks and remove table"""
+ if not hasattr(self, "deleted_task_list"):
+ self.set("deleted_task_list", [])
+
if self.flags.dont_sync_tasks: return
task_names = []
existing_task_data = {}
+
+ fields = ["title", "status", "start_date", "end_date", "description", "task_weight", "task_id"]
+ exclude_fieldtype = ["Button", "Column Break",
+ "Section Break", "Table", "Read Only", "Attach", "Attach Image", "Color", "Geolocation", "HTML", "Image"]
+
+ custom_fields = frappe.get_all("Custom Field", {"dt": "Project Task",
+ "fieldtype": ("not in", exclude_fieldtype)}, "fieldname")
+
+ for d in custom_fields:
+ fields.append(d.fieldname)
+
for d in frappe.get_all('Project Task',
- fields = ["title", "status", "start_date", "end_date", "description", "task_weight", "task_id"],
+ fields = fields,
filters = {'parent': self.name}):
existing_task_data.setdefault(d.task_id, d)
@@ -102,7 +123,7 @@
task = frappe.new_doc("Task")
task.project = self.name
- if not t.task_id or self.is_row_updated(t, existing_task_data):
+ if not t.task_id or self.is_row_updated(t, existing_task_data, fields):
task.update({
"subject": t.title,
"status": t.status,
@@ -134,21 +155,20 @@
# delete
for t in frappe.get_all("Task", ["name"], {"project": self.name, "name": ("not in", task_names)}):
- frappe.delete_doc("Task", t.name)
+ self.deleted_task_list.append(t.name)
def update_costing_and_percentage_complete(self):
self.update_percent_complete()
self.update_costing()
- def is_row_updated(self, row, existing_task_data):
+ def is_row_updated(self, row, existing_task_data, fields):
if self.get("__islocal") or not existing_task_data: return True
d = existing_task_data.get(row.task_id)
- if (d and (row.title != d.title or row.status != d.status
- or getdate(row.start_date) != getdate(d.start_date) or getdate(row.end_date) != getdate(d.end_date)
- or row.description != d.description or row.task_weight != d.task_weight)):
- return True
+ for field in fields:
+ if row.get(field) != d.get(field):
+ return True
def map_custom_fields(self, source, target):
project_task_custom_fields = frappe.get_all("Custom Field", {"dt": "Project Task"}, "fieldname")
@@ -272,9 +292,19 @@
user.welcome_email_sent = 1
def on_update(self):
+ self.delete_task()
+ self.load_tasks()
self.update_costing_and_percentage_complete()
self.update_dependencies_on_duplicated_project()
+ def delete_task(self):
+ if not self.get('deleted_task_list'): return
+
+ for d in self.get('deleted_task_list'):
+ frappe.delete_doc("Task", d)
+
+ self.deleted_task_list = []
+
def update_dependencies_on_duplicated_project(self):
if self.flags.dont_sync_tasks: return
if not self.copied_from:
diff --git a/erpnext/public/build.json b/erpnext/public/build.json
index ed4ebab..75809ce 100644
--- a/erpnext/public/build.json
+++ b/erpnext/public/build.json
@@ -1,49 +1,52 @@
{
- "css/erpnext.css": [
- "public/less/erpnext.less",
- "public/less/hub.less"
- ],
- "js/erpnext-web.min.js": [
- "public/js/website_utils.js",
- "public/js/shopping_cart.js"
- ],
- "js/erpnext.min.js": [
- "public/js/conf.js",
- "public/js/utils.js",
- "public/js/queries.js",
- "public/js/sms_manager.js",
- "public/js/utils/party.js",
- "public/js/templates/address_list.html",
- "public/js/templates/contact_list.html",
- "public/js/controllers/stock_controller.js",
- "public/js/payment/payments.js",
- "public/js/controllers/taxes_and_totals.js",
- "public/js/controllers/transaction.js",
- "public/js/pos/pos.html",
- "public/js/pos/pos_bill_item.html",
- "public/js/pos/pos_bill_item_new.html",
- "public/js/pos/pos_selected_item.html",
- "public/js/pos/pos_item.html",
- "public/js/pos/pos_tax_row.html",
- "public/js/pos/customer_toolbar.html",
- "public/js/pos/pos_invoice_list.html",
- "public/js/payment/pos_payment.html",
- "public/js/payment/payment_details.html",
- "public/js/templates/item_selector.html",
- "public/js/templates/employees_to_mark_attendance.html",
- "public/js/utils/item_selector.js",
- "public/js/help_links.js",
- "public/js/agriculture/ternary_plot.js",
- "public/js/templates/item_quick_entry.html",
- "public/js/utils/item_quick_entry.js",
- "public/js/utils/customer_quick_entry.js",
- "public/js/education/student_button.html",
- "public/js/education/assessment_result_tool.html",
- "public/js/hub/hub_factory.js"
- ],
- "js/item-dashboard.min.js": [
- "stock/dashboard/item_dashboard.html",
- "stock/dashboard/item_dashboard_list.html",
- "stock/dashboard/item_dashboard.js"
- ]
+ "css/erpnext.css": [
+ "public/less/erpnext.less",
+ "public/less/hub.less"
+ ],
+ "js/erpnext-web.min.js": [
+ "public/js/website_utils.js",
+ "public/js/shopping_cart.js"
+ ],
+ "css/erpnext-web.css": [
+ "public/less/website.less"
+ ],
+ "js/erpnext.min.js": [
+ "public/js/conf.js",
+ "public/js/utils.js",
+ "public/js/queries.js",
+ "public/js/sms_manager.js",
+ "public/js/utils/party.js",
+ "public/js/templates/address_list.html",
+ "public/js/templates/contact_list.html",
+ "public/js/controllers/stock_controller.js",
+ "public/js/payment/payments.js",
+ "public/js/controllers/taxes_and_totals.js",
+ "public/js/controllers/transaction.js",
+ "public/js/pos/pos.html",
+ "public/js/pos/pos_bill_item.html",
+ "public/js/pos/pos_bill_item_new.html",
+ "public/js/pos/pos_selected_item.html",
+ "public/js/pos/pos_item.html",
+ "public/js/pos/pos_tax_row.html",
+ "public/js/pos/customer_toolbar.html",
+ "public/js/pos/pos_invoice_list.html",
+ "public/js/payment/pos_payment.html",
+ "public/js/payment/payment_details.html",
+ "public/js/templates/item_selector.html",
+ "public/js/templates/employees_to_mark_attendance.html",
+ "public/js/utils/item_selector.js",
+ "public/js/help_links.js",
+ "public/js/agriculture/ternary_plot.js",
+ "public/js/templates/item_quick_entry.html",
+ "public/js/utils/item_quick_entry.js",
+ "public/js/utils/customer_quick_entry.js",
+ "public/js/education/student_button.html",
+ "public/js/education/assessment_result_tool.html",
+ "public/js/hub/hub_factory.js"
+ ],
+ "js/item-dashboard.min.js": [
+ "stock/dashboard/item_dashboard.html",
+ "stock/dashboard/item_dashboard_list.html",
+ "stock/dashboard/item_dashboard.js"
+ ]
}
diff --git a/erpnext/public/css/website.css b/erpnext/public/css/website.css
deleted file mode 100644
index 9ac9aac..0000000
--- a/erpnext/public/css/website.css
+++ /dev/null
@@ -1,270 +0,0 @@
-.web-long-description {
- font-size: 18px;
- line-height: 200%;
-}
-.web-page-content {
- margin-bottom: 30px;
-}
-.item-stock {
- margin-bottom: 10px !important;
-}
-.product-link {
- display: block;
- text-align: center;
-}
-@media (max-width: 767px) {
- .product-image {
- height: 0px;
- padding: 0px 0px 100%;
- overflow: hidden;
- }
-}
-.product-image-square {
- width: 100%;
- height: 0;
- padding: 50% 0px;
- background-size: cover;
- background-repeat: no-repeat;
- background-position: center top;
-}
-.product-image.missing-image {
- width: 100%;
- height: 0;
- padding: 50% 0px;
- background-size: cover;
- background-repeat: no-repeat;
- background-position: center top;
- position: relative;
- background-color: #EBEFF2;
-}
-.product-image.missing-image .octicon {
- font-size: 32px;
- color: #d1d8dd;
-}
-.product-search {
- margin-bottom: 15px;
-}
-@media (max-width: 767px) {
- .product-search {
- width: 100%;
- }
-}
-.borderless td,
-.borderless th {
- border-bottom: 1px solid #EBEFF2;
- padding-left: 0px !important;
- line-height: 1.8em !important;
-}
-.item-desc {
- border-top: 2px solid #EBEFF2;
- padding-top: 10px;
-}
-.featured-products {
- border-top: 1px solid #EBEFF2;
-}
-.transaction-list-item .indicator {
- font-weight: inherit;
- color: #8D99A6;
-}
-.transaction-list-item .transaction-time {
- margin-top: 5px;
-}
-.transaction-subheading .indicator {
- font-weight: inherit;
- color: #8D99A6;
-}
-.order-container {
- margin: 50px 0px;
-}
-.order-container .order-item-header .h6 {
- padding: 7px 15px;
-}
-.order-container .order-items {
- margin: 30px 0px 0px;
-}
-.order-container .order-item-table {
- margin: 0px -15px;
-}
-.order-container .order-item-header {
- border-bottom: 1px solid #d1d8dd;
-}
-.order-container .order-image-col {
- padding-right: 0px;
-}
-.order-container .order-image {
- max-width: 55px;
- max-height: 55px;
- margin-top: -5px;
-}
-.order-container .order-taxes {
- margin-top: 30px;
-}
-.order-container .order-taxes .row {
- margin-top: 15px;
-}
-.order-container .tax-grand-total-row {
- padding-top: 15px;
- padding-bottom: 30px;
-}
-.order-container .tax-grand-total {
- display: inline-block;
- font-size: 16px;
- font-weight: bold;
- margin-top: 5px;
-}
-.cart-container {
- margin: 50px 0px;
-}
-.cart-container .checkout {
- margin-bottom: 15px;
-}
-.cart-container .cart-item-header .h6 {
- padding: 7px 15px;
-}
-.cart-container .cart-items {
- margin: 30px 0px 0px;
-}
-.cart-container .cart-item-table {
- margin: 0px -15px;
-}
-.cart-container .cart-item-header {
- border-bottom: 1px solid #d1d8dd;
-}
-.cart-container .cart-image-col {
- padding-right: 0px;
-}
-.cart-container .cart-image {
- max-width: 55px;
- max-height: 55px;
- margin-top: -5px;
-}
-.cart-container .cart-taxes {
- margin-top: 30px;
-}
-.cart-container .cart-taxes .row {
- margin-top: 15px;
-}
-.cart-container .tax-grand-total-row {
- border-top: 1px solid #d1d8dd;
- padding-top: 15px;
-}
-.cart-container .cart-addresses {
- margin-top: 50px;
-}
-.cart-items-dropdown .cart-dropdown,
-.item_name_dropdown {
- display: none;
-}
-.cart-dropdown-container {
- width: 400px;
- padding: 15px;
-}
-.cart-dropdown-container .item-price {
- display: block !important;
- padding-bottom: 10px;
-}
-.cart-dropdown-container .cart-item-header {
- border-bottom: 1px solid #d1d8dd;
-}
-.cart-dropdown-container .cart-items-dropdown {
- max-height: 350px;
-}
-.cart-dropdown-container .cart-items-dropdown .cart-dropdown {
- display: block;
- margin-top: 15px;
-}
-.cart-dropdown-container .item_name_dropdown {
- display: block;
-}
-.cart-dropdown-container .item-description,
-.cart-dropdown-container .cart-items .checkout,
-.cart-dropdown-container .item_name_and_description {
- display: none;
-}
-.cart-dropdown-container .checkout-btn {
- padding-bottom: 25px;
-}
-.cart-dropdown-container .col-name-description {
- margin-bottom: 8px;
-}
-.number-spinner {
- width: 100px;
- margin-top: 5px;
-}
-.cart-btn {
- border-color: #ccc;
-}
-.cart-qty {
- text-align: center;
-}
-.product-list-link .row {
- border-bottom: 1px solid #EBEFF2;
-}
-.product-list-link .row:hover {
- background-color: #fafbfc;
-}
-.product-list-link .row > div {
- padding-top: 15px;
- padding-bottom: 15px;
-}
-.product-list-link:first-child .row {
- border-top: 1px solid #EBEFF2;
-}
-.item-group-nav-buttons {
- margin-top: 15px;
-}
-.footer-subscribe .btn-default {
- background-color: transparent;
- border: 1px solid #d1d8dd;
-}
-@media (min-width: 992px) {
- .footer-subscribe {
- max-width: 350px;
- }
-}
-.item-group-content {
- margin-top: 30px;
-}
-.product-image-img {
- border: 1px solid #EBEFF2;
- border-radius: 3px;
-}
-.product-text {
- border-top: 1px solid #EBEFF2;
- padding: 15px;
- word-wrap: break-word;
- height: 75px;
- display: block;
- /* Fallback for non-webkit */
- display: -webkit-box;
- max-width: 100%;
- margin: 0 auto;
- -webkit-line-clamp: 3;
- -webkit-box-orient: vertical;
- overflow: hidden;
- text-overflow: ellipsis;
-}
-.product-image-wrapper {
- padding-bottom: 40px;
-}
-.duration-bar {
- display: inline-block;
- color: white;
- background: #8FD288;
- padding: 3px;
-}
-.duration-invisible {
- visibility: hidden;
-}
-.duration-value {
- float: right;
-}
-.bar-outer-text {
- color: #8FD288;
- background: none;
- float: none;
- border: none;
-}
-.bom-spec {
- margin-bottom: 20px;
-}
diff --git a/erpnext/public/js/controllers/buying.js b/erpnext/public/js/controllers/buying.js
index 2822ae8..0ecf6e1 100644
--- a/erpnext/public/js/controllers/buying.js
+++ b/erpnext/public/js/controllers/buying.js
@@ -26,7 +26,8 @@
};
});
- if (this.frm.doc.__islocal) {
+ if (this.frm.doc.__islocal
+ && frappe.meta.has_field(this.frm.doc.doctype, "disable_rounded_total")) {
this.frm.set_value("disable_rounded_total", cint(frappe.sys_defaults.disable_rounded_total));
}
diff --git a/erpnext/public/less/website.less b/erpnext/public/less/website.less
index 14d033c..084958c 100644
--- a/erpnext/public/less/website.less
+++ b/erpnext/public/less/website.less
@@ -1,7 +1,4 @@
-@border-color: #d1d8dd;
-@light-border-color: #EBEFF2;
-@text-muted: #8D99A6;
-@light-bg: #fafbfc;
+@import "variables.less";
.web-long-description {
font-size: 18px;
@@ -21,6 +18,12 @@
text-align: center;
}
+
+.product-image img {
+ max-height: 500px;
+ margin: 0 auto;
+}
+
@media (max-width: 767px) {
.product-image {
height: 0px;
@@ -221,7 +224,7 @@
.cart-items-dropdown .cart-dropdown {
display:block;
- margin-top:15px;
+ margin-top:15px;
}
.item_name_dropdown {
@@ -342,4 +345,21 @@
.bom-spec {
margin-bottom: 20px;
-}
\ No newline at end of file
+}
+
+.modal-title {
+ margin-top: 5px;
+}
+
+.modal-header {
+ padding: 10px 15px;
+}
+// For Item Alternate Image
+.item-alternative-image {
+ padding: 5px;
+ margin-bottom: 5px;
+
+ &:hover {
+ border-color: @brand-primary;
+ }
+}
diff --git a/erpnext/regional/india/utils.py b/erpnext/regional/india/utils.py
index 2912ab9..9440aff 100644
--- a/erpnext/regional/india/utils.py
+++ b/erpnext/regional/india/utils.py
@@ -111,8 +111,8 @@
out.taxes = get_taxes_and_charges(master_doctype, default_tax)
def calculate_annual_eligible_hra_exemption(doc):
- basic_component = frappe.db.get_value("Company", doc.company, "basic_component")
- hra_component = frappe.db.get_value("Company", doc.company, "hra_component")
+ basic_component = frappe.get_cached_value('Company', doc.company, "basic_component")
+ hra_component = frappe.get_cached_value('Company', doc.company, "hra_component")
annual_exemption, monthly_exemption, hra_amount = 0, 0, 0
if hra_component and basic_component:
assignment = get_salary_assignment(doc.employee, getdate())
diff --git "a/erpnext/regional/report/fichier_des_ecritures_comptables_\133fec\135/fichier_des_ecritures_comptables_\133fec\135.py" "b/erpnext/regional/report/fichier_des_ecritures_comptables_\133fec\135/fichier_des_ecritures_comptables_\133fec\135.py"
index eb4cbf8..a072ed0 100644
--- "a/erpnext/regional/report/fichier_des_ecritures_comptables_\133fec\135/fichier_des_ecritures_comptables_\133fec\135.py"
+++ "b/erpnext/regional/report/fichier_des_ecritures_comptables_\133fec\135/fichier_des_ecritures_comptables_\133fec\135.py"
@@ -33,7 +33,7 @@
def set_account_currency(filters):
- filters["company_currency"] = frappe.db.get_value("Company", filters.company, "default_currency")
+ filters["company_currency"] = frappe.get_cached_value('Company', filters.company, "default_currency")
return filters
@@ -100,7 +100,7 @@
def get_result_as_list(data, filters):
result = []
- company_currency = frappe.db.get_value("Company", filters.company, "default_currency")
+ company_currency = frappe.get_cached_value('Company', filters.company, "default_currency")
accounts = frappe.get_all("Account", filters={"Company": filters.company}, fields=["name", "account_number"])
for d in data:
diff --git a/erpnext/selling/doctype/customer/customer.py b/erpnext/selling/doctype/customer/customer.py
index 2c22543..bd01ec9 100644
--- a/erpnext/selling/doctype/customer/customer.py
+++ b/erpnext/selling/doctype/customer/customer.py
@@ -315,14 +315,14 @@
credit_limit = None
if customer:
- credit_limit, customer_group = frappe.db.get_value("Customer",
+ credit_limit, customer_group = frappe.get_cached_value("Customer",
customer, ["credit_limit", "customer_group"])
if not credit_limit:
- credit_limit = frappe.db.get_value("Customer Group", customer_group, "credit_limit")
+ credit_limit = frappe.get_cached_value("Customer Group", customer_group, "credit_limit")
if not credit_limit:
- credit_limit = frappe.db.get_value("Company", company, "credit_limit")
+ credit_limit = frappe.get_cached_value('Company', company, "credit_limit")
return flt(credit_limit)
diff --git a/erpnext/selling/doctype/installation_note/installation_note.py b/erpnext/selling/doctype/installation_note/installation_note.py
index 9f730f4..ffcbb2d 100644
--- a/erpnext/selling/doctype/installation_note/installation_note.py
+++ b/erpnext/selling/doctype/installation_note/installation_note.py
@@ -33,8 +33,8 @@
self.validate_installation_date()
self.check_item_table()
- from erpnext.controllers.selling_controller import check_active_sales_items
- check_active_sales_items(self)
+ from erpnext.controllers.selling_controller import set_default_income_account_for_item
+ set_default_income_account_for_item(self)
def is_serial_no_added(self, item_code, serial_no):
has_serial_no = frappe.db.get_value("Item", item_code, "has_serial_no")
diff --git a/erpnext/selling/doctype/pos_closing_voucher/pos_closing_voucher.py b/erpnext/selling/doctype/pos_closing_voucher/pos_closing_voucher.py
index a4a6e86..e7fc85e 100644
--- a/erpnext/selling/doctype/pos_closing_voucher/pos_closing_voucher.py
+++ b/erpnext/selling/doctype/pos_closing_voucher/pos_closing_voucher.py
@@ -157,7 +157,7 @@
return {'net_total': net_total, 'grand_total': grand_total, 'total_qty': total_qty}
def get_company_currency(doc):
- currency = frappe.db.get_value("Company", doc.company, "default_currency")
+ currency = frappe.get_cached_value('Company', doc.company, "default_currency")
return frappe.get_doc('Currency', currency)
def get_invoices(filters):
diff --git a/erpnext/selling/doctype/sales_order/sales_order.py b/erpnext/selling/doctype/sales_order/sales_order.py
index b860f7d..f69b59f 100755
--- a/erpnext/selling/doctype/sales_order/sales_order.py
+++ b/erpnext/selling/doctype/sales_order/sales_order.py
@@ -116,7 +116,7 @@
d.delivery_date = self.delivery_date
if getdate(self.transaction_date) > getdate(d.delivery_date):
frappe.msgprint(_("Expected Delivery Date should be after Sales Order Date"),
- indicator='orange', title=_('Warning'))
+ indicator='orange', title=_('Warning'))
if getdate(self.delivery_date) != getdate(max_delivery_date):
self.delivery_date = max_delivery_date
else:
@@ -136,7 +136,7 @@
super(SalesOrder, self).validate_warehouse()
for d in self.get("items"):
- if (frappe.db.get_value("Item", d.item_code, "is_stock_item") == 1 or
+ if (frappe.get_cached_value("Item", d.item_code, "is_stock_item") == 1 or
(self.has_product_bundle(d.item_code) and self.product_bundle_has_stock_item(d.item_code))) \
and not d.warehouse and not cint(d.delivered_by_supplier):
frappe.throw(_("Delivery warehouse required for stock item {0}").format(d.item_code),
@@ -208,7 +208,7 @@
def check_credit_limit(self):
# if bypass credit limit check is set to true (1) at sales order level,
# then we need not to check credit limit and vise versa
- if not cint(frappe.db.get_value("Customer", self.customer, "bypass_credit_limit_check_at_sales_order")):
+ if not cint(frappe.get_cached_value("Customer", self.customer, "bypass_credit_limit_check_at_sales_order")):
check_credit_limit(self.customer, self.company)
def check_nextdoc_docstatus(self):
@@ -281,7 +281,7 @@
item_wh_list = []
def _valid_for_reserve(item_code, warehouse):
if item_code and warehouse and [item_code, warehouse] not in item_wh_list \
- and frappe.db.get_value("Item", item_code, "is_stock_item"):
+ and frappe.get_cached_value("Item", item_code, "is_stock_item"):
item_wh_list.append([item_code, warehouse])
for d in self.get("items"):
@@ -412,7 +412,7 @@
Item {0} is added with and without Ensure Delivery by \
Serial No.").format(item.item_code))
if item.item_code not in reserved_items:
- if not frappe.db.get_value("Item", item.item_code, "has_serial_no"):
+ if not frappe.get_cached_value("Item", item.item_code, "has_serial_no"):
frappe.throw(_("Item {0} has no Serial No. Only serilialized items \
can have delivery based on Serial No").format(item.item_code))
if not frappe.db.exists("BOM", {"item": item.item_code, "is_active": 1}):
diff --git a/erpnext/setup/doctype/company/company.py b/erpnext/setup/doctype/company/company.py
index 85b10dd..057f748 100644
--- a/erpnext/setup/doctype/company/company.py
+++ b/erpnext/setup/doctype/company/company.py
@@ -75,7 +75,9 @@
.format(self.get(field), self.name))
def validate_currency(self):
- self.previous_default_currency = frappe.db.get_value("Company", self.name, "default_currency")
+ if self.is_new():
+ return
+ self.previous_default_currency = frappe.get_cached_value('Company', self.name, "default_currency")
if self.default_currency and self.previous_default_currency and \
self.default_currency != self.previous_default_currency and \
self.check_if_transactions_exist():
@@ -161,7 +163,7 @@
frappe.flags.country_change = False
if not self.get('__islocal') and \
- self.country != frappe.db.get_value('Company', self.name, 'country'):
+ self.country != frappe.get_cached_value('Company', self.name, 'country'):
frappe.flags.country_change = True
def set_default_accounts(self):
@@ -361,7 +363,7 @@
def get_name_with_abbr(name, company):
- company_abbr = frappe.db.get_value("Company", company, "abbr")
+ company_abbr = frappe.get_cached_value('Company', company, "abbr")
parts = name.split(" - ")
if parts[-1].lower() != company_abbr.lower():
@@ -505,7 +507,7 @@
out = {}
date_to_value_dict = {}
- history = frappe.db.get_value("Company", name, "transactions_annual_history")
+ history = frappe.get_cached_value('Company', name, "transactions_annual_history")
try:
date_to_value_dict = json.loads(history) if history and '{' in history else None
@@ -514,7 +516,7 @@
if date_to_value_dict is None:
update_transactions_annual_history(name, True)
- history = frappe.db.get_value("Company", name, "transactions_annual_history")
+ history = frappe.get_cached_value('Company', name, "transactions_annual_history")
return json.loads(history) if history and '{' in history else {}
return date_to_value_dict
diff --git a/erpnext/setup/doctype/email_digest/email_digest.py b/erpnext/setup/doctype/email_digest/email_digest.py
index c9ebada..631c0bc 100644
--- a/erpnext/setup/doctype/email_digest/email_digest.py
+++ b/erpnext/setup/doctype/email_digest/email_digest.py
@@ -22,7 +22,7 @@
self.from_date, self.to_date = self.get_from_to_date()
self.set_dates()
self._accounts = {}
- self.currency = frappe.db.get_value("Company", self.company, "default_currency")
+ self.currency = frappe.db.get_value('Company', self.company, "default_currency")
def get_users(self):
"""get list of users"""
diff --git a/erpnext/setup/doctype/item_group/item_group.py b/erpnext/setup/doctype/item_group/item_group.py
index d4f16be..684febf 100644
--- a/erpnext/setup/doctype/item_group/item_group.py
+++ b/erpnext/setup/doctype/item_group/item_group.py
@@ -4,6 +4,7 @@
from __future__ import unicode_literals
import frappe
import urllib
+import copy
from frappe.utils import nowdate, cint, cstr
from frappe.utils.nestedset import NestedSet
from frappe.website.website_generator import WebsiteGenerator
@@ -175,17 +176,13 @@
clear_cache(frappe.db.get_value('Item Group', item_group_name, 'route'))
def get_item_group_defaults(item, company):
- item_group = frappe.db.get_value("Item", item, "item_group")
- item_group_defaults = frappe.db.sql('''
- select
- expense_account, income_account, buying_cost_center, default_warehouse,
- selling_cost_center, default_supplier
- from
- `tabItem Default` where company = %s and parent = %s and parenttype = 'Item Group'
- ''', (company, item_group), as_dict=1)
+ item = frappe.get_cached_doc("Item", item)
+ item_group = frappe.get_cached_doc("Item Group", item.item_group)
- if item_group_defaults:
- return item_group_defaults[0]
- else:
- return frappe.db.get_value("Item", item, ["name", "item_name", "description", "stock_uom",
- "is_stock_item", "item_code", "item_group"], as_dict=1)
\ No newline at end of file
+ for d in item_group.item_group_defaults or []:
+ if d.company == company:
+ row = copy.deepcopy(d.as_dict())
+ row.pop("name")
+ return row
+
+ return frappe._dict()
\ No newline at end of file
diff --git a/erpnext/setup/setup_wizard/operations/taxes_setup.py b/erpnext/setup/setup_wizard/operations/taxes_setup.py
index dd5c037..82f7512 100644
--- a/erpnext/setup/setup_wizard/operations/taxes_setup.py
+++ b/erpnext/setup/setup_wizard/operations/taxes_setup.py
@@ -51,7 +51,7 @@
}).insert(ignore_permissions=True, ignore_mandatory=True)
except frappe.NameError:
frappe.message_log.pop()
- abbr = frappe.db.get_value('Company', company, 'abbr')
+ abbr = frappe.get_cached_value('Company', company, 'abbr')
account = '{0} - {1}'.format(account_name, abbr)
return frappe.get_doc('Account', account)
diff --git a/erpnext/shopping_cart/doctype/shopping_cart_settings/shopping_cart_settings.py b/erpnext/shopping_cart/doctype/shopping_cart_settings/shopping_cart_settings.py
index 5c24070..be4670e 100644
--- a/erpnext/shopping_cart/doctype/shopping_cart_settings/shopping_cart_settings.py
+++ b/erpnext/shopping_cart/doctype/shopping_cart_settings/shopping_cart_settings.py
@@ -22,7 +22,7 @@
def validate_exchange_rates_exist(self):
"""check if exchange rates exist for all Price List currencies (to company's currency)"""
- company_currency = frappe.db.get_value("Company", self.company, "default_currency")
+ company_currency = frappe.get_cached_value('Company', self.company, "default_currency")
if not company_currency:
msgprint(_("Please specify currency in Company") + ": " + self.company,
raise_exception=ShoppingCartSetupError)
diff --git a/erpnext/stock/__init__.py b/erpnext/stock/__init__.py
index 8ef1415..331472a 100644
--- a/erpnext/stock/__init__.py
+++ b/erpnext/stock/__init__.py
@@ -51,4 +51,4 @@
return account
def get_company_default_inventory_account(company):
- return frappe.db.get_value('Company', company, 'default_inventory_account')
\ No newline at end of file
+ return frappe.get_cached_value('Company', company, 'default_inventory_account')
\ No newline at end of file
diff --git a/erpnext/stock/doctype/bin/bin.py b/erpnext/stock/doctype/bin/bin.py
index efa6c14..f86a77d 100644
--- a/erpnext/stock/doctype/bin/bin.py
+++ b/erpnext/stock/doctype/bin/bin.py
@@ -8,19 +8,11 @@
from frappe.model.document import Document
class Bin(Document):
- def validate(self):
+ def before_save(self):
if self.get("__islocal") or not self.stock_uom:
- self.stock_uom = frappe.db.get_value('Item', self.item_code, 'stock_uom')
-
- self.validate_mandatory()
+ self.stock_uom = frappe.get_cached_value('Item', self.item_code, 'stock_uom')
self.set_projected_qty()
- def validate_mandatory(self):
- qf = ['actual_qty', 'reserved_qty', 'ordered_qty', 'indented_qty']
- for f in qf:
- if (not getattr(self, f, None)) or (not self.get(f)):
- self.set(f, 0.0)
-
def update_stock(self, args, allow_negative_stock=False, via_landed_cost_voucher=False):
'''Called from erpnext.stock.utils.update_bin'''
self.update_qty(args)
diff --git a/erpnext/stock/doctype/item/item.py b/erpnext/stock/doctype/item/item.py
index ba5e827..affaf26 100644
--- a/erpnext/stock/doctype/item/item.py
+++ b/erpnext/stock/doctype/item/item.py
@@ -7,6 +7,7 @@
import json
import erpnext
import frappe
+import copy
from erpnext.controllers.item_variant import (ItemVariantExistsError,
copy_attributes_to_variant, get_variant, make_variant_item_code, validate_item_variant_attributes)
from erpnext.setup.doctype.item_group.item_group import (get_parent_item_groups, invalidate_cache_for)
@@ -926,22 +927,31 @@
frappe.throw(
_("Default Unit of Measure for Item {0} cannot be changed directly because you have already made some transaction(s) with another UOM. You will need to create a new Item to use a different Default UOM.").format(item))
-def get_item_defaults(item, company):
- item_defaults = frappe.db.sql('''
- select
- i.item_name, i.description, i.stock_uom, i.name, i.is_stock_item, i.item_code, i.item_group,
- id.expense_account, id.income_account, id.buying_cost_center, id.default_warehouse,
- id.selling_cost_center, id.default_supplier
- from
- `tabItem` i LEFT JOIN `tabItem Default` id ON i.name = id.parent and id.company = %s
- where
- i.name = %s
- ''', (company, item), as_dict=1)
- if item_defaults:
- return item_defaults[0]
- else:
- return frappe.db.get_value("Item", item, ["name", "item_name", "description", "stock_uom",
- "is_stock_item", "item_code", "item_group"], as_dict=1)
+def get_item_defaults(item_code, company):
+ item = frappe.get_cached_doc('Item', item_code)
+
+ out = item.as_dict()
+
+ for d in item.item_defaults:
+ if d.company == company:
+ row = copy.deepcopy(d.as_dict())
+ row.pop("name")
+ out.update(row)
+ return out
+
+def set_item_default(item_code, company, fieldname, value):
+ item = frappe.get_cached_doc('Item', item_code)
+
+ for d in item.item_defaults:
+ if d.company == company:
+ if not d.get(fieldname):
+ frappe.db.set_value(d.doctype, d.name, fieldname, value)
+ return
+
+ # no row found, add a new row for the company
+ d = item.append('item_defaults', {fieldname: value, company: company})
+ d.db_insert()
+ item.clear_cache()
@frappe.whitelist()
def get_uom_conv_factor(uom, stock_uom):
diff --git a/erpnext/stock/doctype/landed_cost_voucher/landed_cost_voucher.py b/erpnext/stock/doctype/landed_cost_voucher/landed_cost_voucher.py
index d36b6cf..a647717 100644
--- a/erpnext/stock/doctype/landed_cost_voucher/landed_cost_voucher.py
+++ b/erpnext/stock/doctype/landed_cost_voucher/landed_cost_voucher.py
@@ -46,10 +46,10 @@
if not self.get("purchase_receipts"):
frappe.throw(_("Please enter Receipt Document"))
-
+
def validate_purchase_receipts(self):
receipt_documents = []
-
+
for d in self.get("purchase_receipts"):
if frappe.db.get_value(d.receipt_document_type, d.receipt_document, "docstatus") != 1:
frappe.throw(_("Receipt document must be submitted"))
@@ -72,16 +72,16 @@
def validate_applicable_charges_for_item(self):
based_on = self.distribute_charges_based_on.lower()
-
+
total = sum([flt(d.get(based_on)) for d in self.get("items")])
-
+
if not total:
frappe.throw(_("Total {0} for all items is zero, may be you should change 'Distribute Charges Based On'").format(based_on))
-
+
total_applicable_charges = sum([flt(d.applicable_charges) for d in self.get("items")])
precision = get_field_precision(frappe.get_meta("Landed Cost Item").get_field("applicable_charges"),
- currency=frappe.db.get_value("Company", self.company, "default_currency", cache=True))
+ currency=frappe.get_cached_value('Company', self.company, "default_currency"))
diff = flt(self.total_taxes_and_charges) - flt(total_applicable_charges)
diff = flt(diff, precision)
diff --git a/erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.py b/erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.py
index 86ff2ee..6e2863e 100644
--- a/erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.py
+++ b/erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.py
@@ -320,12 +320,6 @@
'asset_category': asset_category, 'serial_no_series': 'ABC.###'})
asset_item = item_data.item_code
- if not frappe.db.exists('Location', 'Test Location'):
- frappe.get_doc({
- 'doctype': 'Location',
- 'location_name': 'Test Location'
- }).insert()
-
pr = make_purchase_receipt(item_code=asset_item, qty=3)
asset = frappe.db.get_value('Asset', {'purchase_receipt': pr.name}, 'name')
asset_movement = frappe.db.get_value('Asset Movement', {'reference_name': pr.name}, 'name')
@@ -348,6 +342,12 @@
order by account desc""", (voucher_type, voucher_no), as_dict=1)
def make_purchase_receipt(**args):
+ if not frappe.db.exists('Location', 'Test Location'):
+ frappe.get_doc({
+ 'doctype': 'Location',
+ 'location_name': 'Test Location'
+ }).insert()
+
frappe.db.set_value("Buying Settings", None, "allow_multiple_items", 1)
pr = frappe.new_doc("Purchase Receipt")
args = frappe._dict(args)
@@ -377,7 +377,7 @@
"serial_no": args.serial_no,
"stock_uom": args.stock_uom or "_Test UOM",
"uom": args.uom or "_Test UOM",
- "cost_center": args.cost_center or frappe.db.get_value('Company', pr.company, 'cost_center'),
+ "cost_center": args.cost_center or frappe.get_cached_value('Company', pr.company, 'cost_center'),
"asset_location": args.location or "Test Location"
})
@@ -388,5 +388,5 @@
return pr
-test_dependencies = ["BOM", "Item Price"]
+test_dependencies = ["BOM", "Item Price", "Location"]
test_records = frappe.get_test_records('Purchase Receipt')
diff --git a/erpnext/stock/doctype/stock_entry/stock_entry.py b/erpnext/stock/doctype/stock_entry/stock_entry.py
index 13cfb69..687790b 100644
--- a/erpnext/stock/doctype/stock_entry/stock_entry.py
+++ b/erpnext/stock/doctype/stock_entry/stock_entry.py
@@ -623,14 +623,14 @@
["Cost Center", "cost_center", "cost_center"]]:
company = frappe.db.get_value(d[0], ret.get(d[1]), "company")
if not ret[d[1]] or (company and self.company != company):
- ret[d[1]] = frappe.db.get_value("Company", self.company, d[2]) if d[2] else None
+ ret[d[1]] = frappe.get_cached_value('Company', self.company, d[2]) if d[2] else None
# update uom
if args.get("uom") and for_update:
ret.update(get_uom_details(args.get('item_code'), args.get('uom'), args.get('qty')))
if not ret["expense_account"]:
- ret["expense_account"] = frappe.db.get_value("Company", self.company, "stock_adjustment_account")
+ ret["expense_account"] = frappe.get_cached_value('Company', self.company, "stock_adjustment_account")
args['posting_date'] = self.posting_date
args['posting_time'] = self.posting_time
diff --git a/erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.py b/erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.py
index bd3577f..43a66a8 100644
--- a/erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.py
+++ b/erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.py
@@ -21,9 +21,9 @@
def validate(self):
if not self.expense_account:
- self.expense_account = frappe.db.get_value("Company", self.company, "stock_adjustment_account")
+ self.expense_account = frappe.get_cached_value('Company', self.company, "stock_adjustment_account")
if not self.cost_center:
- self.cost_center = frappe.db.get_value("Company", self.company, "cost_center")
+ self.cost_center = frappe.get_cached_value('Company', self.company, "cost_center")
self.validate_posting_time()
self.remove_items_with_no_change()
self.validate_data()
diff --git a/erpnext/stock/doctype/warehouse/warehouse.py b/erpnext/stock/doctype/warehouse/warehouse.py
index 3ea2939..850d648 100644
--- a/erpnext/stock/doctype/warehouse/warehouse.py
+++ b/erpnext/stock/doctype/warehouse/warehouse.py
@@ -14,7 +14,7 @@
def autoname(self):
if self.company:
- suffix = " - " + frappe.db.get_value("Company", self.company, "abbr")
+ suffix = " - " + frappe.get_cached_value('Company', self.company, "abbr")
if not self.warehouse_name.endswith(suffix):
self.name = self.warehouse_name + suffix
else:
@@ -87,7 +87,7 @@
self.recalculate_bin_qty(new_name)
def get_new_warehouse_name_without_abbr(self, name):
- company_abbr = frappe.db.get_value("Company", self.company, "abbr")
+ company_abbr = frappe.get_cached_value('Company', self.company, "abbr")
parts = name.rsplit(" - ", 1)
if parts[-1].lower() == company_abbr.lower():
diff --git a/erpnext/stock/get_item_details.py b/erpnext/stock/get_item_details.py
index da92608..e73c627 100644
--- a/erpnext/stock/get_item_details.py
+++ b/erpnext/stock/get_item_details.py
@@ -39,34 +39,18 @@
}
"""
args = process_args(args)
- item_doc = frappe.get_doc("Item", args.item_code)
- item = item_doc
-
+ item = frappe.get_cached_doc("Item", args.item_code)
validate_item_details(args, item)
out = get_basic_details(args, item)
- get_party_item_code(args, item_doc, out)
+ get_party_item_code(args, item, out)
- if frappe.db.exists("Product Bundle", args.item_code):
- valuation_rate = 0.0
- bundled_items = frappe.get_doc("Product Bundle", args.item_code)
-
- for bundle_item in bundled_items.items:
- valuation_rate += \
- flt(get_valuation_rate(bundle_item.item_code, args.company, out.get("warehouse")).get("valuation_rate") \
- * bundle_item.qty)
-
- out.update({
- "valuation_rate": valuation_rate
- })
-
- else:
- out.update(get_valuation_rate(args.item_code, args.company, out.get("warehouse")))
+ set_valuation_rate(out, args)
update_party_blanket_order(args, out)
- get_price_list_rate(args, item_doc, out)
+ get_price_list_rate(args, item, out)
if args.customer and cint(args.is_pos):
out.update(get_pos_profile_item_details(args.company, args))
@@ -80,6 +64,24 @@
args[key] = value
out.update(get_pricing_rule_for_item(args))
+
+ update_stock(args, out)
+
+ if args.transaction_date and item.lead_time_days:
+ out.schedule_date = out.lead_time_date = add_days(args.transaction_date,
+ item.lead_time_days)
+
+ if args.get("is_subcontracted") == "Yes":
+ out.bom = args.get('bom') or get_default_bom(args.item_code)
+
+ get_gross_profit(out)
+ if args.doctype == 'Material Request':
+ out.rate = args.rate or out.price_list_rate
+ out.amount = flt(args.qty * out.rate)
+
+ return out
+
+def update_stock(args, out):
if (args.get("doctype") == "Delivery Note" or
(args.get("doctype") == "Sales Invoice" and args.get('update_stock'))) \
and out.warehouse and out.stock_qty > 0:
@@ -99,19 +101,24 @@
reserved_so = get_so_reservation_for_item(args)
out.serial_no = get_serial_no(out, args.serial_no, sales_order=reserved_so)
- if args.transaction_date and item.lead_time_days:
- out.schedule_date = out.lead_time_date = add_days(args.transaction_date,
- item.lead_time_days)
- if args.get("is_subcontracted") == "Yes":
- out.bom = args.get('bom') or get_default_bom(args.item_code)
+def set_valuation_rate(out, args):
+ if frappe.db.exists("Product Bundle", args.item_code, cache=True):
+ valuation_rate = 0.0
+ bundled_items = frappe.get_doc("Product Bundle", args.item_code)
- get_gross_profit(out)
- if args.doctype == 'Material Request':
- out.rate = args.rate or out.price_list_rate
- out.amount = flt(args.qty * out.rate)
+ for bundle_item in bundled_items.items:
+ valuation_rate += \
+ flt(get_valuation_rate(bundle_item.item_code, args.company, out.get("warehouse")).get("valuation_rate") \
+ * bundle_item.qty)
- return out
+ out.update({
+ "valuation_rate": valuation_rate
+ })
+
+ else:
+ out.update(get_valuation_rate(args.item_code, args.company, out.get("warehouse")))
+
def process_args(args):
if isinstance(args, string_types):
@@ -215,10 +222,9 @@
warehouse = user_default_warehouse or item_defaults.get("default_warehouse") or\
item_group_defaults.get("default_warehouse") or args.warehouse
- material_request_type = ''
if args.get('doctype') == "Material Request" and not args.get('material_request_type'):
args['material_request_type'] = frappe.db.get_value('Material Request',
- args.get('name'), 'material_request_type')
+ args.get('name'), 'material_request_type', cache=True)
#Set the UOM to the Default Sales UOM or Default Purchase UOM if configured in the Item Master
if not args.uom:
@@ -297,7 +303,7 @@
["Cost Center", "cost_center", "cost_center"],
["Warehouse", "warehouse", ""]]:
if not out[d[1]]:
- out[d[1]] = frappe.db.get_value("Company", args.company, d[2]) if d[2] else None
+ out[d[1]] = frappe.get_cached_value('Company', args.company, d[2]) if d[2] else None
for fieldname in ("item_name", "item_group", "barcodes", "brand", "stock_uom"):
out[fieldname] = item.get(fieldname)
@@ -319,15 +325,22 @@
if item.enable_deferred_revenue:
return (item.deferred_revenue_account
or args.deferred_revenue_account
- or frappe.db.get_value("Company", args.company, "default_deferred_revenue_account"))
+ or frappe.get_cached_value('Company', args.company, "default_deferred_revenue_account"))
else:
return None
def get_default_cost_center(args, item, item_group):
- return (frappe.db.get_value("Project", args.get("project"), "cost_center")
- or (item.get("selling_cost_center") if args.get("customer") else item.get("buying_cost_center"))
- or (item_group.get("selling_cost_center") if args.get("customer") else item_group.get("buying_cost_center"))
- or args.get("cost_center"))
+ cost_center = None
+ if args.get('project'):
+ cost_center = frappe.db.get_value("Project", args.get("project"), "cost_center", cache=True)
+
+ if not cost_center:
+ if args.get('customer'):
+ cost_center = item.get('selling_cost_center') or item_group.get('selling_cost_center')
+ else:
+ cost_center = item.get('buying_cost_center') or item_group.get('buying_cost_center')
+
+ return cost_center or args.get("cost_center")
def get_default_supplier(args, item, item_group):
return (item.get("default_supplier")
@@ -363,20 +376,12 @@
def insert_item_price(args):
"""Insert Item Price if Price List and Price List Rate are specified and currency is the same"""
- if frappe.db.get_value("Price List", args.price_list, "currency") == args.currency \
+ if frappe.db.get_value("Price List", args.price_list, "currency", cache=True) == args.currency \
and cint(frappe.db.get_single_value("Stock Settings", "auto_insert_price_list_rate_if_missing")):
if frappe.has_permission("Item Price", "write"):
price_list_rate = (args.rate / args.get('conversion_factor')
if args.get("conversion_factor") else args.rate)
- item_price = frappe.get_doc({
- "doctype": "Item Price",
- "price_list": args.price_list,
- "item_code": args.item_code,
- "currency": args.currency,
- "price_list_rate": price_list_rate
- })
-
name = frappe.db.get_value('Item Price',
{'item_code': args.item_code, 'price_list': args.price_list, 'currency': args.currency}, 'name')
@@ -387,6 +392,13 @@
frappe.msgprint(_("Item Price updated for {0} in Price List {1}").format(args.item_code,
args.price_list))
else:
+ item_price = frappe.get_doc({
+ "doctype": "Item Price",
+ "price_list": args.price_list,
+ "item_code": args.item_code,
+ "currency": args.currency,
+ "price_list_rate": price_list_rate
+ })
item_price.insert()
frappe.msgprint(_("Item Price added for {0} in Price List {1}").format(args.item_code,
args.price_list))
@@ -501,7 +513,7 @@
from erpnext.controllers.accounts_controller import validate_conversion_rate
if (not args.conversion_rate
- and args.currency==frappe.db.get_value("Company", args.company, "default_currency")):
+ and args.currency==frappe.get_cached_value('Company', args.company, "default_currency")):
args.conversion_rate = 1.0
# validate currency conversion rate
@@ -513,7 +525,7 @@
frappe._dict({"fields": args})))
if (not args.plc_conversion_rate
- and args.price_list_currency==frappe.db.get_value("Price List", args.price_list, "currency")):
+ and args.price_list_currency==frappe.db.get_value("Price List", args.price_list, "currency", cache=True)):
args.plc_conversion_rate = 1.0
# validate price list currency conversion rate
@@ -535,7 +547,7 @@
if customer_item_code:
out.customer_item_code = customer_item_code[0].ref_code
else:
- customer_group = frappe.db.get_value("Customer", args.customer, "customer_group")
+ customer_group = frappe.get_cached_value("Customer", args.customer, "customer_group")
customer_group_item_code = item_doc.get("customer_items", {"customer_group": customer_group})
if customer_group_item_code and not customer_group_item_code[0].customer_name:
out.customer_item_code = customer_group_item_code[0].ref_code
@@ -547,8 +559,8 @@
def get_pos_profile_item_details(company, args, pos_profile=None, update_data=False):
res = frappe._dict()
- if not pos_profile:
- pos_profile = get_pos_profile(company, args.get('pos_profile'))
+ if not frappe.flags.pos_profile and not pos_profile:
+ pos_profile = frappe.flags.pos_profile = get_pos_profile(company, args.get('pos_profile'))
if pos_profile:
for fieldname in ("income_account", "cost_center", "warehouse", "expense_account"):
@@ -564,7 +576,7 @@
@frappe.whitelist()
def get_pos_profile(company, pos_profile=None, user=None):
if pos_profile:
- return frappe.get_doc('POS Profile', pos_profile)
+ return frappe.get_cached_doc('POS Profile', pos_profile)
if not user:
user = frappe.session['user']
@@ -618,7 +630,7 @@
@frappe.whitelist()
def get_conversion_factor(item_code, uom):
- variant_of = frappe.db.get_value("Item", item_code, "variant_of")
+ variant_of = frappe.db.get_value("Item", item_code, "variant_of", cache=True)
filters = {"parent": item_code, "uom": uom}
if variant_of:
filters["parent"] = ("in", (item_code, variant_of))
@@ -633,7 +645,7 @@
@frappe.whitelist()
def get_bin_details(item_code, warehouse):
return frappe.db.get_value("Bin", {"item_code": item_code, "warehouse": warehouse},
- ["projected_qty", "actual_qty"], as_dict=True) \
+ ["projected_qty", "actual_qty"], as_dict=True, cache=True) \
or {"projected_qty": 0, "actual_qty": 0}
@frappe.whitelist()
diff --git a/erpnext/stock/stock_balance.py b/erpnext/stock/stock_balance.py
index 90c82c4..09d4e43 100644
--- a/erpnext/stock/stock_balance.py
+++ b/erpnext/stock/stock_balance.py
@@ -148,11 +148,9 @@
mismatch = True
if mismatch:
- bin.projected_qty = (flt(bin.actual_qty) + flt(bin.ordered_qty) +
- flt(bin.indented_qty) + flt(bin.planned_qty) - flt(bin.reserved_qty)
- - flt(bin.reserved_qty_for_production)) - flt(bin.reserved_qty_for_sub_contract)
-
- bin.save()
+ bin.set_projected_qty()
+ bin.db_update()
+ bin.clear_cache()
def set_stock_balance_as_per_serial_no(item_code=None, posting_date=None, posting_time=None,
fiscal_year=None):
diff --git a/erpnext/stock/stock_ledger.py b/erpnext/stock/stock_ledger.py
index 37caf47..928dd88 100644
--- a/erpnext/stock/stock_ledger.py
+++ b/erpnext/stock/stock_ledger.py
@@ -100,7 +100,7 @@
self.company = frappe.db.get_value("Warehouse", self.warehouse, "company")
self.precision = get_field_precision(frappe.get_meta("Stock Ledger Entry").get_field("stock_value"),
- currency=frappe.db.get_value("Company", self.company, "default_currency", cache=True))
+ currency=frappe.get_cached_value('Company', self.company, "default_currency"))
self.prev_stock_value = self.previous_sle.stock_value or 0.0
self.stock_queue = json.loads(self.previous_sle.stock_queue or "[]")
diff --git a/erpnext/templates/generators/item.html b/erpnext/templates/generators/item.html
index 0e09f58..3220722 100644
--- a/erpnext/templates/generators/item.html
+++ b/erpnext/templates/generators/item.html
@@ -8,108 +8,130 @@
{% block page_content %}
{% from "erpnext/templates/includes/macros.html" import product_image %}
-<div class="item-content" style="margin-top:20px;">
+<div class="item-content">
<div class="product-page-content" itemscope itemtype="http://schema.org/Product">
<div class="row">
- <div class="col-sm-6">
+ <div class="row">
{% if slideshow %}
- {% include "templates/includes/slideshow.html" %}
- {% else %}
- {{ product_image(website_image, "product-full-image") }}
- {% endif %}
- </div>
- <div class="col-sm-6" style="padding-left:20px;">
- <h2 itemprop="name" style="margin-top: 0px;">{{ item_name }}</h2>
-
- <p class="text-muted">
- {{ _("Item Code") }}: <span itemprop="productID">{{ variant and variant.name or name }}</span></p>
- <br>
- <div class="item-attribute-selectors">
- {% if has_variants %}
- {% for d in attributes %}
- {% if attribute_values[d.attribute] -%}
- <div class="item-view-attribute {% if (attribute_values[d.attribute] | len)==1 -%} hidden {%- endif %}"
- style="margin-bottom: 10px;">
- <h6 class="text-muted">{{ _(d.attribute) }}</h6>
- <select class="form-control"
- style="max-width: 140px"
- data-attribute="{{ d.attribute }}">
- {% for value in attribute_values[d.attribute] %}
- <option value="{{ value }}"
- {% if selected_attributes and selected_attributes[d.attribute]==value -%}
- selected
- {%- elif disabled_attributes and value in disabled_attributes.get(d.attribute, []) -%}
- disabled
- {%- endif %}>
- {{ _(value) }}
- </option>
- {% endfor %}
- </select>
+ {% set slideshow_items = frappe.get_list(doctype="Website Slideshow Item", fields=["image"], filters={ "parent": doc.slideshow }) %}
+ <div class="col-md-1">
+ {%- for slideshow_item in slideshow_items -%}
+ {% set image_src = slideshow_item['image'] %}
+ {% if image_src %}
+ <div class="item-alternative-image border">
+ <img src="{{ image_src }}" height="50" weight="50" />
</div>
- {%- endif %}
- {% endfor %}
{% endif %}
+ {% endfor %}
</div>
- <br>
- <div style="min-height: 100px; margin: 10px 0;">
- <div itemprop="offers" itemscope itemtype="http://schema.org/Offer">
- <h4 class="item-price hide" itemprop="price"></h4>
- <div class="item-stock hide" itemprop="availability"></div>
+ <div class="col-md-5">
+ <div class="item-image">
+ {% set first_image = slideshow_items[0]['image'] %}
+ {{ product_image(first_image, "product-full-image") }}
</div>
- <div class="item-cart hide">
- <div id="item-spinner">
- <span style="display: inline-block">
- <div class="input-group number-spinner">
- <span class="input-group-btn">
- <button class="btn btn-default cart-btn" data-dir="dwn">
- –</button>
- </span>
- <input class="form-control text-right cart-qty" value="1">
- <span class="input-group-btn">
- <button class="btn btn-default cart-btn" data-dir="up" style="margin-left:-2px;">
+ </div>
+ {% else %}
+ <div class="col-md-6">
+ {{ product_image(website_image, "product-full-image") }}
+ </div>
+ {% endif %}
+ <div class="col-sm-6">
+ <h2 itemprop="name">{{ item_name }}</h2>
+ <p class="text-muted">
+ {{ _("Item Code") }}: <span itemprop="productID">{{ variant and variant.name or name }}</span>
+ </p>
+ <br>
+ <div class="item-attribute-selectors">
+ {% if has_variants and attributes %}
+ {{ attributes }}
+ {#
+
+ {% for d in attributes %}
+ {% if attribute_values[d.attribute] -%}
+ <div class="item-view-attribute {% if (attribute_values[d.attribute] | len)==1 -%} hidden {%- endif %}"
+ style="margin-bottom: 10px;">
+ <h6 class="text-muted">{{ _(d.attribute) }}</h6>
+ <select class="form-control"
+ style="max-width: 140px"
+ data-attribute="{{ d.attribute }}">
+ {% for value in attribute_values[d.attribute] %}
+ <option value="{{ value }}"
+ {% if selected_attributes and selected_attributes[d.attribute]==value -%}
+ selected
+ {%- elif disabled_attributes and value in disabled_attributes.get(d.attribute, []) -%}
+ disabled
+ {%- endif %}>
+ {{ _(value) }}
+ </option>
+ {% endfor %}
+ </select>
+ </div>
+ {%- endif %}
+ {% endfor %}
+
+ #}
+ {% endif %}
+ </div>
+ <br>
+ <div>
+ <div itemprop="offers" itemscope itemtype="http://schema.org/Offer">
+ <h4 class="item-price hide" itemprop="price"></h4>
+ <div class="item-stock hide" itemprop="availability"></div>
+ </div>
+ <div class="item-cart hide">
+ <div id="item-spinner">
+ <span style="display: inline-block">
+ <div class="input-group number-spinner">
+ <span class="input-group-btn">
+ <button class="btn btn-default cart-btn" data-dir="dwn">
+ –</button>
+ </span>
+ <input class="form-control text-right cart-qty" value="1">
+ <span class="input-group-btn">
+ <button class="btn btn-default cart-btn" data-dir="up" style="margin-left:-2px;">
+</button>
- </span>
- </div>
- </span>
- </div>
- <div id="item-add-to-cart">
- <button class="btn btn-primary btn-sm">
- {{ _("Add to Cart") }}</button>
- </div>
- <div id="item-update-cart" style="display: none;">
- <a href="/cart" class='btn btn-sm btn-default'>
- <i class='octicon octicon-check'></i>
- {{ _("View in Cart") }}</a>
+ </span>
+ </div>
+ </span>
+ </div>
+ <div id="item-add-to-cart">
+ <button class="btn btn-primary btn-sm">
+ {{ _("Add to Cart") }}</button>
+ </div>
+ <div id="item-update-cart" style="display: none;">
+ <a href="/cart" class='btn btn-sm btn-default'>
+ <i class='octicon octicon-check'></i>
+ {{ _("View in Cart") }}</a>
+ </div>
</div>
</div>
</div>
</div>
- </div>
- <div class="row item-website-description" style="margin-top:30px; margin-bottom:20px">
- <div class="col-md-12">
- <div class="h6 text-uppercase">{{ _("Description") }}</div>
- <div itemprop="description" class="item-desc">
- {{ web_long_description or description or _("No description given") }}
- </div>
- </div>
- </div>
-
- {% if website_specifications -%}
- <div class="row item-website-specification" style="margin-top: 40px">
- <div class="col-md-12">
- <div class="h6 text-uppercase">{{ _("Specifications") }}</div>
-
- <table class="table borderless" style="width: 100%">
- {% for d in website_specifications -%}
- <tr>
- <td class="text-muted" style="width: 30%;">{{ d.label }}</td>
- <td>{{ d.description }}</td>
- </tr>
- {%- endfor %}
- </table>
+ <div class="row item-website-description margin-top">
+ <div class="col-md-12">
+ <div class="h6 text-uppercase">{{ _("Description") }}</div>
+ <div itemprop="description" class="item-desc">
+ {{ web_long_description or description or _("No description given") }}
+ </div>
+ </div>
</div>
+ {% if website_specifications -%}
+ <div class="row item-website-specification margin-top">
+ <div class="col-md-12">
+ <div class="h6 text-uppercase">{{ _("Specifications") }}</div>
+
+ <table class="table">
+ {% for d in website_specifications -%}
+ <tr>
+ <td class="text-muted" style="width: 30%;">{{ d.label }}</td>
+ <td>{{ d.description }}</td>
+ </tr>
+ {%- endfor %}
+ </table>
+ </div>
+ </div>
+ {%- endif %}
</div>
- {%- endif %}
</div>
</div>
<script>
diff --git a/erpnext/templates/includes/product_page.js b/erpnext/templates/includes/product_page.js
index 798a6cf..ef69e20 100644
--- a/erpnext/templates/includes/product_page.js
+++ b/erpnext/templates/includes/product_page.js
@@ -109,6 +109,13 @@
window.location.href = window.location.pathname + "?variant=" + item_code;
});
+
+ // change the item image src when alternate images are hovered
+ $(document.body).on('mouseover', '.item-alternative-image', (e) => {
+ const $alternative_image = $(e.currentTarget);
+ const src = $alternative_image.find('img').prop('src');
+ $('.item-image img').prop('src', src);
+ });
});
var toggle_update_cart = function(qty) {
diff --git a/erpnext/templates/pages/rfq.py b/erpnext/templates/pages/rfq.py
index aaf4110..62ec609 100644
--- a/erpnext/templates/pages/rfq.py
+++ b/erpnext/templates/pages/rfq.py
@@ -40,9 +40,9 @@
def update_supplier_details(context):
supplier_doc = frappe.get_doc("Supplier", context.doc.supplier)
- context.doc.currency = supplier_doc.default_currency or frappe.db.get_value("Company", context.doc.company, "default_currency")
- context.doc.currency_symbol = frappe.db.get_value("Currency", context.doc.currency, "symbol")
- context.doc.number_format = frappe.db.get_value("Currency", context.doc.currency, "number_format")
+ context.doc.currency = supplier_doc.default_currency or frappe.get_cached_value('Company', context.doc.company, "default_currency")
+ context.doc.currency_symbol = frappe.db.get_value("Currency", context.doc.currency, "symbol", cache=True)
+ context.doc.number_format = frappe.db.get_value("Currency", context.doc.currency, "number_format", cache=True)
context.doc.buying_price_list = supplier_doc.default_price_list or ''
def get_link_quotation(supplier, rfq):
diff --git a/erpnext/utilities/__init__.py b/erpnext/utilities/__init__.py
index 0f641b2..7912a59 100644
--- a/erpnext/utilities/__init__.py
+++ b/erpnext/utilities/__init__.py
@@ -27,7 +27,7 @@
company = company[0][0] if company else None
if company:
- domain = frappe.db.get_value('Company', cstr(company), 'domain')
+ domain = frappe.get_cached_value('Company', cstr(company), 'domain')
return {
'company': company,
diff --git a/erpnext/utilities/activation.py b/erpnext/utilities/activation.py
index b694ea6..8ad042b 100644
--- a/erpnext/utilities/activation.py
+++ b/erpnext/utilities/activation.py
@@ -54,7 +54,7 @@
if get_level() > 6:
return []
- domain = frappe.db.get_value('Company', erpnext.get_default_company(), 'domain')
+ domain = frappe.get_cached_value('Company', erpnext.get_default_company(), 'domain')
messages = []
message_settings = [
diff --git a/erpnext/utilities/product.py b/erpnext/utilities/product.py
index 02b0dfa..6f984a5 100644
--- a/erpnext/utilities/product.py
+++ b/erpnext/utilities/product.py
@@ -20,10 +20,10 @@
if warehouse:
stock_qty = frappe.db.sql("""
- select GREATEST(S.actual_qty - S.reserved_qty - S.reserved_qty_for_production - S.reserved_qty_for_sub_contract, 0) / IFNULL(C.conversion_factor, 1)
+ select GREATEST(S.actual_qty - S.reserved_qty - S.reserved_qty_for_production - S.reserved_qty_for_sub_contract, 0) / IFNULL(C.conversion_factor, 1)
from tabBin S
inner join `tabItem` I on S.item_code = I.Item_code
- left join `tabUOM Conversion Detail` C on I.sales_uom = C.uom and C.parent = I.Item_code
+ left join `tabUOM Conversion Detail` C on I.sales_uom = C.uom and C.parent = I.Item_code
where S.item_code=%s and S.warehouse=%s""", (item_code, warehouse))
if stock_qty:
@@ -37,7 +37,7 @@
batches = frappe.get_all('Batch', filters=[{'item': item_code}], fields=['expiry_date', 'name'])
expired_batches = get_expired_batches(batches)
stock_qty = [list(item) for item in stock_qty]
-
+
for batch in expired_batches:
if warehouse:
stock_qty[0][0] = max(0, stock_qty[0][0] - get_batch_qty(batch, warehouse))
@@ -103,7 +103,7 @@
price_obj["formatted_price"] = fmt_money(price_obj["price_list_rate"], currency=price_obj["currency"])
price_obj["currency_symbol"] = not cint(frappe.db.get_default("hide_currency_symbol")) \
- and (frappe.db.get_value("Currency", price_obj.currency, "symbol") or price_obj.currency) \
+ and (frappe.db.get_value("Currency", price_obj.currency, "symbol", cache=True) or price_obj.currency) \
or ""
uom_conversion_factor = frappe.db.sql("""select C.conversion_factor
diff --git a/erpnext/utilities/transaction_base.py b/erpnext/utilities/transaction_base.py
index d3769a2..6ca3d5b 100644
--- a/erpnext/utilities/transaction_base.py
+++ b/erpnext/utilities/transaction_base.py
@@ -144,7 +144,7 @@
distinct_uoms = list(set([d.get(uom_field) for d in doc.get_all_children()]))
integer_uoms = filter(lambda uom: frappe.db.get_value("UOM", uom,
- "must_be_whole_number") or None, distinct_uoms)
+ "must_be_whole_number", cache=True) or None, distinct_uoms)
if not integer_uoms:
return
diff --git a/erpnext/utilities/user_progress.py b/erpnext/utilities/user_progress.py
index ae156b8..2901d52 100644
--- a/erpnext/utilities/user_progress.py
+++ b/erpnext/utilities/user_progress.py
@@ -7,7 +7,7 @@
def get_slide_settings():
defaults = frappe.defaults.get_defaults()
- domain = frappe.db.get_value('Company', erpnext.get_default_company(), 'domain')
+ domain = frappe.get_cached_value('Company', erpnext.get_default_company(), 'domain')
company = defaults.get("company") or ''
currency = defaults.get("currency") or ''
diff --git a/erpnext/utilities/user_progress_utils.py b/erpnext/utilities/user_progress_utils.py
index 0377a0a..a665c5d 100644
--- a/erpnext/utilities/user_progress_utils.py
+++ b/erpnext/utilities/user_progress_utils.py
@@ -234,6 +234,6 @@
@frappe.whitelist()
def update_default_domain_actions_and_get_state():
- domain = frappe.db.get_value('Company', erpnext.get_default_company(), 'domain')
+ domain = frappe.get_cached_value('Company', erpnext.get_default_company(), 'domain')
update_domain_actions(domain)
return get_domain_actions_state(domain)