Merge branch 'develop' into test-asset-lcv

This commit is contained in:
Marica 2021-08-10 14:38:31 +05:30 committed by GitHub
commit 173c4c8564
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 37 additions and 4 deletions

View File

@ -480,7 +480,7 @@ class SalesInvoice(SellingController):
if not self.pos_profile:
pos_profile = get_pos_profile(self.company) or {}
if not pos_profile:
frappe.throw(_("No POS Profile found. Please create a New POS Profile first"))
return
self.pos_profile = pos_profile.get('name')
pos = {}

View File

@ -27,6 +27,7 @@ class StockController(AccountsController):
if not self.get('is_return'):
self.validate_inspection()
self.validate_serialized_batch()
self.clean_serial_nos()
self.validate_customer_provided_item()
self.set_rate_of_stock_uom()
self.validate_internal_transfer()
@ -72,6 +73,12 @@ class StockController(AccountsController):
frappe.throw(_("Row #{0}: The batch {1} has already expired.")
.format(d.idx, get_link_to_form("Batch", d.get("batch_no"))))
def clean_serial_nos(self):
for row in self.get("items"):
if hasattr(row, "serial_no") and row.serial_no:
# replace commas by linefeed and remove all spaces in string
row.serial_no = row.serial_no.replace(",", "\n").replace(" ", "")
def get_gl_entries(self, warehouse_account=None, default_expense_account=None,
default_cost_center=None):

View File

@ -752,7 +752,7 @@ erpnext.TransactionController = class TransactionController extends erpnext.taxe
this.frm.trigger("item_code", cdt, cdn);
}
else {
// Replacing all occurences of comma with carriage return
// Replace all occurences of comma with line feed
item.serial_no = item.serial_no.replace(/,/g, '\n');
item.conversion_factor = item.conversion_factor || 1;
refresh_field("serial_no", item.name, item.parentfield);

View File

@ -165,8 +165,14 @@ class SerialNo(StockController):
)
ORDER BY
posting_date desc, posting_time desc, creation desc""",
(self.item_code, self.company,
serial_no, serial_no+'\n%', '%\n'+serial_no, '%\n'+serial_no+'\n%'), as_dict=1):
(
self.item_code, self.company,
serial_no,
serial_no+'\n%',
'%\n'+serial_no,
'%\n'+serial_no+'\n%'
),
as_dict=1):
if serial_no.upper() in get_serial_nos(sle.serial_no):
if cint(sle.actual_qty) > 0:
sle_dict.setdefault("incoming", []).append(sle)

View File

@ -174,5 +174,23 @@ class TestSerialNo(unittest.TestCase):
self.assertEqual(sn_doc.warehouse, "_Test Warehouse - _TC")
self.assertEqual(sn_doc.purchase_document_no, se.name)
def test_serial_no_sanitation(self):
"Test if Serial No input is sanitised before entering the DB."
item_code = "_Test Serialized Item"
test_records = frappe.get_test_records('Stock Entry')
se = frappe.copy_doc(test_records[0])
se.get("items")[0].item_code = item_code
se.get("items")[0].qty = 3
se.get("items")[0].serial_no = " _TS1, _TS2 , _TS3 "
se.get("items")[0].transfer_qty = 3
se.set_stock_entry_type()
se.insert()
se.submit()
self.assertEqual(se.get("items")[0].serial_no, "_TS1\n_TS2\n_TS3")
frappe.db.rollback()
def tearDown(self):
frappe.db.rollback()

View File

@ -76,6 +76,7 @@ class StockEntry(StockController):
self.validate_difference_account()
self.set_job_card_data()
self.set_purpose_for_stock_entry()
self.clean_serial_nos()
self.validate_duplicate_serial_no()
if not self.from_bom:

View File

@ -31,6 +31,7 @@ class StockReconciliation(StockController):
self.validate_expense_account()
self.validate_customer_provided_item()
self.set_zero_value_for_customer_provided_items()
self.clean_serial_nos()
self.set_total_qty_and_amount()
self.validate_putaway_capacity()