fix: Item alternative must have similar fields as original item (#20796)
* fix: Item alternative must have similar fields as orignal item * fix: Using db.get_values and meta instead of get_value and get_doc * fix: Made code more DRY Co-authored-by: Nabin Hait <nabinhait@gmail.com>
This commit is contained in:
parent
ed0965a572
commit
b10adbb161
@ -22,6 +22,21 @@ class ItemAlternative(Document):
|
||||
if self.item_code == self.alternative_item_code:
|
||||
frappe.throw(_("Alternative item must not be same as item code"))
|
||||
|
||||
item_meta = frappe.get_meta("Item")
|
||||
fields = ["is_stock_item", "include_item_in_manufacturing","has_serial_no","has_batch_no"]
|
||||
item_data = frappe.db.get_values("Item", self.item_code, fields, as_dict=1)
|
||||
alternative_item_data = frappe.db.get_values("Item", self.alternative_item_code, fields, as_dict=1)
|
||||
|
||||
for field in fields:
|
||||
if item_data[0].get(field) != alternative_item_data[0].get(field):
|
||||
raise_exception, alert = [1, False] if field == "is_stock_item" else [0, True]
|
||||
|
||||
frappe.msgprint(_("The value of {0} differs between Items {1} and {2}") \
|
||||
.format(frappe.bold(item_meta.get_label(field)),
|
||||
frappe.bold(self.alternative_item_code),
|
||||
frappe.bold(self.item_code)),
|
||||
alert=alert, raise_exception=raise_exception)
|
||||
|
||||
def validate_duplicate(self):
|
||||
if frappe.db.get_value("Item Alternative", {'item_code': self.item_code,
|
||||
'alternative_item_code': self.alternative_item_code, 'name': ('!=', self.name)}):
|
||||
|
Loading…
x
Reference in New Issue
Block a user