diff --git a/accounts/Print Format/Sales Invoice Classic/Sales Invoice Classic.txt b/accounts/Print Format/Sales Invoice Classic/Sales Invoice Classic.txt
index 5aefa812f8..fc99597766 100644
--- a/accounts/Print Format/Sales Invoice Classic/Sales Invoice Classic.txt
+++ b/accounts/Print Format/Sales Invoice Classic/Sales Invoice Classic.txt
@@ -2,14 +2,14 @@
{
"creation": "2013-04-19 13:30:27",
"docstatus": 0,
- "modified": "2013-05-28 17:19:38",
+ "modified": "2013-08-07 20:14:53",
"modified_by": "Administrator",
"owner": "Administrator"
},
{
"doc_type": "Sales Invoice",
"doctype": "Print Format",
- "html": "\n\n\n\n\n\n\n\n\n\n\n
\n\n\t\n\t\n
\n\n",
+ "html": "\n\n\n\n\n\n\n\n\n\n\n\n\n\t\n\t\n
\n\n",
"module": "Accounts",
"name": "__common__",
"print_format_type": "Client",
diff --git a/accounts/Print Format/Sales Invoice Modern/Sales Invoice Modern.txt b/accounts/Print Format/Sales Invoice Modern/Sales Invoice Modern.txt
index 2f6251c07b..07946f7fcc 100644
--- a/accounts/Print Format/Sales Invoice Modern/Sales Invoice Modern.txt
+++ b/accounts/Print Format/Sales Invoice Modern/Sales Invoice Modern.txt
@@ -2,14 +2,14 @@
{
"creation": "2013-04-19 13:30:27",
"docstatus": 0,
- "modified": "2013-05-28 17:19:52",
+ "modified": "2013-08-07 20:12:16",
"modified_by": "Administrator",
"owner": "Administrator"
},
{
"doc_type": "Sales Invoice",
"doctype": "Print Format",
- "html": "\n\n\n\n\n\n\n\n\n\n\n\n\n\t\n\t\n
\n\n",
+ "html": "\n\n\n\n\n\n\n\n\n\n\n\n\n\t\n\t\n
\n\n",
"module": "Accounts",
"name": "__common__",
"print_format_type": "Client",
diff --git a/accounts/Print Format/Sales Invoice Spartan/Sales Invoice Spartan.txt b/accounts/Print Format/Sales Invoice Spartan/Sales Invoice Spartan.txt
index b00b3d85f5..57c02fe2ec 100644
--- a/accounts/Print Format/Sales Invoice Spartan/Sales Invoice Spartan.txt
+++ b/accounts/Print Format/Sales Invoice Spartan/Sales Invoice Spartan.txt
@@ -2,14 +2,14 @@
{
"creation": "2013-04-19 13:30:27",
"docstatus": 0,
- "modified": "2013-05-28 17:19:22",
+ "modified": "2013-08-07 19:50:51",
"modified_by": "Administrator",
"owner": "Administrator"
},
{
"doc_type": "Sales Invoice",
"doctype": "Print Format",
- "html": "\n\n\n\n\n\n\n\n\n\n\n\n\n\t\n\t\n
\n\n",
+ "html": "\n\n\n\n\n\n\n\n\n\n\n\n\n\t\n\t\n
\n\n",
"module": "Accounts",
"name": "__common__",
"print_format_type": "Client",
diff --git a/accounts/report/gross_profit/gross_profit.py b/accounts/report/gross_profit/gross_profit.py
index dcef5b815a..3aba234c19 100644
--- a/accounts/report/gross_profit/gross_profit.py
+++ b/accounts/report/gross_profit/gross_profit.py
@@ -10,9 +10,7 @@ def execute(filters=None):
if not filters: filters = {}
stock_ledger_entries = get_stock_ledger_entries(filters)
-
source = get_source_data(filters)
-
item_sales_bom = get_item_sales_bom()
columns = ["Delivery Note/Sales Invoice::120", "Link::30", "Posting Date:Date", "Posting Time",
@@ -20,12 +18,12 @@ def execute(filters=None):
"Qty:Float", "Selling Rate:Currency", "Avg. Buying Rate:Currency",
"Selling Amount:Currency", "Buying Amount:Currency",
"Gross Profit:Currency", "Gross Profit %:Percent", "Project:Link/Project"]
-
data = []
for row in source:
selling_amount = flt(row.amount)
- buying_amount = get_buying_amount(row.item_code, row.warehouse, -1*row.qty,
- row.parenttype, row.name, row.item_row, stock_ledger_entries,
+
+ buying_amount = get_buying_amount(row.item_code, row.parenttype, row.name, row.item_row,
+ stock_ledger_entries.get((row.item_code, row.warehouse), []),
item_sales_bom.get(row.parenttype, {}).get(row.name, webnotes._dict()))
buying_amount = buying_amount > 0 and buying_amount or 0
@@ -56,8 +54,17 @@ def get_stock_ledger_entries(filters):
query += """ and company=%(company)s"""
query += " order by item_code desc, warehouse desc, posting_date desc, posting_time desc, name desc"
+
+ res = webnotes.conn.sql(query, filters, as_dict=True)
+
+ out = {}
+ for r in res:
+ if (r.item_code, r.warehouse) not in out:
+ out[(r.item_code, r.warehouse)] = []
+
+ out[(r.item_code, r.warehouse)].append(r)
- return webnotes.conn.sql(query, filters, as_dict=True)
+ return out
def get_item_sales_bom():
item_sales_bom = {}
diff --git a/buying/Print Format/Purchase Order Classic/Purchase Order Classic.txt b/buying/Print Format/Purchase Order Classic/Purchase Order Classic.txt
index 5c5c8aa577..ff8448fb7c 100644
--- a/buying/Print Format/Purchase Order Classic/Purchase Order Classic.txt
+++ b/buying/Print Format/Purchase Order Classic/Purchase Order Classic.txt
@@ -1,21 +1,22 @@
[
{
- "owner": "Administrator",
+ "creation": "2012-04-17 11:29:12",
"docstatus": 0,
- "creation": "2011-12-13 11:02:59",
+ "modified": "2013-08-07 20:00:45",
"modified_by": "Administrator",
- "modified": "2011-12-13 13:51:41"
+ "owner": "Administrator"
},
{
"doc_type": "Purchase Order",
- "name": "__common__",
- "module": "Buying",
"doctype": "Print Format",
- "html": "\n\n\n\n\n\n\n\n\n\n\n\n\n\t\n\t\n
\n\n",
+ "html": "\n\n\n\n\n\n\n\n\n\n\n\n\n\t\n\t\n
\n\n",
+ "module": "Buying",
+ "name": "__common__",
+ "print_format_type": "Client",
"standard": "Yes"
},
{
- "name": "Purchase Order Classic",
- "doctype": "Print Format"
+ "doctype": "Print Format",
+ "name": "Purchase Order Classic"
}
]
\ No newline at end of file
diff --git a/buying/Print Format/Purchase Order Modern/Purchase Order Modern.txt b/buying/Print Format/Purchase Order Modern/Purchase Order Modern.txt
index 535839f910..3be7eb0f56 100644
--- a/buying/Print Format/Purchase Order Modern/Purchase Order Modern.txt
+++ b/buying/Print Format/Purchase Order Modern/Purchase Order Modern.txt
@@ -1,21 +1,22 @@
[
{
- "owner": "Administrator",
+ "creation": "2012-04-17 11:29:12",
"docstatus": 0,
- "creation": "2011-12-13 11:02:59",
+ "modified": "2013-08-07 20:12:05",
"modified_by": "Administrator",
- "modified": "2011-12-13 13:53:52"
+ "owner": "Administrator"
},
{
"doc_type": "Purchase Order",
- "name": "__common__",
- "module": "Buying",
"doctype": "Print Format",
- "html": "\n\n\n\n\n\n\n\n\n\n\n\n\n\t\n\t\n
\n\n",
+ "html": "\n\n\n\n\n\n\n\n\n\n\n\n\n\t\n\t\n
\n\n",
+ "module": "Buying",
+ "name": "__common__",
+ "print_format_type": "Client",
"standard": "Yes"
},
{
- "name": "Purchase Order Modern",
- "doctype": "Print Format"
+ "doctype": "Print Format",
+ "name": "Purchase Order Modern"
}
]
\ No newline at end of file
diff --git a/buying/Print Format/Purchase Order Spartan/Purchase Order Spartan.txt b/buying/Print Format/Purchase Order Spartan/Purchase Order Spartan.txt
index 04999b53b0..908ee78592 100644
--- a/buying/Print Format/Purchase Order Spartan/Purchase Order Spartan.txt
+++ b/buying/Print Format/Purchase Order Spartan/Purchase Order Spartan.txt
@@ -1,21 +1,22 @@
[
{
- "owner": "Administrator",
+ "creation": "2012-04-17 11:29:12",
"docstatus": 0,
- "creation": "2011-12-13 11:02:59",
+ "modified": "2013-08-07 20:01:38",
"modified_by": "Administrator",
- "modified": "2011-12-13 13:55:23"
+ "owner": "Administrator"
},
{
"doc_type": "Purchase Order",
- "name": "__common__",
- "module": "Buying",
"doctype": "Print Format",
- "html": "\n\n\n\n\n\n\n\n\n\n\n\n\n\t\n\t\n
\n\n",
+ "html": "\n\n\n\n\n\n\n\n\n\n\n\n\n\t\n\t\n
\n\n",
+ "module": "Buying",
+ "name": "__common__",
+ "print_format_type": "Client",
"standard": "Yes"
},
{
- "name": "Purchase Order Spartan",
- "doctype": "Print Format"
+ "doctype": "Print Format",
+ "name": "Purchase Order Spartan"
}
]
\ No newline at end of file
diff --git a/controllers/selling_controller.py b/controllers/selling_controller.py
index eb2e9ef604..033ac83db8 100644
--- a/controllers/selling_controller.py
+++ b/controllers/selling_controller.py
@@ -103,8 +103,8 @@ class SellingController(StockController):
for item in self.doclist.get({"parentfield": self.fname}):
if item.item_code in self.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,
+ buying_amount = get_buying_amount(item.item_code, self.doc.doctype, self.doc.name, item.name,
+ stock_ledger_entries.get((item.item_code, item.warehouse), []),
item_sales_bom)
item.buying_amount = buying_amount >= 0.01 and buying_amount or 0
diff --git a/controllers/stock_controller.py b/controllers/stock_controller.py
index 8384973d48..1aeca1bc73 100644
--- a/controllers/stock_controller.py
+++ b/controllers/stock_controller.py
@@ -38,11 +38,13 @@ class StockController(AccountsController):
return gl_entries
def get_stock_ledger_entries(self, item_list=None, warehouse_list=None):
+ out = {}
+
if not (item_list and warehouse_list):
item_list, warehouse_list = self.get_distinct_item_warehouse()
if item_list and warehouse_list:
- return webnotes.conn.sql("""select item_code, voucher_type, voucher_no,
+ res = webnotes.conn.sql("""select item_code, voucher_type, voucher_no,
voucher_detail_no, posting_date, posting_time, stock_value,
warehouse, actual_qty as qty from `tabStock Ledger Entry`
where ifnull(`is_cancelled`, "No") = "No" and company = %s
@@ -51,6 +53,14 @@ class StockController(AccountsController):
posting_time desc, name desc""" %
('%s', ', '.join(['%s']*len(item_list)), ', '.join(['%s']*len(warehouse_list))),
tuple([self.doc.company] + item_list + warehouse_list), as_dict=1)
+
+ for r in res:
+ if (r.item_code, r.warehouse) not in out:
+ out[(r.item_code, r.warehouse)] = []
+
+ out[(r.item_code, r.warehouse)].append(r)
+
+ return out
def get_distinct_item_warehouse(self):
item_list = []
diff --git a/selling/Print Format/Quotation Classic/Quotation Classic.txt b/selling/Print Format/Quotation Classic/Quotation Classic.txt
index 0a63309354..e7588c4522 100644
--- a/selling/Print Format/Quotation Classic/Quotation Classic.txt
+++ b/selling/Print Format/Quotation Classic/Quotation Classic.txt
@@ -2,14 +2,14 @@
{
"creation": "2013-04-19 13:30:51",
"docstatus": 0,
- "modified": "2013-05-28 17:17:05",
+ "modified": "2013-08-07 19:55:11",
"modified_by": "Administrator",
"owner": "Administrator"
},
{
"doc_type": "Quotation",
"doctype": "Print Format",
- "html": "\n\n\n\n\n\n\n\n\n\n\n\n\n\t\n\t\n
\n\n",
+ "html": "\n\n\n\n\n\n\n\n\n\n\n\n\n\t\n\t\n
\n\n",
"module": "Selling",
"name": "__common__",
"print_format_type": "Client",
diff --git a/selling/Print Format/Quotation Modern/Quotation Modern.txt b/selling/Print Format/Quotation Modern/Quotation Modern.txt
index 0f841aa94d..20d380dcbf 100644
--- a/selling/Print Format/Quotation Modern/Quotation Modern.txt
+++ b/selling/Print Format/Quotation Modern/Quotation Modern.txt
@@ -2,14 +2,14 @@
{
"creation": "2013-04-19 13:30:51",
"docstatus": 0,
- "modified": "2013-05-28 17:18:02",
+ "modified": "2013-08-07 20:12:11",
"modified_by": "Administrator",
"owner": "Administrator"
},
{
"doc_type": "Quotation",
"doctype": "Print Format",
- "html": "\n\n\n\n\n\n\n\n\n\n\n\n\n\t\n\t\n
\n\n",
+ "html": "\n\n\n\n\n\n\n\n\n\n\n\n\n\t\n\t\n
\n\n",
"module": "Selling",
"name": "__common__",
"print_format_type": "Client",
diff --git a/selling/Print Format/Quotation Spartan/Quotation Spartan.txt b/selling/Print Format/Quotation Spartan/Quotation Spartan.txt
index d2bfcd0737..c5b4cb92b3 100644
--- a/selling/Print Format/Quotation Spartan/Quotation Spartan.txt
+++ b/selling/Print Format/Quotation Spartan/Quotation Spartan.txt
@@ -2,14 +2,14 @@
{
"creation": "2013-04-19 13:30:51",
"docstatus": 0,
- "modified": "2013-05-28 17:18:38",
+ "modified": "2013-08-07 19:53:01",
"modified_by": "Administrator",
"owner": "Administrator"
},
{
"doc_type": "Quotation",
"doctype": "Print Format",
- "html": "\n\n\n\n\n\n\n\n\n\n\n\n\n\t\n\t\n
\n\n",
+ "html": "\n\n\n\n\n\n\n\n\n\n\n\n\n\t\n\t\n
\n\n",
"module": "Selling",
"name": "__common__",
"print_format_type": "Client",
diff --git a/selling/Print Format/Sales Order Classic/Sales Order Classic.txt b/selling/Print Format/Sales Order Classic/Sales Order Classic.txt
index 28e3af07eb..7f2748ac0c 100644
--- a/selling/Print Format/Sales Order Classic/Sales Order Classic.txt
+++ b/selling/Print Format/Sales Order Classic/Sales Order Classic.txt
@@ -2,14 +2,14 @@
{
"creation": "2013-04-19 13:30:51",
"docstatus": 0,
- "modified": "2013-05-28 17:20:59",
+ "modified": "2013-08-07 19:45:49",
"modified_by": "Administrator",
"owner": "Administrator"
},
{
"doc_type": "Sales Order",
"doctype": "Print Format",
- "html": "\n\n\n\n\n\n\n\n\n\n\n\n\n\t\n\t\n
\n\n",
+ "html": "\n\n\n\n\n\n\n\n\n\n\n\n\n\t\n\t\n
\n\n",
"module": "Selling",
"name": "__common__",
"print_format_type": "Client",
diff --git a/selling/Print Format/Sales Order Modern/Sales Order Modern.txt b/selling/Print Format/Sales Order Modern/Sales Order Modern.txt
index 5237068e40..e4102b2359 100644
--- a/selling/Print Format/Sales Order Modern/Sales Order Modern.txt
+++ b/selling/Print Format/Sales Order Modern/Sales Order Modern.txt
@@ -2,14 +2,14 @@
{
"creation": "2013-04-19 13:30:51",
"docstatus": 0,
- "modified": "2013-05-28 17:21:05",
+ "modified": "2013-08-07 20:12:23",
"modified_by": "Administrator",
"owner": "Administrator"
},
{
"doc_type": "Sales Order",
"doctype": "Print Format",
- "html": "\n\n\n\n\n\n\n\n\n\n\n\n\n\t\n\t\n
\n\n",
+ "html": "\n\n\n\n\n\n\n\n\n\n\n\n\n\t\n\t\n
\n\n",
"module": "Selling",
"name": "__common__",
"print_format_type": "Client",
diff --git a/selling/Print Format/Sales Order Spartan/Sales Order Spartan.txt b/selling/Print Format/Sales Order Spartan/Sales Order Spartan.txt
index f1f5d921ca..105b65b21b 100644
--- a/selling/Print Format/Sales Order Spartan/Sales Order Spartan.txt
+++ b/selling/Print Format/Sales Order Spartan/Sales Order Spartan.txt
@@ -2,14 +2,14 @@
{
"creation": "2013-04-19 13:30:51",
"docstatus": 0,
- "modified": "2013-05-28 17:20:50",
+ "modified": "2013-08-07 19:45:59",
"modified_by": "Administrator",
"owner": "Administrator"
},
{
"doc_type": "Sales Order",
"doctype": "Print Format",
- "html": "\n\n\n\n\n\n\n\n\n\n\n\n\n\t\n\t\n
\n\n",
+ "html": "\n\n\n\n\n\n\n\n\n\n\n\n\n\t\n\t\n
\n\n",
"module": "Selling",
"name": "__common__",
"print_format_type": "Client",
diff --git a/stock/Print Format/Delivery Note Classic/Delivery Note Classic.txt b/stock/Print Format/Delivery Note Classic/Delivery Note Classic.txt
index 4f6272d773..163dffaa87 100644
--- a/stock/Print Format/Delivery Note Classic/Delivery Note Classic.txt
+++ b/stock/Print Format/Delivery Note Classic/Delivery Note Classic.txt
@@ -2,14 +2,14 @@
{
"creation": "2013-04-19 13:31:11",
"docstatus": 0,
- "modified": "2013-05-28 17:20:31",
+ "modified": "2013-08-07 19:44:55",
"modified_by": "Administrator",
"owner": "Administrator"
},
{
"doc_type": "Delivery Note",
"doctype": "Print Format",
- "html": "\n\n\n\n\n\n\n\n\n\n\n\n\n\t\n\t\n
\n\n",
+ "html": "\n\n\n\n\n\n\n\n\n\n\n\n\n\t\n\t\n
\n\n",
"module": "Stock",
"name": "__common__",
"print_format_type": "Client",
diff --git a/stock/Print Format/Delivery Note Modern/Delivery Note Modern.txt b/stock/Print Format/Delivery Note Modern/Delivery Note Modern.txt
index 82d2376d04..f4323a9e1f 100644
--- a/stock/Print Format/Delivery Note Modern/Delivery Note Modern.txt
+++ b/stock/Print Format/Delivery Note Modern/Delivery Note Modern.txt
@@ -2,14 +2,14 @@
{
"creation": "2013-04-19 13:31:11",
"docstatus": 0,
- "modified": "2013-05-28 17:20:21",
+ "modified": "2013-08-07 20:12:29",
"modified_by": "Administrator",
"owner": "Administrator"
},
{
"doc_type": "Delivery Note",
"doctype": "Print Format",
- "html": "\n\n\n\n\n\n\n\n\n\n\n\n\n\t\n\t\n
\n\n",
+ "html": "\n\n\n\n\n\n\n\n\n\n\n\n\n\t\n\t\n
\n\n",
"module": "Stock",
"name": "__common__",
"print_format_type": "Client",
diff --git a/stock/Print Format/Delivery Note Spartan/Delivery Note Spartan.txt b/stock/Print Format/Delivery Note Spartan/Delivery Note Spartan.txt
index 81ecbd29b5..03fbef521e 100644
--- a/stock/Print Format/Delivery Note Spartan/Delivery Note Spartan.txt
+++ b/stock/Print Format/Delivery Note Spartan/Delivery Note Spartan.txt
@@ -2,14 +2,14 @@
{
"creation": "2013-04-19 13:31:11",
"docstatus": 0,
- "modified": "2013-05-28 17:20:39",
+ "modified": "2013-08-07 19:44:37",
"modified_by": "Administrator",
"owner": "Administrator"
},
{
"doc_type": "Delivery Note",
"doctype": "Print Format",
- "html": "\n\n\n\n\n\n\n\n\n\n\n\n\n\t\n\t\n
\n\n",
+ "html": "\n\n\n\n\n\n\n\n\n\n\n\n\n\t\n\t\n
\n\n",
"module": "Stock",
"name": "__common__",
"print_format_type": "Client",
diff --git a/stock/doctype/stock_ledger_entry/stock_ledger_entry.py b/stock/doctype/stock_ledger_entry/stock_ledger_entry.py
index 4a78421d6c..3fda3ba3dc 100644
--- a/stock/doctype/stock_ledger_entry/stock_ledger_entry.py
+++ b/stock/doctype/stock_ledger_entry/stock_ledger_entry.py
@@ -112,5 +112,4 @@ def on_doctype_update():
where Key_name="posting_sort_index" """):
webnotes.conn.commit()
webnotes.conn.sql("""alter table `tabStock Ledger Entry`
- add index posting_sort_index(posting_date, posting_time, name)""")
- webnotes.conn.begin()
\ No newline at end of file
+ add index posting_sort_index(posting_date, posting_time, name)""")
\ No newline at end of file
diff --git a/stock/doctype/stock_reconciliation/stock_reconciliation.py b/stock/doctype/stock_reconciliation/stock_reconciliation.py
index 36f872eb4f..dbe2d2a4c5 100644
--- a/stock/doctype/stock_reconciliation/stock_reconciliation.py
+++ b/stock/doctype/stock_reconciliation/stock_reconciliation.py
@@ -290,9 +290,8 @@ class DocType(StockController):
self.doc.stock_value_difference = 0.0
for d in self.entries:
- self.doc.stock_value_difference -= get_buying_amount(d.item_code, d.warehouse,
- d.actual_qty, self.doc.doctype, self.doc.name, d.voucher_detail_no,
- stock_ledger_entries)
+ self.doc.stock_value_difference -= get_buying_amount(d.item_code, self.doc.doctype, self.doc.name,
+ d.voucher_detail_no, stock_ledger_entries.get((d.item_code, d.warehouse), []))
webnotes.conn.set(self.doc, "stock_value_difference", self.doc.stock_value_difference)
def make_gl_entries(self):
diff --git a/stock/utils.py b/stock/utils.py
index d53d271e1c..96eeef644e 100644
--- a/stock/utils.py
+++ b/stock/utils.py
@@ -152,32 +152,28 @@ def get_warehouse_list(doctype, txt, searchfield, start, page_len, filters):
wlist.append([w])
return wlist
-def get_buying_amount(item_code, warehouse, qty, voucher_type, voucher_no, voucher_detail_no,
+def get_buying_amount(item_code, voucher_type, voucher_no, voucher_detail_no,
stock_ledger_entries, item_sales_bom=None):
if item_sales_bom and item_sales_bom.get(item_code):
# sales bom item
buying_amount = 0.0
for bom_item in item_sales_bom[item_code]:
if bom_item.get("parent_detail_docname")==voucher_detail_no:
- buying_amount += _get_buying_amount(voucher_type, voucher_no, voucher_detail_no,
- bom_item.item_code, bom_item.warehouse or warehouse,
- bom_item.total_qty or (bom_item.qty * qty), stock_ledger_entries)
+ buying_amount += _get_buying_amount(voucher_type, voucher_no, voucher_detail_no, stock_ledger_entries)
return buying_amount
else:
# doesn't have sales bom
- return _get_buying_amount(voucher_type, voucher_no, voucher_detail_no,
- item_code, warehouse, qty, stock_ledger_entries)
+ return _get_buying_amount(voucher_type, voucher_no, voucher_detail_no, stock_ledger_entries)
-def _get_buying_amount(voucher_type, voucher_no, item_row, item_code, warehouse, qty,
- stock_ledger_entries):
- relevant_stock_ledger_entries = [sle for sle in stock_ledger_entries
- if sle.item_code == item_code and sle.warehouse == warehouse]
-
- for i, sle in enumerate(relevant_stock_ledger_entries):
+def _get_buying_amount(voucher_type, voucher_no, item_row, stock_ledger_entries):
+ # IMP NOTE
+ # stock_ledger_entries should already be filtered by item_code and warehouse and
+ # sorted by posting_date desc, posting_time desc
+ for i, sle in enumerate(stock_ledger_entries):
if sle.voucher_type == voucher_type and sle.voucher_no == voucher_no and \
sle.voucher_detail_no == item_row:
- previous_stock_value = len(relevant_stock_ledger_entries) > i+1 and \
- flt(relevant_stock_ledger_entries[i+1].stock_value) or 0.0
+ previous_stock_value = len(stock_ledger_entries) > i+1 and \
+ flt(stock_ledger_entries[i+1].stock_value) or 0.0
buying_amount = previous_stock_value - flt(sle.stock_value)