Skip to content

Commit

Permalink
Adding support for BillingAccount and Usage (#80)
Browse files Browse the repository at this point in the history
Adding support for BillingAccount and Usage (#80)
  • Loading branch information
gustahrodrigues authored Mar 18, 2022
1 parent f7ca0b0 commit 617e411
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 0 deletions.
54 changes: 54 additions & 0 deletions netsuitesdk/api/billing_account.py
Original file line number Diff line number Diff line change
@@ -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)
40 changes: 40 additions & 0 deletions netsuitesdk/api/usage.py
Original file line number Diff line number Diff line change
@@ -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)
4 changes: 4 additions & 0 deletions netsuitesdk/connection.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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)
2 changes: 2 additions & 0 deletions netsuitesdk/internal/netsuite_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@

# urn:relationships.lists.webservices.netsuite.com
'ns13': [
'BillingAccount',
'CustomerAddressbook', 'CustomerAddressbookList',
'Customer', 'CustomerSearch',
'Vendor', 'VendorSearch',
Expand Down Expand Up @@ -106,6 +107,7 @@
'InvoiceItemList',
'TransactionSearch',
'TransactionSearchAdvanced',
'Usage',
],

# urn:purchases_2017_2.transactions.webservices.netsuite.com
Expand Down

0 comments on commit 617e411

Please sign in to comment.