fix: item variant with manufacturer (backport #38845) (#38847) * fix: item variant with manufacturer (#38845) (cherry picked from commit e0c8ff10daeed0829266aea9142805f68ceedb2b) * chore: fix test case --------- Co-authored-by: rohitwaghchaure <rohitw1991@gmail.com> (cherry picked from commit 4aa960b744c289b0cda9acfae7911b1ef6ffe5d6) Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
This commit is contained in:
parent
637343f751
commit
7320440b61
@ -56,10 +56,24 @@ def make_variant_based_on_manufacturer(template, manufacturer, manufacturer_part
|
|||||||
|
|
||||||
copy_attributes_to_variant(template, variant)
|
copy_attributes_to_variant(template, variant)
|
||||||
|
|
||||||
variant.manufacturer = manufacturer
|
|
||||||
variant.manufacturer_part_no = manufacturer_part_no
|
|
||||||
|
|
||||||
variant.item_code = append_number_if_name_exists("Item", template.name)
|
variant.item_code = append_number_if_name_exists("Item", template.name)
|
||||||
|
variant.flags.ignore_mandatory = True
|
||||||
|
variant.save()
|
||||||
|
|
||||||
|
if not frappe.db.exists(
|
||||||
|
"Item Manufacturer", {"item_code": variant.name, "manufacturer": manufacturer}
|
||||||
|
):
|
||||||
|
manufacturer_doc = frappe.new_doc("Item Manufacturer")
|
||||||
|
manufacturer_doc.update(
|
||||||
|
{
|
||||||
|
"item_code": variant.name,
|
||||||
|
"manufacturer": manufacturer,
|
||||||
|
"manufacturer_part_no": manufacturer_part_no,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
manufacturer_doc.flags.ignore_mandatory = True
|
||||||
|
manufacturer_doc.save(ignore_permissions=True)
|
||||||
|
|
||||||
return variant
|
return variant
|
||||||
|
|
||||||
|
@ -522,39 +522,25 @@ class TestItem(FrappeTestCase):
|
|||||||
self.assertEqual(factor, 1.0)
|
self.assertEqual(factor, 1.0)
|
||||||
|
|
||||||
def test_item_variant_by_manufacturer(self):
|
def test_item_variant_by_manufacturer(self):
|
||||||
fields = [{"field_name": "description"}, {"field_name": "variant_based_on"}]
|
template = make_item(
|
||||||
set_item_variant_settings(fields)
|
"_Test Item Variant By Manufacturer", {"has_variants": 1, "variant_based_on": "Manufacturer"}
|
||||||
|
).name
|
||||||
|
|
||||||
if frappe.db.exists("Item", "_Test Variant Mfg"):
|
for manufacturer in ["DFSS", "DASA", "ASAAS"]:
|
||||||
frappe.delete_doc("Item", "_Test Variant Mfg")
|
if not frappe.db.exists("Manufacturer", manufacturer):
|
||||||
if frappe.db.exists("Item", "_Test Variant Mfg-1"):
|
m_doc = frappe.new_doc("Manufacturer")
|
||||||
frappe.delete_doc("Item", "_Test Variant Mfg-1")
|
m_doc.short_name = manufacturer
|
||||||
if frappe.db.exists("Manufacturer", "MSG1"):
|
m_doc.insert()
|
||||||
frappe.delete_doc("Manufacturer", "MSG1")
|
|
||||||
|
|
||||||
template = frappe.get_doc(
|
self.assertFalse(frappe.db.exists("Item Manufacturer", {"manufacturer": "DFSS"}))
|
||||||
dict(
|
variant = get_variant(template, manufacturer="DFSS", manufacturer_part_no="DFSS-123")
|
||||||
doctype="Item",
|
|
||||||
item_code="_Test Variant Mfg",
|
|
||||||
has_variant=1,
|
|
||||||
item_group="Products",
|
|
||||||
variant_based_on="Manufacturer",
|
|
||||||
)
|
|
||||||
).insert()
|
|
||||||
|
|
||||||
manufacturer = frappe.get_doc(dict(doctype="Manufacturer", short_name="MSG1")).insert()
|
item_manufacturer = frappe.db.exists(
|
||||||
|
"Item Manufacturer", {"manufacturer": "DFSS", "item_code": variant.name}
|
||||||
|
)
|
||||||
|
self.assertTrue(item_manufacturer)
|
||||||
|
|
||||||
variant = get_variant(template.name, manufacturer=manufacturer.name)
|
frappe.delete_doc("Item Manufacturer", item_manufacturer)
|
||||||
self.assertEqual(variant.item_code, "_Test Variant Mfg-1")
|
|
||||||
self.assertEqual(variant.description, "_Test Variant Mfg")
|
|
||||||
self.assertEqual(variant.manufacturer, "MSG1")
|
|
||||||
variant.insert()
|
|
||||||
|
|
||||||
variant = get_variant(template.name, manufacturer=manufacturer.name, manufacturer_part_no="007")
|
|
||||||
self.assertEqual(variant.item_code, "_Test Variant Mfg-2")
|
|
||||||
self.assertEqual(variant.description, "_Test Variant Mfg")
|
|
||||||
self.assertEqual(variant.manufacturer, "MSG1")
|
|
||||||
self.assertEqual(variant.manufacturer_part_no, "007")
|
|
||||||
|
|
||||||
def test_stock_exists_against_template_item(self):
|
def test_stock_exists_against_template_item(self):
|
||||||
stock_item = frappe.get_all("Stock Ledger Entry", fields=["item_code"], limit=1)
|
stock_item = frappe.get_all("Stock Ledger Entry", fields=["item_code"], limit=1)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user