visma-administration


Namevisma-administration JSON
Version 0.7.0 PyPI version JSON
download
home_pagehttps://github.com/viktor2097/visma-administration
SummaryAPI for Visma Administration 200/500/1000/2000
upload_time2024-01-22 18:50:02
maintainer
docs_urlNone
authorViktor Johansson
requires_python
licenseMIT
keywords visma visma administration
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            
[![PyPI version](https://badge.fury.io/py/visma-administration.svg)](https://badge.fury.io/py/visma-administration)
![PyPI - Downloads](https://img.shields.io/pypi/dm/visma-administration)
![GitHub](https://img.shields.io/github/license/viktor2097/visma-administration)
# *Python Visma Administration*  
API for Visma Administration 200/500/1000/2000. 

Visma has added support for a 64-bit API in version 2023.1. Therefore, this package aims to be compatible with both 32-bit and 64-bit versions to maintain backward compatibility. The AdkNet4Wrapper is loaded on 32-bit Python installations, and AdkNet6Wrapper is loaded on 64-bit Python installations.

Writing integrations for Visma's API often involves extensive boilerplate code. This package aims to present the API with a user-friendly, Pythonic interface, and make it more accessible. It's not feature complete, but it covers most basic needs, and you can tap into the underlying C# API if needed.
# Installation
```
pip install visma-administration  
```  

## Usage
### Add companies that you would like to access data from
```py
from visma_administration import Visma
Visma.add_company(name="FTG10", common_path="Z:\\Gemensamma filer", company_path="Z:\\Företag\\FTG10")

# You can then access specific companies with a context manager
with Visma.get_company_api("FTG10") as api:
	pass
```

## CRUD Operations
**Read a single record**
```py
with Visma.get_company_api("FTG10") as api:
    record = api.supplier_invoice_head.get(adk_sup_inv_head_invoice_number="number")
    print(record.adk_sup_inv_head_invoice_number)
```
**Update a record**
```py
with Visma.get_company_api("FTG10") as api:
    record = api.supplier_invoice_head.get(adk_sup_inv_head_invoice_number="number")
    record.adk_sup_inv_head_invoice_date = datetime.now()
    record.adk_sup_inv_head_vat_amount = 5000
    record.adk_sup_inv_head_paymstop = True
    record.adk_sup_inv_head_supplier_name = "Name"
    record.save()
```

**Create a record**
```py
with Visma.get_company_api("FTG10") as api:
    new_record = api.supplier.new() # new method is called
    new_record.adk_supplier_name = "Nvidia"
    new_record.save()
```

**Delete a record**
```py
with Visma.get_company_api("FTG10") as api:
    john = api.supplier.get(adk_supplier_name="John")
    john.delete()
```

**Get multiple records**
```py
with Visma.get_company_api("FTG10") as api:
	invoices = api.supplier_invoice_head.filter(adk_sup_inv_head_invoice_number="f03*")
	total_sum = sum(invoice.adk_sup_inv_head_total for invoice in invoices)
	print(f"Total for all invoices with invoice_number starting as 'f03' is: {total_sum}")

	# filter returns a generator, so you can limit how many items to return
	import itertools  
	suppliers = api.supplier.filter(adk_supplier_name="*N*")  
	suppliers = itertools.islice(suppliers, 5)  
	for supplier in suppliers:  
		print(supplier.adk_supplier_name)  
```
**Working with rows**
 Existing rows can be accessed with: **.rows()** and creating new ones by calling **.create_rows()**
```py
with Visma.get_company_api("FTG10") as api:
	# lets create a new invoice and add rows
	invoice = api.supplier_invoice_head.new()
	invoice.adk_sup_inv_head_invoice_number = "50294785"
	
	# Creates 3 row objects
	rows = invoice.create_rows(quantity=3)
	rows[0].adk_ooi_row_account_number = "5010"
	rows[1].adk_ooi_row_account_number = "4050"
	rows[2].adk_ooi_row_account_number = "3020"
	invoice.save()
	# We now have a new invoice with 3 rows.

	# Here we can access existing rows
	for row in invoice.rows():
		print(row.adk_ooi_row_account_number)
	
	# Delete last row
	# If you would like to delete more than one row,
	# Check the Deleting multiple rows section of the README
	invoice.rows()[-1].delete()
	
	
	
```

### Deleting multiple rows
After **.delete()** is called on a row, Visma automatically reassigns new indexes to every row, therefore according to their documentation, you have to request all rows again to continue working with them.
```py
# If you would like to delete all custom rows, use the code snippet below.
# You have to start deleting them by negative index, since templates
# will automatically readd rows depending on your configurations
nrows = invoice.adk_sup_inv_head_nrows  
for i in range(int(nrows)):  
  invoice.rows()[-1].delete()
```

# Other info
In Visma's documentation you can find a list of DB_fields that you may access through their API.  
For instance  
```  
ADK_DB_PROJECT  
ADK_DB_ACCOUNT  
ADK_DB_SUPPLIER 
```  
  
You can access these fields directly from your instantiated Visma API object,   
ADK_DB_ is removed and the name is lowercased.  
  
For example:  
      
```py  
with visma.get_company_api("company") as api:
    api.supplier  
    api.account  
    api.project  
```  
  
These DB_Field attributes returns an object from which you can request data  
  
```py  
api.supplier.get()  # returns a single object or returns an error  
api.supplier.filter()  # returns multiple objects  
api.supplier.new()  # Gives you a new record  
```

Both `get` and `filter` accepts filtering on a field as argument.
You pass the field name which you want to filter upon, and a valid filter expression ( Visma have documentation for this.
You can filter on multiple fields by just passing multiple filter expressions

```py
"""
This filters on the ADK_SUPPLIER_NAME field of ADK_DB_SUPPLIER
*text* is a valid filter expression which returns a result with inc anywhere inside of the name
Refer to Visma documentation for further information on how to form different types of filter expressions.
"""
result = api.supplier.get(adk_supplier_name="*inc*")
```

Consider whatever `get`, `filter` and `new` returns to be database record(s).
These records have fields associated with them, if you check documentation for ADK_DB_SUPPLIER, you can find a whole bunch of fields associated with it.
```
ADK_SUPPLIER_FIRST
ADK_SUPPLIER_NUMBER
ADK_SUPPLIER_NAME
ADK_SUPPLIER_SHORT_NAME
... And a lot more
```
These fields are mainly used in two ways,
```py
test = api.supplier.get(adk_supplier_name="test")  # Used when filtering
test.adk_supplier_name = "test1"  # Or used when interacting with a supplier record
```
 
  
## Additional information
  
[Documentation for the api can be found here](https://vismaspcs.se/support/utvecklarpaket-eget-bruk)  
  
*Visma has to be installed on the PC you import the package on. Either full client or integration client is fine.* 

  
## License  
  
[![License](http://img.shields.io/:license-mit-blue.svg?style=flat-square)](http://badges.mit-license.org)  
  
- **[MIT license](http://opensource.org/licenses/mit-license.php)**

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/viktor2097/visma-administration",
    "name": "visma-administration",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "visma,visma administration",
    "author": "Viktor Johansson",
    "author_email": "dpedesigns@hotmail.com",
    "download_url": "https://files.pythonhosted.org/packages/e5/6c/dc5d6944f95f65a62f9c54919d0f3b2a967b5e004d8c5319ae7dee41f9f1/visma_administration-0.7.0.tar.gz",
    "platform": null,
    "description": "\n[![PyPI version](https://badge.fury.io/py/visma-administration.svg)](https://badge.fury.io/py/visma-administration)\n![PyPI - Downloads](https://img.shields.io/pypi/dm/visma-administration)\n![GitHub](https://img.shields.io/github/license/viktor2097/visma-administration)\n# *Python Visma Administration*  \nAPI for Visma Administration 200/500/1000/2000. \n\nVisma has added support for a 64-bit API in version 2023.1. Therefore, this package aims to be compatible with both 32-bit and 64-bit versions to maintain backward compatibility. The AdkNet4Wrapper is loaded on 32-bit Python installations, and AdkNet6Wrapper is loaded on 64-bit Python installations.\n\nWriting integrations for Visma's API often involves extensive boilerplate code. This package aims to present the API with a user-friendly, Pythonic interface, and make it more accessible. It's not feature complete, but it covers most basic needs, and you can tap into the underlying C# API if needed.\n# Installation\n```\npip install visma-administration  \n```  \n\n## Usage\n### Add companies that you would like to access data from\n```py\nfrom visma_administration import Visma\nVisma.add_company(name=\"FTG10\", common_path=\"Z:\\\\Gemensamma filer\", company_path=\"Z:\\\\F\u00f6retag\\\\FTG10\")\n\n# You can then access specific companies with a context manager\nwith Visma.get_company_api(\"FTG10\") as api:\n\tpass\n```\n\n## CRUD Operations\n**Read a single record**\n```py\nwith Visma.get_company_api(\"FTG10\") as api:\n    record = api.supplier_invoice_head.get(adk_sup_inv_head_invoice_number=\"number\")\n    print(record.adk_sup_inv_head_invoice_number)\n```\n**Update a record**\n```py\nwith Visma.get_company_api(\"FTG10\") as api:\n    record = api.supplier_invoice_head.get(adk_sup_inv_head_invoice_number=\"number\")\n    record.adk_sup_inv_head_invoice_date = datetime.now()\n    record.adk_sup_inv_head_vat_amount = 5000\n    record.adk_sup_inv_head_paymstop = True\n    record.adk_sup_inv_head_supplier_name = \"Name\"\n    record.save()\n```\n\n**Create a record**\n```py\nwith Visma.get_company_api(\"FTG10\") as api:\n    new_record = api.supplier.new() # new method is called\n    new_record.adk_supplier_name = \"Nvidia\"\n    new_record.save()\n```\n\n**Delete a record**\n```py\nwith Visma.get_company_api(\"FTG10\") as api:\n    john = api.supplier.get(adk_supplier_name=\"John\")\n    john.delete()\n```\n\n**Get multiple records**\n```py\nwith Visma.get_company_api(\"FTG10\") as api:\n\tinvoices = api.supplier_invoice_head.filter(adk_sup_inv_head_invoice_number=\"f03*\")\n\ttotal_sum = sum(invoice.adk_sup_inv_head_total for invoice in invoices)\n\tprint(f\"Total for all invoices with invoice_number starting as 'f03' is: {total_sum}\")\n\n\t# filter returns a generator, so you can limit how many items to return\n\timport itertools  \n\tsuppliers = api.supplier.filter(adk_supplier_name=\"*N*\")  \n\tsuppliers = itertools.islice(suppliers, 5)  \n\tfor supplier in suppliers:  \n\t\tprint(supplier.adk_supplier_name)  \n```\n**Working with rows**\n Existing rows can be accessed with: **.rows()** and creating new ones by calling **.create_rows()**\n```py\nwith Visma.get_company_api(\"FTG10\") as api:\n\t# lets create a new invoice and add rows\n\tinvoice = api.supplier_invoice_head.new()\n\tinvoice.adk_sup_inv_head_invoice_number = \"50294785\"\n\t\n\t# Creates 3 row objects\n\trows = invoice.create_rows(quantity=3)\n\trows[0].adk_ooi_row_account_number = \"5010\"\n\trows[1].adk_ooi_row_account_number = \"4050\"\n\trows[2].adk_ooi_row_account_number = \"3020\"\n\tinvoice.save()\n\t# We now have a new invoice with 3 rows.\n\n\t# Here we can access existing rows\n\tfor row in invoice.rows():\n\t\tprint(row.adk_ooi_row_account_number)\n\t\n\t# Delete last row\n\t# If you would like to delete more than one row,\n\t# Check the Deleting multiple rows section of the README\n\tinvoice.rows()[-1].delete()\n\t\n\t\n\t\n```\n\n### Deleting multiple rows\nAfter **.delete()** is called on a row, Visma automatically reassigns new indexes to every row, therefore according to their documentation, you have to request all rows again to continue working with them.\n```py\n# If you would like to delete all custom rows, use the code snippet below.\n# You have to start deleting them by negative index, since templates\n# will automatically readd rows depending on your configurations\nnrows = invoice.adk_sup_inv_head_nrows  \nfor i in range(int(nrows)):  \n  invoice.rows()[-1].delete()\n```\n\n# Other info\nIn Visma's documentation you can find a list of DB_fields that you may access through their API.  \nFor instance  \n```  \nADK_DB_PROJECT  \nADK_DB_ACCOUNT  \nADK_DB_SUPPLIER \n```  \n  \nYou can access these fields directly from your instantiated Visma API object,   \nADK_DB_ is removed and the name is lowercased.  \n  \nFor example:  \n      \n```py  \nwith visma.get_company_api(\"company\") as api:\n    api.supplier  \n    api.account  \n    api.project  \n```  \n  \nThese DB_Field attributes returns an object from which you can request data  \n  \n```py  \napi.supplier.get()  # returns a single object or returns an error  \napi.supplier.filter()  # returns multiple objects  \napi.supplier.new()  # Gives you a new record  \n```\n\nBoth `get` and `filter` accepts filtering on a field as argument.\nYou pass the field name which you want to filter upon, and a valid filter expression ( Visma have documentation for this.\nYou can filter on multiple fields by just passing multiple filter expressions\n\n```py\n\"\"\"\nThis filters on the ADK_SUPPLIER_NAME field of ADK_DB_SUPPLIER\n*text* is a valid filter expression which returns a result with inc anywhere inside of the name\nRefer to Visma documentation for further information on how to form different types of filter expressions.\n\"\"\"\nresult = api.supplier.get(adk_supplier_name=\"*inc*\")\n```\n\nConsider whatever `get`, `filter` and `new` returns to be database record(s).\nThese records have fields associated with them, if you check documentation for ADK_DB_SUPPLIER, you can find a whole bunch of fields associated with it.\n```\nADK_SUPPLIER_FIRST\nADK_SUPPLIER_NUMBER\nADK_SUPPLIER_NAME\nADK_SUPPLIER_SHORT_NAME\n... And a lot more\n```\nThese fields are mainly used in two ways,\n```py\ntest = api.supplier.get(adk_supplier_name=\"test\")  # Used when filtering\ntest.adk_supplier_name = \"test1\"  # Or used when interacting with a supplier record\n```\n \n  \n## Additional information\n  \n[Documentation for the api can be found here](https://vismaspcs.se/support/utvecklarpaket-eget-bruk)  \n  \n*Visma has to be installed on the PC you import the package on. Either full client or integration client is fine.* \n\n  \n## License  \n  \n[![License](http://img.shields.io/:license-mit-blue.svg?style=flat-square)](http://badges.mit-license.org)  \n  \n- **[MIT license](http://opensource.org/licenses/mit-license.php)**\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "API for Visma Administration 200/500/1000/2000",
    "version": "0.7.0",
    "project_urls": {
        "Download": "https://github.com/viktor2097/visma-administration/archive/0.7.0.tar.gz",
        "Homepage": "https://github.com/viktor2097/visma-administration"
    },
    "split_keywords": [
        "visma",
        "visma administration"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "e56cdc5d6944f95f65a62f9c54919d0f3b2a967b5e004d8c5319ae7dee41f9f1",
                "md5": "c3250edddac16c76a7b7e6e92c76b5e8",
                "sha256": "11adb98034d303cc3aeb48ca6b0abae123f55cfd2050ca1f54437198cab9d8e6"
            },
            "downloads": -1,
            "filename": "visma_administration-0.7.0.tar.gz",
            "has_sig": false,
            "md5_digest": "c3250edddac16c76a7b7e6e92c76b5e8",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 13585,
            "upload_time": "2024-01-22T18:50:02",
            "upload_time_iso_8601": "2024-01-22T18:50:02.774391Z",
            "url": "https://files.pythonhosted.org/packages/e5/6c/dc5d6944f95f65a62f9c54919d0f3b2a967b5e004d8c5319ae7dee41f9f1/visma_administration-0.7.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-01-22 18:50:02",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "viktor2097",
    "github_project": "visma-administration",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "test_requirements": [
        {
            "name": "pytest",
            "specs": [
                [
                    "==",
                    "6.2.2"
                ]
            ]
        }
    ],
    "lcname": "visma-administration"
}
        
Elapsed time: 0.25485s