fix print and preview quote and add broker to req and complete company model.
This commit is contained in:
parent
5ce94214d5
commit
246a2c0759
19 changed files with 872 additions and 260 deletions
|
@ -5,7 +5,7 @@ from simple_history.models import HistoricalRecords
|
|||
from django.core.exceptions import ValidationError
|
||||
from django.utils import timezone
|
||||
from django.conf import settings
|
||||
from accounts.models import Role
|
||||
from accounts.models import Role, Broker
|
||||
from _helpers.utils import generate_unique_slug
|
||||
import random
|
||||
|
||||
|
@ -174,7 +174,7 @@ class ProcessInstance(SluggedModel):
|
|||
blank=True,
|
||||
verbose_name="مرحله فعلی",
|
||||
)
|
||||
|
||||
|
||||
status = models.CharField(
|
||||
max_length=20,
|
||||
choices=STATUS_CHOICES,
|
||||
|
@ -188,6 +188,15 @@ class ProcessInstance(SluggedModel):
|
|||
default='medium',
|
||||
verbose_name="اولویت"
|
||||
)
|
||||
|
||||
broker = models.ForeignKey(
|
||||
Broker,
|
||||
on_delete=models.SET_NULL,
|
||||
verbose_name="کارگزار",
|
||||
blank=True,
|
||||
null=True,
|
||||
related_name='process_instances'
|
||||
)
|
||||
|
||||
completed_at = models.DateTimeField(
|
||||
null=True,
|
||||
|
@ -205,13 +214,6 @@ class ProcessInstance(SluggedModel):
|
|||
return f"{self.process.name} - {self.well.water_subscription_number}"
|
||||
return f"{self.process.name} - {self.requester.get_full_name()}"
|
||||
|
||||
def clean(self):
|
||||
"""اعتبارسنجی مدل"""
|
||||
if self.well and self.representative and self.well.representative != self.representative:
|
||||
raise ValidationError("نماینده درخواست باید همان نماینده ثبت شده در چاه باشد")
|
||||
|
||||
if self.well and self.representative and self.requester == self.representative:
|
||||
raise ValidationError("درخواست کننده نمیتواند نماینده چاه باشد")
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
# Generate unique 5-digit numeric code if missing
|
||||
|
@ -233,6 +235,13 @@ class ProcessInstance(SluggedModel):
|
|||
if self.status == 'completed' and not self.completed_at:
|
||||
self.completed_at = timezone.now()
|
||||
|
||||
# Auto-set broker if not already set
|
||||
if not self.broker:
|
||||
if self.well and hasattr(self.well, 'broker') and self.well.broker:
|
||||
self.broker = self.well.broker
|
||||
elif self.requester and hasattr(self.requester, 'profile') and self.requester.profile and hasattr(self.requester.profile, 'broker') and self.requester.profile.broker:
|
||||
self.broker = self.requester.profile.broker
|
||||
|
||||
super().save(*args, **kwargs)
|
||||
|
||||
def get_status_display_with_color(self):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue