From ac4a8f45e2c5a85aeb574f014af5deb8df77178d Mon Sep 17 00:00:00 2001 From: Kevin Veen-Birkenbach Date: Sun, 1 Nov 2026 16:45:53 +0100 Subject: [PATCH] fix(web-app-erpnext): seed the standard price lists the skipped setup wizard creates The deploy bypasses ERPNext's setup wizard and with it install_defaults, so a site without the store's GUI fixtures had no Standard Selling or Standard Buying price list and every Item Price insert failed with "Could not find Price List: Standard Selling". company.py now creates both after the Company, insert-if-missing, with the wizard's selling and buying flags and the Company's own currency; Price List.on_update fills the Selling and Buying Settings defaults. Co-Authored-By: Claude Opus 5.5 --- .../files/python/apply/company.py | 22 +++++++++- .../files/apply/_fake_frappe.py | 1 + .../files/apply/test_company.py | 40 +++++++++++++++++++ 3 files changed, 62 insertions(+), 1 deletion(-) diff --git a/roles/web-app-erpnext/files/python/apply/company.py b/roles/web-app-erpnext/files/python/apply/company.py index bae4786f52..ce893d26d6 100644 --- a/roles/web-app-erpnext/files/python/apply/company.py +++ b/roles/web-app-erpnext/files/python/apply/company.py @@ -2,7 +2,8 @@ order and invoice for it. The site skips the setup wizard, so nothing else installs the warehouse type, -territory, unit and opportunity type the wizard would create. An existing +territory, unit, opportunity type and standard price lists the wizard would +create; the price lists take the Company's currency. An existing Company keeps its abbreviation, country and currency and only gains the records it lacks; the global default company is set only while none is. @@ -64,6 +65,10 @@ FIXTURES = ( ("UOM", "Unit", {"uom_name": "Unit"}), ("Opportunity Type", "Sales", {"__newname": "Sales"}), ) +PRICE_LISTS = ( + ("Standard Selling", {"selling": 1, "buying": 0}), + ("Standard Buying", {"selling": 0, "buying": 1}), +) INVENTORY_KEYS = { "COMPANY_NAME": "service_provider.company.titel", "COMPANY_ABBR": "applications.web-app-erpnext.services.erpnext.company.abbr", @@ -135,6 +140,20 @@ def ensure_company(name, abbr, country, currency): return [f"Company: {name}"] +def ensure_price_lists(company): + currency = frappe.db.get_value("Company", company, "default_currency") + created = [] + for name, sides in PRICE_LISTS: + if frappe.db.exists("Price List", name): + continue + insert( + "Price List", + {"price_list_name": name, "enabled": 1, "currency": currency, **sides}, + ) + created.append(f"Price List: {name}") + return created + + def ensure_fiscal_year(company): today = getdate() covering = frappe.get_all( @@ -232,6 +251,7 @@ def main(): created = ensure_fixtures() created += ensure_company(name, abbr, country, currency) company_abbr = frappe.db.get_value("Company", name, "abbr") + created += ensure_price_lists(name) created += ensure_fiscal_year(name) created += ensure_tax_accounts(name, company_abbr) created += ensure_default_cash_account(name) diff --git a/tests/unit/python/roles/web-app-erpnext/files/apply/_fake_frappe.py b/tests/unit/python/roles/web-app-erpnext/files/apply/_fake_frappe.py index c4b9ff17de..e2f2b6bbde 100644 --- a/tests/unit/python/roles/web-app-erpnext/files/apply/_fake_frappe.py +++ b/tests/unit/python/roles/web-app-erpnext/files/apply/_fake_frappe.py @@ -26,6 +26,7 @@ NAME_FIELDS = { "Customer Group": "customer_group_name", "Fiscal Year": "year", "Item Group": "item_group_name", + "Price List": "price_list_name", "Role": "role_name", "Supplier Group": "supplier_group_name", "Territory": "territory_name", diff --git a/tests/unit/python/roles/web-app-erpnext/files/apply/test_company.py b/tests/unit/python/roles/web-app-erpnext/files/apply/test_company.py index ef790ec7db..06f647e228 100644 --- a/tests/unit/python/roles/web-app-erpnext/files/apply/test_company.py +++ b/tests/unit/python/roles/web-app-erpnext/files/apply/test_company.py @@ -95,6 +95,46 @@ class TestCompany(unittest.TestCase): records["Supplier Group"]["All Supplier Groups"]["is_group"], 1 ) + def test_creates_the_standard_price_lists_in_the_company_currency(self) -> None: + result = self._run() + + price_lists = self.frappe.records["Price List"] + selling = price_lists["Standard Selling"] + buying = price_lists["Standard Buying"] + self.assertEqual((selling["selling"], selling["buying"]), (1, 0)) + self.assertEqual((buying["selling"], buying["buying"]), (0, 1)) + for price_list in (selling, buying): + self.assertEqual(price_list["enabled"], 1) + self.assertEqual(price_list["currency"], "EUR") + self.assertIn("Price List: Standard Selling", result["created"]) + self.assertIn("Price List: Standard Buying", result["created"]) + + def test_existing_company_gets_price_lists_in_its_own_currency(self) -> None: + _seed_company(self.frappe, COMPANY, "XY", default_cash_account="Cash - XY") + + self._run() + + for price_list in self.frappe.records["Price List"].values(): + self.assertEqual(price_list["currency"], "USD") + + def test_keeps_an_existing_price_list(self) -> None: + self.frappe.seed( + "Price List", + "Standard Selling", + price_list_name="Standard Selling", + enabled=0, + selling=1, + buying=0, + currency="CHF", + ) + + result = self._run() + + self.assertEqual( + self.frappe.records["Price List"]["Standard Selling"]["currency"], "CHF" + ) + self.assertNotIn("Price List: Standard Selling", result["created"]) + def test_creates_a_fiscal_year_covering_today(self) -> None: self._run()