Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from django.db import models
- from django.utils import timezone
- from crm.models import Project
- from crm.models import get_base_record_for_project
- from .user import User
- from misc.generic_models.meta_mixin import MetaMixin
- class Property(models.Model, MetaMixin):
- """Имущество (материальные ценности)"""
- _id_meta = [MetaMixin.FieldTags.PKField, MetaMixin.FieldTags.NotForLog]
- name = models.CharField(verbose_name='Название имущества', max_length=255, null=False, blank=False)
- declared_value = models.PositiveIntegerField(verbose_name='Объявленная стоимость', null=True, blank=True)
- comment = models.TextField(verbose_name='Комментарий', null=True, blank=True)
- serial_number = models.CharField(verbose_name='Серийный номер', max_length=255, null=True, blank=True)
- project = models.ForeignKey(
- Project, verbose_name='проект',
- on_delete=models.PROTECT,
- default=get_base_record_for_project,
- blank=True,
- )
- _project_meta = [MetaMixin.FieldTags.ProjectField]
- def __str__(self):
- return self.name
- __repr__ = __str__
- class Meta:
- verbose_name = 'Имущество'
- verbose_name_plural = 'Имущество'
- class UserProperty(models.Model, MetaMixin):
- """Имущество у сотрудника"""
- meta_tags = [MetaMixin.ModelTags.UserData]
- transfer_date = models.DateTimeField(verbose_name='Дата передачи', null=False, blank=False, default=timezone.now)
- declared_value = models.PositiveIntegerField(verbose_name='Количество', null=True, blank=True)
- return_date = models.DateTimeField(verbose_name='Дата возврата', null=True, blank=True)
- user_property = models.ForeignKey(
- Property,
- verbose_name='Имущество выданное сотруднику',
- related_name='property',
- on_delete=models.CASCADE,
- null=False,
- blank=False,
- )
- _id_meta = [MetaMixin.FieldTags.PKField, MetaMixin.FieldTags.NotForLog]# Мета данные поля id
- user = models.ForeignKey(
- User,
- verbose_name='Ответственный сотрудник по возврату данных',
- related_name='employee_property',
- on_delete=models.CASCADE,
- null=False,
- blank=False,
- )
- _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]
- def check_employee_property(self) -> bool:
- """Проверка на сохранённое имущество у сотрудника"""
- if self.return_date:
- return False
- return True
- def __str__(self):
- return self.employee
- __repr__ = __str__
- class Meta:
- verbose_name = 'Имущество у сотрудника'
- verbose_name_plural = 'Имущество у сотрудника'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement