Skip to content

Commit

Permalink
fix: Data too long for column 'serial_no' at row 1 (backport #40098) (#…
Browse files Browse the repository at this point in the history
…40139)

* fix: Data too long for column 'serial_no' at row 1 (#40098)

(cherry picked from commit 08caa7c)

# Conflicts:
#	erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.py

* chore: fix conflicts

---------

Co-authored-by: rohitwaghchaure <rohitw1991@gmail.com>
  • Loading branch information
mergify[bot] and rohitwaghchaure authored Feb 26, 2024
1 parent ad53633 commit 9d19ec4
Show file tree
Hide file tree
Showing 12 changed files with 60 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -654,7 +654,7 @@
{
"depends_on": "eval:doc.use_serial_batch_fields === 1",
"fieldname": "serial_no",
"fieldtype": "Small Text",
"fieldtype": "Text",
"hidden": 1,
"in_list_view": 1,
"label": "Serial No",
Expand Down Expand Up @@ -853,7 +853,7 @@
],
"istable": 1,
"links": [],
"modified": "2024-02-04 16:36:25.665743",
"modified": "2024-02-25 15:50:17.140269",
"modified_by": "Administrator",
"module": "Accounts",
"name": "POS Invoice Item",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class POSInvoiceItem(Document):
rate_with_margin: DF.Currency
sales_order: DF.Link | None
serial_and_batch_bundle: DF.Link | None
serial_no: DF.SmallText | None
serial_no: DF.Text | None
service_end_date: DF.Date | None
service_start_date: DF.Date | None
service_stop_date: DF.Date | None
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -625,7 +625,7 @@
{
"depends_on": "eval: doc.use_serial_batch_fields === 1 && parent.update_stock === 1",
"fieldname": "serial_no",
"fieldtype": "Small Text",
"fieldtype": "Text",
"label": "Serial No",
"oldfieldname": "serial_no",
"oldfieldtype": "Small Text"
Expand Down Expand Up @@ -926,7 +926,7 @@
"idx": 1,
"istable": 1,
"links": [],
"modified": "2024-02-04 11:52:16.106541",
"modified": "2024-02-25 15:56:44.828634",
"modified_by": "Administrator",
"module": "Accounts",
"name": "Sales Invoice Item",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class SalesInvoiceItem(Document):
sales_invoice_item: DF.Data | None
sales_order: DF.Link | None
serial_and_batch_bundle: DF.Link | None
serial_no: DF.SmallText | None
serial_no: DF.Text | None
service_end_date: DF.Date | None
service_start_date: DF.Date | None
service_stop_date: DF.Date | None
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@
{
"depends_on": "eval:doc.use_serial_batch_fields === 1",
"fieldname": "serial_no",
"fieldtype": "Small Text",
"fieldtype": "Text",
"hidden": 1,
"label": "Serial No",
"print_hide": 1
Expand Down Expand Up @@ -178,7 +178,7 @@
"index_web_pages_for_search": 1,
"istable": 1,
"links": [],
"modified": "2024-02-04 16:41:09.239762",
"modified": "2024-02-25 15:57:35.007501",
"modified_by": "Administrator",
"module": "Assets",
"name": "Asset Capitalization Stock Item",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class AssetCapitalizationStockItem(Document):
parentfield: DF.Data
parenttype: DF.Data
serial_and_batch_bundle: DF.Link | None
serial_no: DF.SmallText | None
serial_no: DF.Text | None
stock_qty: DF.Float
stock_uom: DF.Link
use_serial_batch_fields: DF.Check
Expand Down
56 changes: 34 additions & 22 deletions erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.py
Original file line number Diff line number Diff line change
Expand Up @@ -2200,6 +2200,10 @@ def test_use_serial_batch_fields_for_serial_nos(self):
create_stock_reconciliation,
)

frappe.db.set_single_value(
"Stock Settings", "do_not_update_serial_batch_on_creation_of_auto_bundle", 0
)

item_code = make_item(
"_Test Use Serial Fields Item Serial Item",
properties={"has_serial_no": 1, "serial_no_series": "SNU-TSFISI-.#####"},
Expand Down Expand Up @@ -2280,30 +2284,10 @@ def test_use_serial_batch_fields_for_serial_nos(self):
serial_no_status = frappe.db.get_value("Serial No", sn, "status")
self.assertTrue(serial_no_status != "Active")

def test_auto_set_batch_based_on_bundle(self):
item_code = make_item(
"_Test Auto Set Batch Based on Bundle",
properties={
"has_batch_no": 1,
"batch_number_series": "BATCH-BNU-TASBBB-.#####",
"create_new_batch": 1,
},
).name

frappe.db.set_single_value("Stock Settings", "use_serial_batch_fields", 1)

pr = make_purchase_receipt(
item_code=item_code,
qty=5,
rate=100,
frappe.db.set_single_value(
"Stock Settings", "do_not_update_serial_batch_on_creation_of_auto_bundle", 1
)

self.assertTrue(pr.items[0].batch_no)
batch_no = get_batch_from_bundle(pr.items[0].serial_and_batch_bundle)
self.assertEqual(pr.items[0].batch_no, batch_no)

frappe.db.set_single_value("Stock Settings", "use_serial_batch_fields", 0)

def test_sle_qty_after_transaction(self):
item = make_item(
"_Test Item Qty After Transaction",
Expand Down Expand Up @@ -2393,6 +2377,34 @@ def test_sle_qty_after_transaction(self):
for index, d in enumerate(data):
self.assertEqual(d.qty_after_transaction, 11 + index)

def test_auto_set_batch_based_on_bundle(self):
item_code = make_item(
"_Test Auto Set Batch Based on Bundle",
properties={
"has_batch_no": 1,
"batch_number_series": "BATCH-BNU-TASBBB-.#####",
"create_new_batch": 1,
},
).name

frappe.db.set_single_value(
"Stock Settings", "do_not_update_serial_batch_on_creation_of_auto_bundle", 0
)

pr = make_purchase_receipt(
item_code=item_code,
qty=5,
rate=100,
)

self.assertTrue(pr.items[0].batch_no)
batch_no = get_batch_from_bundle(pr.items[0].serial_and_batch_bundle)
self.assertEqual(pr.items[0].batch_no, batch_no)

frappe.db.set_single_value(
"Stock Settings", "do_not_update_serial_batch_on_creation_of_auto_bundle", 1
)


def prepare_data_for_internal_transfer():
from erpnext.accounts.doctype.sales_invoice.test_sales_invoice import create_internal_supplier
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@
{
"depends_on": "eval:doc.use_serial_batch_fields === 1",
"fieldname": "serial_no",
"fieldtype": "Small Text",
"fieldtype": "Text",
"label": "Serial No",
"no_copy": 1,
"oldfieldname": "serial_no",
Expand Down Expand Up @@ -610,7 +610,7 @@
"index_web_pages_for_search": 1,
"istable": 1,
"links": [],
"modified": "2024-02-04 16:16:47.606270",
"modified": "2024-02-25 15:58:40.982582",
"modified_by": "Administrator",
"module": "Stock",
"name": "Stock Entry Detail",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class StockEntryDetail(Document):
sample_quantity: DF.Int
sco_rm_detail: DF.Data | None
serial_and_batch_bundle: DF.Link | None
serial_no: DF.SmallText | None
serial_no: DF.Text | None
set_basic_rate_manually: DF.Check
ste_detail: DF.Data | None
stock_uom: DF.Link
Expand Down
11 changes: 10 additions & 1 deletion erpnext/stock/doctype/stock_settings/stock_settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
"use_naming_series",
"naming_series_prefix",
"use_serial_batch_fields",
"do_not_update_serial_batch_on_creation_of_auto_bundle",
"stock_planning_tab",
"auto_material_request",
"auto_indent",
Expand Down Expand Up @@ -428,14 +429,22 @@
"fieldname": "use_serial_batch_fields",
"fieldtype": "Check",
"label": "Use Serial / Batch Fields"
},
{
"default": "1",
"depends_on": "use_serial_batch_fields",
"description": "If enabled, do not update serial / batch values in the stock transactions on creation of auto Serial \n / Batch Bundle. ",
"fieldname": "do_not_update_serial_batch_on_creation_of_auto_bundle",
"fieldtype": "Check",
"label": "Do Not Update Serial / Batch on Creation of Auto Bundle"
}
],
"icon": "icon-cog",
"idx": 1,
"index_web_pages_for_search": 1,
"issingle": 1,
"links": [],
"modified": "2024-02-24 12:50:51.740097",
"modified": "2024-02-25 16:32:01.084453",
"modified_by": "Administrator",
"module": "Stock",
"name": "Stock Settings",
Expand Down
1 change: 1 addition & 0 deletions erpnext/stock/doctype/stock_settings/stock_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class StockSettings(Document):
clean_description_html: DF.Check
default_warehouse: DF.Link | None
disable_serial_no_and_batch_selector: DF.Check
do_not_update_serial_batch_on_creation_of_auto_bundle: DF.Check
enable_stock_reservation: DF.Check
item_group: DF.Link | None
item_naming_by: DF.Literal["Item Code", "Naming Series"]
Expand Down
4 changes: 3 additions & 1 deletion erpnext/stock/serial_batch_bundle.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,9 @@ def set_serial_and_batch_bundle(self, sn_doc):
"serial_and_batch_bundle": sn_doc.name,
}

if frappe.db.get_single_value("Stock Settings", "use_serial_batch_fields"):
if not frappe.db.get_single_value(
"Stock Settings", "do_not_update_serial_batch_on_creation_of_auto_bundle"
):
if sn_doc.has_serial_no:
values_to_update["serial_no"] = ",".join(cstr(d.serial_no) for d in sn_doc.entries)
elif sn_doc.has_batch_no and len(sn_doc.entries) == 1:
Expand Down

0 comments on commit 9d19ec4

Please sign in to comment.