Skip to content

Commit

Permalink
[IMP] connector_carepoint: Improved pharmacy handling
Browse files Browse the repository at this point in the history
* Prefer CarepointStore namespace to MedicalPharmacy in order to allow for cssorg
* Bump version, previous versions of stores incompatible
* Implement csorg as carepoint_organization
  • Loading branch information
lasley committed Sep 7, 2016
1 parent 0768882 commit 3fd699a
Show file tree
Hide file tree
Showing 38 changed files with 655 additions and 131 deletions.
1 change: 1 addition & 0 deletions connector_carepoint/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ Known Issues / Roadmap
* Add Rx/OTC Tax delineation
* ``import_dependency`` usage in ``_after_import`` should be replaced for delay
* Needs to be split into multiple modules to isolate dependencies
* Carepoint organizations import as pharmacies, but might be other entities


Bug Tracker
Expand Down
2 changes: 1 addition & 1 deletion connector_carepoint/__openerp__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
{
'name': 'CarePoint Connector',
'description': 'Two-Way Sync With CarePoint',
'version': '9.0.1.0.1',
'version': '9.0.1.2.0',
'category': 'Connector',
'author': "LasLabs",
'license': 'AGPL-3',
Expand Down
6 changes: 4 additions & 2 deletions connector_carepoint/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
from . import stock_warehouse

# Medical Models
from . import medical_pharmacy
from . import medical_patient
from . import medical_physician
from . import medical_prescription_order
Expand All @@ -25,11 +24,14 @@
from . import address
from . import address_abstract
from . import address_patient
from . import address_pharmacy
from . import address_store
from . import address_organization
from . import address_physician

# CarePoint Mappings/Binds
from . import account
from . import carepoint_store
from . import carepoint_organization
from . import carepoint_state
from . import carepoint_item
from . import carepoint_vendor
Expand Down
115 changes: 115 additions & 0 deletions connector_carepoint/models/address_organization.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
# -*- 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.connector import ConnectorUnit
from openerp.addons.connector.unit.mapper import (mapping,
only_create,
)
from ..unit.backend_adapter import CarepointCRUDAdapter
from ..backend import carepoint
from ..unit.import_synchronizer import DelayedBatchImporter

from .address_abstract import (CarepointAddressAbstractImportMapper,
CarepointAddressAbstractImporter,
)

_logger = logging.getLogger(__name__)


class CarepointCarepointAddressOrganization(models.Model):
""" Binding Model for the Carepoint Address Organization """
_name = 'carepoint.carepoint.address.organization'
_inherit = 'carepoint.binding'
_inherits = {'carepoint.address.organization': 'odoo_id'}
_description = 'Carepoint Address Organization Many2Many Rel'
_cp_lib = 'pharmacy_address'

odoo_id = fields.Many2one(
comodel_name='carepoint.address.organization',
string='Company',
required=True,
ondelete='cascade'
)


class CarepointAddressOrganization(models.Model):
""" Adds the ``One2many`` relation to the Carepoint bindings
(``carepoint_bind_ids``)
"""
_name = 'carepoint.address.organization'
_inherit = 'carepoint.address.abstract'
_description = 'Carepoint Address Organization'

carepoint_bind_ids = fields.One2many(
comodel_name='carepoint.carepoint.address.organization',
inverse_name='odoo_id',
string='Carepoint Bindings',
)


@carepoint
class CarepointAddressOrganizationAdapter(CarepointCRUDAdapter):
""" Backend Adapter for the Carepoint Address Organization """
_model_name = 'carepoint.carepoint.address.organization'


@carepoint
class CarepointAddressOrganizationBatchImporter(DelayedBatchImporter):
""" Import the Carepoint Address Organizations.
For every address in the list, a delayed job is created.
"""
_model_name = ['carepoint.carepoint.address.organization']


@carepoint
class CarepointAddressOrganizationImportMapper(
CarepointAddressAbstractImportMapper,
):
_model_name = 'carepoint.carepoint.address.organization'

@mapping
@only_create
def partner_id(self, record):
""" It returns either the commercial partner or parent & defaults """
binder = self.binder_for('carepoint.medical.organization')
organization_id = binder.to_odoo(record['org_id'], browse=True)
_sup = super(CarepointAddressOrganizationImportMapper, self)
return _sup.partner_id(
record, organization_id,
)

@mapping
def carepoint_id(self, record):
return {'carepoint_id': '%d,%d' % (record['org_id'],
record['addr_id'])}


@carepoint
class CarepointAddressOrganizationImporter(
CarepointAddressAbstractImporter,
):
_model_name = ['carepoint.carepoint.address.organization']
_base_mapper = CarepointAddressOrganizationImportMapper

def _import_dependencies(self):
""" Import depends for record """
super(
CarepointAddressOrganizationImporter, self
)._import_dependencies()
self._import_dependency(self.carepoint_record['org_id'],
'carepoint.medical.organization')


@carepoint
class CarepointAddressOrganizationUnit(ConnectorUnit):
_model_name = 'carepoint.carepoint.address.organization'

def _import_addresses(self, organization_id, partner_binding):
adapter = self.unit_for(CarepointCRUDAdapter)
importer = self.unit_for(CarepointAddressOrganizationImporter)
address_ids = adapter.search(org_id=organization_id)
for address_id in address_ids:
importer.run(address_id)
Original file line number Diff line number Diff line change
Expand Up @@ -19,66 +19,66 @@
_logger = logging.getLogger(__name__)


class CarepointCarepointAddressPharmacy(models.Model):
""" Binding Model for the Carepoint Address Pharmacy """
_name = 'carepoint.carepoint.address.pharmacy'
class CarepointCarepointAddressStore(models.Model):
""" Binding Model for the Carepoint Address Store """
_name = 'carepoint.carepoint.address.store'
_inherit = 'carepoint.binding'
_inherits = {'carepoint.address.pharmacy': 'odoo_id'}
_description = 'Carepoint Address Pharmacy Many2Many Rel'
_inherits = {'carepoint.address.store': 'odoo_id'}
_description = 'Carepoint Address Store Many2Many Rel'
_cp_lib = 'store_address' # Name of model in Carepoint lib (snake_case)

odoo_id = fields.Many2one(
comodel_name='carepoint.address.pharmacy',
comodel_name='carepoint.address.store',
string='Company',
required=True,
ondelete='cascade'
)


class CarepointAddressPharmacy(models.Model):
class CarepointAddressStore(models.Model):
""" Adds the ``One2many`` relation to the Carepoint bindings
(``carepoint_bind_ids``)
"""
_name = 'carepoint.address.pharmacy'
_name = 'carepoint.address.store'
_inherit = 'carepoint.address.abstract'
_description = 'Carepoint Address Pharmacy'
_description = 'Carepoint Address Store'

carepoint_bind_ids = fields.One2many(
comodel_name='carepoint.carepoint.address.pharmacy',
comodel_name='carepoint.carepoint.address.store',
inverse_name='odoo_id',
string='Carepoint Bindings',
)


@carepoint
class CarepointAddressPharmacyAdapter(CarepointCRUDAdapter):
""" Backend Adapter for the Carepoint Address Pharmacy """
_model_name = 'carepoint.carepoint.address.pharmacy'
class CarepointAddressStoreAdapter(CarepointCRUDAdapter):
""" Backend Adapter for the Carepoint Address Store """
_model_name = 'carepoint.carepoint.address.store'


@carepoint
class CarepointAddressPharmacyBatchImporter(DelayedBatchImporter):
""" Import the Carepoint Address Pharmacys.
class CarepointAddressStoreBatchImporter(DelayedBatchImporter):
""" Import the Carepoint Address Stores.
For every address in the list, a delayed job is created.
"""
_model_name = ['carepoint.carepoint.address.pharmacy']
_model_name = ['carepoint.carepoint.address.store']


@carepoint
class CarepointAddressPharmacyImportMapper(
class CarepointAddressStoreImportMapper(
CarepointAddressAbstractImportMapper,
):
_model_name = 'carepoint.carepoint.address.pharmacy'
_model_name = 'carepoint.carepoint.address.store'

@mapping
@only_create
def partner_id(self, record):
""" It returns either the commercial partner or parent & defaults """
binder = self.binder_for('carepoint.medical.pharmacy')
pharmacy_id = binder.to_odoo(record['store_id'], browse=True)
_sup = super(CarepointAddressPharmacyImportMapper, self)
binder = self.binder_for('carepoint.carepoint.store')
store_id = binder.to_odoo(record['store_id'], browse=True)
_sup = super(CarepointAddressStoreImportMapper, self)
return _sup.partner_id(
record, pharmacy_id,
record, store_id,
)

@mapping
Expand All @@ -88,26 +88,26 @@ def carepoint_id(self, record):


@carepoint
class CarepointAddressPharmacyImporter(
class CarepointAddressStoreImporter(
CarepointAddressAbstractImporter,
):
_model_name = ['carepoint.carepoint.address.pharmacy']
_base_mapper = CarepointAddressPharmacyImportMapper
_model_name = ['carepoint.carepoint.address.store']
_base_mapper = CarepointAddressStoreImportMapper

def _import_dependencies(self):
""" Import depends for record """
super(CarepointAddressPharmacyImporter, self)._import_dependencies()
super(CarepointAddressStoreImporter, self)._import_dependencies()
self._import_dependency(self.carepoint_record['store_id'],
'carepoint.medical.pharmacy')
'carepoint.carepoint.store')


@carepoint
class CarepointAddressPharmacyUnit(ConnectorUnit):
_model_name = 'carepoint.carepoint.address.pharmacy'
class CarepointAddressStoreUnit(ConnectorUnit):
_model_name = 'carepoint.carepoint.address.store'

def _import_addresses(self, pharmacy_id, partner_binding):
def _import_addresses(self, store_id, partner_binding):
adapter = self.unit_for(CarepointCRUDAdapter)
importer = self.unit_for(CarepointAddressPharmacyImporter)
address_ids = adapter.search(store_id=pharmacy_id)
importer = self.unit_for(CarepointAddressStoreImporter)
address_ids = adapter.search(store_id=store_id)
for address_id in address_ids:
importer.run(address_id)
4 changes: 2 additions & 2 deletions connector_carepoint/models/carepoint_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class CarepointBackend(models.Model):
"in Odoo.",
)
store_ids = fields.One2many(
comodel_name='carepoint.medical.pharmacy',
comodel_name='carepoint.carepoint.store',
inverse_name='backend_id',
string='Store',
readonly=True,
Expand Down Expand Up @@ -224,7 +224,7 @@ def check_carepoint_structure(self):
def synchronize_metadata(self):
session = self.__get_session()
for backend in self:
for model in ('carepoint.medical.pharmacy',
for model in ('carepoint.carepoint.store',
# 'carepoint.res.users',
):
# import directly, do not delay because this
Expand Down
4 changes: 2 additions & 2 deletions connector_carepoint/models/carepoint_item.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class CarepointCarepointItem(models.Model):
)
store_id = fields.Many2one(
string='Store',
comodel_name='carepoint.medical.pharmacy',
comodel_name='carepoint.carepoint.store',
readonly=True,
)

Expand Down Expand Up @@ -110,7 +110,7 @@ def active(self, record):

@mapping
def store_id(self, record):
binder = self.binder_for('carepoint.medical.pharmacy')
binder = self.binder_for('carepoint.carepoint.store')
store_id = binder.to_odoo(record['store_id'])
return {'store_id': store_id}

Expand Down
Loading

0 comments on commit 3fd699a

Please sign in to comment.