def cancel(self, issuer): """ Cancel the :class:`~invoicing.models.Invoice` with the creation of an associated :class:`~invoicing.models.CreditNote` """ from invoicing.models import CreditNote, CreditNoteRevision if not self.is_cancelable(): raise NotCancelableInvoice("Invoice is not cancelable.") credit_note = CreditNote(full_init=False, tenant=self.tenant, account_type=self.account_type, issuer=issuer, organization=self.organization, contact=self.contact, related_to=self, group=self.group) cn_data = credit_note.add_revision(revision=CreditNoteRevision( based_on=self.current_revision)) cn_data.issuer = issuer cn_data.issue_date = datetime_now() cn_data.credit_note_emission_date = datetime.date.today() if self.is_down_payment_invoice(): # XXX should be removed in favor of translatable line items cn_data.line_items = [] credit_note.save() self.set_state(Invoice.STATES.CANCELLED) return credit_note
def cancel(self, issuer): """ Cancel the :class:`~invoicing.models.Invoice` with the creation of an associated :class:`~invoicing.models.CreditNote` """ from invoicing.models import CreditNote, CreditNoteRevision if not self.is_cancelable(): raise NotCancelableInvoice("Invoice is not cancelable.") credit_note = CreditNote( full_init=False, tenant=self.tenant, account_type=self.account_type, issuer=issuer, organization=self.organization, contact=self.contact, related_to=self, group=self.group ) cn_data = credit_note.add_revision(revision=CreditNoteRevision(based_on=self.current_revision)) cn_data.issuer = issuer cn_data.issue_date = datetime_now() cn_data.credit_note_emission_date = datetime.date.today() for item in cn_data.line_items: if not isinstance(item.reference, basestring): item.reference = unicode(item.reference) item.unit_price = -item.unit_price credit_note.save() self.set_state(Invoice.STATES.CANCELLED) return credit_note
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): # 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()