GithubHelp home page GithubHelp logo

stockit's Introduction

Enterprise Stock Manager

This Django project is a comprehensive stock management system for businesses currently under development.

This Django project is a comprehensive stock management system for businesses. It allows users to sign up, create and manage their companies, as well as efficiently manage their stocks, goods entries, inventories, and promotions.

Main Features

**To view the full range of functionalities, not all features are accessible directly from the main branch. Some functionalities are located within specific branches, allowing for a more organized and manageable development process. **

User Account Management: Users can sign up, log in, and manage their user accounts.

Multi-Enterprise Management: Users can register and manage multiple companies from their user account.

Stock Management: Companies can track and manage their product stocks. They can add new products, update stock quantities, etc.

Goods Entry Management: Users can record goods entries into the system, specifying details such as quantity, unit price, etc.

Inventory Management: Companies can conduct regular inventories to check stock levels and update data accordingly.

Promotion Management: Companies can create and manage promotions for their products, specifying discounts, start and end dates, etc.

Current Status

Accessing Features

Register a company

Additionally, when a user registers their company, they are automatically assigned the role of administrator. This is facilitated by a custom permission created for this purpose.

# models.py
class Company(models.Model):
    # fields here

    class Meta:
        verbose_name = "Entreprise"
        permissions = [
            ("company_admin_status", "User has all the rights on company"),
        ]
# func package
def add_company_admin_permission(user):
    content_type = ContentType.objects.get_for_model(Company)
    permissions = Permission.objects.filter(content_type=content_type)
    for perm in permissions:
        if perm.codename == "company_admin_status":
            user.user_permissions.add(perm)

SelectCompanyForm

To access the features of the system, users are required to log in to their accounts. Upon logging in, users must select the company in which they are registered. The selection process is streamlined to display only the companies in which the user is registered. This functionality is achieved by overriding the class constructor of the SelectCompanyForm form. This functionality is implemented using Django's request.session to store the user's company choice.

# forms.py
class SelectCompanyForm(forms.Form):

    def __init__(self, user, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.fields['company'] = forms.ModelChoiceField(queryset=Company.objects.filter(users=user), label="Entreprise")
# views.py
@login_required
def select_company_view(request):
    user = request.user
    if request.method == "POST":
        form = SelectCompanyForm(user, request.POST)
        if form.is_valid():
            company = form.cleaned_data["company"]
            request.session["company"] = f"{company.name} id {company.identification}"
            messages.add_message(request, messages.INFO, f"Choix {company} validé.")
            return redirect(request.path)
    else:
        form = SelectCompanyForm(user)
    return render(request, "account/select_company.html", context={"form": form})

Custom the context processor

Furthermore, the context processor has been modified to display the name of the selected company, ensuring a more personalized user experience.

# context_processor.py
def add_session_company_to_context(request):
    return {"company_session": request.session.get("company", None)}
# settings.py
TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [BASE_DIR / "templates"],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
                'account.context_processors.add_session_company_to_context',
            ],
        },
    },
]

Custom decorator

Moreover, a custom view decorator has been crafted to add specific functionality to views, enhancing the flexibility and control over user interactions within the application.

def company_required(view_func):
    def wrapper(request, *args, **kwargs):
        if not request.session.get("company"):
            return redirect("account:select-company")
        response = view_func(request, *args, **kwargs)
        return response

    return wrapper

Pytest

Furthermore, tests are being implemented progressively alongside the development of each branch, ensuring the robustness and reliability of the system's functionalities.

stockit's People

Contributors

gabigab117 avatar

Watchers

 avatar

stockit's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.