示例#1
0
def add_company(request):
    form1 = UserProfileForm(request.POST)
    form2 = UserCreateForm(request.POST)
    form3 = CompanyForm(request.POST)
    if form1.is_valid() and form2.is_valid() and form3.is_valid():
        up = form1.save(commit=False)
        c = form3.save()
        c.active = True
        c.favorite = True
        c.save()
        u = form2.save()
        up.user = u
        up.save()
        up.companies.add(c)
        for user in User.objects.filter(is_superuser=True):
            user.userprofile.companies.add(c)
            user.userprofile.save()
        # add dossier global
        fy_init = FiscalYear.objects.filter(init=True)[0]
        y_init = Year(fiscal_year=fy_init, active=True, refer_company=c, favorite=False)
        y_init.save()
        c.years.add(y_init)
        tt_init = TemplateTrimester.objects.filter(year=fy_init, favorite=True)[0]
        tri_init = Trimester(template=tt_init, start_date=tt_init.start_date, active=True, refer_year=y_init, favorite=True)
        tri_init.save()
        y_init.trimesters.add(tri_init)
        tp_init = TypeCategory.objects.filter(priority=10)[0]
        cat_init = Category(cat=tp_init, refer_trimester=tri_init, active=True)
        cat_init.save()
        tri_init.categories.add(cat_init)
        # add favorite_year and favorite_trimester
        fy_fav = FiscalYear.objects.filter(favorite=True)[0]
        y_fav = Year(fiscal_year=fy_fav, active=True, refer_company=c, favorite=True)
        y_fav.save()
        c.years.add(y_fav)
        tt_fav = TemplateTrimester.objects.filter(year=fy_fav, favorite=True)[0]
        tri_fav = Trimester(template=tt_fav, start_date=tt_fav.start_date, active=True, refer_year=y_fav, favorite=True)
        tri_fav.save()
        y_fav.trimesters.add(tri_fav)
        for tp in TypeCategory.objects.filter(priority__lt=10).order_by('priority'):
            cat_fav = Category(cat=tp, refer_trimester=tri_fav, active=True)
            cat_fav.save()
            tri_fav.categories.add(cat_fav)
        c = {'return': True, 'list': Company.objects.all(), 'form': [UserProfileForm(), UserCreateForm(), CompanyForm()], 'url': '/company/add/'}
        return render(request, 'list.tpl', c)
    else:
        c = {'view_form': True, 'list': Company.objects.all(), 'form': [form1(), form2(), form3()]}
        return render(request, 'list.tpl', c)
示例#2
0
    fy.save()

for t1 in TemplateTrimester.objects.all():
    t1.favorite = False
    t1.save()

for t2 in Trimester.objects.all():
    t2.favorite = False
    t2.save()

tts = TemplateTrimester.objects.filter(number=trim, year=fy)
if len(tts):
    tt = tts[0]
    tt.favorite = True
    tt.start_date = date
    tt.save()
else:
    tt = TemplateTrimester(number=trim, year=fy, favorite=True, start_date=date)
    tt.save()

for c in Company.objects.all():
    y = Year.objects.filter(fiscal_year=fy, refer_company=c)[0]
    if not y:
        y = Year(fiscal_year=fy, refer_company=c, active=True)
        y.save()
        c.add_year(y)
    new_t1 = Trimester(template=tt, start_date=date, active=True, refer_year=y)
    new_t1.save()
    new_t1.add_categories()
    y.add_trimester(new_t1)
示例#3
0
from utils.models import TemplateTrimester
from datetime import datetime
tt0 = TemplateTrimester(number=3, year=fy1, favorite=False, start_date=datetime(2015, 7, 1))
tt0.save()
tt1 = TemplateTrimester(number=4, year=fy1, favorite=False, start_date=datetime(2015, 10, 1))
tt1.save()
tt2 = TemplateTrimester(number=1, year=fy2, favorite=False, start_date=datetime(2016, 1, 1))
tt2.save()
tt3 = TemplateTrimester(number=2, year=fy2, favorite=True, start_date=datetime(2016, 4, 1))
tt3.save()
tt4 = TemplateTrimester(number=3, year=fy2, favorite=False, start_date=datetime(2016, 7, 1))
tt4.save()

from trimesters.models import Trimester
from datetime import datetime	
t1 = Trimester(template=tt1, start_date=datetime(2015, 10, 1), active=True, refer_year=y11)
t1.save()
t1.add_categories()
y11.add_trimester(t1)
t2 = Trimester(template=tt0, start_date=datetime(2015, 7, 1), active=True, refer_year=y11)
t2.save()
t2.add_categories()
y11.add_trimester(t2)
t3 = Trimester(template=tt2, start_date=datetime(2016, 1, 1), active=True, refer_year=y12)
t3.save()
t3.add_categories()
y12.add_trimester(t3)
t4 = Trimester(template=tt3, start_date=datetime(2016, 4, 1), active=True, refer_year=y12)
t4.save()
t4.add_categories()
y12.add_trimester(t4)