From 4548d6ba623d997333cf6f44c6b823642a8a3f02 Mon Sep 17 00:00:00 2001 From: Lindsay Richter Date: Fri, 17 Oct 2025 10:34:43 -0400 Subject: [PATCH] Add country_code to account and contact entities --- paperless/json_encoders/customers.py | 2 ++ paperless/objects/customers.py | 5 ++++- tests/unit/mock_data/account.json | 3 ++- tests/unit/mock_data/account_list.json | 3 +++ tests/unit/mock_data/contact.json | 3 ++- tests/unit/mock_data/contact_list.json | 5 +++++ tests/unit/test_contacts.py | 12 ++++++++---- 7 files changed, 26 insertions(+), 7 deletions(-) diff --git a/paperless/json_encoders/customers.py b/paperless/json_encoders/customers.py index df72598..88276d1 100644 --- a/paperless/json_encoders/customers.py +++ b/paperless/json_encoders/customers.py @@ -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', @@ -118,6 +119,7 @@ def encode(cls, resource, json_dumps=True): data = {} field_keys = [ 'account_id', + 'country_code', 'email', 'first_name', 'last_name', diff --git a/paperless/objects/customers.py b/paperless/objects/customers.py index f776bea..e7f3217 100644 --- a/paperless/objects/customers.py +++ b/paperless/objects/customers.py @@ -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( @@ -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)) ) @@ -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( @@ -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)) diff --git a/tests/unit/mock_data/account.json b/tests/unit/mock_data/account.json index 02730eb..9a84c79 100644 --- a/tests/unit/mock_data/account.json +++ b/tests/unit/mock_data/account.json @@ -10,6 +10,7 @@ "state": "MA" } ], + "country_code": "1", "created": "2021-01-11T23:57:59+00:00", "credit_cards_enabled": true, "credit_line": 30000, @@ -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": { diff --git a/tests/unit/mock_data/account_list.json b/tests/unit/mock_data/account_list.json index 450fee7..e8858dc 100644 --- a/tests/unit/mock_data/account_list.json +++ b/tests/unit/mock_data/account_list.json @@ -4,6 +4,7 @@ "previous": null, "results": [ { + "country_code": "1", "erp_code": "PPI", "id": 1, "name": "Paperless Parts Inc.", @@ -12,6 +13,7 @@ "type": "customer" }, { + "country_code": "1", "erp_code": "AMC", "id": 2, "name": "ACME Machining", @@ -20,6 +22,7 @@ "type": "customer" }, { + "country_code": "1", "erp_code": null, "id": 3, "name": "A Cut Above CNC", diff --git a/tests/unit/mock_data/contact.json b/tests/unit/mock_data/contact.json index 5d3d30c..5cff7dd 100644 --- a/tests/unit/mock_data/contact.json +++ b/tests/unit/mock_data/contact.json @@ -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", diff --git a/tests/unit/mock_data/contact_list.json b/tests/unit/mock_data/contact_list.json index 62ce7b7..9091c7d 100644 --- a/tests/unit/mock_data/contact_list.json +++ b/tests/unit/mock_data/contact_list.json @@ -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", @@ -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", @@ -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", @@ -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", @@ -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", diff --git a/tests/unit/test_contacts.py b/tests/unit/test_contacts.py index d62066a..745181c 100644 --- a/tests/unit/test_contacts.py +++ b/tests/unit/test_contacts.py @@ -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): @@ -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", @@ -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)) @@ -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.") @@ -131,6 +134,7 @@ 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", @@ -138,7 +142,7 @@ def test_convert_account_to_json(self): "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,