major refactoring adding vendor and customer features

This commit is contained in:
2025-10-11 09:09:25 +02:00
parent f569995883
commit dd16198276
126 changed files with 15109 additions and 3747 deletions

View File

@@ -77,7 +77,7 @@ class VendorService:
new_vendor = Vendor(
**vendor_dict,
owner_id=current_user.id,
owner_user_id=current_user.id,
is_active=True,
is_verified=(current_user.role == "admin"),
)
@@ -129,7 +129,7 @@ class VendorService:
if current_user.role != "admin":
query = query.filter(
(Vendor.is_active == True)
& ((Vendor.is_verified == True) | (Vendor.owner_id == current_user.id))
& ((Vendor.is_verified == True) | (Vendor.owner_user_id == current_user.id))
)
else:
# Admin can apply filters
@@ -295,7 +295,7 @@ class VendorService:
raise InvalidVendorDataException("Vendor code is required", field="vendor_code")
if not vendor_data.vendor_name or not vendor_data.vendor_name.strip():
raise InvalidVendorDataException("Vendor name is required", field="vendor_name")
raise InvalidVendorDataException("Vendor name is required", field="name")
# Validate vendor code format (alphanumeric, underscores, hyphens)
import re
@@ -310,7 +310,7 @@ class VendorService:
if user.role == "admin":
return # Admins have no limit
user_vendor_count = db.query(Vendor).filter(Vendor.owner_id == user.id).count()
user_vendor_count = db.query(Vendor).filter(Vendor.owner_user_id == user.id).count()
max_vendors = 5 # Configure this as needed
if user_vendor_count >= max_vendors:
@@ -345,7 +345,7 @@ class VendorService:
def _can_access_vendor(self, vendor : Vendor, user: User) -> bool:
"""Check if user can access vendor."""
# Admins and owners can always access
if user.role == "admin" or vendor.owner_id == user.id:
if user.role == "admin" or vendor.owner_user_id == user.id:
return True
# Others can only access active and verified vendors
@@ -353,7 +353,7 @@ class VendorService:
def _is_vendor_owner(self, vendor : Vendor, user: User) -> bool:
"""Check if user is vendor owner."""
return vendor.owner_id == user.id
return vendor.owner_user_id == user.id
# Create service instance following the same pattern as other services
vendor_service = VendorService()