forked from routablehq/python-quickbooks
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathattachable.py
More file actions
70 lines (56 loc) · 2.4 KB
/
attachable.py
File metadata and controls
70 lines (56 loc) · 2.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
from six import python_2_unicode_compatible
from .base import Ref, QuickbooksManagedObject, QuickbooksTransactionEntity, AttachableRef
from ..client import QuickBooks
from ..mixins import DeleteMixin
@python_2_unicode_compatible
class Attachable(DeleteMixin, QuickbooksManagedObject, QuickbooksTransactionEntity):
"""
QBO definition: This page covers the Attachable, Upload, and Download resources used for attachment management. Attachments are supplemental information linked to a transaction or Item object. They can be files, notes, or a combination of both.
In the case of file attachments, use an upload endpoint multipart request to upload the files to the QuickBooks attachment list and, optionally, to supply metadata for each via an attachable object. If meta data is not supplied with the upload request, the system creates it.
In the case of a note, use the create attachable endpoint.
For information about attachments, see the Attachments Developer Guide.
"""
class_dict = {
"EntityRef": Ref,
}
list_dict = {
"AttachableRef": AttachableRef,
}
qbo_object_name = "Attachable"
def __init__(self):
super(Attachable, self).__init__()
self.AttachableRef = []
self.FileName = None
self._FilePath = ''
self.Note = ""
self.FileAccessUri = None
self.TempDownloadUri = None
self.Size = None
self.ContentType = None
self.Category = None
self.Lat = None
self.Long = None
self.PlaceName = None
self.ThumbnailFileAccessUri = None
self.ThumbnailTempDownloadUri = None
def __str__(self):
return self.FileName
def to_ref(self):
ref = Ref()
ref.name = self.FileName
ref.type = self.qbo_object_name
ref.value = self.Id
return ref
def save(self, qb=None):
if not qb:
qb = QuickBooks()
if self.Id and int(self.Id) > 0:
json_data = qb.update_object(self.qbo_object_name, self.to_json(), _file_path=self._FilePath)
else:
json_data = qb.create_object(self.qbo_object_name, self.to_json(), _file_path=self._FilePath)
if self.FileName:
obj = type(self).from_json(json_data['AttachableResponse'][0]['Attachable'])
else:
obj = type(self).from_json(json_data['Attachable'])
self.Id = obj.Id
return obj