2013-11-20 07:29:58 +00:00
|
|
|
# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors
|
2013-08-05 09:29:54 +00:00
|
|
|
# License: GNU General Public License v3. See license.txt
|
2013-01-15 13:09:21 +00:00
|
|
|
|
|
|
|
from __future__ import unicode_literals
|
2014-02-14 10:17:51 +00:00
|
|
|
import frappe
|
|
|
|
from frappe import _, msgprint
|
|
|
|
from frappe.utils import flt, _round
|
2013-12-12 13:42:19 +00:00
|
|
|
from erpnext.setup.utils import get_company_currency
|
2014-02-03 10:44:56 +00:00
|
|
|
from erpnext.accounts.party import get_party_details
|
2013-01-15 13:09:21 +00:00
|
|
|
|
2013-12-12 13:42:19 +00:00
|
|
|
from erpnext.controllers.stock_controller import StockController
|
2013-01-30 07:19:08 +00:00
|
|
|
|
2013-03-19 06:31:46 +00:00
|
|
|
class BuyingController(StockController):
|
2013-03-20 07:25:28 +00:00
|
|
|
def validate(self):
|
|
|
|
super(BuyingController, self).validate()
|
2014-04-03 12:08:54 +00:00
|
|
|
if getattr(self, "supplier", None) and not self.supplier_name:
|
2014-04-14 13:50:45 +00:00
|
|
|
self.supplier_name = frappe.db.get_value("Supplier",
|
2014-03-28 08:25:00 +00:00
|
|
|
self.supplier, "supplier_name")
|
2013-10-18 11:30:53 +00:00
|
|
|
self.is_item_table_empty()
|
2013-04-26 08:05:06 +00:00
|
|
|
self.validate_stock_or_nonstock_items()
|
2013-10-10 10:34:40 +00:00
|
|
|
self.validate_warehouse()
|
2014-04-14 13:50:45 +00:00
|
|
|
|
2013-05-24 13:55:01 +00:00
|
|
|
def set_missing_values(self, for_validate=False):
|
2013-06-14 12:14:03 +00:00
|
|
|
super(BuyingController, self).set_missing_values(for_validate)
|
|
|
|
|
2013-08-09 09:59:59 +00:00
|
|
|
self.set_supplier_from_item_default()
|
2013-10-17 11:31:14 +00:00
|
|
|
self.set_price_list_currency("Buying")
|
2014-04-14 13:50:45 +00:00
|
|
|
|
2013-05-24 13:55:01 +00:00
|
|
|
# set contact and address details for supplier, if they are not mentioned
|
2014-04-03 12:08:54 +00:00
|
|
|
if getattr(self, "supplier", None):
|
2014-03-28 08:25:00 +00:00
|
|
|
self.update_if_missing(get_party_details(self.supplier, party_type="Supplier"))
|
2013-07-08 06:38:06 +00:00
|
|
|
|
2014-02-11 10:44:52 +00:00
|
|
|
self.set_missing_item_details()
|
2014-03-28 08:25:00 +00:00
|
|
|
if self.get("__islocal"):
|
2014-01-29 11:01:38 +00:00
|
|
|
self.set_taxes("other_charges", "taxes_and_charges")
|
2013-07-08 07:07:59 +00:00
|
|
|
|
2013-08-09 09:59:59 +00:00
|
|
|
def set_supplier_from_item_default(self):
|
2014-03-28 08:25:00 +00:00
|
|
|
if self.meta.get_field("supplier") and not self.supplier:
|
2014-04-02 12:39:34 +00:00
|
|
|
for d in self.get(self.fname):
|
2014-02-26 07:05:33 +00:00
|
|
|
supplier = frappe.db.get_value("Item", d.item_code, "default_supplier")
|
2013-08-09 09:59:59 +00:00
|
|
|
if supplier:
|
2014-03-28 08:25:00 +00:00
|
|
|
self.supplier = supplier
|
2013-08-09 09:59:59 +00:00
|
|
|
break
|
2014-04-14 13:50:45 +00:00
|
|
|
|
2013-10-10 10:34:40 +00:00
|
|
|
def validate_warehouse(self):
|
2013-12-26 13:00:39 +00:00
|
|
|
from erpnext.stock.utils import validate_warehouse_company
|
2014-04-14 13:50:45 +00:00
|
|
|
|
|
|
|
warehouses = list(set([d.warehouse for d in
|
2014-04-04 05:36:10 +00:00
|
|
|
self.get(self.fname) if getattr(d, "warehouse", None)]))
|
2014-04-14 13:50:45 +00:00
|
|
|
|
2013-10-10 10:34:40 +00:00
|
|
|
for w in warehouses:
|
2014-03-28 08:25:00 +00:00
|
|
|
validate_warehouse_company(w, self.company)
|
2013-08-09 09:59:59 +00:00
|
|
|
|
2013-04-26 08:05:06 +00:00
|
|
|
def validate_stock_or_nonstock_items(self):
|
2014-06-16 10:24:05 +00:00
|
|
|
if self.meta.get_field("other_charges") and not self.get_stock_items():
|
|
|
|
tax_for_valuation = [d.account_head for d in self.get("other_charges")
|
2013-04-26 08:05:06 +00:00
|
|
|
if d.category in ["Valuation", "Valuation and Total"]]
|
|
|
|
if tax_for_valuation:
|
2014-04-14 13:50:45 +00:00
|
|
|
frappe.throw(_("Tax Category can not be 'Valuation' or 'Valuation and Total' as all items are non-stock items"))
|
|
|
|
|
2013-01-21 11:54:31 +00:00
|
|
|
def set_total_in_words(self):
|
2014-02-14 10:17:51 +00:00
|
|
|
from frappe.utils import money_in_words
|
2014-03-28 08:25:00 +00:00
|
|
|
company_currency = get_company_currency(self.company)
|
2013-01-22 05:42:02 +00:00
|
|
|
if self.meta.get_field("in_words"):
|
2014-03-28 08:25:00 +00:00
|
|
|
self.in_words = money_in_words(self.grand_total, company_currency)
|
2013-01-22 05:42:02 +00:00
|
|
|
if self.meta.get_field("in_words_import"):
|
2014-03-28 08:25:00 +00:00
|
|
|
self.in_words_import = money_in_words(self.grand_total_import,
|
|
|
|
self.currency)
|
2014-04-14 13:50:45 +00:00
|
|
|
|
2013-02-06 12:03:46 +00:00
|
|
|
def calculate_taxes_and_totals(self):
|
2014-01-29 11:01:38 +00:00
|
|
|
self.other_fname = "other_charges"
|
2013-05-24 13:55:01 +00:00
|
|
|
super(BuyingController, self).calculate_taxes_and_totals()
|
2013-05-28 11:53:36 +00:00
|
|
|
self.calculate_total_advance("Purchase Invoice", "advance_allocation_details")
|
2014-04-14 13:50:45 +00:00
|
|
|
|
2013-02-08 13:58:14 +00:00
|
|
|
def calculate_item_values(self):
|
2013-05-06 07:22:46 +00:00
|
|
|
for item in self.item_doclist:
|
2013-05-11 14:09:53 +00:00
|
|
|
self.round_floats_in(item)
|
2013-02-08 13:58:14 +00:00
|
|
|
|
2014-02-10 12:24:04 +00:00
|
|
|
if item.discount_percentage == 100.0:
|
2014-02-10 12:56:49 +00:00
|
|
|
item.rate = 0.0
|
|
|
|
elif not item.rate:
|
|
|
|
item.rate = flt(item.price_list_rate * (1.0 - (item.discount_percentage / 100.0)),
|
|
|
|
self.precision("rate", item))
|
2014-04-14 13:50:45 +00:00
|
|
|
|
2014-02-10 13:50:15 +00:00
|
|
|
item.amount = flt(item.rate * item.qty,
|
|
|
|
self.precision("amount", item))
|
2013-05-24 13:55:01 +00:00
|
|
|
item.item_tax_amount = 0.0;
|
2013-12-23 06:44:45 +00:00
|
|
|
|
2014-02-10 13:50:15 +00:00
|
|
|
self._set_in_company_currency(item, "amount", "base_amount")
|
2014-02-10 12:24:04 +00:00
|
|
|
self._set_in_company_currency(item, "price_list_rate", "base_price_list_rate")
|
2014-02-10 12:56:49 +00:00
|
|
|
self._set_in_company_currency(item, "rate", "base_rate")
|
2014-04-14 13:50:45 +00:00
|
|
|
|
|
|
|
|
2013-02-08 13:58:14 +00:00
|
|
|
def calculate_net_total(self):
|
2014-03-28 08:25:00 +00:00
|
|
|
self.net_total = self.net_total_import = 0.0
|
2013-02-08 13:58:14 +00:00
|
|
|
|
|
|
|
for item in self.item_doclist:
|
2014-03-28 08:25:00 +00:00
|
|
|
self.net_total += item.base_amount
|
|
|
|
self.net_total_import += item.amount
|
2014-04-14 13:50:45 +00:00
|
|
|
|
2014-03-28 09:53:26 +00:00
|
|
|
self.round_floats_in(self, ["net_total", "net_total_import"])
|
2014-04-14 13:50:45 +00:00
|
|
|
|
2013-02-08 13:58:14 +00:00
|
|
|
def calculate_totals(self):
|
2014-04-14 13:50:45 +00:00
|
|
|
self.grand_total = flt(self.tax_doclist[-1].total if self.tax_doclist
|
2014-03-28 08:25:00 +00:00
|
|
|
else self.net_total, self.precision("grand_total"))
|
|
|
|
self.grand_total_import = flt(self.grand_total / self.conversion_rate,
|
2013-05-24 13:55:01 +00:00
|
|
|
self.precision("grand_total_import"))
|
2013-02-08 13:58:14 +00:00
|
|
|
|
2014-03-28 08:25:00 +00:00
|
|
|
self.total_tax = flt(self.grand_total - self.net_total,
|
2013-05-10 13:53:02 +00:00
|
|
|
self.precision("total_tax"))
|
2013-02-08 13:58:14 +00:00
|
|
|
|
|
|
|
if self.meta.get_field("rounded_total"):
|
2014-03-28 08:25:00 +00:00
|
|
|
self.rounded_total = _round(self.grand_total)
|
2014-04-14 13:50:45 +00:00
|
|
|
|
2013-02-08 13:58:14 +00:00
|
|
|
if self.meta.get_field("rounded_total_import"):
|
2014-03-28 08:25:00 +00:00
|
|
|
self.rounded_total_import = _round(self.grand_total_import)
|
2014-04-14 13:50:45 +00:00
|
|
|
|
2014-01-16 08:54:32 +00:00
|
|
|
if self.meta.get_field("other_charges_added"):
|
2014-04-14 13:50:45 +00:00
|
|
|
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"]]),
|
2014-01-16 08:54:32 +00:00
|
|
|
self.precision("other_charges_added"))
|
2014-04-14 13:50:45 +00:00
|
|
|
|
2014-01-16 08:54:32 +00:00
|
|
|
if self.meta.get_field("other_charges_deducted"):
|
2014-04-14 13:50:45 +00:00
|
|
|
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"]]),
|
2014-01-16 08:54:32 +00:00
|
|
|
self.precision("other_charges_deducted"))
|
2014-04-14 13:50:45 +00:00
|
|
|
|
2014-01-16 08:54:32 +00:00
|
|
|
if self.meta.get_field("other_charges_added_import"):
|
2014-04-14 13:50:45 +00:00
|
|
|
self.other_charges_added_import = flt(self.other_charges_added /
|
2014-03-28 08:25:00 +00:00
|
|
|
self.conversion_rate, self.precision("other_charges_added_import"))
|
2014-04-14 13:50:45 +00:00
|
|
|
|
2014-01-16 08:54:32 +00:00
|
|
|
if self.meta.get_field("other_charges_deducted_import"):
|
2014-04-14 13:50:45 +00:00
|
|
|
self.other_charges_deducted_import = flt(self.other_charges_deducted /
|
2014-03-28 08:25:00 +00:00
|
|
|
self.conversion_rate, self.precision("other_charges_deducted_import"))
|
2014-04-14 13:50:45 +00:00
|
|
|
|
2013-02-08 13:58:14 +00:00
|
|
|
def calculate_outstanding_amount(self):
|
2014-03-28 08:25:00 +00:00
|
|
|
if self.doctype == "Purchase Invoice" and self.docstatus == 0:
|
|
|
|
self.total_advance = flt(self.total_advance,
|
2013-05-10 13:53:02 +00:00
|
|
|
self.precision("total_advance"))
|
2014-03-28 08:25:00 +00:00
|
|
|
self.total_amount_to_pay = flt(self.grand_total - flt(self.write_off_amount,
|
2013-05-10 13:53:02 +00:00
|
|
|
self.precision("write_off_amount")), self.precision("total_amount_to_pay"))
|
2014-03-28 08:25:00 +00:00
|
|
|
self.outstanding_amount = flt(self.total_amount_to_pay - self.total_advance,
|
2013-05-10 13:53:02 +00:00
|
|
|
self.precision("outstanding_amount"))
|
2014-04-14 13:50:45 +00:00
|
|
|
|
2014-01-02 11:00:16 +00:00
|
|
|
# update valuation rate
|
|
|
|
def update_valuation_rate(self, parentfield):
|
2013-02-08 13:58:14 +00:00
|
|
|
"""
|
|
|
|
item_tax_amount is the total tax amount applied on that item
|
2014-04-14 13:50:45 +00:00
|
|
|
stored for valuation
|
|
|
|
|
2013-02-08 13:58:14 +00:00
|
|
|
TODO: rename item_tax_amount to valuation_tax_amount
|
|
|
|
"""
|
2014-01-02 11:00:16 +00:00
|
|
|
stock_items = self.get_stock_items()
|
2014-04-14 13:50:45 +00:00
|
|
|
|
2014-01-03 06:43:18 +00:00
|
|
|
stock_items_qty, stock_items_amount = 0, 0
|
2014-01-14 12:14:34 +00:00
|
|
|
last_stock_item_idx = 1
|
2014-03-27 10:42:56 +00:00
|
|
|
for d in self.get(parentfield):
|
2014-01-03 06:43:18 +00:00
|
|
|
if d.item_code and d.item_code in stock_items:
|
|
|
|
stock_items_qty += flt(d.qty)
|
2014-02-10 13:50:15 +00:00
|
|
|
stock_items_amount += flt(d.base_amount)
|
2014-01-14 12:14:34 +00:00
|
|
|
last_stock_item_idx = d.idx
|
2014-04-14 13:50:45 +00:00
|
|
|
|
|
|
|
total_valuation_amount = sum([flt(d.tax_amount) for d in
|
|
|
|
self.get("other_charges")
|
2014-01-02 11:00:16 +00:00
|
|
|
if d.category in ["Valuation", "Valuation and Total"]])
|
2014-04-14 13:50:45 +00:00
|
|
|
|
|
|
|
|
2014-01-14 12:14:34 +00:00
|
|
|
valuation_amount_adjustment = total_valuation_amount
|
2014-03-27 10:42:56 +00:00
|
|
|
for i, item in enumerate(self.get(parentfield)):
|
2014-01-03 06:43:18 +00:00
|
|
|
if item.item_code and item.qty and item.item_code in stock_items:
|
2014-02-10 13:50:15 +00:00
|
|
|
item_proportion = flt(item.base_amount) / stock_items_amount if stock_items_amount \
|
2014-01-03 06:43:18 +00:00
|
|
|
else flt(item.qty) / stock_items_qty
|
2014-04-14 13:50:45 +00:00
|
|
|
|
2014-01-14 12:14:34 +00:00
|
|
|
if i == (last_stock_item_idx - 1):
|
2014-04-14 13:50:45 +00:00
|
|
|
item.item_tax_amount = flt(valuation_amount_adjustment,
|
2014-01-14 12:14:34 +00:00
|
|
|
self.precision("item_tax_amount", item))
|
|
|
|
else:
|
2014-04-14 13:50:45 +00:00
|
|
|
item.item_tax_amount = flt(item_proportion * total_valuation_amount,
|
2014-01-14 12:14:34 +00:00
|
|
|
self.precision("item_tax_amount", item))
|
|
|
|
valuation_amount_adjustment -= item.item_tax_amount
|
2014-01-02 11:00:16 +00:00
|
|
|
|
2013-05-11 14:09:53 +00:00
|
|
|
self.round_floats_in(item)
|
2014-04-14 13:50:45 +00:00
|
|
|
|
2014-02-26 07:05:33 +00:00
|
|
|
item.conversion_factor = item.conversion_factor or flt(frappe.db.get_value(
|
2014-04-14 13:50:45 +00:00
|
|
|
"UOM Conversion Detail", {"parent": item.item_code, "uom": item.uom},
|
2014-01-02 11:00:16 +00:00
|
|
|
"conversion_factor")) or 1
|
2013-12-23 06:44:45 +00:00
|
|
|
qty_in_stock_uom = flt(item.qty * item.conversion_factor)
|
2014-04-01 13:24:38 +00:00
|
|
|
rm_supp_cost = item.rm_supp_cost if self.doctype=="Purchase Receipt" else 0.0
|
|
|
|
item.valuation_rate = ((item.base_amount + item.item_tax_amount + rm_supp_cost)
|
2013-12-23 06:44:45 +00:00
|
|
|
/ qty_in_stock_uom)
|
2013-02-27 12:40:30 +00:00
|
|
|
else:
|
2013-05-10 13:53:02 +00:00
|
|
|
item.valuation_rate = 0.0
|
2014-04-14 13:50:45 +00:00
|
|
|
|
2013-03-01 13:21:10 +00:00
|
|
|
def validate_for_subcontracting(self):
|
2014-03-28 08:25:00 +00:00
|
|
|
if not self.is_subcontracted and self.sub_contracted_items:
|
2014-04-14 13:50:45 +00:00
|
|
|
frappe.throw(_("Please enter 'Is Subcontracted' as Yes or No"))
|
|
|
|
|
2014-03-28 08:25:00 +00:00
|
|
|
if self.doctype == "Purchase Receipt" and self.is_subcontracted=="Yes" \
|
|
|
|
and not self.supplier_warehouse:
|
2014-04-14 13:50:45 +00:00
|
|
|
frappe.throw(_("Supplier Warehouse mandatory for sub-contracted Purchase Receipt"))
|
|
|
|
|
2014-05-08 13:38:20 +00:00
|
|
|
def create_raw_materials_supplied(self, raw_material_table):
|
2014-03-28 08:25:00 +00:00
|
|
|
if self.is_subcontracted=="Yes":
|
2014-05-08 13:38:20 +00:00
|
|
|
parent_items = []
|
|
|
|
rm_supplied_idx = 0
|
2014-03-27 10:42:56 +00:00
|
|
|
for item in self.get(self.fname):
|
2014-04-01 13:24:38 +00:00
|
|
|
if self.doctype == "Purchase Receipt":
|
|
|
|
item.rm_supp_cost = 0.0
|
2013-03-01 13:21:10 +00:00
|
|
|
if item.item_code in self.sub_contracted_items:
|
2014-05-08 13:38:20 +00:00
|
|
|
self.update_raw_materials_supplied(item, raw_material_table, rm_supplied_idx)
|
|
|
|
|
|
|
|
if [item.item_code, item.name] not in parent_items:
|
|
|
|
parent_items.append([item.item_code, item.name])
|
|
|
|
|
|
|
|
self.cleanup_raw_materials_supplied(parent_items, raw_material_table)
|
2013-03-01 13:21:10 +00:00
|
|
|
|
2014-04-01 13:24:38 +00:00
|
|
|
elif self.doctype == "Purchase Receipt":
|
|
|
|
for item in self.get(self.fname):
|
|
|
|
item.rm_supp_cost = 0.0
|
|
|
|
|
2014-05-08 13:38:20 +00:00
|
|
|
def update_raw_materials_supplied(self, item, raw_material_table, rm_supplied_idx):
|
|
|
|
bom_items = self.get_items_from_default_bom(item.item_code)
|
2013-03-01 13:21:10 +00:00
|
|
|
raw_materials_cost = 0
|
2014-05-08 13:38:20 +00:00
|
|
|
|
|
|
|
for bom_item in bom_items:
|
|
|
|
# check if exists
|
|
|
|
exists = 0
|
|
|
|
for d in self.get(raw_material_table):
|
|
|
|
if d.main_item_code == item.item_code and d.rm_item_code == bom_item.item_code \
|
|
|
|
and d.reference_name == item.name:
|
|
|
|
rm, exists = d, 1
|
|
|
|
break
|
|
|
|
|
|
|
|
if not exists:
|
|
|
|
rm = self.append(raw_material_table, {})
|
|
|
|
|
|
|
|
required_qty = flt(bom_item.qty_consumed_per_unit) * flt(item.qty) * flt(item.conversion_factor)
|
|
|
|
rm.reference_name = item.name
|
|
|
|
rm.bom_detail_no = bom_item.name
|
|
|
|
rm.main_item_code = item.item_code
|
|
|
|
rm.rm_item_code = bom_item.item_code
|
|
|
|
rm.stock_uom = bom_item.stock_uom
|
|
|
|
rm.required_qty = required_qty
|
|
|
|
|
|
|
|
rm.conversion_factor = item.conversion_factor
|
|
|
|
rm.rate = bom_item.rate
|
|
|
|
rm.amount = required_qty * flt(bom_item.rate)
|
|
|
|
rm.idx = rm_supplied_idx
|
|
|
|
|
2014-05-09 05:24:12 +00:00
|
|
|
if self.doctype == "Purchase Receipt":
|
2014-05-08 13:38:20 +00:00
|
|
|
rm.consumed_qty = required_qty
|
|
|
|
rm.description = bom_item.description
|
|
|
|
if item.batch_no and not rm.batch_no:
|
|
|
|
rm.batch_no = item.batch_no
|
|
|
|
|
|
|
|
rm_supplied_idx += 1
|
2014-04-14 13:50:45 +00:00
|
|
|
|
2014-05-11 06:41:15 +00:00
|
|
|
raw_materials_cost += required_qty * flt(bom_item.rate)
|
2014-04-14 13:50:45 +00:00
|
|
|
|
2014-03-28 08:25:00 +00:00
|
|
|
if self.doctype == "Purchase Receipt":
|
2014-05-08 13:38:20 +00:00
|
|
|
item.rm_supp_cost = raw_materials_cost
|
|
|
|
|
|
|
|
def cleanup_raw_materials_supplied(self, parent_items, raw_material_table):
|
|
|
|
"""Remove all those child items which are no longer present in main item table"""
|
|
|
|
delete_list = []
|
|
|
|
for d in self.get(raw_material_table):
|
|
|
|
if [d.main_item_code, d.reference_name] not in parent_items:
|
|
|
|
# mark for deletion from doclist
|
2014-06-04 11:11:22 +00:00
|
|
|
delete_list.append(d)
|
2014-05-08 13:38:20 +00:00
|
|
|
|
|
|
|
# delete from doclist
|
|
|
|
if delete_list:
|
|
|
|
rm_supplied_details = self.get(raw_material_table)
|
|
|
|
self.set(raw_material_table, [])
|
|
|
|
for d in rm_supplied_details:
|
|
|
|
if d not in delete_list:
|
|
|
|
self.append(raw_material_table, d)
|
2013-03-01 13:21:10 +00:00
|
|
|
|
|
|
|
def get_items_from_default_bom(self, item_code):
|
2014-04-14 13:50:45 +00:00
|
|
|
bom_items = frappe.db.sql("""select t2.item_code, t2.qty_consumed_per_unit,
|
|
|
|
t2.rate, t2.stock_uom, t2.name, t2.description
|
|
|
|
from `tabBOM` t1, `tabBOM Item` t2
|
|
|
|
where t2.parent = t1.name and t1.item = %s and t1.is_default = 1
|
2013-03-01 13:21:10 +00:00
|
|
|
and t1.docstatus = 1 and t1.is_active = 1""", item_code, as_dict=1)
|
|
|
|
if not bom_items:
|
2014-04-14 13:50:45 +00:00
|
|
|
msgprint(_("No default BOM exists for Item {0}").format(item_code), raise_exception=1)
|
|
|
|
|
2013-03-01 13:21:10 +00:00
|
|
|
return bom_items
|
|
|
|
|
2013-02-27 12:41:17 +00:00
|
|
|
@property
|
|
|
|
def sub_contracted_items(self):
|
|
|
|
if not hasattr(self, "_sub_contracted_items"):
|
2013-04-23 10:06:26 +00:00
|
|
|
self._sub_contracted_items = []
|
2014-04-14 13:50:45 +00:00
|
|
|
item_codes = list(set(item.item_code for item in
|
2014-03-27 10:42:56 +00:00
|
|
|
self.get(self.fname)))
|
2013-04-23 10:06:26 +00:00
|
|
|
if item_codes:
|
2014-02-26 07:05:33 +00:00
|
|
|
self._sub_contracted_items = [r[0] for r in frappe.db.sql("""select name
|
2013-04-23 10:06:26 +00:00
|
|
|
from `tabItem` where name in (%s) and is_sub_contracted_item='Yes'""" % \
|
|
|
|
(", ".join((["%s"]*len(item_codes))),), item_codes)]
|
2013-02-27 12:41:17 +00:00
|
|
|
|
|
|
|
return self._sub_contracted_items
|
2014-04-14 13:50:45 +00:00
|
|
|
|
2013-02-27 12:41:17 +00:00
|
|
|
@property
|
|
|
|
def purchase_items(self):
|
|
|
|
if not hasattr(self, "_purchase_items"):
|
2013-04-23 10:06:26 +00:00
|
|
|
self._purchase_items = []
|
2014-04-14 13:50:45 +00:00
|
|
|
item_codes = list(set(item.item_code for item in
|
2014-03-27 10:42:56 +00:00
|
|
|
self.get(self.fname)))
|
2013-04-23 10:06:26 +00:00
|
|
|
if item_codes:
|
2014-02-26 07:05:33 +00:00
|
|
|
self._purchase_items = [r[0] for r in frappe.db.sql("""select name
|
2013-04-23 10:06:26 +00:00
|
|
|
from `tabItem` where name in (%s) and is_purchase_item='Yes'""" % \
|
|
|
|
(", ".join((["%s"]*len(item_codes))),), item_codes)]
|
2013-02-27 12:41:17 +00:00
|
|
|
|
2013-02-27 12:44:28 +00:00
|
|
|
return self._purchase_items
|
2013-10-18 11:30:53 +00:00
|
|
|
|
|
|
|
|
|
|
|
def is_item_table_empty(self):
|
2014-03-27 10:42:56 +00:00
|
|
|
if not len(self.get(self.fname)):
|
2014-04-14 13:50:45 +00:00
|
|
|
frappe.throw(_("Item table can not be blank"))
|