diff --git a/.github/workflows/linters.yml b/.github/workflows/linters.yml index 751b46f4b35..94b76b12ce7 100644 --- a/.github/workflows/linters.yml +++ b/.github/workflows/linters.yml @@ -9,15 +9,16 @@ jobs: name: linters runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - name: Set up Python 3.10 - uses: actions/setup-python@v2 + uses: actions/setup-python@v4 with: python-version: '3.10' + cache: pip - name: Install and Run Pre-commit - uses: pre-commit/action@v2.0.3 + uses: pre-commit/action@v3.0.0 - name: Download Semgrep rules run: git clone --depth 1 https://github.com/frappe/semgrep-rules.git frappe-semgrep-rules diff --git a/erpnext/setup/doctype/company/company.py b/erpnext/setup/doctype/company/company.py index 2477444dab6..58fef47d725 100644 --- a/erpnext/setup/doctype/company/company.py +++ b/erpnext/setup/doctype/company/company.py @@ -167,6 +167,7 @@ class Company(NestedSet): frappe.clear_cache() def create_default_warehouses(self): + parent_warehouse = None for wh_detail in [ {"warehouse_name": _("All Warehouses"), "is_group": 1}, {"warehouse_name": _("Stores"), "is_group": 0}, @@ -174,24 +175,31 @@ class Company(NestedSet): {"warehouse_name": _("Finished Goods"), "is_group": 0}, {"warehouse_name": _("Goods In Transit"), "is_group": 0, "warehouse_type": "Transit"}, ]: - if not frappe.db.exists("Warehouse", "{} - {}".format(wh_detail["warehouse_name"], self.abbr)): - warehouse = frappe.get_doc( - { - "doctype": "Warehouse", - "warehouse_name": wh_detail["warehouse_name"], - "is_group": wh_detail["is_group"], - "company": self.name, - "parent_warehouse": "{} - {}".format(_("All Warehouses"), self.abbr) - if not wh_detail["is_group"] - else "", - "warehouse_type": wh_detail["warehouse_type"] - if "warehouse_type" in wh_detail - else None, - } - ) - warehouse.flags.ignore_permissions = True - warehouse.flags.ignore_mandatory = True - warehouse.insert() + if frappe.db.exists( + "Warehouse", + { + "warehouse_name": wh_detail["warehouse_name"], + "company": self.name, + }, + ): + continue + + warehouse = frappe.get_doc( + { + "doctype": "Warehouse", + "warehouse_name": wh_detail["warehouse_name"], + "is_group": wh_detail["is_group"], + "company": self.name, + "parent_warehouse": parent_warehouse, + "warehouse_type": wh_detail.get("warehouse_type"), + } + ) + warehouse.flags.ignore_permissions = True + warehouse.flags.ignore_mandatory = True + warehouse.insert() + + if wh_detail["is_group"]: + parent_warehouse = warehouse.name def create_default_accounts(self): from erpnext.accounts.doctype.account.chart_of_accounts.chart_of_accounts import create_charts