optimize(various)

This commit is contained in:
Rushabh Mehta
2018-08-08 16:37:31 +05:30
parent 4d0b8da0e5
commit 708e47aadf
90 changed files with 254 additions and 250 deletions

View File

@@ -400,7 +400,7 @@ class AccountsController(TransactionBase):
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 @@ class AccountsController(TransactionBase):
@property
def company_abbr(self):
if not hasattr(self, "_abbr"):
self._abbr = frappe.db.get_value("Company", self.company, "abbr")
self._abbr = frappe.get_cached_value('Company', self.company, "abbr")
return self._abbr
@@ -841,7 +841,7 @@ def get_taxes_and_charges(master_doctype, master_name):
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(

View File

@@ -12,7 +12,7 @@ def print_settings_for_item_table(doc):
}
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"

View File

@@ -8,6 +8,7 @@ from frappe import _, throw
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 @@ class SellingController(StockController):
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)
@@ -349,24 +350,8 @@ class SellingController(StockController):
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)