Beispiel #1
0
    def make_invoice(self, issuer):
        """Creates an invoice based on the current quotation/purchase order"""
        from invoicing.models import Invoice, InvoiceRevision
        # Initialize the invoice
        invoice = Invoice(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,
                          attachments=self.attachments)

        # Save the invoice, based on the quotation/purchase order
        inv_data = invoice.add_revision(revision=InvoiceRevision(
            based_on=self.current_revision))
        inv_data.state = invoice.state
        inv_data.issuer = issuer
        inv_data.issue_date = datetime_now()
        inv_data.invoicing_date = datetime.date.today()
        inv_data.due_date = get_due_date(
            inv_data.invoicing_date,
            self.tenant.tenant_settings.invoicing.payment_conditions)
        invoice.save()

        # Update state
        if self.is_quotation():
            self.state = QUOTATION_STATES.INVOICED
        elif self.is_purchase_order():
            self.state = PURCHASE_ORDER_STATES.INVOICED
        self.save()
        return invoice
Beispiel #2
0
 def make_invoice(self, issuer):
     """Creates an invoice based on the current quotation/purchase order"""
     from invoicing.models import Invoice, InvoiceRevision
     # Initialize the invoice
     invoice = Invoice(
         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,
         attachments=self.attachments
     )
     
     # Save the invoice, based on the quotation/purchase order
     inv_data = invoice.add_revision(revision=InvoiceRevision(based_on=self.current_revision))
     inv_data.state = invoice.state
     inv_data.issuer = issuer
     inv_data.issue_date = datetime_now()
     inv_data.invoicing_date = datetime.date.today()
     inv_data.due_date = get_due_date(inv_data.invoicing_date, self.tenant.tenant_settings.invoicing.payment_conditions)
     invoice.save()
     
     # Update state
     if self.is_quotation():
         self.state = QUOTATION_STATES.INVOICED
     elif self.is_purchase_order():
         self.state = PURCHASE_ORDER_STATES.INVOICED
     self.save()
     return invoice