fix: clear "Retain Sample" and "Max Sample Quantity" in Item card if Has Batch No is uncheck (#30307)

This commit is contained in:
HENRY Florian 2022-03-20 10:57:00 +01:00 committed by GitHub
parent 4859574233
commit ca8d757691
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 29 additions and 0 deletions

View File

@ -107,6 +107,7 @@ class Item(Document):
self.validate_variant_attributes()
self.validate_variant_based_on_change()
self.validate_fixed_asset()
self.clear_retain_sample()
self.validate_retain_sample()
self.validate_uom_conversion_factor()
self.validate_customer_provided_part()
@ -209,6 +210,13 @@ class Item(Document):
frappe.throw(_("{0} Retain Sample is based on batch, please check Has Batch No to retain sample of item").format(
self.item_code))
def clear_retain_sample(self):
if not self.has_batch_no:
self.retain_sample = None
if not self.retain_sample:
self.sample_quantity = None
def add_default_uom_in_conversion_factor_table(self):
if not self.is_new() and self.has_value_changed("stock_uom"):
self.uoms = []

View File

@ -656,6 +656,20 @@ class TestItem(FrappeTestCase):
make_stock_entry(qty=1, item_code=item.name, target="_Test Warehouse - _TC", posting_date = add_days(today(), 5))
self.consume_item_code_with_differet_stock_transactions(item_code=item.name)
@change_settings("Stock Settings", {"sample_retention_warehouse": 0})
def test_retain_sample(self):
frappe.db.set_single_value('Stock Settings', 'sample_retention_warehouse', '_Test Retain Sample Warehouse')
item = make_item("_TestRetainSample", {'has_batch_no': 1, 'retain_sample': 1, 'sample_quantity': 1})
self.assertEqual(item.has_batch_no, 1)
self.assertEqual(item.retain_sample, 1)
self.assertEqual(item.sample_quantity, 1)
item.has_batch_no = None
item.save()
self.assertEqual(item.retain_sample, None)
self.assertEqual(item.sample_quantity, None)
item.delete()
def consume_item_code_with_differet_stock_transactions(self, item_code, warehouse="_Test Warehouse - _TC"):
from erpnext.accounts.doctype.sales_invoice.test_sales_invoice import create_sales_invoice

View File

@ -60,5 +60,12 @@
"warehouse_name": "_Test Warehouse Group-C2",
"is_group": 0,
"parent_warehouse": "_Test Warehouse Group - _TC"
},
{
"company": "_Test Company",
"doctype": "Warehouse",
"warehouse_name": "_Test Retain Sample Warehouse",
"parent_warehouse": "_Test Warehouse Group - _TC",
"is_group": 0
}
]