def post(self, request, *args, **kwargs): self.object = None req_post = request.POST.copy() for key in req_post: if ('valor' in key or 'valiq' in key): req_post[key] = req_post[key].replace('.', '') request.POST = req_post form = GrupoFiscalForm(request.POST) # Tributação normal if request.POST['regime_trib'] == '0': novo_icms_form = ICMSForm(request.POST, prefix='icms_form') # Simples nacional elif request.POST['regime_trib'] == '1': novo_icms_form = ICMSSNForm(request.POST, prefix='icmssn_form') icms_dest_form = ICMSUFDestForm(request.POST, prefix='icms_dest_form') ipi_form = IPIForm(request.POST, prefix='ipi_form') pis_form = PISForm(request.POST, prefix='pis_form') cofins_form = COFINSForm(request.POST, prefix='cofins_form') if (form.is_valid() and novo_icms_form.is_valid() and icms_dest_form.is_valid() and ipi_form.is_valid() and pis_form.is_valid() and cofins_form.is_valid()): self.object = form.save(commit=False) self.object.save() novo_icms_form.instance.grupo_fiscal = self.object novo_icms_form.save() icms_dest_form.instance.grupo_fiscal = self.object icms_dest_form.save() ipi_form.instance.grupo_fiscal = self.object ipi_form.save() pis_form.instance.grupo_fiscal = self.object pis_form.save() cofins_form.instance.grupo_fiscal = self.object cofins_form.save() return self.form_valid(form) icms_form = ICMSForm(request.POST, prefix='icms_form') icmssn_form = ICMSSNForm(request.POST, prefix='icmssn_form') return self.form_invalid(form=form, icms_form=icms_form, icmssn_form=icmssn_form, icms_dest_form=icms_dest_form, ipi_form=ipi_form, pis_form=pis_form, cofins_form=cofins_form)
def get(self, request, *args, **kwargs): self.object = None form = GrupoFiscalForm() # Dados iniciais da situação fiscal da MinhaEmpresa try: user_empresa = MinhaEmpresa.objects.get( m_usuario=Usuario.objects.get(user=request.user)).m_empresa if user_empresa.pessoa_jur_info.sit_fiscal in ('LR', 'LP'): form.initial = {'regime_trib': '0'} else: form.initial = {'regime_trib': '1'} except: pass icms_form = ICMSForm(prefix='icms_form') icmssn_form = ICMSSNForm(prefix='icmssn_form') icms_dest_form = ICMSUFDestForm(prefix='icms_dest_form') ipi_form = IPIForm(prefix='ipi_form') pis_form = PISForm(prefix='pis_form') cofins_form = COFINSForm(prefix='cofins_form') return self.render_to_response( self.get_context_data(form=form, icms_form=icms_form, icmssn_form=icmssn_form, icms_dest_form=icms_dest_form, ipi_form=ipi_form, pis_form=pis_form, cofins_form=cofins_form))
def get(self, request, *args, **kwargs): self.object = self.get_object() form_class = self.get_form_class() form = self.get_form(form_class) if self.object.regime_trib == '0': icms_form = ICMSForm(grupo_fiscal=self.object, prefix='icms_form') icmssn_form = ICMSSNForm(prefix='icmssn_form') elif self.object.regime_trib == '1': icms_form = ICMSForm(prefix='icms_form') icmssn_form = ICMSSNForm(grupo_fiscal=self.object, prefix='icmssn_form') if ICMSUFDest.objects.filter(grupo_fiscal=self.object).count(): icms_dest_form = ICMSUFDestForm(grupo_fiscal=self.object, prefix='icms_dest_form') else: icms_dest_form = ICMSUFDestForm(prefix='icms_dest_form') if IPI.objects.filter(grupo_fiscal=self.object).count(): ipi_form = IPIForm(grupo_fiscal=self.object, prefix='ipi_form') else: ipi_form = IPIForm(prefix='ipi_form') if ICMSUFDest.objects.filter(grupo_fiscal=self.object).count(): pis_form = PISForm(grupo_fiscal=self.object, prefix='pis_form') else: pis_form = PISForm(prefix='pis_form') if ICMSUFDest.objects.filter(grupo_fiscal=self.object).count(): cofins_form = COFINSForm(grupo_fiscal=self.object, prefix='cofins_form') else: cofins_form = COFINSForm(prefix='cofins_form') return self.render_to_response( self.get_context_data(form=form, icms_form=icms_form, icmssn_form=icmssn_form, icms_dest_form=icms_dest_form, ipi_form=ipi_form, pis_form=pis_form, cofins_form=cofins_form))
def post(self, request, *args, **kwargs): req_post = request.POST.copy() for key in req_post: if ('valor' in key or 'valiq' in key): req_post[key] = req_post[key].replace('.', '') request.POST = req_post self.object = self.get_object() form_class = self.get_form_class() form = form_class(request.POST, instance=self.object) if ICMSUFDest.objects.filter(grupo_fiscal=self.object).count(): icms_dest_form = ICMSUFDestForm(request.POST, prefix='icms_dest_form', grupo_fiscal=self.object) else: icms_dest_form = ICMSUFDestForm(request.POST, prefix='icms_dest_form') if IPI.objects.filter(grupo_fiscal=self.object).count(): ipi_form = IPIForm(request.POST, prefix='ipi_form', grupo_fiscal=self.object) else: ipi_form = IPIForm(request.POST, prefix='ipi_form') if ICMSUFDest.objects.filter(grupo_fiscal=self.object).count(): pis_form = PISForm(request.POST, prefix='pis_form', grupo_fiscal=self.object) else: pis_form = PISForm(request.POST, prefix='pis_form') if ICMSUFDest.objects.filter(grupo_fiscal=self.object).count(): cofins_form = COFINSForm(request.POST, prefix='cofins_form', grupo_fiscal=self.object) else: cofins_form = COFINSForm(request.POST, prefix='cofins_form') if form.is_valid(): self.object = form.save(commit=False) if self.object.regime_trib == '0': novo_icms_form = ICMSForm(request.POST, prefix='icms_form') elif self.object.regime_trib == '1': novo_icms_form = ICMSSNForm(request.POST, prefix='icmssn_form') if (novo_icms_form.is_valid() and icms_dest_form.is_valid() and ipi_form.is_valid() and pis_form.is_valid() and cofins_form.is_valid()): self.object = form.save(commit=False) self.object.save() # Mais facil deletar e recriar as entradas. ICMSSN.objects.filter(grupo_fiscal=self.object).delete() ICMS.objects.filter(grupo_fiscal=self.object).delete() novo_icms_form.instance.grupo_fiscal = self.object novo_icms_form.save() icms_dest_form.save() ipi_form.save() pis_form.save() cofins_form.save() return self.form_valid(form) icms_form = ICMSForm(request.POST, prefix='icms_form') icmssn_form = ICMSSNForm(request.POST, prefix='icmssn_form') return self.form_invalid(form=form, icms_form=icms_form, icmssn_form=icmssn_form, icms_dest_form=icms_dest_form, ipi_form=ipi_form, pis_form=pis_form, cofins_form=cofins_form)