Purchase

class moco_wrapper.models.Purchase(moco)
create(purchase_date: datetime.date, currency: str, payment_method: moco_wrapper.models.purchase.PurchasePaymentMethod, items: list, due_date: datetime.date = None, service_period_from: datetime.date = None, service_period_to: datetime.date = None, company_id: int = None, receipt_identifier: str = None, info: str = None, iban: str = None, reference: str = None, custom_properties: dict = None, file: moco_wrapper.util.io.file.File = None, tags: list = None)

Create a new purchase.

Parameters:
  • purchase_date (datetime.date, str) – Date of the purchase
  • currency (str) – Currency
  • payment_method (PurchasePaymentMethod, str) – Method of payment that was used
  • items (List) – List of items that were purchased (minimum 1 item required)
  • due_date (datetime.date, str) – Date the purchase is due (default None)
  • service_period_from (datetime.date, str) – Service period start date (default None)
  • service_period_to (datetime.date, str) – Service period end date (default None)
  • company_id (int) – Id of the supplier company (default None)
  • receipt_identifier (str) – Receipt string (default None)
  • info (str) – Info text (default None)
  • iban (str) – Iban (default None)
  • reference (str) – Reference text (default None)
  • custom_properties (dict) – Custom Properties (default None)
  • file (moco_wrapper.util.io.File) – File attached to the purchase (default None)
  • tags (list) – List of tags (default None)
Returns:

The created purchase

Return type:

moco_wrapper.util.response.ObjectResponse

delete(purchase_id: int)

Deletes a purchase.

Parameters:purchase_id (int) – Id of the purchase to delete
Returns:Empty response on success
Return type:moco_wrapper.util.response.EmptyResponse

Warning

Deletion of a purchase is only possible if the state of the purchase is PurchaseStatus.PENDING and no payments have been registered to the purchase yet

static endpoints() → List[moco_wrapper.util.endpoint.endpoint.Endpoint]

Returns all endpoints associated with the model

Returns:List of Endpoint objects
Return type:moco_wrapper.util.endpoint.Endpoint
get(purchase_id: int)

Retrieve a single purchase.

Parameters:purchase_id (int) – The id of the purchase
Returns:A single purchase
Return type:moco_wrapper.util.response.ObjectResponse
getlist(purchase_id: int = None, category_id: int = None, term: str = None, company_id: int = None, status: moco_wrapper.models.purchase.PurchaseStatus = None, tags: list = None, start_date: datetime.date = None, end_date: datetime.date = None, unpaid: bool = None, payment_method: moco_wrapper.models.purchase.PurchasePaymentMethod = None, sort_by: str = None, sort_order: str = 'asc', page: int = 1)

Retrieve a list of purchases.

Parameters:
  • purchase_id (int) – Id of the purchase (default None)
  • category_id (int) – Id of the category the purchase belongs to (default None)
  • term (str) – Full text search (default None)
  • company_id (int) – Company id of the supplier (default None)
  • status (PurchaseStatus, str) – Status of the purchases
  • tags (list) – List of tags (default None)
  • start_date (datetime.date, str) – Start date filter (if start_date is supplied, end_date must also be supplied) (default None)
  • end_date (datetime.date, str) – End date filter (if end_date is supplied, start_date must also be supplied) (default None)
  • unpaid (bool) – Filter only purchases without a payment (default None)
  • payment_method (PurchasePaymentMethod, str) – Method that was used for payment (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 purchases

Return type:

moco_wrapper.util.response.PagedListResponse

store_document(purchase_id, file)

Stores the document for a purchase.

Parameters:
Returns:

Empty response on success

Return type:

moco_wrapper.util.response.EmptyResponse

update_status(purchase_id: int, status: moco_wrapper.models.purchase.PurchaseStatus)

Updates the state of a purchase.

Parameters:
  • purchase_id (int) – Id of the purchase to update
  • status (PurchaseStatus, str) – New status
Returns:

Empty response on success

Return type:

moco_wrapper.util.response.EmptyResponse

class moco_wrapper.models.purchase.PurchasePaymentMethod

Enumeration for the allowed values than can be supplied for the payment_method argument of Purchase.create().

Example usage:

from moco_wrapper.models.purchase import PurchasePaymentMethod
from moco_wrapper import Moco

m = Moco()
new_purchase = m.Purchase.create(
    ..
    payment_method = PurchasePaymentMethod.CASH
)
BANK_TRANSFER = 'bank_transfer'
CASH = 'cash'
CREDIT_CARD = 'credit_card'
DIRECT_DEBIT = 'direct_debit'
PAYPAL = 'paypal'
class moco_wrapper.models.purchase.PurchaseStatus

Enumeration for the allowed values that can be supplied for the status argument of Purchase.update_status().

Example usage:

from moco_wrapper.models.purchase import PurchaseStatus
from moco_wrapper import Moco

m = Moco()
m.Purchase.update_status(
    ..
    status = PurchaseStatus.APPROVED
)
APPROVED = 'approved'
PENDING = 'pending'