mirror of
https://github.com/frappe/erpnext.git
synced 2026-04-25 01:28:29 +00:00
* fix: manufacturing date issue in the batch (#42034)
(cherry picked from commit eca3e02f8d)
# Conflicts:
# erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.py
* chore: fix conflicts
---------
Co-authored-by: rohitwaghchaure <rohitw1991@gmail.com>
This commit is contained in:
@@ -161,11 +161,25 @@ class Batch(Document):
|
|||||||
self.use_batchwise_valuation = 1
|
self.use_batchwise_valuation = 1
|
||||||
|
|
||||||
def before_save(self):
|
def before_save(self):
|
||||||
|
self.set_expiry_date()
|
||||||
|
|
||||||
|
def set_expiry_date(self):
|
||||||
has_expiry_date, shelf_life_in_days = frappe.db.get_value(
|
has_expiry_date, shelf_life_in_days = frappe.db.get_value(
|
||||||
"Item", self.item, ["has_expiry_date", "shelf_life_in_days"]
|
"Item", self.item, ["has_expiry_date", "shelf_life_in_days"]
|
||||||
)
|
)
|
||||||
|
|
||||||
if not self.expiry_date and has_expiry_date and 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:
|
if has_expiry_date and not self.expiry_date:
|
||||||
frappe.throw(
|
frappe.throw(
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
import frappe
|
import frappe
|
||||||
from frappe.tests.utils import FrappeTestCase, change_settings
|
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
|
from pypika import functions as fn
|
||||||
|
|
||||||
import erpnext
|
import erpnext
|
||||||
@@ -2961,6 +2961,35 @@ class TestPurchaseReceipt(FrappeTestCase):
|
|||||||
self.assertSequenceEqual(expected_gle, gl_entries)
|
self.assertSequenceEqual(expected_gle, gl_entries)
|
||||||
frappe.local.enable_perpetual_inventory["_Test Company"] = old_perpetual_inventory
|
frappe.local.enable_perpetual_inventory["_Test Company"] = old_perpetual_inventory
|
||||||
|
|
||||||
|
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():
|
def prepare_data_for_internal_transfer():
|
||||||
from erpnext.accounts.doctype.sales_invoice.test_sales_invoice import create_internal_supplier
|
from erpnext.accounts.doctype.sales_invoice.test_sales_invoice import create_internal_supplier
|
||||||
|
|||||||
Reference in New Issue
Block a user