|
| 1 | +# Python Manager API |
| 2 | + |
| 3 | +This is a Python module to access the API provided by Manager accounting |
| 4 | +software. |
| 5 | + |
| 6 | +## WARNING |
| 7 | + |
| 8 | +Use at your own risk! Always test API usage on a test business first! |
| 9 | +Not responsible for any data loss or other problems (see license). |
| 10 | + |
| 11 | +## Description |
| 12 | + |
| 13 | +There is no official API documentation, but the API is meant to be self |
| 14 | +documenting by browsing `/api` on a Manager server. |
| 15 | + |
| 16 | +This module design is meant to automate much of the work, eliminate the |
| 17 | +need to worry about GUID, and perform basic type checking and validation. |
| 18 | + |
| 19 | +## Installation |
| 20 | + |
| 21 | +`pip install manager_api` |
| 22 | + |
| 23 | +## Configuration |
| 24 | + |
| 25 | +To open a business, you need the server URL, username, password, and the |
| 26 | +business name. It is recommended to create a separate user with suitable |
| 27 | +permissions for the API access. |
| 28 | + |
| 29 | +If using the local (personal) edition, first use the trial copy of the |
| 30 | +server edition to create a user, then use http://localhost:55667 as the |
| 31 | +server URL. |
| 32 | + |
| 33 | +## Example Usage |
| 34 | + |
| 35 | +``` |
| 36 | +#!/usr/bin/env python3 |
| 37 | +# -*- coding: utf-8 -*- |
| 38 | +
|
| 39 | +from manager_api import Business |
| 40 | +
|
| 41 | +
|
| 42 | +# Open the business. NOTE: Always use a test business first! |
| 43 | +business = Business("http://localhost:55667", "apiuser", "password", "Test Business") |
| 44 | +
|
| 45 | +# Retrieve the 10 most recent payments and display source account, payee, and total amount. |
| 46 | +payments = business.Payment.list()[:10] |
| 47 | +for p in payments: |
| 48 | + p.read() |
| 49 | + p.PaidFrom.read() |
| 50 | + if p.Payee == "Customer": |
| 51 | + p.Customer.read() |
| 52 | + p_to = p.Customer.Name |
| 53 | + elif p.Payee == "Supplier": |
| 54 | + p.Supplier.read() |
| 55 | + p_to = p.Supplier.Name |
| 56 | + else: |
| 57 | + p_to = p.Contact |
| 58 | + p_amt = sum([l.Amount for l in p.Lines]) |
| 59 | + print(f"{p.Key} : {p_amt} : {p.PaidFrom.Name} -> {p_to}") |
| 60 | +
|
| 61 | +# Create a copy of the first payment with a line item doubled. |
| 62 | +print("Creating new payment") |
| 63 | +p = payments[0] |
| 64 | +p.Key = None |
| 65 | +p.Lines[0].Amount *= 2 |
| 66 | +p.Reference = "Test" |
| 67 | +p.create() |
| 68 | +p_amt = sum([l.Amount for l in p.Lines]) |
| 69 | +print(f"{p.Key} : {p_amt} : {p.PaidFrom.Name} -> {p_to}") |
| 70 | +
|
| 71 | +print("Updating the payment") |
| 72 | +p.Reference = "Updated" |
| 73 | +p.update() |
| 74 | +
|
| 75 | +print("Deleting the payment") |
| 76 | +p.delete() |
| 77 | +``` |
0 commit comments