Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: item variant with manufacturer (backport #38845) (backport #38847) #38851

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions erpnext/controllers/item_variant.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,24 @@ def make_variant_based_on_manufacturer(template, manufacturer, manufacturer_part

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.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

Expand Down
44 changes: 15 additions & 29 deletions erpnext/stock/doctype/item/test_item.py
Original file line number Diff line number Diff line change
Expand Up @@ -522,39 +522,25 @@ def test_uom_conv_base_case(self):
self.assertEqual(factor, 1.0)

def test_item_variant_by_manufacturer(self):
fields = [{"field_name": "description"}, {"field_name": "variant_based_on"}]
set_item_variant_settings(fields)
template = make_item(
"_Test Item Variant By Manufacturer", {"has_variants": 1, "variant_based_on": "Manufacturer"}
).name

if frappe.db.exists("Item", "_Test Variant Mfg"):
frappe.delete_doc("Item", "_Test Variant Mfg")
if frappe.db.exists("Item", "_Test Variant Mfg-1"):
frappe.delete_doc("Item", "_Test Variant Mfg-1")
if frappe.db.exists("Manufacturer", "MSG1"):
frappe.delete_doc("Manufacturer", "MSG1")

template = frappe.get_doc(
dict(
doctype="Item",
item_code="_Test Variant Mfg",
has_variant=1,
item_group="Products",
variant_based_on="Manufacturer",
)
).insert()
for manufacturer in ["DFSS", "DASA", "ASAAS"]:
if not frappe.db.exists("Manufacturer", manufacturer):
m_doc = frappe.new_doc("Manufacturer")
m_doc.short_name = manufacturer
m_doc.insert()

manufacturer = frappe.get_doc(dict(doctype="Manufacturer", short_name="MSG1")).insert()
self.assertFalse(frappe.db.exists("Item Manufacturer", {"manufacturer": "DFSS"}))
variant = get_variant(template, manufacturer="DFSS", manufacturer_part_no="DFSS-123")

variant = get_variant(template.name, manufacturer=manufacturer.name)
self.assertEqual(variant.item_code, "_Test Variant Mfg-1")
self.assertEqual(variant.description, "_Test Variant Mfg")
self.assertEqual(variant.manufacturer, "MSG1")
variant.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, 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")
frappe.delete_doc("Item Manufacturer", item_manufacturer)

def test_stock_exists_against_template_item(self):
stock_item = frappe.get_all("Stock Ledger Entry", fields=["item_code"], limit=1)
Expand Down
Loading