Try ERPNext Buy Support Partners Foundation

How to delete warehouses that have a deleted company

Hello all,
A colleague deleted a Child company which has warehouses attached to them on our erpnext production site. I created a new Child company along with its subsequent warehouses. However, I noticed that the old warehouses still exist in the application along with their stocks. I have searched for ways to deleted these warehouses but can’t find them anywhere in the application to do that.

Please can anyone advise me on how to delete these old warehouses so that it doesn’t cause any confusion for the cashiers using the application.

Secondly, when I restrict the cashiers to only generate sales invoice for a child company, they are unable to view the reports for that company even if they try to filter it, they still can’t view the reports. Is there a recommendation to tackling this issue as well?

Thank you very much.

Execute in bench console:

for doc in frappe.get_all('Warehouse', {'company': '<Company Name>'}):
    frappe.delete_doc('Warehouse', doc.name, force=1)

frappe.db.commit()

Thanks snv,
Please I need to clarify some few things. This is a live production site, and I want to know which folder or file in the bench console I will execute this code.

Also about my second question, when I restrict the cashiers to only generate sales invoice for a child company, they are unable to view the reports for that company even if they try to filter it, they still can’t view the reports. Is there a recommendation to tackling this issue as well?

Thank you very much.

bench console is a command you must execute from the frappe-bench directory to open a Python terminal.

Thanks snv,
However, regarding the second question I asked, please do have any recommendation to that?

Hello snv,
This is the response I got after executing the code;
AttributeError Traceback (most recent call last)
~/frappe-bench/apps/frappe/frappe/commands/utils.py in
----> 1 for doc in frappe.get.all(‘Warehouse’, {‘company’: ‘AGS,Mararaba’}):
2 frappe.delete_doc(‘Warehouse’, doc.name, force=1)
3 frappe.db.commit()
4

AttributeError: module ‘frappe’ has no attribute ‘get’

It’s get_all (not dot)

You can Copy + Paste

oh sorry. It was my mistake. Thanks for the correction.

I checked the report issue. I am getting it too. There’s a workaround that worked for me: entering the Company’s name manually. But I think a GitHub issue can be created regarding this.

ok maybe I’ll do that.