-
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.
[ADD] connector_carepoint: Account export
* Add patient account export logic and tests
- Loading branch information
Showing
9 changed files
with
436 additions
and
109 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 was deleted.
Oops, something went wrong.
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,164 @@ | ||
# -*- 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, api | ||
from openerp.addons.connector.connector import ConnectorUnit | ||
from openerp.addons.connector.unit.mapper import (mapping, | ||
ExportMapper, | ||
) | ||
from ..unit.backend_adapter import CarepointCRUDAdapter | ||
from ..unit.mapper import CarepointImportMapper | ||
from ..backend import carepoint | ||
from ..unit.import_synchronizer import (DelayedBatchImporter, | ||
CarepointImporter, | ||
) | ||
from ..unit.export_synchronizer import CarepointExporter | ||
|
||
_logger = logging.getLogger(__name__) | ||
|
||
|
||
class CarepointCarepointAccount(models.Model): | ||
_name = 'carepoint.carepoint.account' | ||
_inherit = 'carepoint.binding' | ||
_inherits = {'carepoint.account': 'odoo_id'} | ||
_description = 'Carepoint CarepointAccount' | ||
_cp_lib = 'account' | ||
|
||
odoo_id = fields.Many2one( | ||
string='CarepointAccount', | ||
comodel_name='carepoint.account', | ||
required=True, | ||
ondelete='restrict', | ||
) | ||
|
||
|
||
class CarepointAccount(models.Model): | ||
_name = 'carepoint.account' | ||
_description = 'CarePoint CarepointAccount' | ||
|
||
patient_id = fields.Many2one( | ||
string='Patient', | ||
comodel_name='medical.patient', | ||
) | ||
carepoint_bind_ids = fields.One2many( | ||
comodel_name='carepoint.carepoint.account', | ||
inverse_name='odoo_id', | ||
string='Carepoint Bindings', | ||
) | ||
|
||
@api.model | ||
def _get_by_patient(self, patient, create=True, recurse=False): | ||
""" It returns the account associated to the patient. | ||
Params: | ||
patient: Recordset singleton of partner to search for | ||
create: Bool determining whether to create account if not exist | ||
recurse: Bool determining whether to recurse into children (this | ||
is only functional when create=True) | ||
Return: | ||
Recordset of patient account | ||
""" | ||
account = self.search([('patient_id', '=', patient.id)], limit=1) | ||
if not create: | ||
return account | ||
if not account: | ||
account = self.create({ | ||
'patient_id': patient.id, | ||
}) | ||
if recurse: | ||
children = self.env['medical.patient'].search([ | ||
('partner_id', 'in', patient.child_ids.ids), | ||
]) | ||
for child in children: | ||
self._get_by_patient(child, create, recurse) | ||
return account | ||
|
||
|
||
@carepoint | ||
class CarepointAccountAdapter(CarepointCRUDAdapter): | ||
_model_name = 'carepoint.carepoint.account' | ||
|
||
|
||
@carepoint | ||
class CarepointAccountUnit(ConnectorUnit): | ||
_model_name = 'carepoint.carepoint.account' | ||
|
||
def _import_accounts(self, patient_id): | ||
adapter = self.unit_for(CarepointAccountAdapter) | ||
importer = self.unit_for(CarepointAccountImporter) | ||
accounts = adapter.search(pat_id=patient_id) | ||
for account in accounts: | ||
importer.run(account) | ||
|
||
|
||
@carepoint | ||
class CarepointAccountBatchImporter(DelayedBatchImporter): | ||
""" Import the Carepoint CarepointAccounts. | ||
For every product category in the list, a delayed job is created. | ||
Import from a date | ||
""" | ||
_model_name = ['carepoint.carepoint.account'] | ||
|
||
|
||
@carepoint | ||
class CarepointAccountImportMapper(CarepointImportMapper): | ||
_model_name = 'carepoint.carepoint.account' | ||
direct = [] | ||
|
||
@mapping | ||
def patient_id(self, record): | ||
binder = self.binder_for('carepoint.medical.patient') | ||
patient_id = binder.to_odoo(record['pat_id']) | ||
return {'patient_id': patient_id} | ||
|
||
@mapping | ||
def carepoint_id(self, record): | ||
return {'carepoint_id': '%s,%s' % (record['pat_id'], record['ID'])} | ||
|
||
|
||
@carepoint | ||
class CarepointAccountImporter(CarepointImporter): | ||
_model_name = ['carepoint.carepoint.account'] | ||
_base_mapper = CarepointAccountImportMapper | ||
|
||
def _import_dependencies(self): | ||
""" Import depends for record """ | ||
record = self.carepoint_record | ||
self._import_dependency(record['pat_id'], | ||
'carepoint.medical.patient') | ||
|
||
|
||
@carepoint | ||
class CarepointAccountExportMapper(ExportMapper): | ||
_model_name = 'carepoint.carepoint.account' | ||
direct = [] | ||
|
||
@mapping | ||
def pat_id(self, binding): | ||
binder = self.binder_for('carepoint.medical.patient') | ||
patient_id = binder.to_backend(binding.patient_id) | ||
return {'pat_id': patient_id} | ||
|
||
@mapping | ||
def ID(self, binding): | ||
return {'ID': binding.carepoint_id} | ||
|
||
@mapping | ||
def static_defaults(self, binding): | ||
return { | ||
'acct_type_cn': 0, | ||
'resp_pty_yn': 0, | ||
'chromis_id': None, | ||
} | ||
|
||
|
||
@carepoint | ||
class CarepointAccountExporter(CarepointExporter): | ||
_model_name = 'carepoint.carepoint.account' | ||
_base_mapper = CarepointAccountExportMapper | ||
|
||
def _export_dependencies(self): | ||
""" Export depends for a record """ | ||
self._export_dependency(self.binding_record.patient_id, | ||
'carepoint.medical.patient') |
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
Oops, something went wrong.