Skip to content

Commit

Permalink
[ADD] connector_carepoint: Add model tests
Browse files Browse the repository at this point in the history
* medical_pharmacy
* procurement_order
* fdb_unit
* account_invoice_line
  • Loading branch information
lasley committed Aug 11, 2016
1 parent cadff65 commit e98c7e6
Show file tree
Hide file tree
Showing 12 changed files with 1,210 additions and 175 deletions.
46 changes: 0 additions & 46 deletions connector_carepoint/models/account_invoice_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from openerp import models, fields
from openerp.addons.connector.connector import ConnectorUnit
from openerp.addons.connector.unit.mapper import (mapping,
changed_by,
only_create,
ExportMapper,
)
Expand All @@ -18,7 +17,6 @@
)
from ..unit.export_synchronizer import (CarepointExporter)
from ..unit.delete_synchronizer import (CarepointDeleter)
from ..connector import add_checkpoint
from .procurement_order import ProcurementOrderUnit


Expand Down Expand Up @@ -95,14 +93,6 @@ class AccountInvoiceLineBatchImporter(DelayedBatchImporter):
"""
_model_name = ['carepoint.account.invoice.line']

def run(self, filters=None):
""" Run the synchronization """
if filters is None:
filters = {}
record_ids = self.backend_adapter.search(**filters)
for record_id in record_ids:
self._import_record(record_id)


@carepoint
class AccountInvoiceLineImportMapper(CarepointImportMapper):
Expand Down Expand Up @@ -158,12 +148,6 @@ class AccountInvoiceLineImporter(CarepointImporter):

_base_mapper = AccountInvoiceLineImportMapper

def _create(self, data):
binding = super(AccountInvoiceLineImporter, self)._create(data)
checkpoint = self.unit_for(AccountInvoiceLineAddCheckpoint)
checkpoint.run(binding.id)
return binding

def _import_dependencies(self):
""" Import depends for record """
record = self.carepoint_record
Expand Down Expand Up @@ -206,22 +190,6 @@ def _after_import(self, binding):
class AccountInvoiceLineExportMapper(ExportMapper):
_model_name = 'carepoint.account.invoice.line'

direct = [
('ref', 'ssn'),
('email', 'email'),
('dob', 'birth_date'),
('dod', 'death_date'),
]

@mapping
def pat_id(self, record):
return {'pat_id': record.carepoint_id}

@changed_by('gender')
@mapping
def gender_cd(self, record):
return {'gender_cd': record.get('gender').upper()}


@carepoint
class AccountInvoiceLineExporter(CarepointExporter):
Expand All @@ -232,17 +200,3 @@ class AccountInvoiceLineExporter(CarepointExporter):
@carepoint
class AccountInvoiceLineDeleteSynchronizer(CarepointDeleter):
_model_name = ['carepoint.account.invoice.line']


@carepoint
class AccountInvoiceLineAddCheckpoint(ConnectorUnit):
""" Add a connector.checkpoint on the carepoint.account.invoice.line
record
"""
_model_name = ['carepoint.account.invoice.line', ]

def run(self, binding_id):
add_checkpoint(self.session,
self.model._name,
binding_id,
self.backend_record.id)
47 changes: 16 additions & 31 deletions connector_carepoint/models/fdb_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,13 @@
import logging
from os import path
from openerp import models, fields
from openerp.addons.connector.queue.job import job
from openerp.addons.connector.unit.mapper import (mapping,
only_create,
)
from ..unit.backend_adapter import CarepointCRUDAdapter
from ..unit.mapper import (CarepointImportMapper,
trim,
)
from ..connector import get_environment
from ..backend import carepoint
from ..unit.import_synchronizer import (DelayedBatchImporter,
CarepointImporter,
Expand Down Expand Up @@ -69,14 +67,6 @@ class FdbUnitBatchImporter(DelayedBatchImporter):
"""
_model_name = ['carepoint.fdb.unit']

def run(self, filters=None):
""" Run the synchronization """
if filters is None:
filters = {}
record_ids = self.backend_adapter.search(**filters)
for record_id in record_ids:
self._import_record(record_id)


@carepoint
class FdbUnitImportMapper(CarepointImportMapper):
Expand All @@ -91,16 +81,8 @@ class FdbUnitImportMapper(CarepointImportMapper):
def carepoint_id(self, record):
return {'carepoint_id': record['str'].strip()}

@mapping
@only_create
def uom_id(self, record):

unit_base = ureg(record['str60'].strip())
unit_base_str = str(unit_base.u)
unit_root = infer_base_unit(unit_base)
unit_root_str = str(unit_root)
unit_converted = unit_base.to(unit_root)

def _uom_category_id(self, unit_root_str):
""" Find or create a UOM category """
categ_obj = self.env['product.uom.categ']
categ_id = categ_obj.search([
('name', '=', unit_root_str),
Expand All @@ -111,13 +93,26 @@ def uom_id(self, record):
categ_id = categ_obj.create({
'name': unit_root_str,
})
return categ_id

@mapping
@only_create
def uom_id(self, record):

unit_base = ureg(record['str60'].strip())
unit_base_str = str(unit_base.u)
unit_root = infer_base_unit(unit_base)
unit_root_str = str(unit_root)
unit_converted = unit_base.to(unit_root)

categ_id = self._uom_category_id(unit_root_str)

uom_obj = self.env['product.uom']
uom_id = uom_obj.search([
('name', '=', unit_base_str),
])
if len(uom_id):
return {'uom_id': uom_id.id}
return {'uom_id': uom_id[0].id}

vals = {
'name': record['str'].strip(),
Expand Down Expand Up @@ -161,13 +156,3 @@ def uom_id(self, record):
class FdbUnitImporter(CarepointImporter):
_model_name = ['carepoint.fdb.unit']
_base_mapper = FdbUnitImportMapper


@job(default_channel='root.carepoint.fdb')
def fdb_unit_import_batch(session, model_name, backend_id, filters=None):
""" Prepare the import of Units from Carepoint """
if filters is None:
filters = {}
env = get_environment(session, model_name, backend_id)
importer = env.get_connector_unit(FdbUnitBatchImporter)
importer.run(filters=filters)
13 changes: 1 addition & 12 deletions connector_carepoint/models/medical_prescription_order_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,6 @@ class MedicalPrescriptionOrderLineBatchImporter(DelayedBatchImporter):
"""
_model_name = ['carepoint.medical.prescription.order.line']

def run(self, filters=None):
""" Run the synchronization """
if filters is None:
filters = {}
record_ids = self.backend_adapter.search(**filters)
for record_id in record_ids:
self._import_record(record_id)


@carepoint
class MedicalPrescriptionOrderLineImportMapper(CarepointImportMapper):
Expand All @@ -98,6 +90,7 @@ class MedicalPrescriptionOrderLineImportMapper(CarepointImportMapper):
('freq_of_admin', 'frequency'),
('units_entered', 'quantity'),
('refills_left', 'refill_qty_remain'),
('refills_orig', 'refill_qty_original')
]

@mapping
Expand All @@ -108,10 +101,6 @@ def name(self, record):
)
return {'name': name}

@mapping
def refill_qty_original(self, record):
return {'refill_qty_original': (record['refills_orig'] or 0) + 1}

@mapping
@only_create
def duration(self, record):
Expand Down
76 changes: 20 additions & 56 deletions connector_carepoint/models/procurement_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

import logging
from openerp import models, fields
from openerp.addons.connector.queue.job import job
from openerp.addons.connector.connector import ConnectorUnit
from openerp.addons.connector.unit.mapper import (mapping,
only_create,
Expand All @@ -15,7 +14,6 @@
from ..unit.import_synchronizer import (DelayedBatchImporter,
CarepointImporter,
)
from ..connector import add_checkpoint, get_environment


_logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -75,17 +73,17 @@ class ProcurementOrderAdapter(CarepointCRUDAdapter):
class ProcurementOrderUnit(ConnectorUnit):
_model_name = 'carepoint.procurement.order'

def __get_order_lines(self, sale_order_id):
def _get_order_lines(self, sale_order_id):
adapter = self.unit_for(CarepointCRUDAdapter)
return adapter.search(order_id=sale_order_id)

def _import_procurements_for_sale(self, sale_order_id):
importer = self.unit_for(ProcurementOrderImporter)
for rec_id in self.__get_order_lines(sale_order_id):
for rec_id in self._get_order_lines(sale_order_id):
importer.run(rec_id)

def _get_order_line_count(self, sale_order_id):
return len(self.__get_order_lines(sale_order_id))
return len(self._get_order_lines(sale_order_id))


@carepoint
Expand All @@ -95,14 +93,6 @@ class ProcurementOrderBatchImporter(DelayedBatchImporter):
"""
_model_name = ['carepoint.procurement.order']

def run(self, filters=None):
""" Run the synchronization """
if filters is None:
filters = {}
record_ids = self.backend_adapter.search(**filters)
for record_id in record_ids:
self._import_record(record_id)


@carepoint
class ProcurementOrderImportMapper(CarepointImportMapper):
Expand All @@ -114,10 +104,9 @@ class ProcurementOrderImportMapper(CarepointImportMapper):
]

@mapping
def prescription_data(self, record):
def name(self, record):
binder = self.binder_for('carepoint.medical.prescription.order.line')
rx_id = binder.to_odoo(record['rx_id'])
rx_id = self.env['medical.prescription.order.line'].browse(rx_id)
rx_id = binder.to_odoo(record['rx_id'], browse=True)
name = 'RX %s - %s' % (record['rx_id'],
rx_id.medicament_id.display_name)
return {'name': name}
Expand All @@ -138,7 +127,11 @@ def order_line_procurement_data(self, record):
line_id = line_id[0]

# Set the sale line to what was dispensed
line_id.product_id = ndc_id.medicament_id.product_id.id
# This is a hack circumventing lack of qty in CP until now
line_id.write({
'product_id': ndc_id.medicament_id.product_id.id,
'product_uom_qty': record['dispense_qty'],
})

procurement_group_id = self.env['procurement.group'].search([
('name', '=', sale_id.name),
Expand All @@ -152,11 +145,10 @@ def order_line_procurement_data(self, record):
sale_id.procurement_group_id = procurement_group_id.id

res = line_id._prepare_order_line_procurement(procurement_group_id.id)
line_id.product_uom_qty = record['dispense_qty']
res.update({'origin': sale_id.name,
'product_uom': line_id.product_uom.id,
'ndc_id': ndc_id.id,
'product_id': ndc_id.medicament_id.product_id.id,
'product_id': line_id.product_id,
})

return res
Expand All @@ -172,12 +164,6 @@ class ProcurementOrderImporter(CarepointImporter):

_base_mapper = ProcurementOrderImportMapper

def _create(self, data):
binding = super(ProcurementOrderImporter, self)._create(data)
checkpoint = self.unit_for(ProcurementOrderAddCheckpoint)
checkpoint.run(binding.id)
return binding

def _import_dependencies(self):
""" Import depends for record """
record = self.carepoint_record
Expand All @@ -188,14 +174,16 @@ def _import_dependencies(self):
self._import_dependency(record['order_id'],
'carepoint.sale.order')

def _after_import(self, binding):
""" Import the stock pickings & invoice lines if all lines imported"""
self.binder_for('carepoint.sale.order')
# def _after_import(self, binding):
# """ Import the stock pickings & invoice lines if all lines
# imported
# """
# self.binder_for('carepoint.sale.order')
# sale_id = binder.to_odoo(self.carepoint_record['order_id'])
proc_unit = self.unit_for(
ProcurementOrderUnit, model='carepoint.procurement.order',
)
proc_unit._get_order_line_count(self.carepoint_record['order_id'])
# proc_unit = self.unit_for(
# ProcurementOrderUnit, model='carepoint.procurement.order',
# )
# proc_unit._get_order_line_count(self.carepoint_record['order_id'])
# if len(binding.sale_line_id.order_id.order_line) == line_cnt:
# record = self.carepoint_record
# picking_unit = self.unit_for(
Expand All @@ -211,27 +199,3 @@ def _after_import(self, binding):
# invoice_unit._import_invoice_lines_for_procurement(
# record['rxdisp_id'], binding.id,
# )


@carepoint
class ProcurementOrderAddCheckpoint(ConnectorUnit):
""" Add a connector.checkpoint on the
carepoint.procurement.order record
"""
_model_name = ['carepoint.procurement.order', ]

def run(self, binding_id):
add_checkpoint(self.session,
self.model._name,
binding_id,
self.backend_record.id)


@job(default_channel='root.carepoint.patient')
def patient_import_batch(session, model_name, backend_id, filters=None):
""" Prepare the import of patients modified on Carepoint """
if filters is None:
filters = {}
env = get_environment(session, model_name, backend_id)
importer = env.get_connector_unit(ProcurementOrderBatchImporter)
importer.run(filters=filters)
1 change: 0 additions & 1 deletion connector_carepoint/models/res_users.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ def employee(self, record):
def odoo_id(self, record):
""" Will bind the user on a existing user
with the same name & email """
self._get_name(record)
user_id = self.env['res.users'].search([
('login', 'ilike', record.get('login_name')),
],
Expand Down
6 changes: 3 additions & 3 deletions connector_carepoint/models/sale_order_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,17 +75,17 @@ class SaleOrderLineAdapter(CarepointCRUDAdapter):
class SaleOrderLineUnit(ConnectorUnit):
_model_name = 'carepoint.sale.order.line'

def __get_order_lines(self, sale_order_id):
def _get_order_lines(self, sale_order_id):
adapter = self.unit_for(CarepointCRUDAdapter)
return adapter.search(order_id=sale_order_id)

def _import_sale_order_lines(self, sale_order_id):
importer = self.unit_for(SaleOrderLineImporter)
for rec_id in self.__get_order_lines(sale_order_id):
for rec_id in self._get_order_lines(sale_order_id):
importer.run(rec_id)

def _get_order_line_count(self, sale_order_id):
return len(self.__get_order_lines(sale_order_id))
return len(self._get_order_lines(sale_order_id))


@carepoint
Expand Down
Loading

0 comments on commit e98c7e6

Please sign in to comment.