def get(self, request, *args, **kwargs): context = self.get_context_data(**kwargs) context['txs_formset'] = TransactionModelFormSet( user_model=self.request.user, je_pk=kwargs['je_pk'], ledger_pk=kwargs['ledger_pk'], entity_slug=kwargs['entity_slug'], queryset=self.get_queryset()) return self.render_to_response(context)
def get_context_data(self, txs_formset=None, **kwargs): context = super(TXSJournalEntryView, self).get_context_data(**kwargs) if not txs_formset: context['txs_formset'] = TransactionModelFormSet( user_model=self.request.user, je_pk=kwargs['je_pk'], ledger_pk=kwargs['ledger_pk'], entity_slug=kwargs['entity_slug'], queryset=self.get_queryset()) else: context['txs_formset'] = txs_formset return context
def post(self, request, **kwargs): txs_formset = TransactionModelFormSet( request.POST, user_model=self.request.user, ledger_pk=kwargs['ledger_pk'], entity_slug=kwargs['entity_slug'], je_pk=kwargs['je_pk']) je_qs = JournalEntryModel.on_coa.for_entity( entity_slug=self.kwargs['entity_slug'], user_model=self.request.user) je_model: JournalEntryModel = get_object_or_404( je_qs, uuid=self.kwargs['je_pk']) if je_model.locked: messages.add_message( self.request, message=_('Cannot update a Locked Journal Entry.'), level=messages.ERROR, extra_tags='is-danger') return self.render_to_response(context=self.get_context_data( txs_formset=txs_formset)) context = self.get_context_data() if txs_formset.is_valid(): txs_formset.save() context['txs_formset'] = txs_formset messages.add_message(request, messages.SUCCESS, 'Successfully saved transactions.', extra_tags='is-success') else: context['txs_formset'] = txs_formset messages.add_message( request, messages.ERROR, 'Hmmm, this doesn\'t add up!. Check your math!', extra_tags='is-danger') return self.render_to_response(context)
def post(self, request, **kwargs): context = self.get_context_data(**kwargs) txs_formset = TransactionModelFormSet( request.POST, user_model=self.request.user, ledger_pk=kwargs['ledger_pk'], entity_slug=kwargs['entity_slug'], je_pk=kwargs['je_pk']) if txs_formset.is_valid(): txs_formset.save() context['txs_formset'] = txs_formset messages.add_message(request, messages.SUCCESS, 'Successfully saved transactions.', extra_tags='is-success') else: context['txs_formset'] = txs_formset messages.add_message( request, messages.ERROR, 'Hmmm, this doesn\'t add up!. Check your math!', extra_tags='is-danger') return self.render_to_response(context)