Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions paperless/json_encoders/customers.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class AccountEncoder(BaseJSONEncoder):
def encode(cls, resource, json_dumps=True):
data = {}
field_keys = [
'country_code',
'credit_cards_enabled',
'credit_line',
'erp_code',
Expand Down Expand Up @@ -118,6 +119,7 @@ def encode(cls, resource, json_dumps=True):
data = {}
field_keys = [
'account_id',
'country_code',
'email',
'first_name',
'last_name',
Expand Down
5 changes: 4 additions & 1 deletion paperless/objects/customers.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ class Account(
_json_encoder = AccountEncoder

name: str = attr.ib(validator=attr.validators.instance_of(str))
country_code: str = attr.ib(validator=attr.validators.instance_of((str, object)))

# not required for instantiation
billing_addresses = attr.ib(
Expand Down Expand Up @@ -229,7 +230,7 @@ def search(cls, search_term):

@attr.s(frozen=False)
class AccountList(FromJSONMixin, PaginatedListMixin):

country_code: str = attr.ib(validator=attr.validators.instance_of((str, object)))
erp_code: str = attr.ib(
validator=attr.validators.optional(attr.validators.instance_of(str))
)
Expand Down Expand Up @@ -311,6 +312,7 @@ class Contact(
email: str = attr.ib(validator=attr.validators.instance_of(str))
first_name: str = attr.ib(validator=attr.validators.instance_of(str))
last_name: str = attr.ib(validator=attr.validators.instance_of(str))
country_code: str = attr.ib(validator=attr.validators.instance_of((str, object)))

# not required for instantiation
address = attr.ib(
Expand Down Expand Up @@ -376,6 +378,7 @@ class ContactList(FromJSONMixin, PaginatedListMixin):
account_id: Optional[int] = attr.ib(
validator=attr.validators.optional(attr.validators.instance_of(int))
)
country_code: str = attr.ib(validator=attr.validators.instance_of((str, object)))
created: str = attr.ib(validator=attr.validators.instance_of(str))
email: str = attr.ib(validator=attr.validators.instance_of(str))
first_name: str = attr.ib(validator=attr.validators.instance_of(str))
Expand Down
3 changes: 2 additions & 1 deletion tests/unit/mock_data/account.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"state": "MA"
}
],
"country_code": "1",
"created": "2021-01-11T23:57:59+00:00",
"credit_cards_enabled": true,
"credit_line": 30000,
Expand All @@ -19,7 +20,7 @@
"notes": null,
"payment_terms": "Net 30",
"payment_terms_period": 30,
"phone": "6035555555",
"phone": "6175671064",
"phone_ext": null,
"purchase_orders_enabled": true,
"salesperson": {
Expand Down
3 changes: 3 additions & 0 deletions tests/unit/mock_data/account_list.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"previous": null,
"results": [
{
"country_code": "1",
"erp_code": "PPI",
"id": 1,
"name": "Paperless Parts Inc.",
Expand All @@ -12,6 +13,7 @@
"type": "customer"
},
{
"country_code": "1",
"erp_code": "AMC",
"id": 2,
"name": "ACME Machining",
Expand All @@ -20,6 +22,7 @@
"type": "customer"
},
{
"country_code": "1",
"erp_code": null,
"id": 3,
"name": "A Cut Above CNC",
Expand Down
3 changes: 2 additions & 1 deletion tests/unit/mock_data/contact.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@
"postal_code": "02114-1702",
"state": "MA"
},
"country_code": "1",
"created": "2021-01-11T23:57:59.114838Z",
"email": "john.smith@paperlessparts.com",
"first_name": "John",
"id": 1,
"last_name": "Smith",
"notes": "test notes",
"phone": "6035555555",
"phone": "6176549944",
"phone_ext": "",
"salesperson": {
"first_name": "William",
Expand Down
5 changes: 5 additions & 0 deletions tests/unit/mock_data/contact_list.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"results": [
{
"account_id": 1,
"country_code": "1",
"created": "2021-01-11T23:58:21+00:00",
"email": "support+1@paperlessparts.com",
"first_name": "Jim",
Expand All @@ -15,6 +16,7 @@
},
{
"account_id": 1,
"country_code": "1",
"created": "2021-01-11T23:58:15+00:00",
"email": "support+2@paperlessparts.com",
"first_name": "Tom",
Expand All @@ -25,6 +27,7 @@
},
{
"account_id": 1,
"country_code": "1",
"created": "2021-01-11T23:58:15+00:00",
"email": "support+3@paperlessparts.com",
"first_name": "Ryan",
Expand All @@ -35,6 +38,7 @@
},
{
"account_id": 1,
"country_code": "1",
"created": "2021-01-11T23:58:15+00:00",
"email": "support+4@paperlessparts.com",
"first_name": "Scott",
Expand All @@ -45,6 +49,7 @@
},
{
"account_id": 1,
"country_code": "1",
"created": "2021-01-11T23:58:15+00:00",
"email": "support+5@paperlessparts.com",
"first_name": "Will",
Expand Down
12 changes: 8 additions & 4 deletions tests/unit/test_contacts.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ def test_get_contact(self):
self.assertEqual(c.id, 1)
self.assertEqual(c.last_name, "Smith")
self.assertEqual(c.notes, "test notes")
self.assertEqual(c.phone, "6035555555")
self.assertEqual(c.country_code, "1")
self.assertEqual(c.phone, "6176549944")
self.assertEqual(c.phone_ext, "")

def test_convert_contact_to_json(self):
Expand All @@ -44,11 +45,12 @@ def test_convert_contact_to_json(self):
c = Contact.get(1)
expected_contact_json = {
"account_id": 1,
"country_code": "1",
"email": "john.smith@paperlessparts.com",
"first_name": "John",
"last_name": "Smith",
"notes": "test notes",
"phone": "6035555555",
"phone": "6176549944",
"phone_ext": "",
"address": {
"address1": "135 PORTLAND ST",
Expand Down Expand Up @@ -104,6 +106,7 @@ def test_get_account(self):
self.assertEqual(ba.country, "USA")
self.assertEqual(ba.postal_code, "02108")
self.assertEqual(ba.state, "MA")
self.assertEqual(a.country_code, "1")
self.assertEqual(a.created, "2021-01-11T23:57:59+00:00")
self.assertEqual(a.credit_cards_enabled, True)
self.assertEqual(a.credit_line, Money(raw_amount=30000))
Expand All @@ -113,7 +116,7 @@ def test_get_account(self):
self.assertIsNone(a.notes)
self.assertEqual(a.payment_terms, "Net 30")
self.assertEqual(a.payment_terms_period, 30)
self.assertEqual(a.phone, "6035555555")
self.assertEqual(a.phone, "6175671064")
self.assertIsNone(a.phone_ext)
self.assertTrue(a.purchase_orders_enabled)
self.assertEqual(sta.address1, "1 City Hall Sq.")
Expand All @@ -131,14 +134,15 @@ def test_convert_account_to_json(self):
self.client.get_resource = MagicMock(return_value=self.mock_account_json)
a = Account.get(1)
expected_account_json = {
"country_code": "1",
"credit_cards_enabled": True,
"credit_line": 30000.0,
"erp_code": "ARUE",
"notes": None,
"name": "Accolades R Us Engineering",
"payment_terms": "Net 30",
"payment_terms_period": 30,
"phone": "6035555555",
"phone": "6175671064",
"phone_ext": None,
"tax_exempt": True,
"tax_rate": None,
Expand Down