Replaced doc, doc.fields frappe/frappe#478
This commit is contained in:
@@ -17,9 +17,9 @@ class BuyingController(StockController):
|
||||
|
||||
def validate(self):
|
||||
super(BuyingController, self).validate()
|
||||
if self.doc.supplier and not self.doc.supplier_name:
|
||||
self.doc.supplier_name = frappe.db.get_value("Supplier",
|
||||
self.doc.supplier, "supplier_name")
|
||||
if self.supplier and not self.supplier_name:
|
||||
self.supplier_name = frappe.db.get_value("Supplier",
|
||||
self.supplier, "supplier_name")
|
||||
self.is_item_table_empty()
|
||||
self.validate_stock_or_nonstock_items()
|
||||
self.validate_warehouse()
|
||||
@@ -31,19 +31,19 @@ class BuyingController(StockController):
|
||||
self.set_price_list_currency("Buying")
|
||||
|
||||
# set contact and address details for supplier, if they are not mentioned
|
||||
if self.doc.supplier:
|
||||
self.doc.update_if_missing(get_party_details(self.doc.supplier, party_type="Supplier"))
|
||||
if self.supplier:
|
||||
self.update_if_missing(get_party_details(self.supplier, party_type="Supplier"))
|
||||
|
||||
self.set_missing_item_details()
|
||||
if self.doc.fields.get("__islocal"):
|
||||
if self.get("__islocal"):
|
||||
self.set_taxes("other_charges", "taxes_and_charges")
|
||||
|
||||
def set_supplier_from_item_default(self):
|
||||
if self.meta.get_field("supplier") and not self.doc.supplier:
|
||||
if self.meta.get_field("supplier") and not self.supplier:
|
||||
for d in self.doclist.get({"doctype": self.tname}):
|
||||
supplier = frappe.db.get_value("Item", d.item_code, "default_supplier")
|
||||
if supplier:
|
||||
self.doc.supplier = supplier
|
||||
self.supplier = supplier
|
||||
break
|
||||
|
||||
def validate_warehouse(self):
|
||||
@@ -53,7 +53,7 @@ class BuyingController(StockController):
|
||||
self.doclist.get({"doctype": self.tname}) if d.warehouse]))
|
||||
|
||||
for w in warehouses:
|
||||
validate_warehouse_company(w, self.doc.company)
|
||||
validate_warehouse_company(w, self.company)
|
||||
|
||||
def validate_stock_or_nonstock_items(self):
|
||||
if not self.get_stock_items():
|
||||
@@ -65,12 +65,12 @@ class BuyingController(StockController):
|
||||
|
||||
def set_total_in_words(self):
|
||||
from frappe.utils import money_in_words
|
||||
company_currency = get_company_currency(self.doc.company)
|
||||
company_currency = get_company_currency(self.company)
|
||||
if self.meta.get_field("in_words"):
|
||||
self.doc.in_words = money_in_words(self.doc.grand_total, company_currency)
|
||||
self.in_words = money_in_words(self.grand_total, company_currency)
|
||||
if self.meta.get_field("in_words_import"):
|
||||
self.doc.in_words_import = money_in_words(self.doc.grand_total_import,
|
||||
self.doc.currency)
|
||||
self.in_words_import = money_in_words(self.grand_total_import,
|
||||
self.currency)
|
||||
|
||||
def calculate_taxes_and_totals(self):
|
||||
self.other_fname = "other_charges"
|
||||
@@ -97,54 +97,54 @@ class BuyingController(StockController):
|
||||
|
||||
|
||||
def calculate_net_total(self):
|
||||
self.doc.net_total = self.doc.net_total_import = 0.0
|
||||
self.net_total = self.net_total_import = 0.0
|
||||
|
||||
for item in self.item_doclist:
|
||||
self.doc.net_total += item.base_amount
|
||||
self.doc.net_total_import += item.amount
|
||||
self.net_total += item.base_amount
|
||||
self.net_total_import += item.amount
|
||||
|
||||
self.round_floats_in(self.doc, ["net_total", "net_total_import"])
|
||||
|
||||
def calculate_totals(self):
|
||||
self.doc.grand_total = flt(self.tax_doclist[-1].total if self.tax_doclist
|
||||
else self.doc.net_total, self.precision("grand_total"))
|
||||
self.doc.grand_total_import = flt(self.doc.grand_total / self.doc.conversion_rate,
|
||||
self.grand_total = flt(self.tax_doclist[-1].total if self.tax_doclist
|
||||
else self.net_total, self.precision("grand_total"))
|
||||
self.grand_total_import = flt(self.grand_total / self.conversion_rate,
|
||||
self.precision("grand_total_import"))
|
||||
|
||||
self.doc.total_tax = flt(self.doc.grand_total - self.doc.net_total,
|
||||
self.total_tax = flt(self.grand_total - self.net_total,
|
||||
self.precision("total_tax"))
|
||||
|
||||
if self.meta.get_field("rounded_total"):
|
||||
self.doc.rounded_total = _round(self.doc.grand_total)
|
||||
self.rounded_total = _round(self.grand_total)
|
||||
|
||||
if self.meta.get_field("rounded_total_import"):
|
||||
self.doc.rounded_total_import = _round(self.doc.grand_total_import)
|
||||
self.rounded_total_import = _round(self.grand_total_import)
|
||||
|
||||
if self.meta.get_field("other_charges_added"):
|
||||
self.doc.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.tax_doclist
|
||||
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.doc.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.tax_doclist
|
||||
if d.add_deduct_tax=="Deduct" and d.category in ["Valuation and Total", "Total"]]),
|
||||
self.precision("other_charges_deducted"))
|
||||
|
||||
if self.meta.get_field("other_charges_added_import"):
|
||||
self.doc.other_charges_added_import = flt(self.doc.other_charges_added /
|
||||
self.doc.conversion_rate, self.precision("other_charges_added_import"))
|
||||
self.other_charges_added_import = flt(self.other_charges_added /
|
||||
self.conversion_rate, self.precision("other_charges_added_import"))
|
||||
|
||||
if self.meta.get_field("other_charges_deducted_import"):
|
||||
self.doc.other_charges_deducted_import = flt(self.doc.other_charges_deducted /
|
||||
self.doc.conversion_rate, self.precision("other_charges_deducted_import"))
|
||||
self.other_charges_deducted_import = flt(self.other_charges_deducted /
|
||||
self.conversion_rate, self.precision("other_charges_deducted_import"))
|
||||
|
||||
def calculate_outstanding_amount(self):
|
||||
if self.doc.doctype == "Purchase Invoice" and self.doc.docstatus == 0:
|
||||
self.doc.total_advance = flt(self.doc.total_advance,
|
||||
if self.doctype == "Purchase Invoice" and self.docstatus == 0:
|
||||
self.total_advance = flt(self.total_advance,
|
||||
self.precision("total_advance"))
|
||||
self.doc.total_amount_to_pay = flt(self.doc.grand_total - flt(self.doc.write_off_amount,
|
||||
self.total_amount_to_pay = flt(self.grand_total - flt(self.write_off_amount,
|
||||
self.precision("write_off_amount")), self.precision("total_amount_to_pay"))
|
||||
self.doc.outstanding_amount = flt(self.doc.total_amount_to_pay - self.doc.total_advance,
|
||||
self.outstanding_amount = flt(self.total_amount_to_pay - self.total_advance,
|
||||
self.precision("outstanding_amount"))
|
||||
|
||||
def _cleanup(self):
|
||||
@@ -208,18 +208,18 @@ class BuyingController(StockController):
|
||||
item.valuation_rate = 0.0
|
||||
|
||||
def validate_for_subcontracting(self):
|
||||
if not self.doc.is_subcontracted and self.sub_contracted_items:
|
||||
if not self.is_subcontracted and self.sub_contracted_items:
|
||||
frappe.msgprint(_("""Please enter whether %s is made for subcontracting or purchasing,
|
||||
in 'Is Subcontracted' field""" % self.doc.doctype), raise_exception=1)
|
||||
in 'Is Subcontracted' field""" % self.doctype), raise_exception=1)
|
||||
|
||||
if self.doc.doctype == "Purchase Receipt" and self.doc.is_subcontracted=="Yes" \
|
||||
and not self.doc.supplier_warehouse:
|
||||
if self.doctype == "Purchase Receipt" and self.is_subcontracted=="Yes" \
|
||||
and not self.supplier_warehouse:
|
||||
frappe.msgprint(_("Supplier Warehouse mandatory subcontracted purchase receipt"),
|
||||
raise_exception=1)
|
||||
|
||||
def update_raw_materials_supplied(self, raw_material_table):
|
||||
self.set(raw_material_table, [])
|
||||
if self.doc.is_subcontracted=="Yes":
|
||||
if self.is_subcontracted=="Yes":
|
||||
for item in self.get(self.fname):
|
||||
if item.item_code in self.sub_contracted_items:
|
||||
self.add_bom_items(item, raw_material_table)
|
||||
@@ -230,7 +230,7 @@ class BuyingController(StockController):
|
||||
for item in bom_items:
|
||||
required_qty = flt(item.qty_consumed_per_unit) * flt(d.qty) * flt(d.conversion_factor)
|
||||
rm_doclist = {
|
||||
"doctype": self.doc.doctype + " Item Supplied",
|
||||
"doctype": self.doctype + " Item Supplied",
|
||||
"reference_name": d.name,
|
||||
"bom_detail_no": item.name,
|
||||
"main_item_code": d.item_code,
|
||||
@@ -241,7 +241,7 @@ class BuyingController(StockController):
|
||||
"rate": item.rate,
|
||||
"amount": required_qty * flt(item.rate)
|
||||
}
|
||||
if self.doc.doctype == "Purchase Receipt":
|
||||
if self.doctype == "Purchase Receipt":
|
||||
rm_doclist.update({
|
||||
"consumed_qty": required_qty,
|
||||
"description": item.description,
|
||||
@@ -251,7 +251,7 @@ class BuyingController(StockController):
|
||||
|
||||
raw_materials_cost += required_qty * flt(item.rate)
|
||||
|
||||
if self.doc.doctype == "Purchase Receipt":
|
||||
if self.doctype == "Purchase Receipt":
|
||||
d.rm_supp_cost = raw_materials_cost
|
||||
|
||||
def get_items_from_default_bom(self, item_code):
|
||||
|
||||
Reference in New Issue
Block a user