class TypAudytu( models.Model): class Meta: verbose_name = _("Typ audytu") verbose_name_plural = _("Typy audytow") default_permissions = ('add', 'change', 'delete', 'list') app_label = 'audyty' ordering = ['id'] nazwa = models.CharField('Nazwa', null=False, blank=False, editable=True, max_length=64) powtarzaj = models.CharField('Powtarzaj', null=False, blank=False, editable=True, choices=RepeatChoice,max_length=64) ile = models.IntegerField('Ile', null=False, blank=False, editable=True, default=1,) sporzadza = ext_models.ForeignKey(Operator, on_delete=models.CASCADE, null=False, blank=False, editable=True, verbose_name='Sporządza', related_name='sporzadzajacy') zatwierdza = ext_models.ForeignKey(Operator, on_delete=models.CASCADE, null=False, blank=False, editable=True, verbose_name='Zatwierdza', related_name='zatwierdzajacy') template = models.TextField('Templatka', null=True, blank=True, editable=True, ) dane = models.TextField('Dane', null=True, blank=True, editable=True, ) opis1title = models.CharField('Tytuł opisu 1', null=True, blank=True, editable=True, max_length=64) opis2title = models.CharField('Tytuł opisu 2', null=True, blank=True, editable=True, max_length=64) opis3title = models.CharField('Tytuł opisu 3', null=True, blank=True, editable=True, max_length=64) copy = models.BooleanField('Czy kopiować opisy', null=False, blank=False, editable=True, default=False,)
class EtapProjektuInw( models.Model): class Meta: verbose_name = _("Etap ") verbose_name_plural = _("Etapy projektu") default_permissions = ('add', 'change', 'delete', 'list') app_label = 'projekty' ordering = ['id'] parent = ext_models.HiddenForeignKey(ProjektInw, on_delete=models.CASCADE, null=False, blank=False, editable=True, verbose_name='Parent', ) projektant = ext_models.ForeignKey(User, on_delete=models.CASCADE, null=False, blank=False, editable=True, verbose_name='Projektant', limit_choices_to = limit_users_change_etapprojektuinw) opis = models.CharField('Opis', null=False, blank=False, editable=True, max_length=64) status = models.CharField('Status', null=False, blank=False, editable=True, default='0',choices=StatusEtapu,max_length=64) data_od = models.DateField('Od', null=False, blank=False, editable=True, default=datetime.now,) data_do = models.DateField('Do', null=False, blank=False, editable=True, default=datetime.now,) def transform_form(self, request, form, is_new_form=False): if is_new_form: form.initial['projektant']=self.parent.projektant
class BiuroProjekt( models.Model): class Meta: verbose_name = _("Biuro projektowe") verbose_name_plural = _("Biura projektowe") default_permissions = ('add', 'change', 'delete', 'list') app_label = 'projekty' ordering = ['id'] nazwa = models.CharField('Nazwa', null=False, blank=False, editable=True, max_length=64) adres = models.CharField('Adres', null=True, blank=True, editable=True, max_length=64) telefon = models.CharField('Nr telefonu', null=False, blank=False, editable=True, max_length=64) email = models.EmailField('Email', null=False, blank=False, editable=True, ) umowa = models.CharField('Umowa projektowa', null=False, blank=False, editable=True, max_length=64) projektant = ext_models.ForeignKey(User, on_delete=models.CASCADE, null=True, blank=True, editable=True, verbose_name='Projektant', limit_choices_to=limit_users_change_etapprojektuinw,related_name='b_projekt') uwagi = models.CharField('Uwagi', null=False, blank=False, editable=True, max_length=64) def __str__(self): return self.nazwa
class NowyKomputer(models.Model): class Meta: verbose_name = _("New computer") verbose_name_plural = _("New computers") default_permissions = ('add', 'change', 'delete', 'list') app_label = 'spisy' ordering = ['id'] hostname = models.CharField('Hostname', null=False, blank=False, editable=True, max_length=64) typ_komputera = ext_models.ForeignKey( TypKomputera, on_delete=models.CASCADE, null=False, blank=False, editable=True, verbose_name='Typ komputera', ) uwagi = models.TextField( 'Uwagi', null=True, blank=True, editable=True, ) operator = ext_models.ForeignKey( UserAD, on_delete=models.CASCADE, null=True, blank=True, editable=True, verbose_name='Operator', ) aktywny = models.BooleanField( 'Aktywny', null=False, blank=False, editable=True, default=False, ) def __str__(self): return self.hostname + "/" + self.operator.loginname
class ProjektNawierzchni( models.Model): class Meta: verbose_name = _("Projekt nawierzchni") verbose_name_plural = _("Projekty nawierzchni") default_permissions = ('add', 'change', 'delete', 'list') app_label = 'projekty' ordering = ['id'] numer = models.CharField('Numer projektu', null=False, blank=False, editable=True, max_length=64) data_prz = models.DateField('Data przyjęcia', null=False, blank=False, editable=True, ) klient_nazwa = models.CharField('Nazwa klienta (Nazwisko i imię)', null=False, blank=False, editable=True, max_length=64) klient_adres = models.CharField('Adres inwestycji', null=False, blank=False, editable=True, max_length=64) klient_tel = models.CharField('Nr tel. klienta', null=False, blank=False, editable=True, max_length=64) klient_email = models.EmailField('Email klienta', null=False, blank=False, editable=True, ) klient_uwagi = models.CharField('Dodatkowe uwagi dotyczące klienta', null=True, blank=True, editable=True, max_length=64) hurtownia = ext_models.ForeignKey(Hurtownia, on_delete=models.CASCADE, null=True, blank=True, editable=True, verbose_name='Hurtownia', ) powierzchnia = models.DecimalField('Powierzchnia', null=False, blank=False, editable=True, max_digits=12, decimal_places=2) typ_projektu = models.CharField('Typ projektu', null=False, blank=False, editable=True, choices=TypProjektuNawierzchni,max_length=1) typ_obiektu = models.CharField('Typ obiektu', null=False, blank=False, editable=True, choices=TypObiektu,max_length=1) region = models.CharField('Region', null=False, blank=False, editable=True, choices=Region,max_length=2) asortymenty = models.ManyToManyField(Asortyment, null=True, blank=True, editable=True, verbose_name='Asortyment', ) status = models.CharField('Status', null=False, blank=False, editable=True, default='0',choices=StatusProjektuNaw,max_length=1) projektant = models.ForeignKey(User, on_delete=models.CASCADE, null=True, blank=True, editable=True, verbose_name='Projektant', limit_choices_to=limit_users_change_projektnawierzchni) def transform_form(self, request, form, is_new_form=False): if is_new_form: form.initial['projektant']=request.user def post(self, request): id = self.id self.save() x=Log() x.application = 'projekty' x.table = 'ProjektNawierzchni' x.group = 'default' x.parent_id = self.id x.date = datetime.now() if id: x.description = "Zmiana projektu, status: %s" % self.get_status_display() else: x.description = "Utworzenie projektu o statusie %s" % self.get_status_display() x.operator = request.user.username x.operator_id = request.user.id x.save() return True
class ProjektInw( models.Model): class Meta: verbose_name = _("Projekt inwestycyjny") verbose_name_plural = _("Projekty inwestycyjne") default_permissions = ('add', 'change', 'delete', 'list') app_label = 'projekty' ordering = ['id'] numer = models.CharField('Numer', null=False, blank=False, editable=True, max_length=64) data_start = models.DateField('Data', null=False, blank=False, editable=True, ) gl_projektant = ext_models.ForeignKey(User, on_delete=models.CASCADE, null=False, blank=False, editable=True, verbose_name='Główny projektant', limit_choices_to = limit_users_change_projektinw,related_name='gl_projektant') projektant = ext_models.ForeignKey(User, on_delete=models.CASCADE, null=False, blank=False, editable=True, verbose_name='Projektant', limit_choices_to=limit_users_change_etapprojektuinw,related_name='projektant') szef = ext_models.ForeignKey(User, on_delete=models.CASCADE, null=True, blank=True, editable=True, verbose_name='Szef regionu', limit_choices_to = limit_users_change_projektinw, related_name='szef') opis_projektu = models.CharField('Opis projektu', null=False, blank=False, editable=True, max_length=64) lokalizacja = models.CharField('Lokalizacja projektu', null=False, blank=False, editable=True, max_length=64) biuro_proj = ext_models.ForeignKey(BiuroProjekt, on_delete=models.CASCADE, null=False, blank=False, editable=True, verbose_name='Biuro projektowe', search_fields=['nazwa__icontains',]) inwestor = models.CharField('Inwestor', null=False, blank=False, editable=True, max_length=64) wykonawca = models.CharField('Generalny wykonawca', null=True, blank=True, editable=True, max_length=64) podwykonawca = models.CharField('Podwykonawca', null=False, blank=False, editable=True, max_length=64) uwagi = models.TextField('Uwagi', null=False, blank=False, editable=True, ) nr_umowy_prow = models.CharField('Nr umowy prowizyjnej', null=False, blank=False, editable=True, max_length=64) material = models.CharField('Materiał', null=False, blank=False, editable=True, max_length=64) status = models.CharField('Status projektu', null=False, blank=False, editable=True, choices=StatusProjektu,max_length=64) typ_projektu = models.CharField('Typ projektu', null=False, blank=False, editable=True, choices=TypProjektu,max_length=64) def transform_form(self, request, form, is_new_form=False): if is_new_form: form.initial['gl_projektant']=request.user def save(self, *args, **kwargs): ret = super().save(*args, **kwargs) #send_mail('Subject', 'Here is the message.', '*****@*****.**', ['*****@*****.**'], fail_silently=False) return ret
class Agreement(models.Model): class Meta: verbose_name = _("Agreement") verbose_name_plural = _("Agreements") default_permissions = ('add', 'change', 'delete', 'list') app_label = 'crh' ordering = ['id'] parent = ext_models.ForeignKey( Ad, on_delete=models.CASCADE, null=False, blank=False, editable=True, verbose_name='Parent', ) doc = ext_models.ForeignKey( AgreementDoc, on_delete=models.CASCADE, null=False, blank=False, editable=True, verbose_name='Doc', ) date = models.DateField( 'Date', null=False, blank=False, editable=True, ) data = models.TextField( 'Data', null=False, blank=False, editable=False, )
class StarySprzet(models.Model): class Meta: verbose_name = _("Old equipment") verbose_name_plural = _("Old equipments") default_permissions = ('add', 'change', 'delete', 'list') app_label = 'spisy' ordering = ['id'] nazwa = models.CharField('Nazwa', null=False, blank=False, editable=True, max_length=64) opis = models.TextField( 'Opis', null=True, blank=True, editable=True, ) do_sprzedania = models.BooleanField( 'Do sprzedania', null=False, blank=False, editable=True, default=False, ) zafakturowany = models.BooleanField( 'Zafakturowany', null=False, blank=False, editable=True, default=False, ) zgoda_na_sprzedaz = models.BooleanField( 'Zgodna na sprzedaż', null=False, blank=False, editable=True, default=False, ) operator = ext_models.ForeignKey(UserAD, on_delete=models.CASCADE, null=True, blank=True, editable=True, verbose_name='Operator', related_name='operator_staregosprzetu')
class TestForUser( models.Model): class Meta: verbose_name = _("Test for user") verbose_name_plural = _("Tests for user") default_permissions = ('add', 'change', 'delete', 'list') app_label = 'audyty' ordering = ['id'] parent = ext_models.ForeignKey(Test, on_delete=models.CASCADE, null=False, blank=False, editable=True, verbose_name='Parent', ) username = models.CharField('None', null=False, blank=False, editable=True, max_length=64) send_date = models.DateTimeField('Date of sending', null=True, blank=True, editable=True, ) close_date = models.DateTimeField('Closing date', null=True, blank=True, editable=True, ) finished = ext_models.NullBooleanField('Finished', null=True, blank=True, editable=True, default=False,) ok = ext_models.NullBooleanField('OK', null=True, blank=True, editable=True, default=False,) closed = ext_models.NullBooleanField('Closed', null=True, blank=True, editable=True, default=False,)
class Lin( models.Model): class Meta: verbose_name = _("Linijki") verbose_name_plural = _("Linijki") default_permissions = ('add', 'change', 'delete', 'list') app_label = 'sprzedaz' ordering = ['id'] parent = ext_models.ForeignKey(Nag, on_delete=models.CASCADE, null=False, blank=False, editable=True, verbose_name='Parent', ) lp = models.IntegerField('LP', null=False, blank=False, editable=True, ) castorama_kar = models.CharField('Nr kartoteki w Castoramie', null=True, blank=True, editable=True, max_length=64) symkar = models.CharField('Symbol kartoteki w Softlabie', null=True, blank=True, editable=True, max_length=64) opis = models.CharField('Opis', null=True, blank=True, editable=True, max_length=64) ilosc = models.DecimalField('Ilość', null=True, blank=True, editable=True, decimal_places=2, max_digits=11) cena = models.DecimalField('Cena netto', null=True, blank=True, editable=True, decimal_places=2, max_digits=11) jz = models.CharField('JZ', null=True, blank=True, editable=True, max_length=16) netto = models.DecimalField('Netto', null=True, blank=True, editable=True, decimal_places=2, max_digits=11)
class AccountOperation(models.Model): class Meta: verbose_name = _("Account operation") verbose_name_plural = _("Account operations") default_permissions = ('add', 'change', 'delete', 'list') app_label = 'schelements' ordering = ['id'] parent = ext_models.HiddenForeignKey( DocItem, on_delete=models.CASCADE, null=False, blank=False, editable=True, verbose_name='Parent', ) date = models.DateTimeField( 'Date', null=False, blank=False, editable=False, default=datetime.datetime.now, ) description = models.CharField('Description', null=False, blank=False, editable=True, max_length=255) payment = models.CharField('Name of payment', null=True, blank=True, editable=True, max_length=64) account_state = ext_models.ForeignKey(AccountState, on_delete=models.CASCADE, null=True, blank=True, editable=True, verbose_name='Account state', related_name='accountoper_set') sign = models.IntegerField( 'Sign - debit or credit', null=False, blank=False, editable=True, ) amount = models.DecimalField('Amount', null=False, blank=False, editable=True, max_digits=16, decimal_places=2) enabled = ext_models.NullBooleanField( 'Enabled', null=True, blank=True, editable=False, default=False, ) def get_account_state(self, account, element, period, target, classifier1=None, classifier2=None, classifier3=None, subcode="", aggregate=False): if type(account) == str: _account = Account.objects.filter(name=account)[0] else: _account = account if type(element) == str: _element = Element.objects.filter(name=element)[0] else: _element = element if type(target) == str: _target = OrgChartElem.objects.filter(code=target)[0] else: _target = target objs = AccountState.objects.filter(parent=_account, target=_target, classifier1value=classifier1, classifier2value=classifier2, classifier3value=classifier3, period=period, subcode=subcode, element=_element) if objs.count() > 0: return objs[0] else: obj = AccountState() obj.parent = _account obj.target = _target obj.classifier1value = classifier1 obj.classifier2value = classifier2 obj.classifier3value = classifier3 obj.period = period obj.subcode = subcode obj.element = _element obj.aggregate = aggregate obj.debit = 0 obj.credit = 0 obj.save() return obj def update_account_state(self, debit, credit): s = self.account_state account = s.parent for period in [s.period, '*']: for target in [s.target, None]: for subcode in [s.subcode, "*"]: state = self.get_account_state(account, s.element, period, target, subcode=subcode, aggregate=True) state.debit += debit state.credit += credit state.save() account = account.parent subcode = "*" while account: for period in [s.period, '*']: for target in [s.target, None]: state = self.get_account_state(account, s.element, period, target, subcode=subcode, aggregate=True) state.debit += debit state.credit += credit state.save() account = account.parent def confirm(self): ret = False with transaction.atomic(): self.refresh_from_db() if not self.enabled: self.enabled = True if self.sign > 0: self.update_account_state(0, self.amount) else: self.update_account_state(self.amount, 0) self.save() ret = True return ret def cancel_confirmation(self): ret = False with transaction.atomic(): self.refresh_from_db() if self.enabled: self.enabled = False if self.sign > 0: self.update_account_state(0, -1 * self.amount) else: self.update_account_state(-1 * self.amount, 0) self.save() ret = True return ret
class Account(TreeModel): class Meta: verbose_name = _("Account") verbose_name_plural = _("Account") default_permissions = ('add', 'change', 'delete', 'list') app_label = 'schelements' ordering = ['id'] parent = ext_models.TreeForeignKey('self', on_delete=models.CASCADE, null=True, blank=True, related_name='children') parent = ext_models.TreeForeignKey( 'self', on_delete=models.CASCADE, null=True, blank=True, editable=True, verbose_name='Parent', ) type1 = models.CharField('Type 1', null=True, blank=True, editable=False, choices=account_type_choice_1, max_length=1) type2 = models.CharField('Type 2', null=True, blank=True, editable=True, choices=account_type_choice_2, max_length=1) name = models.CharField('Name', null=False, blank=False, editable=True, max_length=32) description = models.CharField('Description', null=False, blank=False, editable=True, max_length=256) root_classifier1 = ext_models.ForeignKey( Classifier, on_delete=models.CASCADE, null=True, blank=True, editable=True, verbose_name='Root classifier 1', related_name='baseaccount_rc1_set') root_classifier2 = ext_models.ForeignKey( Classifier, on_delete=models.CASCADE, null=True, blank=True, editable=True, verbose_name='Root classifier 2', related_name='baseaccount_rc2_set') root_classifier3 = ext_models.ForeignKey( Classifier, on_delete=models.CASCADE, null=True, blank=True, editable=True, verbose_name='Root classifier 3', related_name='baseaccount_rc3_set') enabled = ext_models.NullBooleanField( 'Enabled', null=False, blank=False, editable=True, default=True, ) def save(self, *args, **kwargs): if self.parent: self.parent.type1 = 'S' self.parent.save() self.type2 = self.parent.type2 self.type1 = 'A' super().save(*args, **kwargs) def __str__(self): x = self ret = self.name while (x.parent): x = x.parent ret = x.name + "/" + ret ret += ": " ret += self.description return ret
class Report(JSONModel): class Meta: verbose_name = _("Report") verbose_name_plural = _("Reports") default_permissions = ('add', 'change', 'delete', 'list') app_label = 'schreports' ordering = ['id'] ordering = ['parent_id', 'order', 'id'] parent = ext_models.ForeignKey( 'self', on_delete=models.CASCADE, null=True, blank=True, editable=False, verbose_name='Parent', ) order = models.IntegerField( 'Order number', null=True, blank=True, editable=True, ) report_def_name = models.CharField('Report definition name', null=False, blank=False, editable=True, max_length=64) date = models.DateTimeField( 'Date', null=True, blank=True, editable=True, ) def template_for_object(self, context, doc_type): if doc_type == 'pdf': x = ReportDef.objects.filter(name=self.report_def_name) if x.count() > 0: return "%s/report_%s_pdf.html" % (x[0].app, self.report_def_name) return None @staticmethod def get_rep_types(): repdef_list = ReportDef.objects.exclude(name__contains='/') return [pos.name for pos in repdef_list] @staticmethod def get_rep_by_nagid(nagid): r = Report.objects.filter(order=nagid) if r.count() > 0: return r[0] else: return None @staticmethod def filter(f): if f == 'main_reports': return Report.objects.filter(parent=None) else: return Report.objects.all() def getsubreps(self, name): return Report.objects.filter(parent=self).filter( report_def_name__endswith=name) def to_html(self): rep_def = ReportDef.objects.get(name=self.report_def_name) return rep_def.to_html(self) #def __getattr__(self, name): # if name.startswith('json_'): # if not hasattr(self, '_data'): # self._data = json_loads(self.data) # if name[5:] in self._data: # return self._data[name[5:]] # else: # return None # else: # return super().__getattr__(name) def save(self, *args, **kwargs): if self.pk is None: if self.parent: m = Report.objects.filter(parent=self.parent).aggregate( Max('order'))['order__max'] if m: self.order = m + 1 else: self.order = 1 super().save(*args, **kwargs)
class SChApp( models.Model): class Meta: verbose_name = _("SChApp") verbose_name_plural = _("SChApp") default_permissions = ('add', 'change', 'delete', 'list') app_label = 'schbuilder' ordering = ['id'] parent = ext_models.ForeignKey(SChAppSet, on_delete=models.CASCADE, null=False, blank=False, editable=True, verbose_name='Parent', ) name = models.CharField('Name', null=False, blank=False, editable=True, max_length=255) module_title = models.CharField('Module title', null=True, blank=True, editable=True, max_length=32) title = models.CharField('Title', null=True, blank=True, editable=True, max_length=255) perms = models.BooleanField('Perms', null=False, blank=False, editable=True, default=False,) index = models.CharField('Index', null=True, blank=True, editable=True, max_length=255) model_code = models.TextField('Model code', null=True, blank=True, editable=False, ) view_code = models.TextField('View code', null=True, blank=True, editable=False, ) urls_code = models.TextField('Urls code', null=True, blank=True, editable=False, ) tasks_code = models.TextField('Tasks code', null=True, blank=True, editable=True, ) consumer_code = models.TextField('Consumer code', null=True, blank=True, editable=True, ) doc = models.TextField('Doc', null=True, blank=True, editable=False, ) user_param = models.TextField('Urser parameter', null=True, blank=True, editable=True, ) def get_models(self): ret = ["'self'", ] for app in self.parent.schapp_set.all(): for tab in app.schtable_set.all(): if app.name == self.name: ret.append(tab.name) else: ret.append(app.name+"."+tab.name) if self.parent.ext_apps: ext_apps = self.parent.ext_apps.split(',') else: ext_apps = [] if len(ext_apps)>0: for ext_app in ext_apps: if 'schserw.' in ext_app: try: module = __import__(ext_app+'.models') app = getattr(module,ext_app.split('.')[1]) models = getattr(app,'models') for name in dir(models): obj = getattr(models, name) if inspect.isclass(obj): ret.append(ext_app+"."+name) except: pass for ext_app in ext_apps: if not 'schserw.' in ext_app: try: appset = ext_app.split('.')[0] appname = ext_app.split('.')[1] appsetpath = norm_path(os.path.dirname(__file__)+"/../../"+appset) if not appsetpath in sys.path: sys.path.append(appsetpath) module = __import__(appname+'.models') models = getattr(module,'models') for name in dir(models): obj = getattr(models, name) if inspect.isclass(obj): ret.append(appname+"."+name) except: pass return ret def get_urls(self, main=False): ret = [] for table in self.schtable_set.all(): if table.generic: ret.append('table/' + table.name +"/-/form/list/") for field in table.schfield_set.all(): if field.is_rel(): if field.type[0]=='G': if field.name == 'parent' and field.rel_to == "'self'": ret.append('table/'+table.name+"/0/form/tree/") for view in self.schview_set.all(): if view.url and view.url != "": if not main: if view.view_type=='r': url = 'table/' + view.url + "/<<pk>>/action/"+view.name+"/" ret.append(url) if view.view_type=='t': url = 'table/' + view.url + "/action/"+view.name+"/" ret.append(url) if view.view_type=='u': if not (main and '?P' in view.url): ret.append(view.url) for template in self.schtemplate_set.all(): if template.direct_to_template: ret.append(template.get_url_name()) #for wiki in Page.objects.all(): # url = 'schwiki/{{%s}}/{{%s}}/view/' % (wiki.subject, wiki.name) # ret.append(url) for form in self.schform_set.all(): if not form.name.startswith('_'): ret.append('form/' + form.name +"/") return ret def model_code_start(self): if self.model_code: return self.model_code.split('[[[GEN]]]')[0] else: return "" def model_code_end(self): if self.model_code: x = self.model_code.split('[[[GEN]]]') if len(x)>1: return x[1] return "" def __str__(self): return self.name