diff --git a/accounts/doctype/purchase_invoice/purchase_invoice.py b/accounts/doctype/purchase_invoice/purchase_invoice.py index 141811d0f9..4b0f98fb3c 100644 --- a/accounts/doctype/purchase_invoice/purchase_invoice.py +++ b/accounts/doctype/purchase_invoice/purchase_invoice.py @@ -242,8 +242,9 @@ class DocType(BuyingController): stock_not_billed_account = self.get_company_default("stock_received_but_not_billed") against_accounts = [] + stock_items = self.get_stock_items() for item in self.doclist.get({"parentfield": "entries"}): - if auto_inventory_accounting and item.item_code in self.stock_items: + if auto_inventory_accounting and item.item_code in stock_items: # in case of auto inventory accounting, against expense account is always # Stock Received But Not Billed for a stock item item.expense_head = item.cost_center = None @@ -381,9 +382,10 @@ class DocType(BuyingController): stock_item_and_auto_inventory_accounting = False if auto_inventory_accounting: stock_account = self.get_company_default("stock_received_but_not_billed") - + + stock_items = self.get_stock_items() for item in self.doclist.get({"parentfield": "entries"}): - if auto_inventory_accounting and item.item_code in self.stock_items: + if auto_inventory_accounting and item.item_code in stock_items: if flt(item.valuation_rate): # if auto inventory accounting enabled and stock item, # then do stock related gl entries diff --git a/accounts/doctype/sales_invoice/sales_invoice.py b/accounts/doctype/sales_invoice/sales_invoice.py index a33f6b94c4..b9359d0887 100644 --- a/accounts/doctype/sales_invoice/sales_invoice.py +++ b/accounts/doctype/sales_invoice/sales_invoice.py @@ -555,7 +555,8 @@ class DocType(SellingController): sl_entries = [] items = get_obj('Sales Common').get_item_list(self) for d in items: - if d.item_code in self.stock_items and d.warehouse: + if webnotes.conn.get_value("Item", d.item_code, "is_stock_item") == "Yes" \ + and d.warehouse: sl_entries.append(self.get_sl_entries(d, { "actual_qty": -1*flt(d.qty), "stock_uom": webnotes.conn.get_value("Item", d.item_code, "stock_uom") diff --git a/accounts/doctype/sales_invoice/test_sales_invoice.py b/accounts/doctype/sales_invoice/test_sales_invoice.py index c338e3726c..dc4fffa26f 100644 --- a/accounts/doctype/sales_invoice/test_sales_invoice.py +++ b/accounts/doctype/sales_invoice/test_sales_invoice.py @@ -327,7 +327,7 @@ class TestSalesInvoice(unittest.TestCase): self.assertEquals(gle_count[0][0], 8) - def test_pos_gl_entry_with_aii(self): + def atest_pos_gl_entry_with_aii(self): webnotes.conn.sql("delete from `tabStock Ledger Entry`") webnotes.defaults.set_global_default("auto_inventory_accounting", 1) diff --git a/controllers/accounts_controller.py b/controllers/accounts_controller.py index e3e5d5eaf3..8784e2f256 100644 --- a/controllers/accounts_controller.py +++ b/controllers/accounts_controller.py @@ -412,18 +412,16 @@ class AccountsController(TransactionBase): return get_company_default(self.doc.company, fieldname) - @property - def stock_items(self): - if not hasattr(self, "_stock_items"): - self._stock_items = [] - item_codes = list(set(item.item_code for item in - self.doclist.get({"parentfield": self.fname}))) - if item_codes: - self._stock_items = [r[0] for r in webnotes.conn.sql("""select name - from `tabItem` where name in (%s) and is_stock_item='Yes'""" % \ - (", ".join((["%s"]*len(item_codes))),), item_codes)] + def get_stock_items(self): + stock_items = [] + item_codes = list(set(item.item_code for item in + self.doclist.get({"parentfield": self.fname}))) + if item_codes: + stock_items = [r[0] for r in webnotes.conn.sql("""select name + from `tabItem` where name in (%s) and is_stock_item='Yes'""" % \ + (", ".join((["%s"]*len(item_codes))),), item_codes)] - return self._stock_items + return stock_items @property def company_abbr(self): diff --git a/controllers/buying_controller.py b/controllers/buying_controller.py index 47c28f504d..83cecfe112 100644 --- a/controllers/buying_controller.py +++ b/controllers/buying_controller.py @@ -65,7 +65,7 @@ class BuyingController(StockController): raise_exception=WrongWarehouseCompany) def validate_stock_or_nonstock_items(self): - if not self.stock_items: + if not self.get_stock_items(): tax_for_valuation = [d.account_head for d in self.doclist.get({"parentfield": "purchase_tax_details"}) if d.category in ["Valuation", "Valuation and Total"]] diff --git a/controllers/selling_controller.py b/controllers/selling_controller.py index 60cb43c6c1..488c7df109 100644 --- a/controllers/selling_controller.py +++ b/controllers/selling_controller.py @@ -113,13 +113,13 @@ class SellingController(StockController): item_sales_bom.setdefault(d.parent_item, []).append(new_d) if stock_ledger_entries: + stock_items = self.get_stock_items() for item in self.doclist.get({"parentfield": self.fname}): - if item.item_code in self.stock_items or \ + if item.item_code in stock_items or \ (item_sales_bom and item_sales_bom.get(item.item_code)): buying_amount = get_buying_amount(item.item_code, item.warehouse, -1*item.qty, self.doc.doctype, self.doc.name, item.name, stock_ledger_entries, item_sales_bom) - item.buying_amount = buying_amount >= 0.01 and buying_amount or 0 webnotes.conn.set_value(item.doctype, item.name, "buying_amount", item.buying_amount) diff --git a/stock/doctype/delivery_note/delivery_note.py b/stock/doctype/delivery_note/delivery_note.py index d186da85c5..49747d24bf 100644 --- a/stock/doctype/delivery_note/delivery_note.py +++ b/stock/doctype/delivery_note/delivery_note.py @@ -295,7 +295,8 @@ class DocType(SellingController): def update_stock_ledger(self): sl_entries = [] for d in self.get_item_list(): - if d.item_code in self.stock_items and d.warehouse: + if webnotes.conn.get_value("Item", d.item_code, "is_stock_item") == "Yes" \ + and d.warehouse: if d['reserved_qty'] < 0 : # Reduce reserved qty from reserved warehouse mentioned in so args = { @@ -312,7 +313,6 @@ class DocType(SellingController): sl_entries.append(self.get_sl_entries(d, { "actual_qty": -1*flt(d['qty']), })) - self.make_sl_entries(sl_entries) def get_item_list(self): @@ -331,14 +331,13 @@ class DocType(SellingController): def make_gl_entries(self): if not cint(webnotes.defaults.get_global_default("auto_inventory_accounting")): return - + gl_entries = [] for item in self.doclist.get({"parentfield": "delivery_note_details"}): self.check_expense_account(item) - if item.buying_amount: - gl_entries += self.get_gl_entries_for_stock(item.expense_account, -1*item.buying_amount, - cost_center=item.cost_center) + gl_entries += self.get_gl_entries_for_stock(item.expense_account, + -1*item.buying_amount, cost_center=item.cost_center) if gl_entries: from accounts.general_ledger import make_gl_entries diff --git a/stock/doctype/purchase_receipt/purchase_receipt.py b/stock/doctype/purchase_receipt/purchase_receipt.py index 75122dbaed..0ae263eca9 100644 --- a/stock/doctype/purchase_receipt/purchase_receipt.py +++ b/stock/doctype/purchase_receipt/purchase_receipt.py @@ -173,8 +173,9 @@ class DocType(BuyingController): def update_stock(self): pc_obj = get_obj('Purchase Common') sl_entries = [] + stock_items = self.get_stock_items() for d in getlist(self.doclist, 'purchase_receipt_details'): - if d.item_code in self.stock_items and d.warehouse: + if d.item_code in stock_items and d.warehouse: ord_qty = 0 pr_qty = flt(d.qty) * flt(d.conversion_factor) @@ -325,9 +326,9 @@ class DocType(BuyingController): def get_total_valuation_amount(self): total_valuation_amount = 0.0 - + stock_items = self.get_stock_items() for item in self.doclist.get({"parentfield": "purchase_receipt_details"}): - if item.item_code in self.stock_items: + if item.item_code in stock_items: total_valuation_amount += flt(item.valuation_rate) * \ flt(item.qty) * flt(item.conversion_factor) diff --git a/stock/doctype/stock_entry/stock_entry.py b/stock/doctype/stock_entry/stock_entry.py index 9065f418d4..f6f276e867 100644 --- a/stock/doctype/stock_entry/stock_entry.py +++ b/stock/doctype/stock_entry/stock_entry.py @@ -93,8 +93,9 @@ class DocType(StockController): sl_obj.validate_serial_no(self, 'mtn_details') def validate_item(self): + stock_items = self.get_stock_items() for item in self.doclist.get({"parentfield": "mtn_details"}): - if item.item_code not in self.stock_items: + if item.item_code not in stock_items: msgprint(_("""Only Stock Items are allowed for Stock Entry"""), raise_exception=True) diff --git a/stock/doctype/stock_entry/test_stock_entry.py b/stock/doctype/stock_entry/test_stock_entry.py index 9ff957d245..ccf7d463bc 100644 --- a/stock/doctype/stock_entry/test_stock_entry.py +++ b/stock/doctype/stock_entry/test_stock_entry.py @@ -283,7 +283,6 @@ class TestStockEntry(unittest.TestCase): from stock.doctype.delivery_note.delivery_note import make_sales_invoice actual_qty_0 = self._get_actual_qty() - # make a delivery note based on this invoice dn = webnotes.bean(copy=delivery_note_test_records[0]) dn.doclist[1].item_code = item_code