mirror of
https://github.com/frappe/erpnext.git
synced 2026-02-19 09:35:03 +00:00
fix: Warranty Expiry Date not set in the serial number (#42513)
* fix: Warranty Expiry Date not set in the serial number * chore: fix linters issue
This commit is contained in:
@@ -6,7 +6,7 @@ import json
|
||||
|
||||
import frappe
|
||||
from frappe.tests.utils import FrappeTestCase
|
||||
from frappe.utils import add_days, cstr, flt, nowdate, nowtime, today
|
||||
from frappe.utils import add_days, cstr, flt, getdate, nowdate, nowtime, today
|
||||
|
||||
from erpnext.accounts.doctype.account.test_account import get_inventory_account
|
||||
from erpnext.accounts.utils import get_balance_on
|
||||
@@ -2032,6 +2032,40 @@ class TestDeliveryNote(FrappeTestCase):
|
||||
|
||||
self.assertRaises(frappe.ValidationError, dn5.submit)
|
||||
|
||||
def test_warranty_expiry_date_for_serial_item(self):
|
||||
item_code = make_item(
|
||||
"Test Warranty Expiry Date Item",
|
||||
properties={
|
||||
"has_serial_no": 1,
|
||||
"serial_no_series": "TWE.#####",
|
||||
"is_stock_item": 1,
|
||||
"warranty_period": 100,
|
||||
},
|
||||
).name
|
||||
|
||||
se = make_stock_entry(
|
||||
item_code=item_code,
|
||||
target="_Test Warehouse - _TC",
|
||||
qty=2,
|
||||
basic_rate=50,
|
||||
posting_date=nowdate(),
|
||||
)
|
||||
|
||||
serial_nos = get_serial_nos_from_bundle(se.items[0].serial_and_batch_bundle)
|
||||
create_delivery_note(
|
||||
item_code=item_code,
|
||||
qty=2,
|
||||
rate=300,
|
||||
use_serial_batch_fields=0,
|
||||
serial_no=serial_nos,
|
||||
)
|
||||
|
||||
for row in serial_nos:
|
||||
sn = frappe.get_doc("Serial No", row)
|
||||
self.assertEqual(getdate(sn.warranty_expiry_date), getdate(add_days(nowdate(), 100)))
|
||||
self.assertEqual(sn.status, "Delivered")
|
||||
self.assertEqual(sn.warranty_period, 100)
|
||||
|
||||
|
||||
def create_delivery_note(**args):
|
||||
dn = frappe.new_doc("Delivery Note")
|
||||
|
||||
@@ -393,32 +393,6 @@ class SerialandBatchBundle(Document):
|
||||
|
||||
self.calculate_qty_and_amount(save=True)
|
||||
self.validate_quantity(row, qty_field=qty_field)
|
||||
self.set_warranty_expiry_date()
|
||||
|
||||
def set_warranty_expiry_date(self):
|
||||
if self.type_of_transaction != "Outward":
|
||||
return
|
||||
|
||||
if not (self.docstatus == 1 and self.voucher_type == "Delivery Note" and self.has_serial_no):
|
||||
return
|
||||
|
||||
warranty_period = frappe.get_cached_value("Item", self.item_code, "warranty_period")
|
||||
|
||||
if not warranty_period:
|
||||
return
|
||||
|
||||
warranty_expiry_date = add_days(self.posting_date, cint(warranty_period))
|
||||
|
||||
serial_nos = self.get_serial_nos()
|
||||
if not serial_nos:
|
||||
return
|
||||
|
||||
sn_table = frappe.qb.DocType("Serial No")
|
||||
(
|
||||
frappe.qb.update(sn_table)
|
||||
.set(sn_table.warranty_expiry_date, warranty_expiry_date)
|
||||
.where(sn_table.name.isin(serial_nos))
|
||||
).run()
|
||||
|
||||
def validate_voucher_no(self):
|
||||
if not (self.voucher_type and self.voucher_no):
|
||||
|
||||
@@ -4,7 +4,7 @@ import frappe
|
||||
from frappe import _, bold
|
||||
from frappe.model.naming import make_autoname
|
||||
from frappe.query_builder.functions import CombineDatetime, Sum, Timestamp
|
||||
from frappe.utils import cint, cstr, flt, get_link_to_form, now, nowtime, today
|
||||
from frappe.utils import add_days, cint, cstr, flt, get_link_to_form, now, nowtime, today
|
||||
from pypika import Order
|
||||
|
||||
from erpnext.stock.deprecated_serial_batch import (
|
||||
@@ -338,7 +338,8 @@ class SerialBatchBundle:
|
||||
status = "Delivered"
|
||||
|
||||
sn_table = frappe.qb.DocType("Serial No")
|
||||
(
|
||||
|
||||
query = (
|
||||
frappe.qb.update(sn_table)
|
||||
.set(sn_table.warehouse, warehouse)
|
||||
.set(
|
||||
@@ -351,7 +352,19 @@ class SerialBatchBundle:
|
||||
)
|
||||
.set(sn_table.company, self.sle.company)
|
||||
.where(sn_table.name.isin(serial_nos))
|
||||
).run()
|
||||
)
|
||||
|
||||
if status == "Delivered":
|
||||
warranty_period = frappe.get_cached_value("Item", self.sle.item_code, "warranty_period")
|
||||
if warranty_period:
|
||||
warranty_expiry_date = add_days(self.sle.posting_date, cint(warranty_period))
|
||||
query = query.set(sn_table.warranty_expiry_date, warranty_expiry_date)
|
||||
query = query.set(sn_table.warranty_period, warranty_period)
|
||||
else:
|
||||
query = query.set(sn_table.warranty_expiry_date, None)
|
||||
query = query.set(sn_table.warranty_period, 0)
|
||||
|
||||
query.run()
|
||||
|
||||
def set_batch_no_in_serial_nos(self):
|
||||
entries = frappe.get_all(
|
||||
|
||||
Reference in New Issue
Block a user