diff --git a/base_partner_validate_address/README.rst b/base_partner_validate_address/README.rst new file mode 100644 index 000000000..7a5dc054b --- /dev/null +++ b/base_partner_validate_address/README.rst @@ -0,0 +1,69 @@ +.. image:: https://img.shields.io/badge/license-LGPL--3-blue.svg + :target: http://www.gnu.org/licenses/lgpl.html + :alt: License: LGPL-3 + +============================= +Base Partner Validate Address +============================= + +Adds an abstract core for address verification via remote interfaces. + +Installation +============ + + +Configuration +============= + +Usage +===== + +.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas + :alt: Try me on Runbot + :target: https://runbot.odoo-community.org/runbot/149/10.0 + +Known Issues / Roadmap +====================== + +Known Issues +------------ + + +Roadmap +------- + +Bug Tracker +=========== + +Bugs are tracked on `GitHub Issues +`_. In case of trouble, please +check there if your issue has already been reported. If you spotted it first, +help us smash it by providing detailed and welcomed feedback. + +Credits +======= + +Images +------ + +* Odoo Community Association: `Icon `_. + +Contributors +------------ + +* Dave Lasley + +Maintainer +---------- + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +This module is maintained by the OCA. + +OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use. + +To contribute to this module, please visit https://odoo-community.org. diff --git a/base_partner_validate_address/__init__.py b/base_partner_validate_address/__init__.py new file mode 100644 index 000000000..93390e621 --- /dev/null +++ b/base_partner_validate_address/__init__.py @@ -0,0 +1,6 @@ +# -*- coding: utf-8 -*- +# Copyright 2016-2017 LasLabs Inc. +# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html). + +from . import models +from . import wizards diff --git a/base_partner_validate_address/__manifest__.py b/base_partner_validate_address/__manifest__.py new file mode 100644 index 000000000..5bcc4d3ee --- /dev/null +++ b/base_partner_validate_address/__manifest__.py @@ -0,0 +1,23 @@ +# -*- coding: utf-8 -*- +# Copyright 2016-2017 LasLabs Inc. +# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html). + +{ + 'name': 'Base Partner Validate Address', + 'summary': 'Provides an abstract interface/adapter mechanism allowing ' + 'for the unification of address verification providers.', + 'version': '10.0.1.0.0', + 'category': 'Extra Tools', + 'website': 'https://laslabs.com/', + 'author': 'LasLabs, Odoo Community Association (OCA)', + 'license': 'LGPL-3', + 'application': False, + 'installable': True, + 'depends': [ + 'base_external_system', + ], + 'data': [ + 'security/ir.model.access.csv', + 'wizards/wizard_address_validate_view.xml', + ], +} diff --git a/base_partner_validate_address/models/__init__.py b/base_partner_validate_address/models/__init__.py new file mode 100644 index 000000000..0806f2bd1 --- /dev/null +++ b/base_partner_validate_address/models/__init__.py @@ -0,0 +1,7 @@ +# -*- coding: utf-8 -*- +# Copyright 2016-2017 LasLabs Inc. +# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html). + +from . import address_validate +from . import res_company +from . import res_partner diff --git a/base_partner_validate_address/models/address_validate.py b/base_partner_validate_address/models/address_validate.py new file mode 100644 index 000000000..d8fd3d054 --- /dev/null +++ b/base_partner_validate_address/models/address_validate.py @@ -0,0 +1,84 @@ +# -*- coding: utf-8 -*- +# Copyright 2017 LasLabs Inc. +# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html). + +from odoo import api, fields, models + + +class AddressValidate(models.Model): + """Child modules should inherit this model to create new validators. + + In the ``_get_interface_types`` method, new interfaces should add + themselves:: + + @api.model + def _get_interface_types(self): + res = super()._get_interface_types() + return res + [('easypost', 'EasyPost')] + + The following methods must be implemented for each adapter, where + ```` is equal to the interface name (``easypost`` in above): + + * ``_get_client``: Return a usable API client for the + validator. + * ``_test_connector``: Test the connection to the API, and + escalate to super if success. + * ``_get_address``: Return the suggested address for a + partner using the API. It should accept an authenticated API + client as the first parameter and a ``res.partner`` singleton + as the second. + + If the remote system does not disconnect automatically, destruction can + be implemented in: + + * ``_destroy_client``: Destroy the connection. It should accept + an instance of the client as returned by ``_get_client``. + """ + + _name = 'address.validate' + _description = 'Address Validator Interface' + _inherit = 'external.system.adapter' + + interface_type = fields.Selection( + selection='_get_interface_types', + required=True, + ) + + @api.model + def _get_interface_types(self): + """Child modules should add themselves to these selection values.""" + return [] + + @api.multi + def get_address(self, partner): + """Returns an address suggestion from the interface. + + Args: + partner (ResPartner): Partner record to get address for. + + Returns: + dict: The suggested address. Should contain keys: ``street``, + ``street2``, ``city``, ``state_id``, ``zip``, ``country_id``, + ``is_valid``, and ``validation_messages``. + """ + self.ensure_one() + with self.interface.client() as client: + return self.__interface_method('get_address')(client, partner) + + @api.multi + def external_get_client(self): + return self.__interface_method('get_client')() + + @api.multi + def external_destroy_client(self, client): + try: + return self.__interface_method('destroy_client')(client) + except AttributeError: + pass + + @api.multi + def external_test_connector(self): + return self.__interface_method('test_connector')() + + def __interface_method(self, method_name): + return getattr(self, '%s_%s' % (self.interface_type, method_name)) diff --git a/base_partner_validate_address/models/res_company.py b/base_partner_validate_address/models/res_company.py new file mode 100644 index 000000000..4f92ed26e --- /dev/null +++ b/base_partner_validate_address/models/res_company.py @@ -0,0 +1,15 @@ +# -*- coding: utf-8 -*- +# Copyright 2017 LasLabs Inc. +# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html). + +from odoo import fields, models + + +class ResCompany(models.Model): + _inherit = 'res.company' + + default_address_validate_id = fields.Many2one( + string='Default Address Validator', + comodel_name='address.validate', + domain="[('company_ids', 'in', id)]", + ) diff --git a/base_partner_validate_address/models/res_partner.py b/base_partner_validate_address/models/res_partner.py new file mode 100644 index 000000000..1a6ed7adf --- /dev/null +++ b/base_partner_validate_address/models/res_partner.py @@ -0,0 +1,12 @@ +# -*- coding: utf-8 -*- +# Copyright 2017 LasLabs Inc. +# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html). + +from odoo import fields, models + + +class ResPartner(models.Model): + _inherit = 'res.partner' + + latitude = fields.Float() + longitude = fields.Float() diff --git a/base_partner_validate_address/security/ir.model.access.csv b/base_partner_validate_address/security/ir.model.access.csv new file mode 100644 index 000000000..3915b9dc6 --- /dev/null +++ b/base_partner_validate_address/security/ir.model.access.csv @@ -0,0 +1,2 @@ +id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink +access_address_validate_admin,access_address_validate_admin,model_address_validate,base.group_system,1,1,1,1 diff --git a/base_partner_validate_address/static/description/icon.png b/base_partner_validate_address/static/description/icon.png new file mode 100644 index 000000000..3a0328b51 Binary files /dev/null and b/base_partner_validate_address/static/description/icon.png differ diff --git a/base_partner_validate_address/wizards/__init__.py b/base_partner_validate_address/wizards/__init__.py new file mode 100644 index 000000000..616ca461a --- /dev/null +++ b/base_partner_validate_address/wizards/__init__.py @@ -0,0 +1,5 @@ +# -*- coding: utf-8 -*- +# Copyright 2016-2017 LasLabs Inc. +# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html). + +from . import wizard_address_validate diff --git a/base_partner_validate_address/wizards/wizard_address_validate.py b/base_partner_validate_address/wizards/wizard_address_validate.py new file mode 100644 index 000000000..6a618a4f0 --- /dev/null +++ b/base_partner_validate_address/wizards/wizard_address_validate.py @@ -0,0 +1,123 @@ +# -*- coding: utf-8 -*- +# Copyright 2017 LasLabs Inc. +# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html). + +from odoo import api, fields, models + + +class WizardAddressValidate(models.TransientModel): + _name = 'wizard.address.validate' + _description = 'Validate Address Wizard' + + partner_id = fields.Many2one( + string='Partner', + comodel_name='res.partner', + required=True, + default=lambda s: s._default_partner_id(), + ) + interface_id = fields.Many2one( + string='Validation Interface', + comodel_name='address.validate', + default=lambda s: s._default_interface_id(), + ) + street = fields.Char() + street2 = fields.Char() + city = fields.Char() + zip = fields.Char() + state_id = fields.Many2one( + string='State', + comodel_name='res.country.state', + ) + country_id = fields.Many2one( + string='Country', + comodel_name='res.country', + ) + latitude = fields.Float() + longitude = fields.Float() + is_valid = fields.Boolean() + validation_messages = fields.Text() + street_original = fields.Char( + related='partner_id.street', + readonly=True, + ) + street2_original = fields.Char( + related='partner_id.street2', + readonly=True, + ) + city_original = fields.Char( + related='partner_id.city', + readonly=True, + ) + zip_original = fields.Char( + related='partner_id.zip', + readonly=True, + ) + state_id_original = fields.Many2one( + string='State', + comodel_name='res.country.state', + related='partner_id.state_id', + readonly=True, + ) + country_id_original = fields.Many2one( + string='Country', + comodel_name='res.country', + related='partner_id.country_id', + readonly=True, + ) + latitude_original = fields.Float( + string='Latitude', + related='partner_id.latitude', + ) + longitude_original = fields.Float( + string='Longitude', + related='partner_id.longitude', + ) + + @api.model + def _default_partner_id(self): + active_model = self.env.context.get('active_model') + active_id = self.env.context.get('active_id') + if active_model == 'res.partner': + return active_id + if active_model == 'res.company': + company = self.env['res.company'].browse(active_id) + return company.partner_id.id + + @api.model + def _default_interface_id(self): + return self.env.user.company_id.default_address_validate_id.id + + @api.multi + def action_validate(self): + """Get the suggested address from the provider.""" + self.ensure_one() + self.write( + self.interface_id.get_address(self.partner_id) + ) + return { + 'context': self.env.context, + 'view_type': 'form', + 'view_mode': 'form', + 'res_model': self._name, + 'src_model': 'res.partner', + 'res_id': self.id, + 'view_id': False, + 'type': 'ir.actions.act_window', + 'target': 'new', + } + + @api.multi + def action_confirm(self): + """Copy the validated information to the partner.""" + for record in self: + record.partner_id.write({ + 'street': record.street, + 'street2': record.street2, + 'city': record.city, + 'state_id': record.state_id.id, + 'country_id': record.country_id.id, + 'zip': record.zip, + }) + return { + 'type': 'ir.actions.act_window_close', + } diff --git a/base_partner_validate_address/wizards/wizard_address_validate_view.xml b/base_partner_validate_address/wizards/wizard_address_validate_view.xml new file mode 100644 index 000000000..1c3240fb4 --- /dev/null +++ b/base_partner_validate_address/wizards/wizard_address_validate_view.xml @@ -0,0 +1,83 @@ + + + + + + + + Address Verification Form + wizard.address.validate + +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + + + + + + + diff --git a/oca_dependencies.txt b/oca_dependencies.txt index d8a2d4efc..ad9fd7b38 100644 --- a/oca_dependencies.txt +++ b/oca_dependencies.txt @@ -1 +1,2 @@ product-attribute +server-tools