Merge branch 'master' into edge

This commit is contained in:
Anand Doshi
2013-03-22 14:16:53 +05:30
22 changed files with 247 additions and 259 deletions

View File

@@ -308,4 +308,24 @@ cur_frm.cscript.on_submit = function(doc, cdt, cdn) {
if(cint(wn.boot.notification_settings.delivery_note)) {
cur_frm.email_doc(wn.boot.notification_settings.delivery_note_message);
}
}
// expense account
cur_frm.fields_dict['delivery_note_details'].grid.get_field('expense_account').get_query = function(doc) {
return {
"query": "accounts.utils.get_account_list",
"filters": {
"is_pl_account": "Yes",
"debit_or_credit": "Debit",
"company": doc.company
}
}
}
// cost center
cur_frm.fields_dict["delivery_note_details"].grid.get_field("cost_center").get_query = function(doc) {
return {
query: "accounts.utils.get_cost_center_list",
filters: { company_name: doc.company}
}
}

View File

@@ -144,6 +144,8 @@ class DocType(SellingController):
self.validate_mandatory()
self.validate_reference_value()
self.validate_for_items()
self.validate_warehouse()
sales_com_obj.validate_max_discount(self, 'delivery_note_details')
sales_com_obj.get_allocated_sum(self)
sales_com_obj.check_conversion_rate(self)
@@ -203,6 +205,12 @@ class DocType(SellingController):
else:
chk_dupl_itm.append(f)
def validate_warehouse(self):
for d in self.get_item_list():
if webnotes.conn.get_value("Item", d['item_code'], "is_stock_item") == "Yes":
if not d['warehouse']:
msgprint("Please enter Warehouse for item %s as it is stock item"
% d['item_code'], raise_exception=1)
def validate_items_with_prevdoc(self, d):
"""check if same item, warehouse present in prevdoc"""
@@ -393,41 +401,17 @@ class DocType(SellingController):
total = (amount/self.doc.net_total)*self.doc.grand_total
get_obj('Sales Common').check_credit(self, total)
def set_buying_amount(self):
from stock.utils import get_buying_amount, get_sales_bom
stock_ledger_entries = self.get_stock_ledger_entries()
item_sales_bom = get_sales_bom()
if stock_ledger_entries:
for item in self.doclist.get({"parentfield": "delivery_note_details"}):
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,
item_sales_bom)
item.buying_amount = buying_amount > 0 and buying_amount or 0
webnotes.conn.set_value("Delivery Note Item", item.name, "buying_amount",
item.buying_amount)
self.validate_warehouse()
def validate_warehouse(self):
for d in self.get_item_list():
if webnotes.conn.get_value("Item", d['item_code'], "is_stock_item") == "Yes":
if not d['warehouse']:
msgprint("Please enter Warehouse for item %s as it is stock item"
% d['item_code'], raise_exception=1)
def make_gl_entries(self):
if not cint(webnotes.defaults.get_global_default("auto_inventory_accounting")):
return
against_stock_account = self.get_default_account("stock_delivered_but_not_billed")
total_buying_amount = self.get_total_buying_amount()
super(DocType, self).make_gl_entries(against_stock_account, -1*total_buying_amount)
def get_total_buying_amount(self):
total_buying_amount = sum([item.buying_amount for item in
self.doclist.get({"parentfield": "delivery_note_details"})])
return total_buying_amount
gl_entries = []
for item in self.doclist.get({"parentfield": "delivery_note_details"}):
self.check_expense_account(item)
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
make_gl_entries(gl_entries)

View File

@@ -56,15 +56,19 @@ class TestDeliveryNote(unittest.TestCase):
self._insert_purchase_receipt()
dn = webnotes.bean(copy=test_records[0])
dn.doclist[1].expense_account = "Cost of Goods Sold - _TC"
dn.doclist[1].cost_center = "Auto Inventory Accounting - _TC"
stock_in_hand_account = webnotes.conn.get_value("Company", dn.doc.company,
"stock_in_hand_account")
from accounts.utils import get_balance_on
prev_bal = get_balance_on(stock_in_hand_account, dn.doc.posting_date)
dn.insert()
dn.submit()
gl_entries = webnotes.conn.sql("""select account, debit, credit
from `tabGL Entry` where voucher_type='Delivery Note' and voucher_no=%s
order by account asc""", dn.doc.name, as_dict=1)
@@ -72,9 +76,8 @@ class TestDeliveryNote(unittest.TestCase):
expected_values = sorted([
[stock_in_hand_account, 0.0, 375.0],
["Stock Delivered But Not Billed - _TC", 375.0, 0.0]
["Cost of Goods Sold - _TC", 375.0, 0.0]
])
for i, gle in enumerate(gl_entries):
self.assertEquals(expected_values[i][0], gle.account)
self.assertEquals(expected_values[i][1], gle.debit)

View File

@@ -2,7 +2,7 @@
{
"creation": "2013-03-07 11:42:59",
"docstatus": 0,
"modified": "2013-03-07 15:46:43",
"modified": "2013-03-21 18:36:22",
"modified_by": "Administrator",
"owner": "Administrator"
},
@@ -236,6 +236,7 @@
"doctype": "DocField",
"fieldname": "batch_no",
"fieldtype": "Link",
"hidden": 0,
"label": "Batch No",
"oldfieldname": "batch_no",
"oldfieldtype": "Link",
@@ -243,6 +244,28 @@
"print_hide": 1,
"read_only": 0
},
{
"doctype": "DocField",
"fieldname": "expense_account",
"fieldtype": "Link",
"hidden": 1,
"label": "Expense Account",
"no_copy": 1,
"options": "Account",
"print_hide": 1,
"width": "120px"
},
{
"doctype": "DocField",
"fieldname": "cost_center",
"fieldtype": "Link",
"hidden": 1,
"label": "Cost Center",
"no_copy": 1,
"options": "Cost Center",
"print_hide": 1,
"width": "120px"
},
{
"doctype": "DocField",
"fieldname": "item_group",

View File

@@ -1,8 +1,8 @@
[
{
"creation": "2013-02-22 01:28:01",
"creation": "2013-03-08 15:37:16",
"docstatus": 0,
"modified": "2013-03-07 07:03:22",
"modified": "2013-03-21 17:29:45",
"modified_by": "Administrator",
"owner": "Administrator"
},
@@ -10,7 +10,7 @@
"autoname": "ITEMCUST/.#####",
"description": "For the convenience of customers, these codes can be used in print formats like Invoices and Delivery Notes",
"doctype": "DocType",
"in_create": 1,
"in_create": 0,
"istable": 1,
"module": "Stock",
"name": "__common__",

View File

@@ -1,15 +1,15 @@
[
{
"creation": "2013-02-22 01:28:01",
"creation": "2013-03-08 15:37:16",
"docstatus": 0,
"modified": "2013-03-07 07:03:22",
"modified": "2013-03-21 17:29:15",
"modified_by": "Administrator",
"owner": "Administrator"
},
{
"autoname": "RFD/.#####",
"doctype": "DocType",
"in_create": 1,
"in_create": 0,
"istable": 1,
"module": "Stock",
"name": "__common__",

View File

@@ -19,7 +19,8 @@ cur_frm.fields_dict['delivery_note'].get_query = function(doc, cdt, cdn) {
}
cur_frm.fields_dict['item_details'].grid.get_field('item_code').get_query = function(doc, cdt, cdn) {
cur_frm.fields_dict['item_details'].grid.get_field('item_code').get_query =
function(doc, cdt, cdn) {
var query = 'SELECT name, item_name, description FROM `tabItem` WHERE name IN ( \
SELECT item_code FROM `tabDelivery Note Item` dnd \
WHERE parent="' + doc.delivery_note + '" AND IFNULL(qty, 0) > IFNULL(packed_qty, 0)) AND %(key)s LIKE "%s" LIMIT 50';
@@ -34,9 +35,10 @@ cur_frm.add_fetch("item_code", "net_weight", "net_weight");
cur_frm.add_fetch("item_code", "weight_uom", "weight_uom");
cur_frm.cscript.onload_post_render = function(doc, cdt, cdn) {
console.log(make_doclist(cdt, cdn));
if(doc.delivery_note && doc.__islocal) {
var ps_detail = getchildren('Packing Slip Item', doc.name, 'item_details');
if(!(flt(ps_detail[0].net_weight) && cstr(ps_detail[0].weight_uom))) {
if(!(flt(ps_detail.net_weight) && cstr(ps_detail.weight_uom))) {
cur_frm.cscript.update_item_details(doc);
}
}

View File

@@ -40,15 +40,12 @@ class DocType:
"""
Validates if delivery note has status as submitted
"""
res = webnotes.conn.sql("""\
SELECT docstatus FROM `tabDelivery Note`
WHERE name=%(delivery_note)s
""", self.doc.fields)
res = webnotes.conn.sql("""SELECT docstatus FROM `tabDelivery Note`
WHERE name=%(delivery_note)s""", self.doc.fields)
if not(res and res[0][0]==0):
webnotes.msgprint("""Invalid Delivery Note. Delivery Note should exist
and should be in draft state. Please rectify and try again.""",
raise_exception=1)
and should be in draft state. Please rectify and try again.""", raise_exception=1)
def validate_case_nos(self):
@@ -65,11 +62,10 @@ class DocType:
raise_exception=1)
res = webnotes.conn.sql("""\
SELECT name FROM `tabPacking Slip`
res = webnotes.conn.sql("""SELECT name FROM `tabPacking Slip`
WHERE delivery_note = %(delivery_note)s AND docstatus = 1 AND
(from_case_no BETWEEN %(from_case_no)s AND %(to_case_no)s
OR to_case_no BETWEEN %(from_case_no)s AND %(to_case_no)s)\
OR to_case_no BETWEEN %(from_case_no)s AND %(to_case_no)s)
""", self.doc.fields)
if res:
@@ -133,10 +129,10 @@ class DocType:
item['recommended_qty'] = (flt(item['qty']) - flt(item['packed_qty'])) / no_of_cases
item['specified_qty'] = flt(ps_item_qty[item['item_code']])
webnotes.msgprint("""\
webnotes.msgprint("""
Invalid Quantity specified (%(specified_qty)s %(stock_uom)s).
%(packed_qty)s out of %(qty)s %(stock_uom)s already packed for %(item_code)s.
<b>Recommended quantity for %(item_code)s = %(recommended_qty)s \
<b>Recommended quantity for %(item_code)s = %(recommended_qty)s
%(stock_uom)s</b>""" % item, raise_exception=1)
@@ -167,16 +163,15 @@ class DocType:
for item in dn_details:
new_packed_qty = flt(item['packed_qty'])
if (new_packed_qty < 0) or (new_packed_qty > flt(item['qty'])):
webnotes.msgprint("Invalid new packed quantity for item %s. \
Please try again or contact support@erpnext.com" % item['item_code'], raise_exception=1)
webnotes.msgprint("""Invalid new packed quantity for item %s.
Please try again or contact support@erpnext.com""" %
item['item_code'], raise_exception=1)
webnotes.conn.sql("""\
UPDATE `tabDelivery Note Item`
SET packed_qty = %s
WHERE parent = %s AND item_code = %s""",
webnotes.conn.sql("""UPDATE `tabDelivery Note Item`
SET packed_qty = %s WHERE parent = %s AND item_code = %s""",
(new_packed_qty, self.doc.delivery_note, item['item_code']))
webnotes.conn.set_value("Delivery Note", self.doc.delivery_note,
"modified", now())
webnotes.conn.set_value("Delivery Note", self.doc.delivery_note, "modified", now())
def update_item_details(self):
@@ -191,8 +186,7 @@ class DocType:
def set_item_details(self, row):
res = webnotes.conn.sql("""\
SELECT item_name, SUM(IFNULL(qty, 0)) as total_qty,
res = webnotes.conn.sql("""SELECT item_name, SUM(IFNULL(qty, 0)) as total_qty,
IFNULL(packed_qty, 0) as packed_qty, stock_uom
FROM `tabDelivery Note Item`
WHERE parent=%s AND item_code=%s GROUP BY item_code""",
@@ -203,10 +197,9 @@ class DocType:
if not row.qty:
row.qty = qty >= 0 and qty or 0
res = webnotes.conn.sql("""\
SELECT net_weight, weight_uom FROM `tabItem`
WHERE name=%s""", self.doc.item_code, as_dict=1)
res = webnotes.conn.sql("""SELECT net_weight, weight_uom FROM `tabItem`
WHERE name=%s""", row.item_code, as_dict=1)
if res and len(res)>0:
row.net_weight = res[0]["net_weight"]
row.weight_uom = res[0]["weight_uom"]
@@ -217,8 +210,7 @@ class DocType:
Returns the next case no. for a new packing slip for a delivery
note
"""
recommended_case_no = webnotes.conn.sql("""\
SELECT MAX(to_case_no) FROM `tabPacking Slip`
recommended_case_no = webnotes.conn.sql("""SELECT MAX(to_case_no) FROM `tabPacking Slip`
WHERE delivery_note = %(delivery_note)s AND docstatus=1""", self.doc.fields)
return cint(recommended_case_no[0][0]) + 1

View File

@@ -318,10 +318,14 @@ class DocType(BuyingController):
if not cint(webnotes.defaults.get_global_default("auto_inventory_accounting")):
return
from accounts.general_ledger import make_gl_entries
against_stock_account = self.get_default_account("stock_received_but_not_billed")
total_valuation_amount = self.get_total_valuation_amount()
gl_entries = self.get_gl_entries_for_stock(against_stock_account, total_valuation_amount)
super(DocType, self).make_gl_entries(against_stock_account, total_valuation_amount)
if gl_entries:
make_gl_entries(gl_entries, cancel=self.doc.docstatus == 2)
def get_total_valuation_amount(self):
total_valuation_amount = 0.0

View File

@@ -173,13 +173,17 @@ class DocType(StockController):
if not self.doc.expense_adjustment_account:
webnotes.msgprint(_("Please enter Expense/Adjustment Account"), raise_exception=1)
from accounts.general_ledger import make_gl_entries
cost_center = "Auto Inventory Accounting - %s" % (self.company_abbr,)
total_valuation_amount = self.get_total_valuation_amount()
super(DocType, self).make_gl_entries(self.doc.expense_adjustment_account,
total_valuation_amount, cost_center)
gl_entries = self.get_gl_entries_for_stock(self.doc.expense_adjustment_account,
total_valuation_amount, cost_center=cost_center)
if gl_entries:
make_gl_entries(gl_entries, cancel=self.doc.docstatus == 2)
def get_total_valuation_amount(self):
total_valuation_amount = 0
for item in self.doclist.get({"parentfield": "mtn_details"}):

View File

@@ -26,7 +26,7 @@ class TestStockEntry(unittest.TestCase):
self.assertTrue(mr_name)
def atest_material_receipt_gl_entry(self):
def test_material_receipt_gl_entry(self):
webnotes.conn.sql("delete from `tabStock Ledger Entry`")
webnotes.defaults.set_global_default("auto_inventory_accounting", 1)
@@ -63,7 +63,7 @@ class TestStockEntry(unittest.TestCase):
webnotes.defaults.set_global_default("auto_inventory_accounting", 0)
def atest_material_issue_gl_entry(self):
def test_material_issue_gl_entry(self):
webnotes.conn.sql("delete from `tabStock Ledger Entry`")
webnotes.defaults.set_global_default("auto_inventory_accounting", 1)
@@ -151,7 +151,7 @@ class TestStockEntry(unittest.TestCase):
self.assertEquals(expected_sle[i][1], sle.warehouse)
self.assertEquals(expected_sle[i][2], sle.actual_qty)
def acheck_gl_entries(self, voucher_type, voucher_no, expected_gl_entries):
def check_gl_entries(self, voucher_type, voucher_no, expected_gl_entries):
# check gl entries
gl_entries = webnotes.conn.sql("""select account, debit, credit

View File

@@ -309,10 +309,14 @@ class DocType(StockController):
if not self.doc.expense_account:
msgprint(_("Please enter Expense Account"), raise_exception=1)
from accounts.general_ledger import make_gl_entries
cost_center = "Auto Inventory Accounting - %s" % (self.company_abbr,)
super(DocType, self).make_gl_entries(self.doc.expense_account,
self.doc.stock_value_difference, cost_center)
gl_entries = self.get_gl_entries_for_stock(self.doc.expense_account,
self.doc.stock_value_difference, cost_center=cost_center)
if gl_entries:
make_gl_entries(gl_entries, cancel=self.doc.docstatus == 2)
@webnotes.whitelist()
def upload():

View File

@@ -171,7 +171,8 @@ def get_buying_amount(item_code, warehouse, qty, voucher_type, voucher_no, vouch
buying_amount = 0.0
for bom_item in item_sales_bom[item_code]:
buying_amount += _get_buying_amount(voucher_type, voucher_no, "[** No Item Row **]",
bom_item.item_code, warehouse, bom_item.qty * qty, stock_ledger_entries)
bom_item.item_code, bom_item.warehouse or warehouse,
bom_item.total_qty or (bom_item.qty * qty), stock_ledger_entries)
return buying_amount
else:
# doesn't have sales bom
@@ -184,21 +185,10 @@ def _get_buying_amount(voucher_type, voucher_no, item_row, item_code, warehouse,
if sle.voucher_type == voucher_type and sle.voucher_no == voucher_no and \
(sle.voucher_detail_no == item_row or (sle.voucher_type != "Stock Reconciliation"
and sle.item_code == item_code and sle.warehouse == warehouse and flt(sle.qty) == qty)):
# print "previous_sle", stock_ledger_entries[i+1]
# print "current sle", sle
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)
return buying_amount
return 0.0
def get_sales_bom():
item_sales_bom = {}
# for r in webnotes.conn.sql("""select parent_item, item_code, qty, warehouse, voucher_detail_no
# from `tabDelivery Note Packing Item` where docstatus = 1""", as_dict=1):
for r in webnotes.conn.sql("""select parent, item_code, qty from `tabSales BOM Item`""",
as_dict=1):
item_sales_bom.setdefault(r.parent, []).append(r)
return item_sales_bom
return 0.0