mirror of
https://github.com/frappe/erpnext.git
synced 2026-02-16 16:15:02 +00:00
fix: manufacturing date issue in the batch (#42034)
This commit is contained in:
@@ -161,11 +161,25 @@ class Batch(Document):
|
||||
self.use_batchwise_valuation = 1
|
||||
|
||||
def before_save(self):
|
||||
self.set_expiry_date()
|
||||
|
||||
def set_expiry_date(self):
|
||||
has_expiry_date, shelf_life_in_days = frappe.db.get_value(
|
||||
"Item", self.item, ["has_expiry_date", "shelf_life_in_days"]
|
||||
)
|
||||
|
||||
if not self.expiry_date and has_expiry_date and shelf_life_in_days:
|
||||
self.expiry_date = add_days(self.manufacturing_date, shelf_life_in_days)
|
||||
if (
|
||||
not self.manufacturing_date
|
||||
and self.reference_doctype in ["Stock Entry", "Purchase Receipt", "Purchase Invoice"]
|
||||
and self.reference_name
|
||||
):
|
||||
self.manufacturing_date = frappe.db.get_value(
|
||||
self.reference_doctype, self.reference_name, "posting_date"
|
||||
)
|
||||
|
||||
if self.manufacturing_date:
|
||||
self.expiry_date = add_days(self.manufacturing_date, shelf_life_in_days)
|
||||
|
||||
if has_expiry_date and not self.expiry_date:
|
||||
frappe.throw(
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
import frappe
|
||||
from frappe.tests.utils import FrappeTestCase, change_settings
|
||||
from frappe.utils import add_days, cint, cstr, flt, nowtime, today
|
||||
from frappe.utils import add_days, cint, cstr, flt, getdate, nowtime, today
|
||||
from pypika import functions as fn
|
||||
|
||||
import erpnext
|
||||
@@ -3001,6 +3001,35 @@ class TestPurchaseReceipt(FrappeTestCase):
|
||||
),
|
||||
)
|
||||
|
||||
def test_manufacturing_and_expiry_date_for_batch(self):
|
||||
item = make_item(
|
||||
"_Test Manufacturing and Expiry Date For Batch",
|
||||
{
|
||||
"is_purchase_item": 1,
|
||||
"is_stock_item": 1,
|
||||
"has_batch_no": 1,
|
||||
"create_new_batch": 1,
|
||||
"batch_number_series": "B-MEBATCH.#####",
|
||||
"has_expiry_date": 1,
|
||||
"shelf_life_in_days": 5,
|
||||
},
|
||||
)
|
||||
|
||||
pr = make_purchase_receipt(
|
||||
qty=10,
|
||||
rate=100,
|
||||
item_code=item.name,
|
||||
posting_date=today(),
|
||||
)
|
||||
|
||||
pr.reload()
|
||||
self.assertTrue(pr.items[0].serial_and_batch_bundle)
|
||||
|
||||
batch_no = get_batch_from_bundle(pr.items[0].serial_and_batch_bundle)
|
||||
batch = frappe.get_doc("Batch", batch_no)
|
||||
self.assertEqual(batch.manufacturing_date, getdate(today()))
|
||||
self.assertEqual(batch.expiry_date, getdate(add_days(today(), 5)))
|
||||
|
||||
|
||||
def prepare_data_for_internal_transfer():
|
||||
from erpnext.accounts.doctype.sales_invoice.test_sales_invoice import create_internal_supplier
|
||||
|
||||
Reference in New Issue
Block a user