Merge branch 'master' of github.com:webnotes/erpnext

This commit is contained in:
Anand Doshi
2013-03-12 11:06:06 +05:30
20 changed files with 655 additions and 230 deletions

View File

@@ -25,6 +25,8 @@ from webnotes.model.bean import getlist
from webnotes.model.code import get_obj
from webnotes import _, msgprint
from stock.utils import get_buying_amount, get_sales_bom
session = webnotes.session
month_map = {'Monthly': 1, 'Quarterly': 3, 'Half-yearly': 6, 'Yearly': 12}
@@ -95,7 +97,8 @@ class DocType(SellingController):
if not self.doc.recurring_id:
get_obj('Authorization Control').validate_approving_authority(self.doc.doctype,
self.doc.company, self.doc.grand_total, self)
self.set_buying_amount()
self.check_prev_docstatus()
get_obj("Sales Common").update_prevdoc_detail(1,self)
@@ -126,7 +129,7 @@ class DocType(SellingController):
self.check_next_docstatus()
sales_com_obj.update_prevdoc_detail(0, self)
self.make_gl_entries(is_cancel=1)
self.make_gl_entries()
def on_update_after_submit(self):
self.validate_recurring_invoice()
@@ -618,8 +621,7 @@ class DocType(SellingController):
'is_cancelled' : (update_stock==1) and 'No' or 'Yes',
'batch_no' : cstr(d['batch_no']),
'serial_no' : d['serial_no']
})
})
def update_stock_ledger(self, update_stock):
self.values = []
@@ -647,14 +649,29 @@ class DocType(SellingController):
return ret
def make_gl_entries(self, is_cancel=0):
from accounts.general_ledger import make_gl_entries
gl_entries = []
auto_inventory_accounting = webnotes.conn.get_value("Global Defaults", None,
"automatic_inventory_accounting")
abbr = self.get_company_abbr()
def make_gl_entries(self):
from accounts.general_ledger import make_gl_entries, merge_similar_entries
# parent's gl entry
gl_entries = []
self.make_customer_gl_entry(gl_entries)
self.make_tax_gl_entries(gl_entries)
self.make_item_gl_entries(gl_entries)
# merge gl entries before adding pos entries
gl_entries = merge_similar_entries(gl_entries)
self.make_pos_gl_entries(gl_entries)
update_outstanding = cint(self.doc.is_pos) and self.doc.write_off_account and 'No' or 'Yes'
if gl_entries:
make_gl_entries(gl_entries, cancel=(self.doc.docstatus == 2),
update_outstanding=update_outstanding, merge_entries=False)
def make_customer_gl_entry(self, gl_entries):
if self.doc.grand_total:
gl_entries.append(
self.get_gl_dict({
@@ -664,10 +681,10 @@ class DocType(SellingController):
"remarks": self.doc.remarks,
"against_voucher": self.doc.name,
"against_voucher_type": self.doc.doctype,
}, is_cancel)
})
)
# tax table gl entries
def make_tax_gl_entries(self, gl_entries):
for tax in self.doclist.get({"parentfield": "other_charges"}):
if flt(tax.tax_amount):
gl_entries.append(
@@ -677,11 +694,21 @@ class DocType(SellingController):
"credit": flt(tax.tax_amount),
"remarks": self.doc.remarks,
"cost_center": tax.cost_center_other_charges
}, is_cancel)
})
)
def make_item_gl_entries(self, gl_entries):
# item gl entries
for item in getlist(self.doclist, 'entries'):
auto_inventory_accounting = \
cint(webnotes.defaults.get_global_default("auto_inventory_accounting"))
if auto_inventory_accounting:
if cint(self.doc.is_pos) and cint(self.doc.update_stock):
stock_account = self.get_stock_in_hand_account()
else:
stock_account = "Stock Delivered But Not Billed - %s" % (self.company_abbr,)
for item in self.doclist.get({"parentfield": "entries"}):
# income account gl entries
if flt(item.amount):
gl_entries.append(
@@ -691,35 +718,33 @@ class DocType(SellingController):
"credit": item.amount,
"remarks": self.doc.remarks,
"cost_center": item.cost_center
}, is_cancel)
})
)
# if auto inventory accounting enabled and stock item,
# then do stock related gl entries
if auto_inventory_accounting and item.delivery_note and \
webnotes.conn.get_value("Item", item.item_code, "is_stock_item")=="Yes":
# to-do
purchase_rate = webnotes.conn.get_value("Delivery Note Item",
item.dn_detail, "purchase_rate")
valuation_amount = purchase_rate * item.qty
# expense account gl entries
if flt(valuation_amount):
gl_entries.append(
self.get_gl_dict({
"account": item.expense_account,
"against": "Stock Delivered But Not Billed - %s" % (abbr,),
"debit": valuation_amount,
"remarks": self.doc.remarks or "Accounting Entry for Stock"
}, is_cancel)
)
gl_entries.append(
self.get_gl_dict({
"account": "Stock Delivered But Not Billed - %s" % (abbr,),
"against": item.expense_account,
"credit": valuation_amount,
"remarks": self.doc.remarks or "Accounting Entry for Stock"
}, is_cancel)
)
if self.doc.is_pos and self.doc.cash_bank_account and self.doc.paid_amount:
# expense account gl entries
if auto_inventory_accounting and flt(item.buying_amount):
self.check_expense_account(item)
gl_entries.append(
self.get_gl_dict({
"account": item.expense_account,
"against": stock_account,
"debit": item.buying_amount,
"remarks": self.doc.remarks or "Accounting Entry for Stock",
"cost_center": item.cost_center
})
)
gl_entries.append(
self.get_gl_dict({
"account": stock_account,
"against": item.expense_account,
"credit": item.buying_amount,
"remarks": self.doc.remarks or "Accounting Entry for Stock"
})
)
def make_pos_gl_entries(self, gl_entries):
if cint(self.doc.is_pos) and self.doc.cash_bank_account and self.doc.paid_amount:
# POS, make payment entries
gl_entries.append(
self.get_gl_dict({
@@ -729,7 +754,7 @@ class DocType(SellingController):
"remarks": self.doc.remarks,
"against_voucher": self.doc.name,
"against_voucher_type": self.doc.doctype,
}, is_cancel)
})
)
gl_entries.append(
self.get_gl_dict({
@@ -737,7 +762,7 @@ class DocType(SellingController):
"against": self.doc.debit_to,
"debit": self.doc.paid_amount,
"remarks": self.doc.remarks,
}, is_cancel)
})
)
# write off entries, applicable if only pos
if self.doc.write_off_account and self.doc.write_off_amount:
@@ -749,7 +774,7 @@ class DocType(SellingController):
"remarks": self.doc.remarks,
"against_voucher": self.doc.name,
"against_voucher_type": self.doc.doctype,
}, is_cancel)
})
)
gl_entries.append(
self.get_gl_dict({
@@ -758,23 +783,50 @@ class DocType(SellingController):
"debit": self.doc.write_off_amount,
"remarks": self.doc.remarks,
"cost_center": self.doc.write_off_cost_center
}, is_cancel)
})
)
def set_buying_amount(self):
if cint(self.doc.is_pos) and cint(self.doc.update_stock):
stock_ledger_entries = self.get_stock_ledger_entries()
item_sales_bom = get_sales_bom()
else:
stock_ledger_entries = item_sales_bom = None
for item in self.doclist.get({"parentfield": "entries"}):
if item.item_code in self.stock_items:
item.buying_amount = self.get_item_buying_amount(item, stock_ledger_entries,
item_sales_bom)
webnotes.conn.set_value("Sales Invoice Item", item.name,
"buying_amount", item.buying_amount)
def get_item_buying_amount(self, item, stock_ledger_entries, item_sales_bom):
item_buying_amount = 0
if stock_ledger_entries:
# is pos and update stock
item_buying_amount = get_buying_amount(item.item_code, item.warehouse, item.qty,
self.doc.doctype, self.doc.name, item.name, stock_ledger_entries, item_sales_bom)
elif item.delivery_note and item.dn_detail:
# against delivery note
dn_item = webnotes.conn.get_value("Delivery Note Item", item.dn_detail,
["buying_amount", "qty"], as_dict=1)
item_buying_rate = flt(dn_item.buying_amount) / flt(dn_item.qty)
item_buying_amount = item_buying_rate * flt(item.qty)
return item_buying_amount
update_outstanding = self.doc.is_pos and self.doc.write_off_account and 'No' or 'Yes'
merge_entries=cint(self.doc.is_pos)!=1 and 1 or 0
if gl_entries:
make_gl_entries(gl_entries, cancel=is_cancel,
update_outstanding=update_outstanding, merge_entries=merge_entries)
def check_expense_account(self, item):
if not item.expense_account:
msgprint(_("""Expense account is mandatory for item: """) + item.item_code,
raise_exception=1)
def update_c_form(self):
"""Update amended id in C-form"""
if self.doc.c_form_no and self.doc.amended_from:
webnotes.conn.sql("""update `tabC-Form Invoice Detail` set invoice_no = %s,
invoice_date = %s, territory = %s, net_total = %s,
grand_total = %s where invoice_no = %s and parent = %s""", (self.doc.name, self.doc.amended_from, self.doc.c_form_no))
invoice_date = %s, territory = %s, net_total = %s,
grand_total = %s where invoice_no = %s and parent = %s""",
(self.doc.name, self.doc.amended_from, self.doc.c_form_no))
def check_next_docstatus(self):
submit_jv = webnotes.conn.sql("select t1.name from `tabJournal Voucher` t1,`tabJournal Voucher Detail` t2 where t1.name = t2.parent and t2.against_invoice = '%s' and t1.docstatus = 1" % (self.doc.name))

View File

@@ -53,16 +53,17 @@ class TestSalesInvoice(unittest.TestCase):
"Batched for Billing")
def test_sales_invoice_gl_entry_without_aii(self):
webnotes.defaults.set_global_default("auto_inventory_accounting", 0)
si = webnotes.bean(webnotes.copy_doclist(test_records[1]))
si.insert()
si.submit()
webnotes.defaults.set_global_default("auto_inventory_accounting", 0)
gl_entries = webnotes.conn.sql("""select account, debit, credit
from `tabGL Entry` where voucher_type='Sales Invoice' and voucher_no=%s
order by account asc""", si.doc.name, as_dict=1)
self.assertTrue(gl_entries)
expected_values = sorted([
[si.doc.debit_to, 630.0, 0.0],
[test_records[1][1]["income_account"], 0.0, 500.0],
@@ -74,8 +75,20 @@ class TestSalesInvoice(unittest.TestCase):
self.assertEquals(expected_values[i][0], gle.account)
self.assertEquals(expected_values[i][1], gle.debit)
self.assertEquals(expected_values[i][2], gle.credit)
# cancel
si.cancel()
gle_count = webnotes.conn.sql("""select count(name) from `tabGL Entry`
where voucher_type='Sales Invoice' and voucher_no=%s
and ifnull(is_cancelled, 'No') = 'Yes'
order by account asc""", si.doc.name)
self.assertEquals(gle_count[0][0], 8)
def test_sales_invoice_gl_entry_with_aii_delivery_note(self):
webnotes.conn.sql("delete from `tabStock Ledger Entry`")
def test_sales_invoice_gl_entry_with_aii(self):
webnotes.defaults.set_global_default("auto_inventory_accounting", 1)
self._insert_purchase_receipt()
@@ -83,8 +96,10 @@ class TestSalesInvoice(unittest.TestCase):
si_against_dn = webnotes.copy_doclist(test_records[1])
si_against_dn[1]["delivery_note"] = dn.doc.name
si = webnotes.bean(si_against_dn)
si_against_dn[1]["dn_detail"] = dn.doclist[1].name
si = webnotes.bean(si_against_dn)
si.insert()
si.submit()
gl_entries = webnotes.conn.sql("""select account, debit, credit
@@ -100,15 +115,154 @@ class TestSalesInvoice(unittest.TestCase):
["Stock Delivered But Not Billed - _TC", 0.0, 375.0],
[test_records[1][1]["expense_account"], 375.0, 0.0]
])
print expected_values
print gl_entries
for i, gle in enumerate(gl_entries):
self.assertEquals(expected_values[i][0], gle.account)
self.assertEquals(expected_values[i][1], gle.debit)
self.assertEquals(expected_values[i][2], gle.credit)
si.cancel()
gl_entries = webnotes.conn.sql("""select account, debit, credit
from `tabGL Entry` where voucher_type='Sales Invoice' and voucher_no=%s
and ifnull(is_cancelled, 'No') = 'No'
order by account asc, name asc""", si.doc.name, as_dict=1)
expected_values = sorted([
[si.doc.debit_to, 630.0, 0.0],
[si.doc.debit_to, 0.0, 630.0],
[test_records[1][1]["income_account"], 0.0, 500.0],
[test_records[1][1]["income_account"], 500.0, 0.0],
[test_records[1][2]["account_head"], 0.0, 80.0],
[test_records[1][2]["account_head"], 80.0, 0.0],
[test_records[1][3]["account_head"], 0.0, 50.0],
[test_records[1][3]["account_head"], 50.0, 0.0],
["Stock Delivered But Not Billed - _TC", 0.0, 375.0],
["Stock Delivered But Not Billed - _TC", 375.0, 0.0],
[test_records[1][1]["expense_account"], 375.0, 0.0],
[test_records[1][1]["expense_account"], 0.0, 375.0]
])
for i, gle in enumerate(gl_entries):
self.assertEquals(expected_values[i][0], gle.account)
self.assertEquals(expected_values[i][1], gle.debit)
self.assertEquals(expected_values[i][2], gle.credit)
webnotes.defaults.set_global_default("auto_inventory_accounting", 0)
def test_pos_gl_entry_with_aii(self):
webnotes.conn.sql("delete from `tabStock Ledger Entry`")
webnotes.defaults.set_global_default("auto_inventory_accounting", 1)
self._insert_purchase_receipt()
self._insert_pos_settings()
pos = webnotes.copy_doclist(test_records[1])
pos[0]["is_pos"] = 1
pos[0]["update_stock"] = 1
pos[0]["posting_time"] = "12:05"
pos[0]["cash_bank_account"] = "_Test Account Bank Account - _TC"
pos[0]["paid_amount"] = 600.0
si = webnotes.bean(pos)
si.insert()
si.submit()
# check stock ledger entries
sle = webnotes.conn.sql("""select * from `tabStock Ledger Entry`
where voucher_type = 'Sales Invoice' and voucher_no = %s""", si.doc.name, as_dict=1)[0]
self.assertTrue(sle)
self.assertEquals([sle.item_code, sle.warehouse, sle.actual_qty],
["_Test Item", "_Test Warehouse", -5.0])
# check gl entries
stock_in_hand_account = webnotes.conn.get_value("Company", "_Test Company",
"stock_in_hand_account")
gl_entries = webnotes.conn.sql("""select account, debit, credit
from `tabGL Entry` where voucher_type='Sales Invoice' and voucher_no=%s
order by account asc, debit asc""", si.doc.name, as_dict=1)
self.assertTrue(gl_entries)
expected_gl_entries = sorted([
[si.doc.debit_to, 630.0, 0.0],
[test_records[1][1]["income_account"], 0.0, 500.0],
[test_records[1][2]["account_head"], 0.0, 80.0],
[test_records[1][3]["account_head"], 0.0, 50.0],
[stock_in_hand_account, 0.0, 375.0],
[test_records[1][1]["expense_account"], 375.0, 0.0],
[si.doc.debit_to, 0.0, 600.0],
["_Test Account Bank Account - _TC", 600.0, 0.0]
])
for i, gle in enumerate(gl_entries):
self.assertEquals(expected_gl_entries[i][0], gle.account)
self.assertEquals(expected_gl_entries[i][1], gle.debit)
self.assertEquals(expected_gl_entries[i][2], gle.credit)
# cancel
si.cancel()
gl_count = webnotes.conn.sql("""select count(name)
from `tabGL Entry` where voucher_type='Sales Invoice' and voucher_no=%s
and ifnull(is_cancelled, 'No') = 'Yes'
order by account asc, name asc""", si.doc.name)
self.assertEquals(gl_count[0][0], 16)
webnotes.defaults.set_global_default("auto_inventory_accounting", 0)
def test_sales_invoice_gl_entry_with_aii_no_item_code(self):
webnotes.defaults.set_global_default("auto_inventory_accounting", 1)
si_copy = webnotes.copy_doclist(test_records[1])
si_copy[1]["item_code"] = None
si = webnotes.bean(si_copy)
si.insert()
si.submit()
gl_entries = webnotes.conn.sql("""select account, debit, credit
from `tabGL Entry` where voucher_type='Sales Invoice' and voucher_no=%s
order by account asc""", si.doc.name, as_dict=1)
self.assertTrue(gl_entries)
expected_values = sorted([
[si.doc.debit_to, 630.0, 0.0],
[test_records[1][1]["income_account"], 0.0, 500.0],
[test_records[1][2]["account_head"], 0.0, 80.0],
[test_records[1][3]["account_head"], 0.0, 50.0],
])
for i, gle in enumerate(gl_entries):
self.assertEquals(expected_values[i][0], gle.account)
self.assertEquals(expected_values[i][1], gle.debit)
self.assertEquals(expected_values[i][2], gle.credit)
webnotes.defaults.set_global_default("auto_inventory_accounting", 0)
def test_sales_invoice_gl_entry_with_aii_non_stock_item(self):
webnotes.defaults.set_global_default("auto_inventory_accounting", 1)
si_copy = webnotes.copy_doclist(test_records[1])
si_copy[1]["item_code"] = "_Test Non Stock Item"
si = webnotes.bean(si_copy)
si.insert()
si.submit()
gl_entries = webnotes.conn.sql("""select account, debit, credit
from `tabGL Entry` where voucher_type='Sales Invoice' and voucher_no=%s
order by account asc""", si.doc.name, as_dict=1)
self.assertTrue(gl_entries)
expected_values = sorted([
[si.doc.debit_to, 630.0, 0.0],
[test_records[1][1]["income_account"], 0.0, 500.0],
[test_records[1][2]["account_head"], 0.0, 80.0],
[test_records[1][3]["account_head"], 0.0, 50.0],
])
for i, gle in enumerate(gl_entries):
self.assertEquals(expected_values[i][0], gle.account)
self.assertEquals(expected_values[i][1], gle.debit)
self.assertEquals(expected_values[i][2], gle.credit)
webnotes.defaults.set_global_default("auto_inventory_accounting", 0)
def _insert_purchase_receipt(self):
from stock.doctype.purchase_receipt.test_purchase_receipt import test_records \
@@ -126,6 +280,23 @@ class TestSalesInvoice(unittest.TestCase):
dn.submit()
return dn
def _insert_pos_settings(self):
ps = webnotes.bean([
{
"cash_bank_account": "_Test Account Bank Account - _TC",
"company": "_Test Company",
"conversion_rate": 1.0,
"cost_center": "_Test Cost Center - _TC",
"currency": "INR",
"doctype": "POS Setting",
"income_account": "_Test Account Bank Account - _TC",
"price_list_name": "_Test Price List",
"territory": "_Test Territory",
"warehouse": "_Test Warehouse"
}
])
ps.insert()
test_dependencies = ["Journal Voucher"]
test_records = [
@@ -178,7 +349,19 @@ test_records = [
"doctype": "Sales Taxes and Charges",
"parentfield": "other_charges",
"tax_amount": 31.8,
}
},
{
"parentfield": "sales_team",
"doctype": "Sales Team",
"sales_person": "_Test Sales Person 1",
"allocated_percentage": 65.5,
},
{
"parentfield": "sales_team",
"doctype": "Sales Team",
"sales_person": "_Test Sales Person 2",
"allocated_percentage": 34.5,
},
],
[
{
@@ -207,13 +390,13 @@ test_records = [
"description": "_Test Item",
"doctype": "Sales Invoice Item",
"parentfield": "entries",
"qty": 1.0,
"qty": 5.0,
"basic_rate": 500.0,
"amount": 500.0,
"export_rate": 500.0,
"export_amount": 500.0,
"income_account": "Sales - _TC",
"expense_account": "_Test Account Cost for Goods Sold",
"expense_account": "_Test Account Cost for Goods Sold - _TC",
"cost_center": "_Test Cost Center - _TC",
},
{

View File

@@ -1,8 +1,8 @@
[
{
"creation": "2013-03-05 09:11:04",
"creation": "2013-03-07 11:42:55",
"docstatus": 0,
"modified": "2013-03-07 07:03:30",
"modified": "2013-03-11 14:58:50",
"modified_by": "Administrator",
"owner": "Administrator"
},
@@ -30,7 +30,8 @@
"fieldname": "barcode",
"fieldtype": "Data",
"label": "Barcode",
"print_hide": 1
"print_hide": 1,
"read_only": 0
},
{
"doctype": "DocField",
@@ -42,6 +43,7 @@
"oldfieldtype": "Link",
"options": "Item",
"print_hide": 0,
"read_only": 0,
"reqd": 0,
"search_index": 1
},
@@ -63,6 +65,7 @@
"oldfieldname": "item_name",
"oldfieldtype": "Data",
"print_hide": 1,
"read_only": 0,
"reqd": 1,
"search_index": 0
},
@@ -74,6 +77,7 @@
"oldfieldname": "description",
"oldfieldtype": "Text",
"print_width": "200px",
"read_only": 0,
"reqd": 1,
"width": "200px"
},
@@ -84,6 +88,7 @@
"label": "Qty",
"oldfieldname": "qty",
"oldfieldtype": "Currency",
"read_only": 0,
"reqd": 0
},
{
@@ -102,6 +107,7 @@
"oldfieldtype": "Currency",
"options": "currency",
"print_hide": 1,
"read_only": 0,
"reqd": 0
},
{
@@ -111,7 +117,8 @@
"label": "Discount (%)",
"oldfieldname": "adj_rate",
"oldfieldtype": "Float",
"print_hide": 1
"print_hide": 1,
"read_only": 0
},
{
"doctype": "DocField",
@@ -121,6 +128,7 @@
"oldfieldname": "export_rate",
"oldfieldtype": "Currency",
"options": "currency",
"read_only": 0,
"reqd": 1
},
{
@@ -155,6 +163,7 @@
"oldfieldtype": "Currency",
"options": "Company:company:default_currency",
"print_hide": 1,
"read_only": 0,
"reqd": 1,
"search_index": 0
},
@@ -179,7 +188,8 @@
"oldfieldname": "warehouse",
"oldfieldtype": "Link",
"options": "Warehouse",
"print_hide": 1
"print_hide": 1,
"read_only": 0
},
{
"doctype": "DocField",
@@ -192,9 +202,20 @@
"options": "Account",
"print_hide": 1,
"print_width": "120px",
"read_only": 0,
"reqd": 1,
"width": "120px"
},
{
"doctype": "DocField",
"fieldname": "expense_account",
"fieldtype": "Link",
"hidden": 1,
"in_filter": 1,
"label": "Expense Account",
"options": "Account",
"print_hide": 1
},
{
"doctype": "DocField",
"fieldname": "cost_center",
@@ -206,6 +227,7 @@
"options": "Cost Center",
"print_hide": 1,
"print_width": "120px",
"read_only": 0,
"reqd": 0,
"width": "120px"
},
@@ -217,7 +239,8 @@
"label": "Serial No",
"oldfieldname": "serial_no",
"oldfieldtype": "Small Text",
"print_hide": 0
"print_hide": 0,
"read_only": 0
},
{
"doctype": "DocField",
@@ -225,7 +248,8 @@
"fieldtype": "Link",
"label": "Batch No",
"options": "Batch",
"print_hide": 1
"print_hide": 1,
"read_only": 0
},
{
"doctype": "DocField",
@@ -249,7 +273,8 @@
"label": "Brand Name",
"oldfieldname": "brand",
"oldfieldtype": "Data",
"print_hide": 1
"print_hide": 1,
"read_only": 0
},
{
"doctype": "DocField",
@@ -328,7 +353,8 @@
"fieldname": "time_log_batch",
"fieldtype": "Link",
"label": "Time Log Batch",
"options": "Time Log Batch"
"options": "Time Log Batch",
"read_only": 0
},
{
"doctype": "DocField",
@@ -353,6 +379,17 @@
"print_hide": 1,
"read_only": 1
},
{
"doctype": "DocField",
"fieldname": "buying_amount",
"fieldtype": "Currency",
"hidden": 1,
"label": "Buying Amount",
"no_copy": 1,
"options": "Company:company:default_currency",
"print_hide": 1,
"read_only": 1
},
{
"allow_on_submit": 1,
"doctype": "DocField",
@@ -361,6 +398,7 @@
"label": "Page Break",
"no_copy": 1,
"print_hide": 1,
"read_only": 0,
"report_hide": 1
}
]

View File

@@ -25,7 +25,7 @@ def execute(filters=None):
for row in delivery_note_items:
selling_amount = flt(row.amount)
buying_amount = get_buying_amount(row.item_code, row.warehouse,
row.qty, row.name, row.item_row, stock_ledger_entries, item_sales_bom)
row.qty, "Delivery Note", row.name, row.item_row, stock_ledger_entries, item_sales_bom)
if selling_amount:
gross_profit = selling_amount - buying_amount
gross_profit_percent = (gross_profit / selling_amount) * 100.0