diff --git a/netsuitesdk/api/billing_account.py b/netsuitesdk/api/billing_account.py new file mode 100644 index 0000000..026231d --- /dev/null +++ b/netsuitesdk/api/billing_account.py @@ -0,0 +1,54 @@ +from collections import OrderedDict + +from .base import ApiBase +import logging + +logger = logging.getLogger(__name__) + + +class BillingAccount(ApiBase): + SIMPLE_FIELDS = [ + 'createdBy', + 'createdDate', + 'customFieldList', + 'customerDefault', + 'frequency', + 'idNumber', + 'inactive', + 'lastBillCycleDate', + 'lastBillDate', + 'memo', + 'name', + 'nextBillCycleDate', + 'startDate', + 'nullFieldList', + ] + + RECORD_REF_FIELDS = [ + 'billingSchedule', + 'cashSaleForm', + 'class', + 'currency', + 'customForm', + 'customer', + 'department', + 'invoiceForm', + 'location', + 'subsidiary', + ] + + def __init__(self, ns_client): + ApiBase.__init__(self, ns_client=ns_client, type_name='BillingAccount') + + def post(self, data) -> OrderedDict: + assert data['externalId'], 'missing external id' + billing_account = self.ns_client.BillingAccount(**data) + + self.build_simple_fields(self.SIMPLE_FIELDS, data, billing_account) + + self.build_record_ref_fields(self.RECORD_REF_FIELDS, data, billing_account) + + logger.debug('able to create billing account = %s', billing_account) + + res = self.ns_client.upsert(billing_account) + return self._serialize(res) diff --git a/netsuitesdk/api/usage.py b/netsuitesdk/api/usage.py new file mode 100644 index 0000000..cbd498b --- /dev/null +++ b/netsuitesdk/api/usage.py @@ -0,0 +1,40 @@ +from collections import OrderedDict + +from .base import ApiBase +import logging + +logger = logging.getLogger(__name__) + + +class Usage(ApiBase): + SIMPLE_FIELDS = [ + 'memo', + 'usageDate', + 'usageQuantity', + 'nullFieldList', + ] + + RECORD_REF_FIELDS = [ + 'customForm', + 'customer', + 'item', + 'subscriptionPlan', + 'usageSubscription', + 'usageSubscriptionLine', + ] + + def __init__(self, ns_client): + ApiBase.__init__(self, ns_client=ns_client, type_name='Usage') + + def post(self, data) -> OrderedDict: + assert data['externalId'], 'missing external id' + usage = self.ns_client.Usage(**data) + + self.build_simple_fields(self.SIMPLE_FIELDS, data, usage) + + self.build_record_ref_fields(self.RECORD_REF_FIELDS, data, usage) + + logger.debug('able to create usage = %s', usage) + + res = self.ns_client.upsert(usage) + return self._serialize(res) diff --git a/netsuitesdk/connection.py b/netsuitesdk/connection.py index 63c6e60..818f0e0 100644 --- a/netsuitesdk/connection.py +++ b/netsuitesdk/connection.py @@ -1,4 +1,5 @@ from .api.accounts import Accounts +from .api.billing_account import BillingAccount from .api.classifications import Classifications from .api.credit_memos import CreditMemos from .api.departments import Departments @@ -8,6 +9,7 @@ from .api.vendor_credits import VendorCredits from .api.vendors import Vendors from .api.subsidiaries import Subsidiaries +from .api.usage import Usage from .api.journal_entries import JournalEntries from .api.employees import Employees from .api.expense_reports import ExpenseReports @@ -43,6 +45,7 @@ def __init__(self, account, consumer_key, consumer_secret, token_key, token_secr ) self.client = ns_client self.accounts = Accounts(ns_client) + self.billing_accounts = BillingAccount(ns_client) self.classifications = Classifications(ns_client) self.departments = Departments(ns_client) self.currencies = Currencies(ns_client) @@ -69,3 +72,4 @@ def __init__(self, account, consumer_key, consumer_secret, token_key, token_secr self.tax_items = TaxItems(ns_client) self.tax_groups = TaxGroups(ns_client) self.credit_memos = CreditMemos(ns_client) + self.usages = Usage(ns_client) diff --git a/netsuitesdk/internal/netsuite_types.py b/netsuitesdk/internal/netsuite_types.py index 47c6058..c1b5855 100644 --- a/netsuitesdk/internal/netsuite_types.py +++ b/netsuitesdk/internal/netsuite_types.py @@ -74,6 +74,7 @@ # urn:relationships.lists.webservices.netsuite.com 'ns13': [ + 'BillingAccount', 'CustomerAddressbook', 'CustomerAddressbookList', 'Customer', 'CustomerSearch', 'Vendor', 'VendorSearch', @@ -106,6 +107,7 @@ 'InvoiceItemList', 'TransactionSearch', 'TransactionSearchAdvanced', + 'Usage', ], # urn:purchases_2017_2.transactions.webservices.netsuite.com