def achats(request): enterprise_of_current_user = Employee.get_enterprise_of_current_user( request.user) q = Achat.objects.filter(product_owner=enterprise_of_current_user) table = None total = 0 if q.exists(): table = AchatTable(q) total = sum_amounts(q, 'XAF') else: table = AchatTable([]) RequestConfig(request).configure(table) return render(request, 'finance/achats.html', { 'table': table, 'total': total, })
def ventes(request): """If the enterprise of the user has no data it returns an empty list.""" enterprise_of_current_user = Employee.get_enterprise_of_current_user( request.user) q = Vente.objects.filter(product_owner=enterprise_of_current_user) table = None total = 0 if q.exists(): table = VenteTable(q) total = sum_amounts(q, 'XAF') else: table = VenteTable([]) RequestConfig(request).configure(table) return render(request, 'finance/ventes.html', { 'table': table, 'total': total, })
def labels_tex(request, article_type): enterprise_of_current_user = Employee.get_enterprise_of_current_user( request.user) if article_type == 'Clothes': articles = Clothes.objects.filter( product_owner=enterprise_of_current_user) elif article_type == 'Shoes': articles = Shoe.objects.filter( product_owner=enterprise_of_current_user) elif article_type == 'Accessories': articles = Accessory.objects.filter( product_owner=enterprise_of_current_user) else: return HttpResponse("article_type %s inconnu." % article_type) total_articles = len(articles) template = get_template('labels/labels.tex') latex_source = template.render({ 'articles': articles, 'total_articles': total_articles }).encode('utf-8') return make_pdf(latex_source)
def get_context_data(self, **kwargs): context = super(ArticleFilteredView, self).get_context_data(**kwargs) enterprise_of_current_user = Employee.get_enterprise_of_current_user( self.request.user) context['enterprise'] = enterprise_of_current_user return context
def test_func(self): return Employee.is_current_user_employee(self.request.user)
def qs(self): parent = super(ArticleFilter, self).qs enterprise_of_current_user = Employee.get_enterprise_of_current_user( self.request.user) return parent.filter(product_owner=enterprise_of_current_user)
def form_valid(self, form): enterprise_of_current_user = Employee.get_enterprise_of_current_user( self.request.user) form.generate_inventory(enterprise_of_current_user) return super(InventoryCreationView, self).form_valid(form)
def get_queryset(self): enterprise_of_current_user = Employee.get_enterprise_of_current_user( self.request.user) return InventoryClothes.objects.filter( article__product_owner=enterprise_of_current_user)
def get_queryset(self): enterprise = Employee.get_enterprise_of_current_user(self.request.user) return FraisArrivage.objects.filter( arrivage_ref__enterprise=enterprise)
def arrivages(request): if request is None: return Arrivage.objects.none() enterprise = Employee.get_enterprise_of_current_user(request.user) return Arrivage.objects.filter(enterprise=enterprise)
def get_initial(self): initial = super(ArrivageCreationView, self).get_initial() initial['devise'] = Currency.objects.first() enterprise = Employee.get_enterprise_of_current_user(self.request.user) initial['enterprise'] = enterprise.pk return initial
def get_context_data(self, **kwargs): """To calculate the total of frais and achats.""" context = super(ArrivageListView, self).get_context_data(**kwargs) arrivages = self.get_queryset() total_frais = 0 total_frais_all_inventories = 0 total_achats = 0 total_achats_all_inventories = 0 try: target_currency = Currency.objects.filter(default=True)[0] logger.debug('target_currency: %s' % target_currency) logger.debug('target') except: logger.fatal('target_currency not set') raise Exception("Please set a default currency using admin.") context['target_currency'] = target_currency for a in arrivages: total_achats += a.get_total_achats() total_achats_all_inventories += total_achats total_frais += a.get_total_frais() total_frais_all_inventories += total_frais logger.debug('total_achats__all_inventories: %s' % total_achats_all_inventories) context['total_achats'] = total_achats context['total_frais'] = total_frais context['target_currency'] = target_currency context['total_frais_all_inventories'] = total_frais_all_inventories logger.debug('total_frais_all_inventories: %s' % total_frais_all_inventories) context['total_achats_all_inventories'] = total_achats_all_inventories cout_de_revient = total_achats_all_inventories + total_frais_all_inventories context['total_cout_revient'] = cout_de_revient enterprise_of_current_user = Employee.get_enterprise_of_current_user(self.request.user) q = Vente.objects.filter(product_owner=enterprise_of_current_user) montant_ventes = 0 if q.exists(): logger.debug('Il existe des ventes') e_sum = q.aggregate(Sum('montant')) e_sum = e_sum['montant__sum'] logger.debug('total des montants des ventes: %s' % e_sum) if e_sum: montant_ventes = e_sum else: logger.debug("Le montant des ventes est zéro. (liquidation, cadeaux)") context['total_ventes'] = montant_ventes else: logger.debug("Il n'existe pas encore de ventes.") if total_frais_all_inventories and total_achats_all_inventories: logger.debug('total frais ET total achats') solde = montant_ventes - (total_frais_all_inventories + total_achats_all_inventories) logger.debug('Le solde: %s' % solde) context['solde'] = solde taux_de_marge = (solde / (total_frais_all_inventories + total_achats_all_inventories))* 100 context['taux_de_marge'] = taux_de_marge elif total_frais_all_inventories: logger.debug('total frais uniquement') solde = montant_ventes - total_frais_all_inventories logger.debug('Le solde: %s' % solde) context['solde'] = solde else: logger.debug('total achats uniquement') solde = montant_ventes - total_achats_all_inventories logger.debug('Le solde: %s' % solde) context['solde'] = solde return context