Cleanup and test cases for serialized item

This commit is contained in:
Nabin Hait
2015-07-24 13:26:36 +05:30
parent f061877b4f
commit 3cf67a462b
21 changed files with 275 additions and 218 deletions

View File

@@ -24,8 +24,7 @@ erpnext.stock.DeliveryNoteController = erpnext.selling.SellingController.extend(
cur_frm.add_custom_button(__('Make Installation Note'), this.make_installation_note);
if (doc.docstatus==1) {
cur_frm.add_custom_button(__('Make Sales Return'), this.make_sales_return,
frappe.boot.doctype_icons["Delivery Note"]);
cur_frm.add_custom_button(__('Make Sales Return'), this.make_sales_return);
this.show_stock_ledger();
this.show_general_ledger();
@@ -33,7 +32,7 @@ erpnext.stock.DeliveryNoteController = erpnext.selling.SellingController.extend(
if(doc.docstatus==0 && !doc.__islocal) {
cur_frm.add_custom_button(__('Make Packing Slip'),
cur_frm.cscript['Make Packing Slip'], frappe.boot.doctype_icons["Packing Slip"], "btn-default");
cur_frm.cscript['Make Packing Slip'], frappe.boot.doctype_icons["Packing Slip"]);
}
erpnext.stock.delivery_note.set_print_hide(doc, dt, dn);
@@ -57,7 +56,7 @@ erpnext.stock.DeliveryNoteController = erpnext.selling.SellingController.extend(
company: cur_frm.doc.company
}
})
}, "icon-download", "btn-default");
});
}
},

View File

@@ -209,7 +209,7 @@
"fieldname": "is_return",
"fieldtype": "Check",
"label": "Is Return",
"no_copy": 1,
"no_copy": 0,
"permlevel": 0,
"precision": "",
"print_hide": 1,
@@ -220,7 +220,7 @@
"fieldname": "return_against",
"fieldtype": "Link",
"label": "Return Against Delivery Note",
"no_copy": 1,
"no_copy": 0,
"options": "Delivery Note",
"permlevel": 0,
"precision": "",
@@ -1092,7 +1092,7 @@
"idx": 1,
"in_create": 0,
"is_submittable": 1,
"modified": "2015-07-17 13:29:28.019506",
"modified": "2015-07-24 11:49:15.056249",
"modified_by": "Administrator",
"module": "Stock",
"name": "Delivery Note",

View File

@@ -395,5 +395,5 @@ def make_packing_slip(source_name, target_doc=None):
@frappe.whitelist()
def make_sales_return(source_name, target_doc=None):
from erpnext.utilities.transaction_base import make_return_doc
from erpnext.controllers.sales_and_purchase_return import make_return_doc
return make_return_doc("Delivery Note", source_name, target_doc)

View File

@@ -177,8 +177,9 @@ class TestDeliveryNote(unittest.TestCase):
self.assertRaises(SerialNoStatusError, dn.submit)
def check_serial_no_values(self, serial_no, field_values):
serial_no = frappe.get_doc("Serial No", serial_no)
for field, value in field_values.items():
self.assertEquals(cstr(frappe.db.get_value("Serial No", serial_no, field)), value)
self.assertEquals(cstr(serial_no.get(field)), value)
def test_sales_return_for_non_bundled_items(self):
set_perpetual_inventory()
@@ -286,6 +287,45 @@ class TestDeliveryNote(unittest.TestCase):
self.assertEquals(gle_warehouse_amount, 1400)
set_perpetual_inventory(0)
def test_return_for_serialized_items(self):
se = make_serialized_item()
serial_no = get_serial_nos(se.get("items")[0].serial_no)[0]
dn = create_delivery_note(item_code="_Test Serialized Item With Series", rate=500, serial_no=serial_no)
self.check_serial_no_values(serial_no, {
"status": "Delivered",
"warehouse": "",
"delivery_document_no": dn.name
})
# return entry
dn1 = create_delivery_note(item_code="_Test Serialized Item With Series",
is_return=1, return_against=dn.name, qty=-1, rate=500, serial_no=serial_no)
self.check_serial_no_values(serial_no, {
"status": "Sales Returned",
"warehouse": "_Test Warehouse - _TC",
"delivery_document_no": ""
})
dn1.cancel()
self.check_serial_no_values(serial_no, {
"status": "Delivered",
"warehouse": "",
"delivery_document_no": dn.name
})
dn.cancel()
self.check_serial_no_values(serial_no, {
"status": "Available",
"warehouse": "_Test Warehouse - _TC",
"delivery_document_no": "",
"purchase_document_no": se.name
})
def create_delivery_note(**args):
dn = frappe.new_doc("Delivery Note")

View File

@@ -31,12 +31,10 @@ erpnext.stock.PurchaseReceiptController = erpnext.buying.BuyingController.extend
if(this.frm.doc.docstatus == 1) {
if(this.frm.doc.__onload && !this.frm.doc.__onload.billing_complete) {
cur_frm.add_custom_button(__('Make Purchase Invoice'), this.make_purchase_invoice,
frappe.boot.doctype_icons["Purchase Invoice"]);
cur_frm.add_custom_button(__('Make Purchase Invoice'), this.make_purchase_invoice);
}
cur_frm.add_custom_button(__('Make Purchase Return'), this.make_purchase_return,
frappe.boot.doctype_icons["Purchase Receipt"]);
cur_frm.add_custom_button(__('Make Purchase Return'), this.make_purchase_return);
this.show_stock_ledger();
this.show_general_ledger();
@@ -54,7 +52,7 @@ erpnext.stock.PurchaseReceiptController = erpnext.buying.BuyingController.extend
company: cur_frm.doc.company
}
})
}, "icon-download", "btn-default");
});
}
this.frm.toggle_reqd("supplier_warehouse", this.frm.doc.is_subcontracted==="Yes");

View File

@@ -135,7 +135,7 @@
"fieldname": "is_return",
"fieldtype": "Check",
"label": "Is Return",
"no_copy": 1,
"no_copy": 0,
"permlevel": 0,
"precision": "",
"print_hide": 1,
@@ -146,7 +146,7 @@
"fieldname": "return_against",
"fieldtype": "Link",
"label": "Return Against Purchase Receipt",
"no_copy": 1,
"no_copy": 0,
"options": "Purchase Receipt",
"permlevel": 0,
"precision": "",
@@ -877,7 +877,7 @@
"icon": "icon-truck",
"idx": 1,
"is_submittable": 1,
"modified": "2015-07-17 13:29:10.298448",
"modified": "2015-07-24 11:49:35.580382",
"modified_by": "Administrator",
"module": "Stock",
"name": "Purchase Receipt",

View File

@@ -469,5 +469,5 @@ def get_invoiced_qty_map(purchase_receipt):
@frappe.whitelist()
def make_purchase_return(source_name, target_doc=None):
from erpnext.utilities.transaction_base import make_return_doc
from erpnext.controllers.sales_and_purchase_return import make_return_doc
return make_return_doc("Purchase Receipt", source_name, target_doc)

View File

@@ -6,7 +6,7 @@ from __future__ import unicode_literals
import unittest
import frappe
import frappe.defaults
from frappe.utils import cint, flt
from frappe.utils import cint, flt, cstr
class TestPurchaseReceipt(unittest.TestCase):
def test_make_purchase_invoice(self):
@@ -127,7 +127,6 @@ class TestPurchaseReceipt(unittest.TestCase):
return_pr = make_purchase_receipt(is_return=1, return_against=pr.name, qty=-2)
# check sle
outgoing_rate = frappe.db.get_value("Stock Ledger Entry", {"voucher_type": "Purchase Receipt",
"voucher_no": return_pr.name}, "outgoing_rate")
@@ -151,6 +150,34 @@ class TestPurchaseReceipt(unittest.TestCase):
set_perpetual_inventory(0)
def test_purchase_return_for_serialized_items(self):
def _check_serial_no_values(serial_no, field_values):
serial_no = frappe.get_doc("Serial No", serial_no)
for field, value in field_values.items():
self.assertEquals(cstr(serial_no.get(field)), value)
from erpnext.stock.doctype.serial_no.serial_no import get_serial_nos
pr = make_purchase_receipt(item_code="_Test Serialized Item With Series", qty=1)
serial_no = get_serial_nos(pr.get("items")[0].serial_no)[0]
_check_serial_no_values(serial_no, {
"status": "Available",
"warehouse": "_Test Warehouse - _TC",
"purchase_document_no": pr.name
})
return_pr = make_purchase_receipt(item_code="_Test Serialized Item With Series", qty=-1,
is_return=1, return_against=pr.name, serial_no=serial_no)
_check_serial_no_values(serial_no, {
"status": "Purchase Returned",
"warehouse": "",
"purchase_document_no": pr.name,
"delivery_document_no": return_pr.name
})
def get_gl_entries(voucher_type, voucher_no):
return frappe.db.sql("""select account, debit, credit

View File

@@ -244,7 +244,7 @@
"in_filter": 1,
"label": "Delivery Document Type",
"no_copy": 1,
"options": "\nDelivery Note\nSales Invoice\nStock Entry",
"options": "\nDelivery Note\nSales Invoice\nStock Entry\nPurchase Receipt",
"permlevel": 0,
"read_only": 1
},
@@ -418,7 +418,7 @@
"icon": "icon-barcode",
"idx": 1,
"in_create": 0,
"modified": "2015-07-13 05:28:27.961178",
"modified": "2015-07-24 03:55:29.946944",
"modified_by": "Administrator",
"module": "Stock",
"name": "Serial No",

View File

@@ -33,10 +33,7 @@ class SerialNo(StockController):
self.validate_warehouse()
self.validate_item()
self.on_stock_ledger_entry()
valid_purchase_document_type = ("Purchase Receipt", "Stock Entry", "Serial No")
self.validate_value("purchase_document_type", "in", valid_purchase_document_type)
def set_maintenance_status(self):
if not self.warranty_expiry_date and not self.amc_expiry_date:
self.maintenance_status = None
@@ -122,9 +119,10 @@ class SerialNo(StockController):
self.delivery_document_no = delivery_sle.voucher_no
self.delivery_date = delivery_sle.posting_date
self.delivery_time = delivery_sle.posting_time
self.customer, self.customer_name = \
frappe.db.get_value(delivery_sle.voucher_type, delivery_sle.voucher_no,
["customer", "customer_name"])
if delivery_sle.voucher_type in ("Delivery Note", "Sales Invoice"):
self.customer, self.customer_name = \
frappe.db.get_value(delivery_sle.voucher_type, delivery_sle.voucher_no,
["customer", "customer_name"])
if self.warranty_period:
self.warranty_expiry_date = add_days(cstr(delivery_sle.posting_date),
cint(self.warranty_period))
@@ -234,10 +232,10 @@ def validate_serial_no(sle, item_det):
frappe.throw(_("Serial No {0} does not belong to Warehouse {1}").format(serial_no,
sle.warehouse), SerialNoWarehouseError)
if sle.voucher_type in ("Delivery Note", "Sales Invoice") \
if sle.voucher_type in ("Delivery Note", "Sales Invoice") and sle.is_cancelled=="No" \
and sr.status != "Available":
frappe.throw(_("Serial No {0} status must be 'Available' to Deliver").format(serial_no),
SerialNoStatusError)
frappe.throw(_("Serial No {0} status must be 'Available' to Deliver").format(serial_no),
SerialNoStatusError)
elif sle.actual_qty < 0:
# transfer out