Invoice

class moco_wrapper.models.Invoice(moco)

Model for handling invoices.

create(customer_id: int, recipient_address: str, created_date: datetime.date, due_date: datetime.date, service_period_from: datetime.date, service_period_to: datetime.date, title: str, tax: float, currency: str, items: list, status: moco_wrapper.models.invoice.InvoiceStatus = <InvoiceStatus.CREATED: 'created'>, change_address: moco_wrapper.models.invoice.InvoiceChangeAddress = <InvoiceChangeAddress.INVOICE: 'invoice'>, salutation: str = None, footer: str = None, discount: float = None, cash_discount: float = None, cash_discount_days: int = None, project_id: int = None, tags: list = [])

Creates a new invoice.

Parameters:
  • customer_id (int) – Id of the customer/company
  • recipient_address (str) – Customers address
  • created_date (datetime.date, str) – Creation date of the invoice
  • due_date (datetime.date, str) – Date the invoice is due
  • service_period_from (datetime.date, str) – Service period start date
  • service_period_to (datetime.date, str) – Service period end date
  • title (str) – Title of the invoice
  • tax (float) – Tax percent (between 0.0 and 100.0)
  • currency (str) – Currency code (e.g. EUR)
  • items (list) – Invoice items
  • status (InvoiceStatus, str) – State of the invoice (default InvoiceStatus.CREATED)
  • change_address (InvoiceChangeAddress, str) – Address propagation (default InvoiceChangeAddress.INVOICE)
  • salutation (str) – Salutation text (default None)
  • footer (str) – Footer text (default None)
  • discount (float) – Discount in percent (between 0.0 and 100.0) (default None)
  • cash_discount (float) – Cash discount in percent (between 0.0 and 100.0) (default None)
  • cash_discount_days (float) – How many days is the cash discount valid (ex. 4) (default None)
  • project_id (int) – Id of the project the invoice belongs to (default None)
  • tags (list) – List of tags (default [])
Returns:

The created invoice

Return type:

moco_wrapper.util.response.JsonResponse

Note

Note that if you create an invoice with a project, that project must also belong to the customer the invoice was created for.

get(invoice_id: int)

Retrieve a single invoice.

Parameters:invoice_id (int) – Invoice id
Returns:Single invoice object
Return type:moco_wrapper.util.response.JsonResponse
getlist(status: moco_wrapper.models.invoice.InvoiceStatus = None, date_from: datetime.date = None, date_to: datetime.date = None, tags: list = None, identifier: str = None, term: str = None, sort_by: str = None, sort_order: str = 'asc', page: int = 1)

Retrieve a list of invoices.

Parameters:
  • status (InvoiceStatus, str) – State of the invoice (default None)
  • date_from (datetime.date, str) – Starting date (default None)
  • date_to (datetime.date, str) – End date (default None)
  • tags (list) – List of tags (default None)
  • identifier (str) – Identifier string (e.g. R1903-003) (default None)
  • term (str) – Wildcard search term (default None)
  • sort_by (str) – Field to sort results by (default None)
  • sort_order (str) – asc or desc (default "asc")
  • page (int) – Page number (default 1)
Returns:

List of invoice objects

Return type:

moco_wrapper.util.response.ListingResponse

locked(status: moco_wrapper.models.invoice.InvoiceStatus = None, date_from: datetime.date = None, date_to: datetime.date = None, identifier: str = None, sort_by: str = None, sort_order: str = 'asc', page: int = 1)

Retrieve a list of locked invoices.

Parameters:
  • status (InvoiceStatus, str) – State of the invoice (default None)
  • date_from (datetime.date, str) – Start date (default None)
  • date_to (datetime.date, str) – End date (default None)
  • identifier (str) – Identifier string (ex. R1903-003) (default None)
  • sort_by (str) – Field to sort results by (default None)
  • sort_order (str) – asc or desc (default "asc")
  • page (int) – Page number (default 1)
Returns:

List of invoice objects

Return type:

moco_wrapper.util.response.ListingResponse

pdf(invoice_id: int)

Retrieve the invoice document as pdf.

Parameters:invoice_id (int) – Invoice id
Returns:Invoice pdf
Return type:moco_wrapper.util.response.FileResponse
send_emaiL(invoice_id: int, emails_to: str, subject: str, text: str, emails_cc: str = None, emails_bcc: str = None)

Send an invoice by mail

Parameters:
  • invoice_id (int) – Id of the invoice to send
  • emails_to (str, list) – Target email adress (or a list of mutiple email adresses)
  • subject (str) – Email subject
  • text (str) – Email text
  • emails_cc (str, list) – Email address for cc (or a list of mutiple email adresses) (default None)
  • emails_bcc (str, list) – Email address for bcc (or a list of mutiple email adresses) (default None)

Note

If you want to send an email to the default recipient configured in the project or customer, set emails_to and emails_cc To None.

timesheet(invoice_id: int)

Retrieve the invoice timesheet document as pdf.

Note

Invoices that have timesheets cannot be created over the api and must be created manually by billing unbilled tasks.

Parameters:invoice_id (int) – Invoice id
Returns:Invoice timesheet as pdf
Return type:moco_wrapper.util.response.FileResponse
update_status(invoice_id: int, status: moco_wrapper.models.invoice.InvoiceStatus)

Updates the state of an invoices.

Parameters:
  • invoice_id (int) – Invoice id
  • status (InvoiceStatus, str) – New state of the invoice
Returns:

Empty response on success

Return type:

moco_wrapper.util.response.EmptyResponse

class moco_wrapper.models.invoice.InvoiceStatus

Enumeration for allowed values that can be supplied for the status argument of Invoice.getlist(), Invoice.update_status() and Invoice.create().

Example usage:

from moco_wrapper.models.invoice import InvoiceStatus
from moco_wrapper import Moco

m = Moco()
new_invoice = m.Invoice.create(
    ..
    status = InvoiceStatus.DRAFT
)
CREATED = 'created'
DRAFT = 'draft'
IGNORED = 'ignored'

Warning

Do not use IGNORED for creating invoices, only updating and filtering.

OVERDUE = 'overdue'
PAID = 'paid'
PARTIALLY_PAID = 'partially_paid'
SENT = 'sent'
class moco_wrapper.models.invoice.InvoiceChangeAddress

Enumeration for allowed values that can be supplied for change_address argument of Invoice.create().

from moco_wrapper.models.invoice import InvoiceChangeAddress
from moco_wrapper import Moco

m = Moco()
new_invoice = m.Invoice.create(
    ..
    change_address = InvoiceChangeAddress.PROJECT
)
CUSTOMER = 'customer'
INVOICE = 'invoice'
PROJECT = 'project'