-
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: Inventory handling
* Restructure medicament and rename to carepoint.item * Add stock.warehouse & add to medical.pharmacy depends * Add carepoint vendor
- Loading branch information
Showing
29 changed files
with
1,226 additions
and
524 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,8 @@ addons: | |
- python-simplejson | ||
- python-serial | ||
- python-yaml | ||
- sqlite3 | ||
- libsqlite3-dev | ||
|
||
env: | ||
global: | ||
|
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
19 changes: 6 additions & 13 deletions
19
connector_carepoint/data/carepoint_carepoint_account_data.xml
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 |
---|---|---|
@@ -1,16 +1,9 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<openerp> | ||
<data noupdate="1"> | ||
<odoo noupdate="1"> | ||
|
||
<record model="medical.patient" id="patient_null"> | ||
<field name="name">Null Patient</field> | ||
<field name="active" eval="False" /> | ||
</record> | ||
|
||
<record model="carepoint.carepoint.account" id="account_null"> | ||
<field name="patient_id" ref="connector_carepoint.patient_null" /> | ||
<field name="carepoint_id">0</field> | ||
</record> | ||
<record model="medical.patient" id="patient_null"> | ||
<field name="name">Null Patient</field> | ||
<field name="active" eval="False" /> | ||
</record> | ||
|
||
</data> | ||
</openerp> | ||
</odoo> |
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,178 @@ | ||
# -*- 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.unit.mapper import (mapping, | ||
only_create, | ||
changed_by, | ||
ExportMapper, | ||
) | ||
from ..unit.backend_adapter import CarepointCRUDAdapter | ||
from ..unit.mapper import CarepointImportMapper, trim | ||
from ..backend import carepoint | ||
from ..unit.import_synchronizer import (DelayedBatchImporter, | ||
CarepointImporter, | ||
) | ||
from ..unit.export_synchronizer import CarepointExporter | ||
|
||
_logger = logging.getLogger(__name__) | ||
|
||
|
||
class CarepointCarepointItem(models.Model): | ||
_name = 'carepoint.carepoint.item' | ||
_inherit = 'carepoint.binding' | ||
_inherits = {'carepoint.item': 'odoo_id'} | ||
_description = 'Carepoint Item' | ||
_cp_lib = 'item' # Name of model in Carepoint lib (snake_case) | ||
|
||
odoo_id = fields.Many2one( | ||
string='Item', | ||
comodel_name='carepoint.item', | ||
required=True, | ||
ondelete='restrict', | ||
) | ||
store_id = fields.Many2one( | ||
string='Store', | ||
comodel_name='carepoint.medical.pharmacy', | ||
readonly=True, | ||
) | ||
|
||
|
||
class CarepointItem(models.Model): | ||
_name = 'carepoint.item' | ||
_inherits = {'medical.medicament': 'medicament_id'} | ||
|
||
medicament_id = fields.Many2one( | ||
string='Medicament', | ||
comodel_name='medical.medicament', | ||
ondelete='cascade', | ||
required=True, | ||
) | ||
warehouse_id = fields.Many2one( | ||
string='Warehouse', | ||
comodel_name='stock.warehouse', | ||
required=True, | ||
) | ||
carepoint_bind_ids = fields.One2many( | ||
comodel_name='carepoint.carepoint.item', | ||
inverse_name='odoo_id', | ||
string='Carepoint Bindings', | ||
) | ||
store_on_hand = fields.Float( | ||
compute="_compute_store_qty", | ||
) | ||
store_on_order = fields.Float( | ||
compute="_compute_store_qty", | ||
) | ||
|
||
@api.multi | ||
def _compute_store_qty(self): | ||
""" Return the current quantity for one product. | ||
Can be inherited to change the way the quantity is computed, | ||
according to a backend / location. | ||
:returns: dict of quantity fields | ||
""" | ||
self.ensure_one() | ||
context_product = product.with_context(warehouse=warehouse.id) | ||
avail = context_product._product_available() | ||
return avail.values()[0] | ||
|
||
|
||
@carepoint | ||
class CarepointItemAdapter(CarepointCRUDAdapter): | ||
_model_name = 'carepoint.carepoint.item' | ||
|
||
|
||
@carepoint | ||
class CarepointItemBatchImporter(DelayedBatchImporter): | ||
""" Import the Carepoint Items. | ||
For every product category in the list, a delayed job is created. | ||
Import from a date | ||
""" | ||
_model_name = ['carepoint.carepoint.item'] | ||
|
||
|
||
@carepoint | ||
class CarepointItemImportMapper(CarepointImportMapper): | ||
_model_name = 'carepoint.carepoint.item' | ||
|
||
direct = [ | ||
(trim('DESCR'), 'name'), | ||
(trim('UPCCODE'), 'barcode'), | ||
('add_date', 'created_at'), | ||
('chg_date', 'updated_at'), | ||
] | ||
|
||
@mapping | ||
def active(self, record): | ||
"""Check if the product is active in Carepoint | ||
and set active flag in OpenERP | ||
status == 1 in Carepoint means active""" | ||
return {'active': (record.get('ACTIVE_YN') == 1)} | ||
|
||
@mapping | ||
def store_id(self, record): | ||
binder = self.binder_for('carepoint.medical.pharmacy') | ||
store_id = binder.to_odoo(record['store_id']) | ||
return {'store_id': store_id} | ||
|
||
@mapping | ||
def warehouse_id(self, record): | ||
binder = self.binder_for('carepoint.stock.warehouse') | ||
store_id = binder.to_odoo(record['store_id']) | ||
return {'warehouse_id': store_id} | ||
|
||
@mapping | ||
def carepoint_id(self, record): | ||
return {'carepoint_id': record['item_id']} | ||
|
||
@mapping | ||
@only_create | ||
def odoo_id(self, record): | ||
""" It binds on a medicament of an existing NDC """ | ||
ndc_id = self.env['fdb.ndc'].search( | ||
[('name', '=', record['NDC'].strip())], | ||
limit=1, | ||
) | ||
if len(ndc_id): | ||
return {'odoo_id': ndc_id[0].medicament_id.id} | ||
|
||
|
||
@carepoint | ||
class CarepointItemImporter(CarepointImporter): | ||
_model_name = ['carepoint.carepoint.item'] | ||
|
||
_base_mapper = CarepointItemImportMapper | ||
|
||
def _import_dependencies(self): | ||
""" Import depends for record """ | ||
record = self.carepoint_record | ||
self._import_dependency(record['NDC'].strip(), | ||
'carepoint.fdb.ndc.cs.ext') | ||
self._import_dependency(record['NDC'].strip(), | ||
'carepoint.fdb.ndc') | ||
self._import_dependency(record['VENDOR'].strip(), | ||
'carepoint.carepoint.vendor') | ||
|
||
|
||
@carepoint | ||
class CarepointItemExportMapper(ExportMapper): | ||
_model_name = 'carepoint.carepoint.item' | ||
|
||
direct = [ | ||
('name', 'DESCR'), | ||
('barcode', 'UPCCODE'), | ||
] | ||
|
||
@mapping | ||
@changed_by('active') | ||
def active_yn(self, record): | ||
return {'ACTIVE_YN': record.active} | ||
|
||
|
||
@carepoint | ||
class CarepointItemExporter(CarepointExporter): | ||
_model_name = ['carepoint.carepoint.item'] | ||
_base_mapper = CarepointItemExportMapper |
Oops, something went wrong.