Removed tname and fname from code

This commit is contained in:
Nabin Hait
2014-12-26 13:15:21 +05:30
parent 79f091e2fe
commit dd38a266b8
37 changed files with 168 additions and 279 deletions

View File

@@ -102,12 +102,12 @@ class AccountsController(TransactionBase):
def set_missing_item_details(self):
"""set missing item values"""
from erpnext.stock.get_item_details import get_item_details
if hasattr(self, "fname"):
if hasattr(self, "items"):
parent_dict = {}
for fieldname in self.meta.get_valid_columns():
parent_dict[fieldname] = self.get(fieldname)
for item in self.get(self.fname):
for item in self.get("items"):
if item.get("item_code"):
args = parent_dict.copy()
args.update(item.as_dict())
@@ -166,8 +166,6 @@ class AccountsController(TransactionBase):
self.meta.get_label("conversion_rate"), self.company)
self.conversion_rate = flt(self.conversion_rate)
self.item_doclist = self.get(self.fname)
self.tax_doclist = self.get(self.other_fname)
self.calculate_item_values()
self.initialize_taxes()
@@ -181,7 +179,7 @@ class AccountsController(TransactionBase):
self._cleanup()
def initialize_taxes(self):
for tax in self.tax_doclist:
for tax in self.get("taxes"):
tax.item_wise_tax_detail = {}
tax_fields = ["total", "tax_amount_after_discount_amount",
"tax_amount_for_current_item", "grand_total_for_current_item",
@@ -216,30 +214,30 @@ class AccountsController(TransactionBase):
# inclusive tax cannot be of type Actual
throw(_("Charge of type 'Actual' in row {0} cannot be included in Item Rate").format(tax.idx))
elif tax.charge_type == "On Previous Row Amount" and \
not cint(self.tax_doclist[cint(tax.row_id) - 1].included_in_print_rate):
not cint(self.get("taxes")[cint(tax.row_id) - 1].included_in_print_rate):
# referred row should also be inclusive
_on_previous_row_error(tax.row_id)
elif tax.charge_type == "On Previous Row Total" and \
not all([cint(t.included_in_print_rate) for t in self.tax_doclist[:cint(tax.row_id) - 1]]):
not all([cint(t.included_in_print_rate) for t in self.get("taxes")[:cint(tax.row_id) - 1]]):
# all rows about the reffered tax should be inclusive
_on_previous_row_error("1 - %d" % (tax.row_id,))
def calculate_taxes(self):
# maintain actual tax rate based on idx
actual_tax_dict = dict([[tax.idx, flt(tax.rate, self.precision("tax_amount", tax))] for tax in self.tax_doclist
actual_tax_dict = dict([[tax.idx, flt(tax.rate, self.precision("tax_amount", tax))] for tax in self.get("taxes")
if tax.charge_type == "Actual"])
for n, item in enumerate(self.item_doclist):
for n, item in enumerate(self.get("items")):
item_tax_map = self._load_item_tax_rate(item.item_tax_rate)
for i, tax in enumerate(self.tax_doclist):
for i, tax in enumerate(self.get("taxes")):
# tax_amount represents the amount of tax for the current step
current_tax_amount = self.get_current_tax_amount(item, tax, item_tax_map)
# Adjust divisional loss to the last item
if tax.charge_type == "Actual":
actual_tax_dict[tax.idx] -= current_tax_amount
if n == len(self.item_doclist) - 1:
if n == len(self.get("items")) - 1:
current_tax_amount += actual_tax_dict[tax.idx]
# store tax_amount for current item as it will be used for
@@ -268,18 +266,18 @@ class AccountsController(TransactionBase):
self.precision("total", tax))
else:
tax.grand_total_for_current_item = \
flt(self.tax_doclist[i-1].grand_total_for_current_item +
flt(self.get("taxes")[i-1].grand_total_for_current_item +
current_tax_amount, self.precision("total", tax))
# in tax.total, accumulate grand total of each item
tax.total += tax.grand_total_for_current_item
# set precision in the last item iteration
if n == len(self.item_doclist) - 1:
if n == len(self.get("items")) - 1:
self.round_off_totals(tax)
# adjust Discount Amount loss in last tax iteration
if i == (len(self.tax_doclist) - 1) and self.discount_amount_applied:
if i == (len(self.get("taxes")) - 1) and self.discount_amount_applied:
self.adjust_discount_amount_loss(tax)
def round_off_totals(self, tax):
@@ -308,10 +306,10 @@ class AccountsController(TransactionBase):
current_tax_amount = (tax_rate / 100.0) * item.base_amount
elif tax.charge_type == "On Previous Row Amount":
current_tax_amount = (tax_rate / 100.0) * \
self.tax_doclist[cint(tax.row_id) - 1].tax_amount_for_current_item
self.get("taxes")[cint(tax.row_id) - 1].tax_amount_for_current_item
elif tax.charge_type == "On Previous Row Total":
current_tax_amount = (tax_rate / 100.0) * \
self.tax_doclist[cint(tax.row_id) - 1].grand_total_for_current_item
self.get("taxes")[cint(tax.row_id) - 1].grand_total_for_current_item
current_tax_amount = flt(current_tax_amount, self.precision("tax_amount", tax))
@@ -335,7 +333,7 @@ class AccountsController(TransactionBase):
return tax.rate
def _cleanup(self):
for tax in self.tax_doclist:
for tax in self.get("taxes"):
tax.item_wise_tax_detail = json.dumps(tax.item_wise_tax_detail, separators=(',', ':'))
def _set_in_company_currency(self, item, print_field, base_field):
@@ -461,7 +459,7 @@ class AccountsController(TransactionBase):
else:
already_billed = frappe.db.sql("""select sum(%s) from `tab%s`
where %s=%s and docstatus=1 and parent != %s""" %
(based_on, self.tname, item_ref_dn, '%s', '%s'),
(based_on, self.doctype + " Item", item_ref_dn, '%s', '%s'),
(item.get(item_ref_dn), self.name))[0][0]
total_billed_amt = flt(flt(already_billed) + flt(item.get(based_on)),
@@ -481,7 +479,7 @@ class AccountsController(TransactionBase):
def get_stock_items(self):
stock_items = []
item_codes = list(set(item.item_code for item in self.get(self.fname)))
item_codes = list(set(item.item_code for item in self.get("items")))
if item_codes:
stock_items = [r[0] for r in frappe.db.sql("""select name
from `tabItem` where name in (%s) and is_stock_item='Yes'""" % \

View File

@@ -14,9 +14,9 @@ from erpnext.controllers.stock_controller import StockController
class BuyingController(StockController):
def __setup__(self):
if hasattr(self, "fname"):
if hasattr(self, "items"):
self.table_print_templates = {
self.fname: "templates/print_formats/includes/item_grid.html",
"items": "templates/print_formats/includes/item_grid.html",
"taxes": "templates/print_formats/includes/taxes.html",
}
@@ -50,7 +50,7 @@ class BuyingController(StockController):
def set_supplier_from_item_default(self):
if self.meta.get_field("supplier") and not self.supplier:
for d in self.get(self.fname):
for d in self.get("items"):
supplier = frappe.db.get_value("Item", d.item_code, "default_supplier")
if supplier:
self.supplier = supplier
@@ -60,7 +60,7 @@ class BuyingController(StockController):
from erpnext.stock.utils import validate_warehouse_company
warehouses = list(set([d.warehouse for d in
self.get(self.fname) if getattr(d, "warehouse", None)]))
self.get("items") if getattr(d, "warehouse", None)]))
for w in warehouses:
validate_warehouse_company(w, self.company)
@@ -82,12 +82,11 @@ class BuyingController(StockController):
self.currency)
def calculate_taxes_and_totals(self):
self.other_fname = "taxes"
super(BuyingController, self).calculate_taxes_and_totals()
self.calculate_total_advance("Purchase Invoice", "advances")
def calculate_item_values(self):
for item in self.item_doclist:
for item in self.get("items"):
self.round_floats_in(item)
if item.discount_percentage == 100.0:
@@ -108,14 +107,14 @@ class BuyingController(StockController):
def calculate_net_total(self):
self.net_total = self.net_total_import = 0.0
for item in self.item_doclist:
for item in self.get("items"):
self.net_total += item.base_amount
self.net_total_import += item.amount
self.round_floats_in(self, ["net_total", "net_total_import"])
def calculate_totals(self):
self.grand_total = flt(self.tax_doclist[-1].total if self.tax_doclist else self.net_total)
self.grand_total = flt(self.get("taxes")[-1].total if self.get("taxes") else self.net_total)
self.grand_total_import = flt(self.grand_total / self.conversion_rate)
self.total_tax = flt(self.grand_total - self.net_total, self.precision("total_tax"))
@@ -130,12 +129,12 @@ class BuyingController(StockController):
self.rounded_total_import = rounded(self.grand_total_import)
if self.meta.get_field("other_charges_added"):
self.other_charges_added = flt(sum([flt(d.tax_amount) for d in self.tax_doclist
self.other_charges_added = flt(sum([flt(d.tax_amount) for d in self.get("taxes")
if d.add_deduct_tax=="Add" and d.category in ["Valuation and Total", "Total"]]),
self.precision("other_charges_added"))
if self.meta.get_field("other_charges_deducted"):
self.other_charges_deducted = flt(sum([flt(d.tax_amount) for d in self.tax_doclist
self.other_charges_deducted = flt(sum([flt(d.tax_amount) for d in self.get("taxes")
if d.add_deduct_tax=="Deduct" and d.category in ["Valuation and Total", "Total"]]),
self.precision("other_charges_deducted"))
@@ -216,12 +215,12 @@ class BuyingController(StockController):
if self.doctype == "Purchase Receipt" and not self.supplier_warehouse:
frappe.throw(_("Supplier Warehouse mandatory for sub-contracted Purchase Receipt"))
for item in self.get(self.fname):
for item in self.get("items"):
if item in self.sub_contracted_items and not item.bom:
frappe.throw(_("Please select BOM in BOM field for Item {0}").format(item.item_code))
else:
for item in self.get(self.fname):
for item in self.get("items"):
if item.bom:
item.bom = None
@@ -229,7 +228,7 @@ class BuyingController(StockController):
if self.is_subcontracted=="Yes":
parent_items = []
rm_supplied_idx = 0
for item in self.get(self.fname):
for item in self.get("items"):
if self.doctype == "Purchase Receipt":
item.rm_supp_cost = 0.0
if item.item_code in self.sub_contracted_items:
@@ -241,7 +240,7 @@ class BuyingController(StockController):
self.cleanup_raw_materials_supplied(parent_items, raw_material_table)
elif self.doctype == "Purchase Receipt":
for item in self.get(self.fname):
for item in self.get("items"):
item.rm_supp_cost = 0.0
def update_raw_materials_supplied(self, item, raw_material_table, rm_supplied_idx):
@@ -336,7 +335,7 @@ class BuyingController(StockController):
if not hasattr(self, "_sub_contracted_items"):
self._sub_contracted_items = []
item_codes = list(set(item.item_code for item in
self.get(self.fname)))
self.get("items")))
if item_codes:
self._sub_contracted_items = [r[0] for r in frappe.db.sql("""select name
from `tabItem` where name in (%s) and is_sub_contracted_item='Yes'""" % \
@@ -349,7 +348,7 @@ class BuyingController(StockController):
if not hasattr(self, "_purchase_items"):
self._purchase_items = []
item_codes = list(set(item.item_code for item in
self.get(self.fname)))
self.get("items")))
if item_codes:
self._purchase_items = [r[0] for r in frappe.db.sql("""select name
from `tabItem` where name in (%s) and is_purchase_item='Yes'""" % \
@@ -359,11 +358,11 @@ class BuyingController(StockController):
def is_item_table_empty(self):
if not len(self.get(self.fname)):
if not len(self.get("items")):
frappe.throw(_("Item table can not be blank"))
def set_qty_as_per_stock_uom(self):
for d in self.get(self.fname):
for d in self.get("items"):
if d.meta.get_field("stock_qty") and not d.stock_qty:
if not d.conversion_factor:
frappe.throw(_("Row {0}: Conversion Factor is mandatory"))

View File

@@ -12,9 +12,9 @@ from erpnext.controllers.stock_controller import StockController
class SellingController(StockController):
def __setup__(self):
if hasattr(self, "fname"):
if hasattr(self, "items"):
self.table_print_templates = {
self.fname: "templates/print_formats/includes/item_grid.html",
"items": "templates/print_formats/includes/item_grid.html",
"taxes": "templates/print_formats/includes/taxes.html",
}
@@ -24,7 +24,7 @@ class SellingController(StockController):
def onload(self):
if self.doctype in ("Sales Order", "Delivery Note", "Sales Invoice"):
for item in self.get(self.fname):
for item in self.get("items"):
item.update(get_available_qty(item.item_code,
item.warehouse))
@@ -124,8 +124,6 @@ class SellingController(StockController):
self.grand_total_export or self.rounded_total_export, self.currency)
def calculate_taxes_and_totals(self):
self.other_fname = "taxes"
super(SellingController, self).calculate_taxes_and_totals()
self.calculate_total_advance("Sales Invoice", "advances")
@@ -133,21 +131,21 @@ class SellingController(StockController):
self.calculate_contribution()
def determine_exclusive_rate(self):
if not any((cint(tax.included_in_print_rate) for tax in self.tax_doclist)):
if not any((cint(tax.included_in_print_rate) for tax in self.get("taxes"))):
# no inclusive tax
return
for item in self.item_doclist:
for item in self.get("items"):
item_tax_map = self._load_item_tax_rate(item.item_tax_rate)
cumulated_tax_fraction = 0
for i, tax in enumerate(self.tax_doclist):
for i, tax in enumerate(self.get("taxes")):
tax.tax_fraction_for_current_item = self.get_current_tax_fraction(tax, item_tax_map)
if i==0:
tax.grand_total_fraction_for_current_item = 1 + tax.tax_fraction_for_current_item
else:
tax.grand_total_fraction_for_current_item = \
self.tax_doclist[i-1].grand_total_fraction_for_current_item \
self.get("taxes")[i-1].grand_total_fraction_for_current_item \
+ tax.tax_fraction_for_current_item
cumulated_tax_fraction += tax.tax_fraction_for_current_item
@@ -181,17 +179,17 @@ class SellingController(StockController):
elif tax.charge_type == "On Previous Row Amount":
current_tax_fraction = (tax_rate / 100.0) * \
self.tax_doclist[cint(tax.row_id) - 1].tax_fraction_for_current_item
self.get("taxes")[cint(tax.row_id) - 1].tax_fraction_for_current_item
elif tax.charge_type == "On Previous Row Total":
current_tax_fraction = (tax_rate / 100.0) * \
self.tax_doclist[cint(tax.row_id) - 1].grand_total_fraction_for_current_item
self.get("taxes")[cint(tax.row_id) - 1].grand_total_fraction_for_current_item
return current_tax_fraction
def calculate_item_values(self):
if not self.discount_amount_applied:
for item in self.item_doclist:
for item in self.get("items"):
self.round_floats_in(item)
if item.discount_percentage == 100:
@@ -210,14 +208,14 @@ class SellingController(StockController):
def calculate_net_total(self):
self.net_total = self.net_total_export = 0.0
for item in self.item_doclist:
for item in self.get("items"):
self.net_total += item.base_amount
self.net_total_export += item.amount
self.round_floats_in(self, ["net_total", "net_total_export"])
def calculate_totals(self):
self.grand_total = flt(self.tax_doclist[-1].total if self.tax_doclist else self.net_total)
self.grand_total = flt(self.get("taxes")[-1].total if self.get("taxes") else self.net_total)
self.grand_total_export = flt(self.grand_total / self.conversion_rate)
@@ -238,7 +236,7 @@ class SellingController(StockController):
if grand_total_for_discount_amount:
# calculate item amount after Discount Amount
for item in self.item_doclist:
for item in self.get("items"):
distributed_amount = flt(self.discount_amount) * item.base_amount / grand_total_for_discount_amount
item.base_amount = flt(item.base_amount - distributed_amount, self.precision("base_amount", item))
@@ -248,7 +246,7 @@ class SellingController(StockController):
def get_grand_total_for_discount_amount(self):
actual_taxes_dict = {}
for tax in self.tax_doclist:
for tax in self.get("taxes"):
if tax.charge_type == "Actual":
actual_taxes_dict.setdefault(tax.idx, tax.tax_amount)
elif tax.row_id in actual_taxes_dict:
@@ -306,7 +304,7 @@ class SellingController(StockController):
throw(_("Order Type must be one of {0}").format(comma_or(valid_types)))
def validate_max_discount(self):
for d in self.get(self.fname):
for d in self.get("items"):
discount = flt(frappe.db.get_value("Item", d.item_code, "max_discount"))
if discount and flt(d.discount_percentage) > discount:
@@ -314,7 +312,7 @@ class SellingController(StockController):
def get_item_list(self):
il = []
for d in self.get(self.fname):
for d in self.get("items"):
reserved_warehouse = ""
reserved_qty_for_main_item = 0
@@ -390,14 +388,14 @@ class SellingController(StockController):
return so_qty, so_warehouse
def check_stop_sales_order(self, ref_fieldname):
for d in self.get(self.fname):
for d in self.get("items"):
if d.get(ref_fieldname):
status = frappe.db.get_value("Sales Order", d.get(ref_fieldname), "status")
if status == "Stopped":
frappe.throw(_("Sales Order {0} is stopped").format(d.get(ref_fieldname)))
def check_active_sales_items(obj):
for d in obj.get(obj.fname):
for d in obj.get("items"):
if d.item_code:
item = frappe.db.sql("""select docstatus, is_sales_item,
is_service_item, income_account from tabItem where name = %s""",

View File

@@ -77,7 +77,7 @@ class StockController(AccountsController):
return [frappe._dict({ "name": voucher_detail_no, "expense_account": default_expense_account,
"cost_center": default_cost_center }) for voucher_detail_no, sle in sle_map.items()]
else:
details = self.get(self.fname)
details = self.get("items")
if default_expense_account or default_cost_center:
for d in details:
@@ -91,8 +91,8 @@ class StockController(AccountsController):
def get_items_and_warehouses(self):
items, warehouses = [], []
if hasattr(self, "fname"):
item_doclist = self.get(self.fname)
if hasattr(self, "items"):
item_doclist = self.get("items")
elif self.doctype == "Stock Reconciliation":
import json
item_doclist = []
@@ -208,7 +208,7 @@ class StockController(AccountsController):
def get_serialized_items(self):
serialized_items = []
item_codes = list(set([d.item_code for d in self.get(self.fname)]))
item_codes = list(set([d.item_code for d in self.get("items")]))
if item_codes:
serialized_items = frappe.db.sql_list("""select name from `tabItem`
where has_serial_no='Yes' and name in ({})""".format(", ".join(["%s"]*len(item_codes))),