Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from datetime import timedelta
- from typing import Optional
- from django.db import models
- from django.utils import timezone
- from crm.models import Project
- from core.models.crm_settings import CrmSettings
- from crm.models import get_base_record_for_project
- from crm_call.models import CallData
- from misc.generic_models.generic_model import GenericModel
- from misc.generic_models.meta_mixin import MetaMixin
- from users.models import User
- def default_listen_date_to():
- return timezone.now() + timedelta(minutes=1440)
- class Listen(GenericModel):
- """Используется для хранения информации о прослушке звонков."""
- # TODO: В будущем планируется изменить на unique=False (у одного звонка будет несколько слушующих)
- call_data = models.ForeignKey(CallData, verbose_name='Запись звонка', on_delete=models.CASCADE, unique=True,
- related_name='to_listen')
- user_to_listen = models.ForeignKey(User, verbose_name='Сотрудник', related_name='to_listen',
- on_delete=models.SET_NULL, null=True, blank=True)
- listen_date_to = models.DateTimeField('Прослушать до', default=default_listen_date_to)
- meta_tags = [MetaMixin.ModelTags.UserData]
- _id_meta = [MetaMixin.FieldTags.PKField, MetaMixin.FieldTags.NotForLog]# Мета данные поля id
- _user_meta = [MetaMixin.FieldTags.UserField]
- project = models.ForeignKey(
- Project,
- verbose_name='проект',
- on_delete=models.PROTECT,
- default=get_base_record_for_project,
- blank=True,
- )
- _project_meta = [MetaMixin.FieldTags.ProjectField]
- class Meta:
- verbose_name = 'Прослушка'
- verbose_name_plural = 'Прослушка'
- @staticmethod
- def get_default_listen_date_to(user: Optional[User] = None):
- project_id = (user.project_id if user else None) or get_base_record_for_project()
- crm_settings, is_created = CrmSettings.objects.get_or_create(project_id=project_id)
- return timezone.now() + timedelta(minutes=crm_settings.time_to_evaluate_calls)
- def get_call_data_str(self):
- """Возвращает строку таблицы CallData"""
- if self.call_data:
- return str(self.call_data)
- ---------------------------
- def get_user_to_listen_field(self, obj) -> dict:
- """Определяет возвращаемое значение для поля user_to_listen."""
- value = GenericSerializer.DEFAULT_EMPTY
- verbose = GenericSerializer.DEFAULT_EMPTY
- is_readonly = False
- if obj.to_listen.exists() and obj.to_listen.all().first().user_to_listen:
- value = obj.to_listen.all().first().user_to_listen.id
- verbose = obj.to_listen.all().first().user_to_listen.get_full_name()
- if obj.qualitymaps.all():
- is_readonly = True
- value = 'Звонок прослушан'
- verbose = 'Звонок прослушан'
- return self.get_table_field(field_name='user_to_listen_field', value=value, instance=obj, verbose=verbose,
- is_readonly=is_readonly)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement