RamezIssac/django-erp-framework

Getting Started "You don’t have permission to view or edit anything."

Parthian opened this issue · 14 comments

I've installed django-erp-framework twice. Once on my localhost and once on my opalstack hosting account.

Both result in an admin page stating

[ERP Framework System](http://127.0.0.1:8000/erp-system/)
Welcome, . [View site](http://127.0.0.1:8000/) / 
Dashboard Home
You don’t have permission to view or edit anything.

I suspect I'm missing an active User rather than just superuser.

Clicking logout results in a debug page stating the following - I've also commented on the other open issue - #31 (comment) - suspect they are related. Am I missing a step?
Can't wait to get started. So close.

TemplateDoesNotExist   admin/logout.html
C:\django\bms\lib\site-packages\django\template\loader.py, line 47, in select_template django.contrib.admin.sites.logout
C:\django\bms\Scripts\python.exe 3.10.5
['C:\\django\\bms\\bmsproj',  'C:\\Program Files\\Python310\\python310.zip',  'C:\\Program Files\\Python310\\DLLs',  'C:\\Program Files\\Python310\\lib',  'C:\\Program Files\\Python310',  'C:\\django\\bms',  'C:\\django\\bms\\lib\\site-packages']

Django tried loading these templates, in this order:</p>
        
C:\django\bms\lib\site-packages\django\contrib\auth\templates\admin\logout.html (Source does not exist)
C:\django\bms\lib\site-packages\crispy_bootstrap4\templates\admin\logout.html (Source does not exist)
C:\django\bms\lib\site-packages\reversion\templates\admin\logout.html (Source does not exist)</li>
C:\django\bms\lib\site-packages\tabular_permissions\templates\admin\logout.html (Source does not exist)
C:\django\bms\lib\site-packages\slick_reporting\templates\admin\logout.html (Source does not exist)
C:\django\bms\lib\site-packages\django\contrib\admin\templates\admin\logout.html (Source does not exist)

On reflection the "you don't have permission to view or edit anything" will be because I've no models at the start.
So the linked to comment 31 has this issue when I try to add models/admin content.

from erp_framework.admin.admin import erp_framework_site, EntityAdmin #, TransactionAdmin, TransactionItemAdmin
ImportError: cannot import name 'erp_framework_site' from 'erp_framework.admin.admin' (/home/myuser/apps/myproject/env/lib/python3.10/site-packages/erp_framework/admin/admin.py)

This in admin.py
from erp_framework.admin.admin import erp_framework_site

And note, I'm not including Jazzmin, want to try a before and after.

Got a solution to above. As the author states the docs are out of date but take a look at the example shop.
https://github.com/RamezIssac/my-shop/
https://github.com/RamezIssac/my-shop/tree/main/my_shop - settings.py and urls.py

I changed my urls.py to

from django.conf import settings
from django.conf.urls.static import static
from django.contrib import admin
from django.urls import path
from erp_framework.sites import erp_admin_site
urlpatterns = [
    path("admin/", admin.site.urls), # /admin is now for user/groups/password etc.
    path('', erp_admin_site.urls), # this is critical. the home page IS the former admin. 
]

The docs (to me) inferred that all models will be like this.
class MyModell(EntityModel):
I changed them back to (models.Model): I'm not quite sure about this yet, Could be a coincidence as I changed a lot.

admin.py

from django.contrib import admin
from myapp.models import *
from erp_framework.admin.admin import EntityAdmin #  BUT erp_framework_site, IS MISSING
# this is the correct way - erp_framework_site replaced with erp_admin_site
from erp_framework.sites import erp_admin_site # erp_framework_site

# And again the docs - https://django-erp-framework.readthedocs.io/en/latest/tutorial/tutorial_1.html infer that you need to use EntityAdmin but not so. 
# Again, this is just to get you started by changing as little as possible from the traditional django approach

class MyModelAdmin(admin.ModelAdmin):
    list_display = ('name',) # usual stuff here

erp_admin_site.register(Role, RoleAdmin)

Hope that helps someone get started.
And logout now works too.

Great news you got it working by checking the my-shop demo project! 💪

Also you can use the develop branch as it's the active branch till a release is made.

Let me know if you face any other issue

Yes. It's always tricky when a lot of changes are made. Could you maybe do a quick update to the docs https://django-erp-framework.readthedocs.io/en/latest/getting_started/index.html "Follow to the tutorial to create sample erp system which tracks sales and expense and profitability. Sample ERP System Tutorial" and send people to the shop instead?
And to change the urls.py part.

There are some other references to the shop but I was blundering around all confused until I found it. Straightforward after that.

Next trick is to do a fancy report and chart.

Could you explain EntityModel and EntityAdmin. Sometimes they are used and sometimes not. Is there a simple way to choose which approach to use traditional or Entity.
I've looked at the following but can't see a strong use case.
https://django-erp-framework.readthedocs.io/en/latest/topics/base_classes.html

PS
I think this is the smartest thing I've seen django do. It would be good to get disussions going in Discord to help promote it. I've already asked about django-erp-framework in the django channel but no replies.

Sure!

EntityModel: is an abstract class with some fields that i see usually needed in an ERP solution , like notes , owner, creation date, lastmod and lastmod_user.

TransactionModel is a similar abstract model class with "value" and date field already there.
TransactionItemModel and QuantitativeTransactionItemModel do the same thing, have fields like price , quantity shipped.

EntityAdmin: is a customized ModelAdmin assuming that the model it work with in an EntityModel.
same goes for the sibiling TransactionAdmin and TransactionItemAdmin

You can skip the entityadmin and model all together if you see you dont need them.

For the documentation: i will work on it as soon as i can, a PR is very welcome and appreciated!

a PR is very welcome and appreciated!

I'm not an active Github user. Do you mean a Pull Request. If so what should it contain that makes a postive difference. My guess is a bug report with a specific problem rather than the more vague discussion style in Issues?

Currently trying to get a simple Report. I've got a good start to my models. And the big breakthrough was when I realised from the urls.py from shop is that the traditional admin is really in the root of the project (www.myproject.com) rather than /admin. With /admin existing purely for logging in and adding Users/Groups.

So I've added a simple reports.py with an Employee model and a link to a Role model.
I've already got an app config in my settings.py but I've added the following to init.py your docs suggest this but my-shop doesn't do it (trying everything).
default_app_config = 'humanresources.apps.HumanresourcesConfig'

Restart django but no Reports.

Stumped.

@register_report_view
class EmployeeReportView(ReportView):
    report_model = Employee
    report_title = "Employee Report"
    columns = [
        "employee_id",
        "firstname",
        "surname",
        ("role__name", {"verbose_name": "Role Name"}),
    ]

I'm not an active Github user. Do you mean a Pull Request. If so what should it contain that makes a postive difference. My guess is a bug report with a specific problem rather than the more vague discussion style in Issues?

Yes, i meant a Pull request , maybe in the docs clarifying what i missed and you caught.
In any way i'm happy to support .

So for the reports not showing ... which version are you installing ?
From pypi or the develop branch ? I would sugget the develop branch as there is some addition not yet published.
I will soon, returning slowly from a long awaited vacation.

So, no reports , this means that the reports.py is not imported
The develop branch have the auto import of reports.py , however, You can always do it in your app config ready

Here i put the reports in an erp.py file and i imported it
https://github.com/RamezIssac/my-shop/blob/main/request_analytics/apps.py

I installed 1.5.2 using pip install django-erp-framework
Just tried the approach listed here https://github.com/RamezIssac/django-erp-framework

(env) $ pip install -e git+https://github.com/RamezIssac/django-erp-framework.git#egg=django-erp-framework@develop
DEPRECATION: git+https://github.com/RamezIssac/django-erp-framework.git#egg=django-erp-framework@develop contains an egg fragment with a non-PEP 508 name pip 25.0 will enforce this behaviour change. A possible replacement is to use the req @ url syntax, and remove the egg fragment. Discussion can be found at pypa/pip#11617
ERROR: Invalid requirement: 'django-erp-framework@develop'

Tried some other approaches to install using pip but always stuck at 1.5.2 e.g.
pip install git+https://github.com/RamezIssac/django-erp-framework.git@develop

And I have the following in my apps.py
from django.apps import AppConfig

class HumanresourcesConfig(AppConfig):
    default_auto_field = 'django.db.models.BigAutoField'
    name = 'humanresources'
    def ready(self):
        super().ready()
        from . import reports

hmmm, You have jazzmin integration ?
If not then maybe you wont see the reports section

Yes. I tried without zazzmin at first then had a suspicion it would be best to include it.
But reports don't appear. Do I have to make an url for reports? I note that the my-shop has no traditional Apps/Models in the LHS models, only a list of Reports.

Still struggling.
I can't upgrade to develop branch. Seems to be still 1.5.2. Using django 4.2.3 and Postgresql 14.8

I'm trying urls straight to a report. E.g.
in reports.py I add the following code. And note if I leave out report_title I get an Internal Server Error and my uwsgi log indicates that there is a problem with my ReportView. This indicates that a lot is working. The ReportView code knows I've missed something from the class.

@register_report_view
class EmployeeList(ReportView):
    report_model = Employee
    base_model = Employee # so my-shop example with both the same
    report_title = "Employee ERP Report"
    columns = [
        "firstname",
        "surname",
        "email",
    ]
    limit_records = 10

I can't see any Reports on the LH Sidebar so am trying to view them directly.
This url follows the pattern in my-shop reports/modelname/classnameinreport.py
https://website.com/reports/employee/employeelist/
Resulting in

"Exception Value: | Report employee.employeelist is not found, Did you register it? If yes, then maybe it's has different namespace ? Options are: humanresources.employeelist"
"Exception Location: | /home/username/apps/appname/env/lib/python3.10/site-packages/erp_framework/reporting/registry.py, line 187, in get erp_framework.admin.base.get_report_view"

Where humanresources is my app name. I've tried countless variants of the url.

UPDATE

A look through the code and a look at the slick reporting docs suggests the following.
urls.py updated with
path("reports/employees/", EmployeeList.as_view(), name="employee-list"),
path('', erp_admin_site.urls),

AND reports.py
Add this to my class EmployeeList(ReportView):
template_name = "slick_reporting/simple_report.html"

This to replace the site-packages\erp_framework\reporting\views.py
class ReportView(ReportViewBase):
template_name = "erp_framework/report.html"

https://mywebsite.com/reports/employees/ and I have a nice form.

Still nothing in the LH Sidebar and I don't think I should need to put the path in urls for everything but proves almost everything is working.

Hello , i acknowledge receving this update. will try and find the time to address it asap.

Good news Ramez. I can't get github commands to move to the develop branch to work so just downloaded the files and copied them over my current erp-framework folder.

And it works!

So now I have Reports on the LHS sidebar.

Can't understand why my upgrade attempts fail. Maybe you should just release 1.5.3 and future folks will have a working system.

Great news !
Release will come soon yes.

Let me know if you face any other thing