diff --git a/delivery_partner_ups/README.rst b/delivery_partner_ups/README.rst new file mode 100644 index 00000000..5896d237 --- /dev/null +++ b/delivery_partner_ups/README.rst @@ -0,0 +1,29 @@ +*************************************** +Hibou - UPS Partner Shipping Accounts +*************************************** + +Adds UPS shipping accounts. + +For more information and add-ons, visit `Hibou.io `_. + + +============= +Main Features +============= + +* Adds UPS to the delivery type selection field. +* Adds new required field of UPS Account ZIP. +* Validates entered UPS account numbers are the correct length. + +.. image:: https://user-images.githubusercontent.com/15882954/41176879-e7dc5a66-6b16-11e8-82a2-9b6cd0c909fd.png + :alt: 'Register Payment Detail' + :width: 988 + :align: left + +======= +License +======= + +Please see `LICENSE `_. + +Copyright Hibou Corp. 2018 diff --git a/delivery_partner_ups/__init__.py b/delivery_partner_ups/__init__.py new file mode 100644 index 00000000..0650744f --- /dev/null +++ b/delivery_partner_ups/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/delivery_partner_ups/__manifest__.py b/delivery_partner_ups/__manifest__.py new file mode 100755 index 00000000..b9cff5ac --- /dev/null +++ b/delivery_partner_ups/__manifest__.py @@ -0,0 +1,19 @@ +{ + 'name': 'UPS Partner Shipping Accounts', + 'author': 'Hibou Corp. ', + 'version': '13.0.1.0.0', + 'category': 'Stock', + 'sequence': 95, + 'summary': 'UPS Partner Shipping Accounts', + 'description': """ + """, + 'website': 'https://hibou.io/', + 'depends': [ + 'delivery_partner', + ], + 'data': [ + 'views/delivery_views.xml', + ], + 'installable': True, + 'application': False, +} diff --git a/delivery_partner_ups/models/__init__.py b/delivery_partner_ups/models/__init__.py new file mode 100644 index 00000000..be8cabd6 --- /dev/null +++ b/delivery_partner_ups/models/__init__.py @@ -0,0 +1 @@ +from . import delivery diff --git a/delivery_partner_ups/models/delivery.py b/delivery_partner_ups/models/delivery.py new file mode 100644 index 00000000..dd9a3239 --- /dev/null +++ b/delivery_partner_ups/models/delivery.py @@ -0,0 +1,19 @@ +import re + +from odoo import fields, models +from odoo.exceptions import ValidationError + + +class PartnerShippingAccount(models.Model): + _inherit = 'partner.shipping.account' + + delivery_type = fields.Selection(selection_add=[('ups', 'UPS')]) + ups_zip = fields.Char(string='UPS Account ZIP') + + def ups_check_validity(self): + m = re.search(r'^[\dA-Z]{6}$', self.name or '') + if not m: + raise ValidationError('UPS Account numbers must be 6 Alpha-numeric characters.') + m = re.search(r'^\d{5}$', self.ups_zip or '') + if not m: + raise ValidationError('UPS requires the 5 digit account ZIP.') diff --git a/delivery_partner_ups/tests/__init__.py b/delivery_partner_ups/tests/__init__.py new file mode 100644 index 00000000..9df4d58c --- /dev/null +++ b/delivery_partner_ups/tests/__init__.py @@ -0,0 +1 @@ +from . import test_ups_account diff --git a/delivery_partner_ups/tests/test_ups_account.py b/delivery_partner_ups/tests/test_ups_account.py new file mode 100644 index 00000000..f4391039 --- /dev/null +++ b/delivery_partner_ups/tests/test_ups_account.py @@ -0,0 +1,61 @@ +from odoo.tests.common import TransactionCase +from odoo.exceptions import ValidationError + + +class TestAccount(TransactionCase): + + def setUp(self): + super(TestAccount, self).setUp() + self.PartnerShippingAccount = self.env['partner.shipping.account'] + self.partner = self.env.ref('base.res_partner_12') + + def test_ups_account_information(self): + # Create object and confirm that validation error raises if ups account number is blank or not 8 digits + with self.assertRaises(ValidationError): + wrong_account_number = self.PartnerShippingAccount.create({ + 'name': '1234567', + 'description': 'Error Account', + 'partner_id': self.partner.id, + 'delivery_type': 'ups', + 'note': 'This is a note', + 'ups_zip': '12345' + }) + + with self.assertRaises(ValidationError): + no_account_number = self.PartnerShippingAccount.create({ + 'name': '', + 'description': 'Error Account', + 'partner_id': self.partner.id, + 'delivery_type': 'ups', + 'note': 'This is a note', + 'ups_zip': '12345' + }) + # Create object and confirm that validation error raises if zipcode is blank or not 5 digits + with self.assertRaises(ValidationError): + wrong_zip_code = self.PartnerShippingAccount.create({ + 'name': '123456', + 'description': 'Error Account', + 'partner_id': self.partner.id, + 'delivery_type': 'ups', + 'note': 'This is a note', + 'ups_zip': '1234' + }) + + with self.assertRaises(ValidationError): + no_zip_code = self.PartnerShippingAccount.create({ + 'name': '123456', + 'description': 'Error Account', + 'partner_id': self.partner.id, + 'delivery_type': 'ups', + 'note': 'This is a note', + 'ups_zip': '' + }) + + _ = self.PartnerShippingAccount.create({ + 'name': '123456', + 'description': 'Error Account', + 'partner_id': self.partner.id, + 'delivery_type': 'ups', + 'note': 'This is a note', + 'ups_zip': '12345' + }) diff --git a/delivery_partner_ups/views/delivery_views.xml b/delivery_partner_ups/views/delivery_views.xml new file mode 100644 index 00000000..d5c8a4e7 --- /dev/null +++ b/delivery_partner_ups/views/delivery_views.xml @@ -0,0 +1,13 @@ + + + + partner.shipping.account.form.inherit + partner.shipping.account + + + + + + + +