Browse Source

fix: batch nos in packed items (bp #26105)

* test: batch info in packed_items

* fix(ux): make packed items editable

* refactor: allow custom table name for set_batch

In some doctypes there are multiple child tables requiring batched
items. This change makes the function a bit more flexible.

* fix: Auto fetch batch_nos in packed_item table
develop
Ankush 3 years ago
committed by GitHub
parent
commit
5708b7140b
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      erpnext/stock/doctype/batch/batch.py
  2. 3
      erpnext/stock/doctype/delivery_note/delivery_note.js
  3. 5
      erpnext/stock/doctype/delivery_note/delivery_note.json
  4. 7
      erpnext/stock/doctype/delivery_note/delivery_note.py
  5. 29
      erpnext/stock/doctype/delivery_note/test_delivery_note.py

4
erpnext/stock/doctype/batch/batch.py

@ -226,9 +226,9 @@ def split_batch(batch_no, item_code, warehouse, qty, new_batch_id=None):
return batch.name
def set_batch_nos(doc, warehouse_field, throw=False):
def set_batch_nos(doc, warehouse_field, throw=False, child_table="items"):
"""Automatically select `batch_no` for outgoing items in item table"""
for d in doc.items:
for d in doc.get(child_table):
qty = d.get('stock_qty') or d.get('transfer_qty') or d.get('qty') or 0
has_batch_no = frappe.db.get_value('Item', d.item_code, 'has_batch_no')
warehouse = d.get(warehouse_field, None)

3
erpnext/stock/doctype/delivery_note/delivery_note.js

@ -78,6 +78,9 @@ frappe.ui.form.on("Delivery Note", {
});
erpnext.accounts.dimensions.setup_dimension_filters(frm, frm.doctype);
frm.set_df_property('packed_items', 'cannot_add_rows', true);
frm.set_df_property('packed_items', 'cannot_delete_rows', true);
},
print_without_amount: function(frm) {

5
erpnext/stock/doctype/delivery_note/delivery_note.json

@ -554,8 +554,7 @@
"oldfieldname": "packing_details",
"oldfieldtype": "Table",
"options": "Packed Item",
"print_hide": 1,
"read_only": 1
"print_hide": 1
},
{
"fieldname": "product_bundle_help",
@ -1289,7 +1288,7 @@
"idx": 146,
"is_submittable": 1,
"links": [],
"modified": "2021-04-15 23:55:49.620641",
"modified": "2021-06-11 19:27:30.901112",
"modified_by": "Administrator",
"module": "Stock",
"name": "Delivery Note",

7
erpnext/stock/doctype/delivery_note/delivery_note.py

@ -129,12 +129,13 @@ class DeliveryNote(SellingController):
self.validate_uom_is_integer("uom", "qty")
self.validate_with_previous_doc()
if self._action != 'submit' and not self.is_return:
set_batch_nos(self, 'warehouse', True)
from erpnext.stock.doctype.packed_item.packed_item import make_packing_list
make_packing_list(self)
if self._action != 'submit' and not self.is_return:
set_batch_nos(self, 'warehouse', throw=True)
set_batch_nos(self, 'warehouse', throw=True, child_table="packed_items")
self.update_current_stock()
if not self.installation_status: self.installation_status = 'Not Installed'

29
erpnext/stock/doctype/delivery_note/test_delivery_note.py

@ -7,7 +7,7 @@ import unittest
import frappe
import json
import frappe.defaults
from frappe.utils import cint, nowdate, nowtime, cstr, add_days, flt, today
from frappe.utils import nowdate, nowtime, cstr, flt
from erpnext.stock.stock_ledger import get_previous_sle
from erpnext.accounts.utils import get_balance_on
from erpnext.stock.doctype.purchase_receipt.test_purchase_receipt import get_gl_entries
@ -18,9 +18,11 @@ from erpnext.stock.doctype.serial_no.serial_no import get_serial_nos, SerialNoWa
from erpnext.stock.doctype.stock_reconciliation.test_stock_reconciliation \
import create_stock_reconciliation, set_valuation_method
from erpnext.selling.doctype.sales_order.test_sales_order import make_sales_order, create_dn_against_so
from erpnext.accounts.doctype.account.test_account import get_inventory_account, create_account
from erpnext.accounts.doctype.account.test_account import get_inventory_account
from erpnext.stock.doctype.warehouse.test_warehouse import get_warehouse
from erpnext.stock.doctype.item.test_item import create_item
from erpnext.stock.doctype.item.test_item import make_item
from erpnext.selling.doctype.product_bundle.test_product_bundle import make_product_bundle
class TestDeliveryNote(unittest.TestCase):
def test_over_billing_against_dn(self):
@ -277,8 +279,6 @@ class TestDeliveryNote(unittest.TestCase):
dn.cancel()
def test_sales_return_for_non_bundled_items_full(self):
from erpnext.stock.doctype.item.test_item import make_item
company = frappe.db.get_value('Warehouse', 'Stores - TCP1', 'company')
make_item("Box", {'is_stock_item': 1})
@ -741,6 +741,25 @@ class TestDeliveryNote(unittest.TestCase):
self.assertEqual(si2.items[0].qty, 2)
self.assertEqual(si2.items[1].qty, 1)
def test_delivery_note_bundle_with_batched_item(self):
batched_bundle = make_item("_Test Batched bundle", {"is_stock_item": 0})
batched_item = make_item("_Test Batched Item",
{"is_stock_item": 1, "has_batch_no": 1, "create_new_batch": 1, "batch_number_series": "TESTBATCH.#####"}
)
make_product_bundle(parent=batched_bundle.name, items=[batched_item.name])
make_stock_entry(item_code=batched_item.name, target="_Test Warehouse - _TC", qty=10, basic_rate=42)
try:
dn = create_delivery_note(item_code=batched_bundle.name, qty=1)
except frappe.ValidationError as e:
if "batch" in str(e).lower():
self.fail("Batch numbers not getting added to bundled items in DN.")
raise e
self.assertTrue("TESTBATCH" in dn.packed_items[0].batch_no, "Batch number not added in packed item")
def create_delivery_note(**args):
dn = frappe.new_doc("Delivery Note")
args = frappe._dict(args)

Loading…
Cancel
Save