aii: gl_entries for sales invoice

This commit is contained in:
Nabin Hait
2013-03-11 16:32:33 +05:30
parent fd6d2e0d2f
commit 8c7234f270
15 changed files with 484 additions and 139 deletions

View File

@@ -25,6 +25,8 @@ from webnotes.model.bean import getlist
from webnotes.model.code import get_obj from webnotes.model.code import get_obj
from webnotes import _, msgprint from webnotes import _, msgprint
from stock.utils import get_buying_amount, get_sales_bom
session = webnotes.session session = webnotes.session
month_map = {'Monthly': 1, 'Quarterly': 3, 'Half-yearly': 6, 'Yearly': 12} month_map = {'Monthly': 1, 'Quarterly': 3, 'Half-yearly': 6, 'Yearly': 12}
@@ -95,7 +97,8 @@ class DocType(SellingController):
if not self.doc.recurring_id: if not self.doc.recurring_id:
get_obj('Authorization Control').validate_approving_authority(self.doc.doctype, get_obj('Authorization Control').validate_approving_authority(self.doc.doctype,
self.doc.company, self.doc.grand_total, self) self.doc.company, self.doc.grand_total, self)
self.set_buying_amount()
self.check_prev_docstatus() self.check_prev_docstatus()
get_obj("Sales Common").update_prevdoc_detail(1,self) get_obj("Sales Common").update_prevdoc_detail(1,self)
@@ -126,7 +129,7 @@ class DocType(SellingController):
self.check_next_docstatus() self.check_next_docstatus()
sales_com_obj.update_prevdoc_detail(0, self) 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): def on_update_after_submit(self):
self.validate_recurring_invoice() self.validate_recurring_invoice()
@@ -619,8 +622,7 @@ class DocType(SellingController):
'is_cancelled' : (update_stock==1) and 'No' or 'Yes', 'is_cancelled' : (update_stock==1) and 'No' or 'Yes',
'batch_no' : cstr(d['batch_no']), 'batch_no' : cstr(d['batch_no']),
'serial_no' : d['serial_no'] 'serial_no' : d['serial_no']
}) })
def update_stock_ledger(self, update_stock): def update_stock_ledger(self, update_stock):
self.values = [] self.values = []
@@ -648,14 +650,29 @@ class DocType(SellingController):
return ret return ret
def make_gl_entries(self, is_cancel=0): def make_gl_entries(self):
from accounts.general_ledger import make_gl_entries from accounts.general_ledger import make_gl_entries, merge_similar_entries
gl_entries = []
auto_inventory_accounting = webnotes.conn.get_value("Global Defaults", None,
"automatic_inventory_accounting")
abbr = self.get_company_abbr()
# 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: if self.doc.grand_total:
gl_entries.append( gl_entries.append(
self.get_gl_dict({ self.get_gl_dict({
@@ -665,10 +682,10 @@ class DocType(SellingController):
"remarks": self.doc.remarks, "remarks": self.doc.remarks,
"against_voucher": self.doc.name, "against_voucher": self.doc.name,
"against_voucher_type": self.doc.doctype, "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"}): for tax in self.doclist.get({"parentfield": "other_charges"}):
if flt(tax.tax_amount): if flt(tax.tax_amount):
gl_entries.append( gl_entries.append(
@@ -678,11 +695,21 @@ class DocType(SellingController):
"credit": flt(tax.tax_amount), "credit": flt(tax.tax_amount),
"remarks": self.doc.remarks, "remarks": self.doc.remarks,
"cost_center": tax.cost_center_other_charges "cost_center": tax.cost_center_other_charges
}, is_cancel) })
) )
def make_item_gl_entries(self, gl_entries):
# item 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 # income account gl entries
if flt(item.amount): if flt(item.amount):
gl_entries.append( gl_entries.append(
@@ -692,35 +719,31 @@ class DocType(SellingController):
"credit": item.amount, "credit": item.amount,
"remarks": self.doc.remarks, "remarks": self.doc.remarks,
"cost_center": item.cost_center "cost_center": item.cost_center
}, is_cancel) })
) )
# if auto inventory accounting enabled and stock item,
# then do stock related gl entries # expense account gl entries
if auto_inventory_accounting and item.delivery_note and \ if auto_inventory_accounting and flt(item.buying_amount):
webnotes.conn.get_value("Item", item.item_code, "is_stock_item")=="Yes": gl_entries.append(
# to-do self.get_gl_dict({
purchase_rate = webnotes.conn.get_value("Delivery Note Item", "account": item.expense_account,
item.dn_detail, "purchase_rate") "against": stock_account,
valuation_amount = purchase_rate * item.qty "debit": item.buying_amount,
# expense account gl entries "remarks": self.doc.remarks or "Accounting Entry for Stock",
if flt(valuation_amount): "cost_center": item.cost_center
gl_entries.append( })
self.get_gl_dict({ )
"account": item.expense_account, gl_entries.append(
"against": "Stock Delivered But Not Billed - %s" % (abbr,), self.get_gl_dict({
"debit": valuation_amount, "account": stock_account,
"remarks": self.doc.remarks or "Accounting Entry for Stock" "against": item.expense_account,
}, is_cancel) "credit": item.buying_amount,
) "remarks": self.doc.remarks or "Accounting Entry for Stock"
gl_entries.append( })
self.get_gl_dict({ )
"account": "Stock Delivered But Not Billed - %s" % (abbr,),
"against": item.expense_account, def make_pos_gl_entries(self, gl_entries):
"credit": valuation_amount, if cint(self.doc.is_pos) and self.doc.cash_bank_account and self.doc.paid_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:
# POS, make payment entries # POS, make payment entries
gl_entries.append( gl_entries.append(
self.get_gl_dict({ self.get_gl_dict({
@@ -730,7 +753,7 @@ class DocType(SellingController):
"remarks": self.doc.remarks, "remarks": self.doc.remarks,
"against_voucher": self.doc.name, "against_voucher": self.doc.name,
"against_voucher_type": self.doc.doctype, "against_voucher_type": self.doc.doctype,
}, is_cancel) })
) )
gl_entries.append( gl_entries.append(
self.get_gl_dict({ self.get_gl_dict({
@@ -738,7 +761,7 @@ class DocType(SellingController):
"against": self.doc.debit_to, "against": self.doc.debit_to,
"debit": self.doc.paid_amount, "debit": self.doc.paid_amount,
"remarks": self.doc.remarks, "remarks": self.doc.remarks,
}, is_cancel) })
) )
# write off entries, applicable if only pos # write off entries, applicable if only pos
if self.doc.write_off_account and self.doc.write_off_amount: if self.doc.write_off_account and self.doc.write_off_amount:
@@ -750,7 +773,7 @@ class DocType(SellingController):
"remarks": self.doc.remarks, "remarks": self.doc.remarks,
"against_voucher": self.doc.name, "against_voucher": self.doc.name,
"against_voucher_type": self.doc.doctype, "against_voucher_type": self.doc.doctype,
}, is_cancel) })
) )
gl_entries.append( gl_entries.append(
self.get_gl_dict({ self.get_gl_dict({
@@ -759,23 +782,45 @@ class DocType(SellingController):
"debit": self.doc.write_off_amount, "debit": self.doc.write_off_amount,
"remarks": self.doc.remarks, "remarks": self.doc.remarks,
"cost_center": self.doc.write_off_cost_center "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 update_c_form(self): def update_c_form(self):
"""Update amended id in C-form""" """Update amended id in C-form"""
if self.doc.c_form_no and self.doc.amended_from: if self.doc.c_form_no and self.doc.amended_from:
webnotes.conn.sql("""update `tabC-Form Invoice Detail` set invoice_no = %s, webnotes.conn.sql("""update `tabC-Form Invoice Detail` set invoice_no = %s,
invoice_date = %s, territory = %s, net_total = %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)) 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): 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)) 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") "Batched for Billing")
def test_sales_invoice_gl_entry_without_aii(self): 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 = webnotes.bean(webnotes.copy_doclist(test_records[1]))
si.insert() si.insert()
si.submit() si.submit()
webnotes.defaults.set_global_default("auto_inventory_accounting", 0)
gl_entries = webnotes.conn.sql("""select account, debit, credit gl_entries = webnotes.conn.sql("""select account, debit, credit
from `tabGL Entry` where voucher_type='Sales Invoice' and voucher_no=%s from `tabGL Entry` where voucher_type='Sales Invoice' and voucher_no=%s
order by account asc""", si.doc.name, as_dict=1) order by account asc""", si.doc.name, as_dict=1)
self.assertTrue(gl_entries) self.assertTrue(gl_entries)
expected_values = sorted([ expected_values = sorted([
[si.doc.debit_to, 630.0, 0.0], [si.doc.debit_to, 630.0, 0.0],
[test_records[1][1]["income_account"], 0.0, 500.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][0], gle.account)
self.assertEquals(expected_values[i][1], gle.debit) self.assertEquals(expected_values[i][1], gle.debit)
self.assertEquals(expected_values[i][2], gle.credit) 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) webnotes.defaults.set_global_default("auto_inventory_accounting", 1)
self._insert_purchase_receipt() self._insert_purchase_receipt()
@@ -83,8 +96,10 @@ class TestSalesInvoice(unittest.TestCase):
si_against_dn = webnotes.copy_doclist(test_records[1]) si_against_dn = webnotes.copy_doclist(test_records[1])
si_against_dn[1]["delivery_note"] = dn.doc.name 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.insert()
si.submit() si.submit()
gl_entries = webnotes.conn.sql("""select account, debit, credit 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], ["Stock Delivered But Not Billed - _TC", 0.0, 375.0],
[test_records[1][1]["expense_account"], 375.0, 0.0] [test_records[1][1]["expense_account"], 375.0, 0.0]
]) ])
print expected_values
print gl_entries
for i, gle in enumerate(gl_entries): for i, gle in enumerate(gl_entries):
self.assertEquals(expected_values[i][0], gle.account) self.assertEquals(expected_values[i][0], gle.account)
self.assertEquals(expected_values[i][1], gle.debit) self.assertEquals(expected_values[i][1], gle.debit)
self.assertEquals(expected_values[i][2], gle.credit) 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) 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): def _insert_purchase_receipt(self):
from stock.doctype.purchase_receipt.test_purchase_receipt import test_records \ from stock.doctype.purchase_receipt.test_purchase_receipt import test_records \
@@ -126,6 +280,23 @@ class TestSalesInvoice(unittest.TestCase):
dn.submit() dn.submit()
return dn 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_dependencies = ["Journal Voucher"]
test_records = [ test_records = [
@@ -178,7 +349,19 @@ test_records = [
"doctype": "Sales Taxes and Charges", "doctype": "Sales Taxes and Charges",
"parentfield": "other_charges", "parentfield": "other_charges",
"tax_amount": 31.8, "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", "description": "_Test Item",
"doctype": "Sales Invoice Item", "doctype": "Sales Invoice Item",
"parentfield": "entries", "parentfield": "entries",
"qty": 1.0, "qty": 5.0,
"basic_rate": 500.0, "basic_rate": 500.0,
"amount": 500.0, "amount": 500.0,
"export_rate": 500.0, "export_rate": 500.0,
"export_amount": 500.0, "export_amount": 500.0,
"income_account": "Sales - _TC", "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", "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, "docstatus": 0,
"modified": "2013-03-07 07:03:30", "modified": "2013-03-11 14:58:50",
"modified_by": "Administrator", "modified_by": "Administrator",
"owner": "Administrator" "owner": "Administrator"
}, },
@@ -30,7 +30,8 @@
"fieldname": "barcode", "fieldname": "barcode",
"fieldtype": "Data", "fieldtype": "Data",
"label": "Barcode", "label": "Barcode",
"print_hide": 1 "print_hide": 1,
"read_only": 0
}, },
{ {
"doctype": "DocField", "doctype": "DocField",
@@ -42,6 +43,7 @@
"oldfieldtype": "Link", "oldfieldtype": "Link",
"options": "Item", "options": "Item",
"print_hide": 0, "print_hide": 0,
"read_only": 0,
"reqd": 0, "reqd": 0,
"search_index": 1 "search_index": 1
}, },
@@ -63,6 +65,7 @@
"oldfieldname": "item_name", "oldfieldname": "item_name",
"oldfieldtype": "Data", "oldfieldtype": "Data",
"print_hide": 1, "print_hide": 1,
"read_only": 0,
"reqd": 1, "reqd": 1,
"search_index": 0 "search_index": 0
}, },
@@ -74,6 +77,7 @@
"oldfieldname": "description", "oldfieldname": "description",
"oldfieldtype": "Text", "oldfieldtype": "Text",
"print_width": "200px", "print_width": "200px",
"read_only": 0,
"reqd": 1, "reqd": 1,
"width": "200px" "width": "200px"
}, },
@@ -84,6 +88,7 @@
"label": "Qty", "label": "Qty",
"oldfieldname": "qty", "oldfieldname": "qty",
"oldfieldtype": "Currency", "oldfieldtype": "Currency",
"read_only": 0,
"reqd": 0 "reqd": 0
}, },
{ {
@@ -102,6 +107,7 @@
"oldfieldtype": "Currency", "oldfieldtype": "Currency",
"options": "currency", "options": "currency",
"print_hide": 1, "print_hide": 1,
"read_only": 0,
"reqd": 0 "reqd": 0
}, },
{ {
@@ -111,7 +117,8 @@
"label": "Discount (%)", "label": "Discount (%)",
"oldfieldname": "adj_rate", "oldfieldname": "adj_rate",
"oldfieldtype": "Float", "oldfieldtype": "Float",
"print_hide": 1 "print_hide": 1,
"read_only": 0
}, },
{ {
"doctype": "DocField", "doctype": "DocField",
@@ -121,6 +128,7 @@
"oldfieldname": "export_rate", "oldfieldname": "export_rate",
"oldfieldtype": "Currency", "oldfieldtype": "Currency",
"options": "currency", "options": "currency",
"read_only": 0,
"reqd": 1 "reqd": 1
}, },
{ {
@@ -155,6 +163,7 @@
"oldfieldtype": "Currency", "oldfieldtype": "Currency",
"options": "Company:company:default_currency", "options": "Company:company:default_currency",
"print_hide": 1, "print_hide": 1,
"read_only": 0,
"reqd": 1, "reqd": 1,
"search_index": 0 "search_index": 0
}, },
@@ -179,7 +188,8 @@
"oldfieldname": "warehouse", "oldfieldname": "warehouse",
"oldfieldtype": "Link", "oldfieldtype": "Link",
"options": "Warehouse", "options": "Warehouse",
"print_hide": 1 "print_hide": 1,
"read_only": 0
}, },
{ {
"doctype": "DocField", "doctype": "DocField",
@@ -192,9 +202,20 @@
"options": "Account", "options": "Account",
"print_hide": 1, "print_hide": 1,
"print_width": "120px", "print_width": "120px",
"read_only": 0,
"reqd": 1, "reqd": 1,
"width": "120px" "width": "120px"
}, },
{
"doctype": "DocField",
"fieldname": "expense_account",
"fieldtype": "Link",
"hidden": 1,
"in_filter": 1,
"label": "Expense Account",
"options": "Account",
"print_hide": 1
},
{ {
"doctype": "DocField", "doctype": "DocField",
"fieldname": "cost_center", "fieldname": "cost_center",
@@ -206,6 +227,7 @@
"options": "Cost Center", "options": "Cost Center",
"print_hide": 1, "print_hide": 1,
"print_width": "120px", "print_width": "120px",
"read_only": 0,
"reqd": 0, "reqd": 0,
"width": "120px" "width": "120px"
}, },
@@ -217,7 +239,8 @@
"label": "Serial No", "label": "Serial No",
"oldfieldname": "serial_no", "oldfieldname": "serial_no",
"oldfieldtype": "Small Text", "oldfieldtype": "Small Text",
"print_hide": 0 "print_hide": 0,
"read_only": 0
}, },
{ {
"doctype": "DocField", "doctype": "DocField",
@@ -225,7 +248,8 @@
"fieldtype": "Link", "fieldtype": "Link",
"label": "Batch No", "label": "Batch No",
"options": "Batch", "options": "Batch",
"print_hide": 1 "print_hide": 1,
"read_only": 0
}, },
{ {
"doctype": "DocField", "doctype": "DocField",
@@ -249,7 +273,8 @@
"label": "Brand Name", "label": "Brand Name",
"oldfieldname": "brand", "oldfieldname": "brand",
"oldfieldtype": "Data", "oldfieldtype": "Data",
"print_hide": 1 "print_hide": 1,
"read_only": 0
}, },
{ {
"doctype": "DocField", "doctype": "DocField",
@@ -328,7 +353,8 @@
"fieldname": "time_log_batch", "fieldname": "time_log_batch",
"fieldtype": "Link", "fieldtype": "Link",
"label": "Time Log Batch", "label": "Time Log Batch",
"options": "Time Log Batch" "options": "Time Log Batch",
"read_only": 0
}, },
{ {
"doctype": "DocField", "doctype": "DocField",
@@ -353,6 +379,17 @@
"print_hide": 1, "print_hide": 1,
"read_only": 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, "allow_on_submit": 1,
"doctype": "DocField", "doctype": "DocField",
@@ -361,6 +398,7 @@
"label": "Page Break", "label": "Page Break",
"no_copy": 1, "no_copy": 1,
"print_hide": 1, "print_hide": 1,
"read_only": 0,
"report_hide": 1 "report_hide": 1
} }
] ]

View File

@@ -25,7 +25,7 @@ def execute(filters=None):
for row in delivery_note_items: for row in delivery_note_items:
selling_amount = flt(row.amount) selling_amount = flt(row.amount)
buying_amount = get_buying_amount(row.item_code, row.warehouse, 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: if selling_amount:
gross_profit = selling_amount - buying_amount gross_profit = selling_amount - buying_amount
gross_profit_percent = (gross_profit / selling_amount) * 100.0 gross_profit_percent = (gross_profit / selling_amount) * 100.0

View File

@@ -21,7 +21,7 @@ from webnotes.utils import flt
from utilities.transaction_base import TransactionBase from utilities.transaction_base import TransactionBase
class AccountsController(TransactionBase): class AccountsController(TransactionBase):
def get_gl_dict(self, args, cancel): def get_gl_dict(self, args, cancel=None):
"""this method populates the common properties of a gl entry record""" """this method populates the common properties of a gl entry record"""
gl_dict = { gl_dict = {
'company': self.doc.company, 'company': self.doc.company,
@@ -30,7 +30,7 @@ class AccountsController(TransactionBase):
'voucher_no': self.doc.name, 'voucher_no': self.doc.name,
'aging_date': self.doc.fields.get("aging_date") or self.doc.posting_date, 'aging_date': self.doc.fields.get("aging_date") or self.doc.posting_date,
'remarks': self.doc.remarks, 'remarks': self.doc.remarks,
'is_cancelled': cancel and "Yes" or "No", 'is_cancelled': self.doc.docstatus == 2 and "Yes" or "No",
'fiscal_year': self.doc.fiscal_year, 'fiscal_year': self.doc.fiscal_year,
'debit': 0, 'debit': 0,
'credit': 0, 'credit': 0,

View File

@@ -37,4 +37,27 @@ class SellingController(AccountsController):
self.doc.grand_total or self.doc.rounded_total, company_currency) self.doc.grand_total or self.doc.rounded_total, company_currency)
if self.meta.get_field("in_words_export"): if self.meta.get_field("in_words_export"):
self.doc.in_words_export = money_in_words(disable_rounded_total and self.doc.in_words_export = money_in_words(disable_rounded_total and
self.doc.grand_total_export or self.doc.rounded_total_export, self.doc.currency) self.doc.grand_total_export or self.doc.rounded_total_export, self.doc.currency)
def get_stock_ledger_entries(self):
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,
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
and item_code in (%s) and warehouse in (%s)
order by item_code desc, warehouse desc, posting_date desc,
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)
def get_distinct_item_warehouse(self):
item_list = []
warehouse_list = []
for item in self.doclist.get({"parentfield": self.fname}) \
+ self.doclist.get({"parentfield": "packing_details"}):
item_list.append(item.item_code)
warehouse_list.append(item.warehouse)
return list(set(item_list)), list(set(warehouse_list))

View File

@@ -1,6 +1,14 @@
erpnext.updates = [ erpnext.updates = [
["5th March", ["Refactored Upload Attendace Tool"]],
["4th March", ["Lead organization added in Quotation classic/spartan/modern print format"]],
["1st March", [ ["1st March", [
"Time Log, Time Log Batch: Created feature to batch Time Logs so that they can be tracked for billing." "Time Log, Time Log Batch: Created feature to batch Time Logs so that they can be tracked for billing.",
"Sub-contracting code refactored for PO",
]],
["28th February", [
"Datatype validation in Voucher Import Tool",
"Fixes for conversion factor in old invoices",
"Fixed asynchronus issue in purchase cycle"
]], ]],
["27th February", [ ["27th February", [
"Time Log: Created Time Log System, with Calendar View." "Time Log: Created Time Log System, with Calendar View."

View File

@@ -0,0 +1,10 @@
import webnotes
def execute():
dn_list = webnotes.conn.sql("""select name from `tabDelivery Note` where docstatus < 2""")
for dn in dn_list:
webnotes.bean("Delivery Note", dn[0]).set_buying_amount()
si_list = webnotes.conn.sql("""select name from `tabSales Invoice` where docstatus < 2""")
for si in si_list:
webnotes.bean("Sales Invoice", si[0]).set_buying_amount()

View File

@@ -4,5 +4,19 @@ test_records = [
"sales_person_name": "_Test Sales Person", "sales_person_name": "_Test Sales Person",
"parent_sales_person": "All Sales Persons", "parent_sales_person": "All Sales Persons",
"is_group": "No" "is_group": "No"
}],
[{
"doctype": "Sales Person",
"sales_person_name": "_Test Sales Person 1",
"parent_sales_person": "All Sales Persons",
"is_group": "No"
}],
[{
"doctype": "Sales Person",
"sales_person_name": "_Test Sales Person 2",
"parent_sales_person": "All Sales Persons",
"is_group": "No"
}] }]
] ]

View File

@@ -225,7 +225,12 @@ class DocType(SellingController):
bin = sql("select actual_qty, projected_qty from `tabBin` where item_code = %s and warehouse = %s", (d.item_code, d.warehouse), as_dict = 1) bin = sql("select actual_qty, projected_qty from `tabBin` where item_code = %s and warehouse = %s", (d.item_code, d.warehouse), as_dict = 1)
d.actual_qty = bin and flt(bin[0]['actual_qty']) or 0 d.actual_qty = bin and flt(bin[0]['actual_qty']) or 0
d.projected_qty = bin and flt(bin[0]['projected_qty']) or 0 d.projected_qty = bin and flt(bin[0]['projected_qty']) or 0
def on_update(self):
self.doclist = get_obj('Sales Common').make_packing_list(self,'delivery_note_details')
sl = get_obj('Stock Ledger')
sl.scrub_serial_nos(self)
sl.scrub_serial_nos(self, 'packing_details')
def on_submit(self): def on_submit(self):
self.validate_packed_qty() self.validate_packed_qty()
@@ -252,6 +257,7 @@ class DocType(SellingController):
self.credit_limit() self.credit_limit()
self.set_buying_amount()
self.make_gl_entries() self.make_gl_entries()
# set DN status # set DN status
@@ -387,13 +393,19 @@ class DocType(SellingController):
if amount != 0: if amount != 0:
total = (amount/self.doc.net_total)*self.doc.grand_total total = (amount/self.doc.net_total)*self.doc.grand_total
get_obj('Sales Common').check_credit(self, total) get_obj('Sales Common').check_credit(self, total)
def set_buying_amount(self):
def on_update(self): from stock.utils import get_buying_amount, get_sales_bom
self.doclist = get_obj('Sales Common').make_packing_list(self,'delivery_note_details') stock_ledger_entries = self.get_stock_ledger_entries()
sl = get_obj('Stock Ledger') item_sales_bom = get_sales_bom()
sl.scrub_serial_nos(self)
sl.scrub_serial_nos(self, 'packing_details') if stock_ledger_entries:
for item in self.doclist.get({"parentfield": "delivery_note_details"}):
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)
webnotes.conn.set_value("Delivery Note Item", item.name, "buying_amount",
item.buying_amount)
def make_gl_entries(self): def make_gl_entries(self):
if not cint(webnotes.defaults.get_global_default("auto_inventory_accounting")): if not cint(webnotes.defaults.get_global_default("auto_inventory_accounting")):
@@ -426,38 +438,6 @@ class DocType(SellingController):
make_gl_entries(gl_entries, cancel=self.doc.docstatus == 2) make_gl_entries(gl_entries, cancel=self.doc.docstatus == 2)
def get_total_buying_amount(self): def get_total_buying_amount(self):
from stock.utils import get_buying_amount, get_sales_bom total_buying_amount = sum([item.buying_amount for item in
stock_ledger_entries = self.get_stock_ledger_entries() self.doclist.get({"parentfield": "delivery_note_details"})])
item_sales_bom = get_sales_bom() return total_buying_amount
total_buying_amount = 0
if stock_ledger_entries:
for item in self.doclist.get({"parentfield": "delivery_note_details"}):
buying_amount = get_buying_amount(item.item_code, item.warehouse, item.qty,
self.doc.name, item.name, stock_ledger_entries, item_sales_bom)
total_buying_amount += buying_amount
return total_buying_amount
def get_stock_ledger_entries(self):
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,
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
and item_code in (%s) and warehouse in (%s)
order by item_code desc, warehouse desc, posting_date desc,
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)
def get_distinct_item_warehouse(self):
item_list = []
warehouse_list = []
for item in self.doclist.get({"parentfield": "delivery_note_details"}) \
+ self.doclist.get({"parentfield": "packing_details"}):
item_list.append(item.item_code)
warehouse_list.append(item.warehouse)
return list(set(item_list)), list(set(warehouse_list))

View File

@@ -48,6 +48,8 @@ class TestDeliveryNote(unittest.TestCase):
def test_delivery_note_gl_entry(self): def test_delivery_note_gl_entry(self):
webnotes.conn.sql("""delete from `tabBin`""") webnotes.conn.sql("""delete from `tabBin`""")
webnotes.conn.sql("delete from `tabStock Ledger Entry`")
webnotes.defaults.set_global_default("auto_inventory_accounting", 1) webnotes.defaults.set_global_default("auto_inventory_accounting", 1)
self.assertEqual(cint(webnotes.defaults.get_global_default("auto_inventory_accounting")), 1) self.assertEqual(cint(webnotes.defaults.get_global_default("auto_inventory_accounting")), 1)

View File

@@ -1,8 +1,8 @@
[ [
{ {
"creation": "2013-02-22 01:28:00", "creation": "2013-03-07 11:42:59",
"docstatus": 0, "docstatus": 0,
"modified": "2013-03-07 07:03:20", "modified": "2013-03-07 15:46:43",
"modified_by": "Administrator", "modified_by": "Administrator",
"owner": "Administrator" "owner": "Administrator"
}, },
@@ -30,7 +30,8 @@
"fieldname": "barcode", "fieldname": "barcode",
"fieldtype": "Data", "fieldtype": "Data",
"label": "Barcode", "label": "Barcode",
"print_hide": 1 "print_hide": 1,
"read_only": 0
}, },
{ {
"doctype": "DocField", "doctype": "DocField",
@@ -42,6 +43,7 @@
"oldfieldtype": "Link", "oldfieldtype": "Link",
"options": "Item", "options": "Item",
"print_width": "150px", "print_width": "150px",
"read_only": 0,
"reqd": 1, "reqd": 1,
"search_index": 1, "search_index": 1,
"width": "150px" "width": "150px"
@@ -64,6 +66,7 @@
"oldfieldtype": "Data", "oldfieldtype": "Data",
"print_hide": 1, "print_hide": 1,
"print_width": "150px", "print_width": "150px",
"read_only": 0,
"reqd": 1, "reqd": 1,
"width": "150px" "width": "150px"
}, },
@@ -75,6 +78,7 @@
"oldfieldname": "description", "oldfieldname": "description",
"oldfieldtype": "Small Text", "oldfieldtype": "Small Text",
"print_width": "300px", "print_width": "300px",
"read_only": 0,
"reqd": 1, "reqd": 1,
"width": "300px" "width": "300px"
}, },
@@ -87,6 +91,7 @@
"oldfieldname": "qty", "oldfieldname": "qty",
"oldfieldtype": "Currency", "oldfieldtype": "Currency",
"print_width": "100px", "print_width": "100px",
"read_only": 0,
"reqd": 1, "reqd": 1,
"width": "100px" "width": "100px"
}, },
@@ -115,6 +120,7 @@
"options": "currency", "options": "currency",
"print_hide": 1, "print_hide": 1,
"print_width": "100px", "print_width": "100px",
"read_only": 0,
"reqd": 0, "reqd": 0,
"width": "100px" "width": "100px"
}, },
@@ -128,6 +134,7 @@
"oldfieldtype": "Float", "oldfieldtype": "Float",
"print_hide": 1, "print_hide": 1,
"print_width": "100px", "print_width": "100px",
"read_only": 0,
"width": "100px" "width": "100px"
}, },
{ {
@@ -140,6 +147,7 @@
"options": "currency", "options": "currency",
"print_hide": 0, "print_hide": 0,
"print_width": "150px", "print_width": "150px",
"read_only": 0,
"reqd": 0, "reqd": 0,
"width": "150px" "width": "150px"
}, },
@@ -181,6 +189,7 @@
"options": "Company:company:default_currency", "options": "Company:company:default_currency",
"print_hide": 1, "print_hide": 1,
"print_width": "150px", "print_width": "150px",
"read_only": 0,
"reqd": 0, "reqd": 0,
"width": "150px" "width": "150px"
}, },
@@ -208,6 +217,7 @@
"options": "Warehouse", "options": "Warehouse",
"print_hide": 1, "print_hide": 1,
"print_width": "100px", "print_width": "100px",
"read_only": 0,
"width": "100px" "width": "100px"
}, },
{ {
@@ -219,7 +229,8 @@
"no_copy": 1, "no_copy": 1,
"oldfieldname": "serial_no", "oldfieldname": "serial_no",
"oldfieldtype": "Text", "oldfieldtype": "Text",
"print_hide": 0 "print_hide": 0,
"read_only": 0
}, },
{ {
"doctype": "DocField", "doctype": "DocField",
@@ -229,7 +240,8 @@
"oldfieldname": "batch_no", "oldfieldname": "batch_no",
"oldfieldtype": "Link", "oldfieldtype": "Link",
"options": "Batch", "options": "Batch",
"print_hide": 1 "print_hide": 1,
"read_only": 0
}, },
{ {
"doctype": "DocField", "doctype": "DocField",
@@ -375,6 +387,17 @@
"print_hide": 1, "print_hide": 1,
"read_only": 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, "allow_on_submit": 1,
"doctype": "DocField", "doctype": "DocField",
@@ -383,6 +406,7 @@
"label": "Page Break", "label": "Page Break",
"oldfieldname": "page_break", "oldfieldname": "page_break",
"oldfieldtype": "Check", "oldfieldtype": "Check",
"print_hide": 1 "print_hide": 1,
"read_only": 0
} }
] ]

View File

@@ -127,4 +127,23 @@ test_records = [
"is_sub_contracted_item": "Yes", "is_sub_contracted_item": "Yes",
"stock_uom": "_Test UOM" "stock_uom": "_Test UOM"
}], }],
[{
"doctype": "Item",
"item_code": "_Test Non Stock Item",
"item_name": "_Test Non Stock Item",
"description": "_Test Non Stock Item",
"item_group": "_Test Item Group Desktops",
"is_stock_item": "No",
"is_asset_item": "No",
"has_batch_no": "No",
"has_serial_no": "No",
"is_purchase_item": "Yes",
"is_sales_item": "Yes",
"is_service_item": "No",
"is_sample_item": "No",
"inspection_required": "No",
"is_pro_applicable": "No",
"is_sub_contracted_item": "No",
"stock_uom": "_Test UOM"
}],
] ]

View File

@@ -36,7 +36,6 @@ def update_entries_after(args, verbose=1):
} }
""" """
previous_sle = get_sle_before_datetime(args) previous_sle = get_sle_before_datetime(args)
qty_after_transaction = flt(previous_sle.get("qty_after_transaction")) qty_after_transaction = flt(previous_sle.get("qty_after_transaction"))
valuation_rate = flt(previous_sle.get("valuation_rate")) valuation_rate = flt(previous_sle.get("valuation_rate"))
stock_queue = json.loads(previous_sle.get("stock_queue") or "[]") stock_queue = json.loads(previous_sle.get("stock_queue") or "[]")
@@ -214,7 +213,6 @@ def get_moving_average_values(qty_after_transaction, sle, valuation_rate):
def get_fifo_values(qty_after_transaction, sle, stock_queue): def get_fifo_values(qty_after_transaction, sle, stock_queue):
incoming_rate = flt(sle.incoming_rate) incoming_rate = flt(sle.incoming_rate)
actual_qty = flt(sle.actual_qty) actual_qty = flt(sle.actual_qty)
if not stock_queue: if not stock_queue:
stock_queue.append([0, 0]) stock_queue.append([0, 0])

View File

@@ -164,23 +164,24 @@ def get_warehouse_list(doctype, txt, searchfield, start, page_len, filters):
wlist.append([w]) wlist.append([w])
return wlist return wlist
def get_buying_amount(item_code, warehouse, qty, voucher_no, voucher_detail_no, def get_buying_amount(item_code, warehouse, qty, voucher_type, voucher_no, voucher_detail_no,
stock_ledger_entries, item_sales_bom): stock_ledger_entries, item_sales_bom):
if item_sales_bom.get(item_code): if item_sales_bom.get(item_code):
# sales bom item # sales bom item
buying_amount = 0.0 buying_amount = 0.0
for bom_item in item_sales_bom[item_code]: for bom_item in item_sales_bom[item_code]:
buying_amount += _get_buying_amount(voucher_no, "[** No Item Row **]", buying_amount += _get_buying_amount(voucher_type, voucher_no, "[** No Item Row **]",
item_code, warehouse, bom_item.qty * qty, stock_ledger_entries) item_code, warehouse, bom_item.qty * qty, stock_ledger_entries)
return buying_amount return buying_amount
else: else:
# doesn't have sales bom # doesn't have sales bom
return _get_buying_amount(voucher_no, voucher_detail_no, item_code, warehouse, qty, return _get_buying_amount(voucher_type, voucher_no, voucher_detail_no,
stock_ledger_entries) item_code, warehouse, qty, stock_ledger_entries)
def _get_buying_amount(voucher_no, item_row, item_code, warehouse, qty, stock_ledger_entries): def _get_buying_amount(voucher_type, voucher_no, item_row, item_code, warehouse, qty,
stock_ledger_entries):
for i, sle in enumerate(stock_ledger_entries): for i, sle in enumerate(stock_ledger_entries):
if sle.voucher_type == "Delivery Note" and sle.voucher_no == voucher_no: if sle.voucher_type == voucher_type and sle.voucher_no == voucher_no:
if (sle.voucher_detail_no == item_row) or \ if (sle.voucher_detail_no == item_row) or \
(sle.item_code == item_code and sle.warehouse == warehouse and \ (sle.item_code == item_code and sle.warehouse == warehouse and \
abs(flt(sle.qty)) == qty): abs(flt(sle.qty)) == qty):