Invoicing

Embedded resources

InvoiceRevision

class invoicing.models.embedded.InvoiceRevision(*args, **kwargs)

An InvoiceRevision object is the state of the invoice at a specified time.

When an invoice is updated, a revision is automatically created.

duplicate(issuer=None)

Return the duplicate of the current revision with generated revision unique parameters.

get_customer_display(only_company=False)

Returns the customer’s name according to this scheme:

  • Organization (Contact), if either organization and contact are supplied
  • Organization, if only organization is supplied
  • Contact, if only contact is supplied
  • None, if neither organization nor contact are supplied
Parameters:only_company – forces to only display the company in the first case
class invoicing.api.resources.embedded.InvoiceRevisionResource(api_name=None)
hydrate(bundle)

Set issue data and issuer on POST, extracted from request

InvoiceItem

class invoicing.models.embedded.InvoiceItem(*args, **kwargs)

An InvoiceItem is an Item embedded in the InvoiceRevision items list.

It corresponds to the line of an invoice.

total_price

Return the total price for this item, considering the quantity.

class invoicing.api.resources.embedded.InvoiceItemResource(api_name=None)

InvoiceNote

class invoicing.models.embedded.InvoiceNote(*args, **kwargs)

A note associated to an InvoiceBase.

class invoicing.api.resources.embedded.InvoiceNoteResource(api_name=None)
full_hydrate(bundle)

Set issuer on POST, extracted from request

SnapshotCurrency

class invoicing.models.embedded.SnapshotCurrency(*args, **kwargs)

A time-freezed Currency

display_symbol

The display symbol associated to the currency (e.g. ‘€’, ‘$’, ‘£’).

The symbol attribute is in the iso4217 format (e.g. ‘EUR’, ‘USD’, ‘GBP’)

from_currency(currency_from, amount)

Convert a given amount from a source currency.

Parameters:
  • currency_from – iso4217 representation of the source currency
  • amount – int/float/decimal value to be converted
rate(symbol)

Get the rate applied to a specific currency

Parameters:symbol – iso4217 representation of the target currency
refresh_rates()

Refresh rates of the Currency object.

Must only be used on embedded :class:`~invoicing.models.Currency` objects

to_currency(currency_to, amount)

Convert a given amount to a targetted currency.

Parameters:
  • currency_to – iso4217 representation of the target currency
  • amount – int/float/decimal value to be converted
class invoicing.api.resources.embedded.SnapshotCurrencyResource(api_name=None)
hydrate(bundle)

If an id is present in serialized data (data comes from a Currency and not a SnapshotCurrency), the currency is fetch and exchange rates are updated based on their current rates.

ExchangeRate

class invoicing.models.embedded.ExchangeRate(*args, **kwargs)

Exchange rates are included in every Currency objects.

They represent the rate between two currencies at a specific time.

class invoicing.api.resources.embedded.ExchangeRateResource(api_name=None)

Main resources

InvoiceBase

class invoicing.models.InvoiceBase(full_init=True, *args, **kwargs)

Base class for all quotations and invoices (either payable or receivable).

add_revision(revision=None, *args, **kwargs)

Add a InvoiceRevision.

The InvoiceRevision can be created with defaults by passing arguments.

delete(*args, **kwargs)

Some InvoiceBase can only be deleted according to some rules.

duplicate_revision(issuer=None)

Duplicate a InvoiceRevision.

The default behavior to keep an history of all modifications on the Invoice.

filename

Return a filename based on invoice base type and reference

gen_pdf()

Process PDF generation based on InvoiceBaseReport

get_pdf(issuer=None, language=None)

Return the cached PDF or generate and cache it.

is_cancelable()

Determine if the InvoiceBase could be canceled. Always False in the base class.

is_created()

True if the Invoice is already saved (e.g. exists in the database).

is_credit_note()

Always False in the base class.

is_deletable()

Determine if the InvoiceBase could be deleted. Always False in the base class.

is_down_payment_invoice()

Always False in the base class.

is_invoice()

Always False in the base class.

is_invoice_instance()

Always False in the base class.

is_issuable()

Determine if the InvoiceBase could be sent. Always False in the base class.

is_modifiable()

Determine if the InvoiceBase could be modified. Always True in the base class.

is_quotation()

Always False in the base class.

is_quotation_instance()

Always False in the base class.

keywords

Genere a keywords list for the PDF headers.

manage_amounts()

Set total and amount of the Quotation/Invoice.

Includes InvoiceItem‘s unit prices and taxes.

classmethod post_client_changed_invoice_state(sender, document, previous_state, **kwargs)

Post client changed invoice state hook handler

  • Fire invoice registration signal
  • Add timeline and notification entries
classmethod post_delete(sender, document, **kwargs)

Post delete hook handler

  • Deletes related attachments, if exists
  • De-index invoice based document from elasticsearch
  • Removes timeline and notification entries
classmethod post_save(sender, document, created, **kwargs)

Post save hook handler

  • Removes related TTL
  • Index invoice based document in elasticsearch
  • Add timeline and notification entries
classmethod pre_save(sender, document, **kwargs)

Pre save hook handler On creation:

  • Add issuer to subscribers list
  • Add organization name to revision
  • Manage total / amount
reload(*args, **kwargs)

Reload the Invoice from the database.

Delete the existing cached attributes.

revision(revision_id=None, get_pos=False)

Returns the appropriate InvoiceRevision.

If there is no revision_id supplied, returns the lastest revision.

send_by_mail(subject, message, to=[], cc=[], bcc=[], issuer=None)

Send the InvoiceBase by e-mail.

set_state(new_state, force=False, issuer=None)

Set a new state to the Quotation/Invoice.

Parameters:
  • new_state – a state among the (CreditNote).STATES
  • force – do not check for possible states (for automatic state assignation)
  • issuer – a VosaeUser object to be associated to the state modification
sub_total

Do a sum of the InvoiceItem prices and cache it.

This does not contains taxes.

taxes_amounts

Do a sum of the InvoiceItem taxes and cache it.

This does not contains InvoiceItem unit prices.

class invoicing.api.resources.InvoiceBaseResource(api_name=None)
do_export(request, serializer, export_objects)

Export

full_hydrate(bundle)

InvoiceBase hydratation:

  • Handle current revision immutable state if InvoiceBase is not modifiable
  • Process some automatic affectation
  • Add history entry
generate_pdf(request, **kwargs)

Generate a PDF

hydrate(bundle)

If the InvoiceBase is modifiable, a new revision is added, otherwise the current_revision is cloned from the saved obj preventing data alteration but still allowing related updates such as attachments or notes.

mark_as_state(request, invoicebase_state, **kwargs)

Set state for an InvoiceBase.

obj_delete(bundle, **kwargs)

Raises a BadRequest if the InvoiceBase is not in a deletable state

prepend_urls()

Add urls for resources actions.

send_by_mail(request, **kwargs)

Send an InvoiceBase by mail.

Quotation

class invoicing.models.Quotation(full_init=True, *args, **kwargs)

Quotations specific class.

genere_reference(customer_settings)

Genere a unique reference for an Quotation object.

Use the VosaeCustomer quotations numbering counter.

get_possible_states()

List the available states for the Quotation, depending of its current state.

is_deletable()

A Quotation is deletable if not linked to any Invoice or DownPaymentInvoice.

is_issuable()

Determine if the Quotation could be sent.

is_modifiable()

A Quotation is modifiable unless it has been invoiced.

is_quotation()

True if the Quotation is a quotation object (and not an inherited).

is_quotation_instance()

True if the Quotation is an instance of Quotation.

make_down_payment(issuer, percentage, tax, date)

Creates a down payment invoice based on the current quotation

make_invoice(issuer)

Creates an invoice based on the current quotation

static manage_states()

An Invoice state can be modified by the time.

This method allows tasks scripts to update Invoices state on a regular basis.

classmethod post_make_down_payment_invoice(sender, document, new_document, **kwargs)

Post make down payment invoice hook handler

  • Add timeline and notification entries
  • Add a statistic entry
classmethod post_make_invoice(sender, document, new_document, **kwargs)

Post make invoice hook handler

  • Add timeline and notification entries
classmethod post_save(sender, document, created, **kwargs)

Post save hook handler

If created, increments the appropriate VosaeCustomer quotations numbering counter.

classmethod pre_save(sender, document, **kwargs)

Pre save hook handler

  • Set the type and reference
class invoicing.api.resources.QuotationResource(api_name=None)
make_down_payment_invoice(request, **kwargs)

Create a down payment invoice from a quotation

make_invoice(request, **kwargs)

Create an invoice from a quotation

prepend_urls()

Add urls for resources actions.

Invoice

class invoicing.models.Invoice(full_init=True, *args, **kwargs)

Invoices specific class.

cancel(issuer)

Cancel the Invoice with the creation of an associated CreditNote

down_payments

Property returning a list of down payment invoices (retrieved from related quotation)

filename

Return a filename based on invoice base type and reference

genere_reference(customer_settings)

Genere a unique reference for an Invoice object.

Use the VosaeCustomer invoices numbering counter.

get_possible_states()

List the available states for the Invoice, depending of its current state.

is_cancelable()

True if the Invoice is in a cancelable state. When cancelable, a credit note could be created.

is_deletable()

Determine if the Invoice could be deleted.

is_invoice()

True if the Invoice is an invoice (and not inherited).

is_invoice_instance()

True if the Invoice is an instance of Invoice.

is_issuable()

Determine if the Quotation could be sent.

is_modifiable()

True if the Invoice is still in a modifiable state.

is_paid()

True if the Invoice is paid.

is_payable()

True if the Invoice is in a payable state.

manage_amounts()

Set total and amount of the Invoice.

Includes InvoiceItem‘s unit prices and taxes.

Invoice checks for related down-payments and substracts their individual amounts to its amount.

static manage_states()

An Invoice state can be modified by the time.

This method allows tasks scripts to update Invoices state on a regular basis.

classmethod post_cancel_invoice(sender, document, credit_note, **kwargs)

Post cancel invoice hook handler

  • Update related quotation state, if invoice
  • Add timeline and notification entries
classmethod post_delete(sender, document, **kwargs)

Post delete hook handler

  • Update related quotation to remove linked invoices references
classmethod pre_save(sender, document, **kwargs)

Pre save hook handler

  • Manage payments and balance
  • Manage reference counters
class invoicing.api.resources.InvoiceResource(api_name=None)
invoice_cancel(request, **kwargs)

Cancel the invoice and returns the associated credit note.

prepend_urls()

Add urls for resources actions.

DownPaymentInvoice

class invoicing.models.DownPaymentInvoice(*args, **kwargs)

Base class for all down payments invoices (either payable or receivable).

is_down_payment_invoice()

True if the DownPaymentInvoice is a down-payment invoice.

is_modifiable()

A DownPaymentInvoice is automatically generated and can’t be modified at any time.

manage_amounts()

Set total and amount of the DownPaymentInvoice.

Includes InvoiceItem‘s unit prices and taxes.

DownPaymentInvoices don’t care about since it is fixed on creation. Only balance is calculated.

classmethod pre_save(sender, document, **kwargs)

Pre save hook handler

A DownPaymentInvoice must not save its item because of the translations.

class invoicing.api.resources.DownPaymentInvoiceResource(api_name=None)

CreditNote

class invoicing.models.CreditNote(*args, **kwargs)

Class for all credit notes (either payable or receivable).

genere_reference(customer_settings)

Genere a unique reference for an CreditNote object.

Use the VosaeCustomer credit notes numbering counter.

is_issuable()

Determine if the CreditNote could be sent. It is automatically generated and so could be sent at any time.

is_modifiable()

A CreditNote is automatically generated and can’t be modified at any time.

classmethod post_save(sender, document, created, **kwargs)

Post save hook handler

If created, increments the appropriate VosaeCustomer quotations numbering counter.

classmethod pre_save(sender, document, **kwargs)

Pre save hook handler

If credit note is in its creation process, affects the base type and the reference

set_total()

Set the total amount and adjusts it if the credit note is associated to an Invoice and if there is any down payment.

class invoicing.api.resources.CreditNoteResource(api_name=None)

Tax

class invoicing.models.Tax(*args, **values)

A tax is associated to Items and InvoiceItems.

save(*args, **kwargs)

The Tax rate should not be updated.

If needed, the tax must be removed and then re-added with the updated rate value.

class invoicing.api.resources.TaxResource(api_name=None)
hydrate_rate(bundle)

Rate is immutable, on PUT, ensures that rate is equal to the initial value

Item

class invoicing.models.Item(*args, **values)

An item represents an invoicable product or service.

classmethod post_delete(sender, document, **kwargs)

Post save hook handler

  • De-index item from elasticsearch
classmethod post_save(sender, document, created, **kwargs)

Post save hook handler

  • Index item in elasticsearch
class invoicing.api.resources.ItemResource(api_name=None)

Payment

class invoicing.models.Payment(*args, **values)

A payment, representing money flows within the company.

Amount can be negative (debit) or positive (credit).

classmethod post_delete(sender, document, **kwargs)

Post delete hook handler

Removes payment from related document

classmethod post_save(sender, document, created, **kwargs)

Post save hook handler

  • Associates payment to related document
  • Creates a payment statistic entry
classmethod pre_save(sender, document, **kwargs)

Pre save hook handler

Validates payment amount

class invoicing.api.resources.PaymentResource(api_name=None)
full_hydrate(bundle)

Set issuer on POST, extracted from request

Currency

class invoicing.models.Currency(*args, **values)

Currencies are globals: they do not belongs to VosaeCustomers.

static convert(currency_from, currency_to, amount)

Convert a Currency to another. Based on the current rates.

display_symbol

The display symbol associated to the currency (e.g. ‘€’, ‘$’, ‘£’).

The symbol attribute is in the iso4217 format (e.g. ‘EUR’, ‘USD’, ‘GBP’)

from_currency(currency_from, amount)

Convert a Currency to another. Based on the current rates.

Parameters:
  • currency_from – iso4217 representation of the source currency
  • amount – int/float/decimal value to be converted
get_snapshot()

Return the snapshot associated to the currency.

rate(symbol)

Return the rate associated to the specified symbol.

Parameters:symbol – iso4217 representation of the target currency
static refresh_currencies()

A Currency contains rates which should be updated.

This method allows tasks scripts to update currencies rates on a regular basis.

to_currency(currency_to, amount)

Convert a Currency to another. Based on the current rates.

Parameters:
  • currency_to – iso4217 representation of the target currency
  • amount – int/float/decimal value to be converted
class invoicing.api.resources.CurrencyResource(api_name=None)