-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[IMP] connector_carepoint: Upgrade address handling
* Add Abstract importer logic * Add partner sync logic * Implement new logic in address_patient
- Loading branch information
Showing
4 changed files
with
147 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
# -*- coding: utf-8 -*- | ||
# Copyright 2015-2016 LasLabs Inc. | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). | ||
|
||
import logging | ||
from openerp import models, fields | ||
from openerp.addons.connector.unit.mapper import (mapping, | ||
only_create, | ||
) | ||
from ..unit.mapper import CarepointImportMapper | ||
from ..backend import carepoint | ||
from ..unit.import_synchronizer import CarepointImporter | ||
|
||
|
||
_logger = logging.getLogger(__name__) | ||
|
||
|
||
class CarepointAddressAbstract(models.AbstractModel): | ||
""" Adds the ``one2many`` relation to the Carepoint bindings | ||
(``carepoint_bind_ids``) | ||
""" | ||
_inherits = {'carepoint.address': 'address_id', | ||
'res.partner': 'partner_id', | ||
} | ||
_name = 'carepoint.address.abstract' | ||
_description = 'Carepoint Address Abstract' | ||
|
||
address_id = fields.Many2one( | ||
string='Address', | ||
comodel_name='carepoint.address', | ||
required=True, | ||
ondelete='cascade', | ||
) | ||
partner_id = fields.Many2one( | ||
string='Partner', | ||
comodel_name='res.partner', | ||
required=True, | ||
ondelete='cascade', | ||
) | ||
|
||
|
||
@carepoint | ||
class CarepointAddressAbstractImportMapper(CarepointImportMapper): | ||
|
||
def _get_partner_defaults(self, record): | ||
""" It provides a method for partner defaults | ||
This could be handy to provide custom defaults via modules | ||
Params: | ||
record: ``dict`` of carepoint record | ||
""" | ||
return { | ||
'type': 'delivery', | ||
'customer': True, | ||
} | ||
|
||
def _has_empty_address(self, partner): | ||
""" It determines if the provided partner has an empty address. | ||
Currently only looks at ``street`` and ``street2``. | ||
""" | ||
return not any([partner.street, partner.street2]) | ||
|
||
def _partner_or_parent_and_default(self, record, medical_entity): | ||
""" It returns vals for partner associate/create for medical_entity | ||
Params: | ||
record: ``dict`` of carepoint record | ||
medical_entity: Recordset with a ``partner_id`` column | ||
Return: | ||
``dict`` of values for mapping | ||
""" | ||
if not self._has_empty_address(medical_entity.commercial_partner_id): | ||
return {'partner_id': medical_entity.commercial_partner_id.id} | ||
else: | ||
vals = self._get_partner_defaults(record) | ||
vals.update({ | ||
'parent_id': medical_entity.commercial_partner_id.id, | ||
}) | ||
return vals | ||
|
||
@mapping | ||
@only_create | ||
def address_id(self, record): | ||
binder = self.binder_for('carepoint.carepoint.address') | ||
address_id = binder.to_odoo(record['addr_id']) | ||
return {'address_id': address_id} | ||
|
||
|
||
@carepoint | ||
class CarepointAddressAbstractImporter(CarepointImporter): | ||
|
||
def _import_dependencies(self): | ||
""" Import depends for record """ | ||
self._import_dependency(self.carepoint_record['addr_id'], | ||
'carepoint.carepoint.address') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters