def get_exportable_documents(export): documents = [] if 'QUOTATION' in export.documents_types: full_export = Quotation.full_export(export.tenant, export.from_date, export.to_date) documents.append(full_export) serializer = QuotationCSVSerializer() documents.append(( [serializer.serialize(full_export[0])], lambda buf: '{0}/{1}.csv'.format(_('Quotations'), _('Quotations')), lambda buf: buf )) if 'INVOICE' in export.documents_types: full_export = Invoice.full_export(export.tenant, export.from_date, export.to_date) documents.append(full_export) serializer = InvoiceCSVSerializer() documents.append(( [serializer.serialize(full_export[0])], lambda buf: '{0}/{1}.csv'.format(_('Invoices'), _('Invoices')), lambda buf: buf )) if 'CREDIT_NOTE' in export.documents_types: full_export = CreditNote.full_export(export.tenant, export.from_date, export.to_date) documents.append(full_export) serializer = CreditNoteCSVSerializer() documents.append(( [serializer.serialize(full_export[0])], lambda buf: '{0}/{1}.csv'.format(_('Credit notes'), _('Credit notes')), lambda buf: buf )) return documents
def forwards(self, orm): from invoicing.models import InvoiceBaseGroup # Process quotations for quotation in Quotation.objects(): group = InvoiceBaseGroup(tenant=quotation.tenant, quotation=quotation).save() if quotation._data.get('down_payments'): group.down_payment_invoices = dereference(quotation._data.get('down_payments'), DownPaymentInvoice) for down_payment_invoice in group.down_payment_invoices: down_payment_invoice.update(set__group=group) if quotation._data.get('related_invoice'): group.invoice = dereference(quotation._data.get('related_invoice'), Invoice) group.invoice.update(set__group=group) if quotation._data.get('related_invoices_cancelled'): group.invoices_cancelled = dereference(quotation._data.get('related_invoices_cancelled'), Invoice) for invoice_cancelled in group.invoices_cancelled: invoice_cancelled.update(set__group=group) group.save() quotation.update(set__group=group) # Process invoices and down-payment invoices for invoice in Invoice.objects(): if not invoice.group.id: # Can only be an invoice: down-payment invoices are linked to quotations, so group is set group = InvoiceBaseGroup(tenant=quotation.tenant, invoice=invoice).save() invoice.update(set__group=group) else: group = invoice.group if invoice._data.get('related_credit_note'): group.credit_notes = [dereference(invoice._data.get('related_credit_note'), CreditNote)] for credit_note in group.credit_notes: credit_note.update(set__group=group, set__related_to=invoice) group.save()
def forwards(self, orm): # Quotation for quotation in Quotation.objects(): quotation._changed_fields = [ 'tenant', 'issuer', 'organization', 'contact', 'attachments', 'related_invoice', 'down_payments', 'subscribers' ] set_embedded_changed_fields(quotation) quotation.save() # Invoice for invoice in Invoice.objects(): invoice._changed_fields = [ 'tenant', 'issuer', 'organization', 'contact', 'attachments', 'related_quotation', 'payments', 'subscribers' ] set_embedded_changed_fields(invoice) invoice.save() # DownPaymentInvoice for down_payment_invoice in DownPaymentInvoice.objects(): down_payment_invoice._changed_fields = [ 'tenant', 'issuer', 'organization', 'contact', 'attachments', 'related_quotation', 'payments', 'tax_applied', 'subscribers' ] set_embedded_changed_fields(down_payment_invoice) down_payment_invoice.save() # CreditNote for credit_note in CreditNote.objects(): credit_note._changed_fields = [ 'tenant', 'issuer', 'organization', 'contact', 'attachments', 'related_invoice', 'subscribers' ] set_embedded_changed_fields(credit_note) credit_note.save() # Item for item in Item.objects(): item._changed_fields = ['tenant', 'currency', 'tax'] item.save() # Payment for payment in Payment.objects(): payment._changed_fields = ['tenant', 'issuer', 'currency'] payment.save() # Tax for tax in Tax.objects(): tax._changed_fields = ['tenant'] tax.save()
def forwards(self, orm): # Quotation for quotation in Quotation.objects(): quotation._changed_fields = ['tenant', 'issuer', 'organization', 'contact', 'attachments', 'related_invoice', 'down_payments', 'subscribers'] set_embedded_changed_fields(quotation) quotation.save() # Invoice for invoice in Invoice.objects(): invoice._changed_fields = ['tenant', 'issuer', 'organization', 'contact', 'attachments', 'related_quotation', 'payments', 'subscribers'] set_embedded_changed_fields(invoice) invoice.save() # DownPaymentInvoice for down_payment_invoice in DownPaymentInvoice.objects(): down_payment_invoice._changed_fields = ['tenant', 'issuer', 'organization', 'contact', 'attachments', 'related_quotation', 'payments', 'tax_applied', 'subscribers'] set_embedded_changed_fields(down_payment_invoice) down_payment_invoice.save() # CreditNote for credit_note in CreditNote.objects(): credit_note._changed_fields = ['tenant', 'issuer', 'organization', 'contact', 'attachments', 'related_invoice', 'subscribers'] set_embedded_changed_fields(credit_note) credit_note.save() # Item for item in Item.objects(): item._changed_fields = ['tenant', 'currency', 'tax'] item.save() # Payment for payment in Payment.objects(): payment._changed_fields = ['tenant', 'issuer', 'currency'] payment.save() # Tax for tax in Tax.objects(): tax._changed_fields = ['tenant'] tax.save()
def update_invoices_states(): from invoicing.models import Quotation, Invoice Quotation.manage_states() Invoice.manage_states()