Exemplo n.º 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)
Exemplo n.º 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)
Exemplo n.º 3
0
fy2 = FiscalYear(name='2016')
fy2.save()

country1 = Country(name='Belgium')
country1.save()

from companies.models import Company
c1 = Company(name='Alpha',slug='alpha',vat_number='123456789', country=country1, active=True)
c1.save()
up.add_company(c1)
c2 = Company(name='Beta',slug='beta',vat_number='123456780', country=country1, active=True)
c2.save()
up.add_company(c2)

from years.models import Year
y11 = Year(fiscal_year=fy1, refer_company=c1, active=True)
y11.save()
c1.add_year(y11)
y12 = Year(fiscal_year=fy2, refer_company=c1, active=True)
y12.save()
c1.add_year(y12)
y21 = Year(fiscal_year=fy1, refer_company=c2, active=True)
y21.save()
c2.add_year(y21)
y22 = Year(fiscal_year=fy2, refer_company=c2, active=True)
y22.save()
c2.add_year(y22)


from categories.models import TypeCategory
tc1 = TypeCategory(name='Sales', priority=1, active=True)