From 4c5720d2a9a8771669248f8fea0891ea3e95229a Mon Sep 17 00:00:00 2001 From: Ted Salmon Date: Tue, 31 Jan 2017 18:12:30 -0800 Subject: [PATCH 1/9] Add UOMs back (+4 squashed commits) Squashed commits: [345fdd3] Allow Rx substitution using GCN if not same product [bcfe1bd] Remove required from pathology in disease [ee23f93] Fix day reference [1b47c9f] Fix bugs and usability issues identified in LABS-362 Squashed commits: [94b0b23] [IMP] medical_medicament_us: Improve nested NDC form * Create custom nested NDC form with active toggle and split groups [a8b8b33] [IMP] medical: Move active toggle to abstract entity * Move active toggle button to abstract entity button box to reduce code dup [6e50f1d] [IMP] medical_medicament_us: Add active flag * Add an active flag for NDCs to allow for more granular reporting [1ec637c] [FIX] medical_center: Move centers in patient view * Move medical centers to right group in patient view, instead of title area [b3657e5] [IMP] medical: Patient view xpaths * Switch patient view xpaths to use pre-defined entity groups to provide commonality [43451d3] [FIX] website_sale_medical_prescription: Fix gender attribute [4117591] [FIX] website_medical_patient: Fix gender attribute [038ec40] [FIX] sale_medical_prescription: Fix attributes * Fix patients assigned as partners * Fix usage of dosage quantity as order line [7a3793f] [IMP] sale_stock_medical_prescription_us: Switch to product_uom * Switch reference to use product_uom days instead of now nonexistent medicament [1ce4261] [IMP] medical_medication: Remove uom data * Remove UOM data in favor of product_uom, which contains the same thing now [9be7200] [IMP] sale_stock_medical_prescription: Change rx force context key * Change context key to force prescription dispenses from `__rx_force__` to `rx_no_validate` to match partner Id validate skip introduced in OCA/partner-contact#373 [3742154] [IMP] medical_patient_us: Activate module [b7e00e7] [FIX] medical_medicament_us: Fix GCN display (#127) * [FIX] medical_medicament_us: Fix GCN display * Add `name_get` to display GCN with prepended zero pads. * [IMP] medical_medicament_us: Change GCN to int * Updates per PR * [FIX] website_sale_medical_medicament_us: Fix GCN * Update GCN to appropriate code --- .../models/medical_medicament_ndc.py | 3 + .../views/medical_medicament_view.xml | 22 ++++- medical_medication/__manifest__.py | 3 +- medical_medication/data/product_uom.xml | 26 ++---- medical_medication/data/product_uom_categ.xml | 8 ++ .../models/medical_patient_disease.py | 1 - medical_patient_us/__manifest__.py | 2 +- oca_dependencies.txt | 1 + .../models/sale_order_line.py | 88 ++++++++++++------- .../models/__init__.py | 1 + .../models/medical_prescription_order_line.py | 2 +- .../models/sale_order_line.py | 26 ++++++ .../static/src/js/form_checkout.js | 2 +- 13 files changed, 128 insertions(+), 57 deletions(-) mode change 100755 => 100644 medical_medication/data/product_uom.xml create mode 100644 medical_medication/data/product_uom_categ.xml create mode 100644 sale_stock_medical_prescription_us/models/sale_order_line.py diff --git a/medical_medicament_us/models/medical_medicament_ndc.py b/medical_medicament_us/models/medical_medicament_ndc.py index 7ba66e691..c71addead 100644 --- a/medical_medicament_us/models/medical_medicament_ndc.py +++ b/medical_medicament_us/models/medical_medicament_ndc.py @@ -22,3 +22,6 @@ class MedicalMedicamentNdc(models.Model): comodel_name='medical.medicament', required=True, ) + active = fields.Boolean( + default=True, + ) diff --git a/medical_medicament_us/views/medical_medicament_view.xml b/medical_medicament_us/views/medical_medicament_view.xml index 5cd334d4c..185a7497d 100644 --- a/medical_medicament_us/views/medical_medicament_view.xml +++ b/medical_medicament_us/views/medical_medicament_view.xml @@ -22,7 +22,27 @@ - + +
+ + + + + + + + +
+
diff --git a/medical_medication/__manifest__.py b/medical_medication/__manifest__.py index c8cfa16b8..6e422b78e 100644 --- a/medical_medication/__manifest__.py +++ b/medical_medication/__manifest__.py @@ -19,8 +19,9 @@ "medical_medicament", ], "data": [ - "data/product_uom.xml", "data/medical_medication_dosage.xml", + "data/product_uom_categ.xml", + "data/product_uom.xml", "security/ir.model.access.csv", "views/medical_medication_dosage_view.xml", "views/medical_medication_template_view.xml", diff --git a/medical_medication/data/product_uom.xml b/medical_medication/data/product_uom.xml old mode 100755 new mode 100644 index cc7f16170..9069d386e --- a/medical_medication/data/product_uom.xml +++ b/medical_medication/data/product_uom.xml @@ -1,16 +1,7 @@ - - - + - - Litre(s) - - reference - 1.0 - mL @@ -37,43 +28,40 @@ - - Time - Hour(s) - + smaller Minute(s) - + smaller Day(s) 1.0 - + reference Month(s) - + bigger Year(s) - + bigger Indefinitely - + bigger diff --git a/medical_medication/data/product_uom_categ.xml b/medical_medication/data/product_uom_categ.xml new file mode 100644 index 000000000..bc5648971 --- /dev/null +++ b/medical_medication/data/product_uom_categ.xml @@ -0,0 +1,8 @@ + + + + + Time + + + diff --git a/medical_patient_disease/models/medical_patient_disease.py b/medical_patient_disease/models/medical_patient_disease.py index 6212d1614..16174c26e 100644 --- a/medical_patient_disease/models/medical_patient_disease.py +++ b/medical_patient_disease/models/medical_patient_disease.py @@ -27,7 +27,6 @@ class MedicalPatientDisease(models.Model): string='Pathology', comodel_name='medical.pathology', index=True, - required=True, help='Pathology (disease type) the patient was diagnosed with.', ) physician_id = fields.Many2one( diff --git a/medical_patient_us/__manifest__.py b/medical_patient_us/__manifest__.py index adc3a1a28..8ef3135a1 100644 --- a/medical_patient_us/__manifest__.py +++ b/medical_patient_us/__manifest__.py @@ -10,7 +10,7 @@ 'category': 'Medical', 'website': 'https://laslabs.com', 'licence': 'AGPL-3', - 'installable': False, + 'installable': True, 'auto_install': False, 'depends': [ 'medical', diff --git a/oca_dependencies.txt b/oca_dependencies.txt index 8af061aaf..11f72a0ab 100644 --- a/oca_dependencies.txt +++ b/oca_dependencies.txt @@ -1,4 +1,5 @@ partner-contact +product-attribute # Waiting on merge of OCA/website#270 website https://github.com/laslabs/website.git release/10.0/website_field_autocomplete_related server-tools diff --git a/sale_stock_medical_prescription/models/sale_order_line.py b/sale_stock_medical_prescription/models/sale_order_line.py index cbf8af7ed..3add89a36 100644 --- a/sale_stock_medical_prescription/models/sale_order_line.py +++ b/sale_stock_medical_prescription/models/sale_order_line.py @@ -1,17 +1,19 @@ # -*- coding: utf-8 -*- -# Copyright 2016-2017 LasLabs Inc. -# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html). +# © 2016 LasLabs Inc. +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). -from odoo import _, api, fields, models +from odoo import fields, models, api, _ from odoo.exceptions import ValidationError +import logging -class SaleOrderLine(models.Model): +_logger = logging.getLogger(__name__) + +class SaleOrderLine(models.Model): _inherit = 'sale.order.line' dispense_qty = fields.Float( - string='Dispense Quantity', default=0.0, readonly=True, store=True, @@ -19,71 +21,93 @@ class SaleOrderLine(models.Model): ) @api.multi - @api.depends('product_uom', 'prescription_order_line_id.dispense_uom_id') + @api.depends('product_uom', + 'prescription_order_line_id.dispense_uom_id', + ) def _compute_dispense_qty(self): - for record in self: - rx_line = record.prescription_order_line_id + for rec_id in self: + rx_line = rec_id.prescription_order_line_id if not rx_line: return - if record.product_uom == rx_line.dispense_uom_id: - record.dispense_qty = record.product_uom_qty + if rec_id.product_uom == rx_line.dispense_uom_id: + rec_id.dispense_qty = rec_id.product_uom_qty else: - record.dispense_qty = record.product_uom._compute_quantity( - record.product_uom_qty, + rec_id.dispense_qty = rec_id.product_uom._compute_quantity( + rec_id.product_uom_qty, rx_line.dispense_uom_id, ) @api.multi @api.constrains('product_id', 'prescription_order_line_id') def _check_product(self): - if self.env.context.get('__rx_force__'): + if self.env.context.get('rx_no_validate'): return True - for record in self: - if not record.prescription_order_line_id: + for rec_id in self: + if not rec_id.prescription_order_line_id: continue - rx_line = record.prescription_order_line_id - if rx_line.medicament_id.product_id != record.product_id: + rx_line = rec_id.prescription_order_line_id + if rx_line.medicament_id.product_id != rec_id.product_id: if not rx_line.is_substitutable: raise ValidationError(_( 'Products must be same on Order and Rx lines. ' 'Got %s on order line %s, expected %s from %r' ) % ( - record.product_id.name, record.name, + rec_id.product_id.name, rec_id.name, rx_line.medicament_id.product_id.name, rx_line, )) else: + # @TODO: implement determination for what drugs can be + # substituted pass + @api.multi + @api.constrains('patient_id', 'prescription_order_line_id') + def _check_patient(self): + if self.env.context.get('rx_no_validate'): + return True + for rec_id in self: + if not rec_id.prescription_order_line_id: + continue + rx_line = rec_id.prescription_order_line_id + if rec_id.patient_id != rx_line.patient_id: + raise ValidationError(_( + 'Patients must be same on Order and Rx lines. ' + 'Got %s on order line %d, expected %s from rx line %d' + ) % ( + rec_id.patient_id.name, rec_id.id, + rx_line.patient_id.name, rx_line.id, + )) + @api.multi @api.constrains('dispense_qty', 'prescription_order_line_id', 'state') def _check_can_dispense(self): - if self.env.context.get('__rx_force__'): + if self.env.context.get('rx_no_validate'): return True - for record in self: + for rec_id in self: conditions = [ - record.product_id.is_medicament, - record.prescription_order_line_id, + rec_id.product_id.is_medicament, + rec_id.prescription_order_line_id, ] if not all(conditions): continue - rx_line = record.prescription_order_line_id + rx_line = rec_id.prescription_order_line_id if not rx_line.can_dispense: raise ValidationError(_( 'Cannot dispense %s because there are related, ' 'pending order(s). \n' 'Currently %.2f processed %.2f pending %.2f exception' ) % ( - record.dispense_qty, + rec_id.dispense_qty, rx_line.dispensed_qty, rx_line.pending_dispense_qty, rx_line.exception_dispense_qty, )) - if record.dispense_qty > rx_line.can_dispense_qty: + if rec_id.dispense_qty > rx_line.can_dispense_qty: raise ValidationError(_( 'Cannot dispense - %s goes over Rx qty by %d' ) % ( - record.name, - record.dispense_qty - rx_line.can_dispense_qty + rec_id.name, + rec_id.dispense_qty - rx_line.can_dispense_qty )) @api.multi @@ -93,16 +117,16 @@ def _prepare_order_line_procurement(self, group_id=False): group_id=group_id ) if self.product_id.is_medicament: - medicament = self.env['medical.medicament'].get_by_product( + medicament_id = self.env['medical.medicament'].get_by_product( self.product_id, ) - warehouse = self.order_id.warehouse_id - if medicament.is_prescription: + warehouse_id = self.order_id.warehouse_id + if medicament_id.is_prescription: res['route_ids'] = [ - (6, 0, [warehouse.prescription_route_id.id]) + (6, 0, [warehouse_id.prescription_route_id.id]) ] else: res['route_ids'] = [ - (6, 0, [warehouse.otc_route_id.id]) + (6, 0, [warehouse_id.otc_route_id.id]) ] return res diff --git a/sale_stock_medical_prescription_us/models/__init__.py b/sale_stock_medical_prescription_us/models/__init__.py index 1cf2bba0f..9e4106c83 100644 --- a/sale_stock_medical_prescription_us/models/__init__.py +++ b/sale_stock_medical_prescription_us/models/__init__.py @@ -5,3 +5,4 @@ from . import procurement_order from . import medical_prescription_order_line from . import res_company +from . import sale_order_line diff --git a/sale_stock_medical_prescription_us/models/medical_prescription_order_line.py b/sale_stock_medical_prescription_us/models/medical_prescription_order_line.py index 377daf954..0866e57fa 100644 --- a/sale_stock_medical_prescription_us/models/medical_prescription_order_line.py +++ b/sale_stock_medical_prescription_us/models/medical_prescription_order_line.py @@ -42,7 +42,7 @@ class MedicalPrescriptionOrderLine(models.Model): @api.multi def _compute_dispense_remain(self): - day_uom_id = self.env.ref('medical_medication.product_uom_day') + day_uom_id = self.env.ref('product_uom.product_uom_day') for record in self: if not record.duration_uom_id or record.duration <= 0: diff --git a/sale_stock_medical_prescription_us/models/sale_order_line.py b/sale_stock_medical_prescription_us/models/sale_order_line.py new file mode 100644 index 000000000..8629622b2 --- /dev/null +++ b/sale_stock_medical_prescription_us/models/sale_order_line.py @@ -0,0 +1,26 @@ +# -*- coding: utf-8 -*- +# Copyright 2017 LasLabs Inc. +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from odoo import api, models +from odoo.exceptions import ValidationError + + +class SaleOrderLine(models.Model): + _inherit = 'sale.order.line' + + @api.multi + @api.constrains('product_id', 'prescription_order_line_id') + def _check_product(self): + if self.env.context.get('rx_no_validate'): + return True + for record in self: + try: + super(SaleOrderLine, self)._check_product() + except ValidationError: + gcn = record.prescription_order_line_id.medicament_id.gcn_id + equivalents = self.env['medical.medicament'].search([ + ('gcn_id', '=', gcn.id), + ]) + if record.product_id not in equivalents.mapped('product_id'): + raise diff --git a/website_sale_medical_prescription/static/src/js/form_checkout.js b/website_sale_medical_prescription/static/src/js/form_checkout.js index 830903e17..bf149018e 100644 --- a/website_sale_medical_prescription/static/src/js/form_checkout.js +++ b/website_sale_medical_prescription/static/src/js/form_checkout.js @@ -32,7 +32,7 @@ odoo.define('website_sale_medical_prescription.form_checkout', function(require) var $target = $(event.currentTarget); var $isPreg = $target.parents('.js_medical_prescription_patient') .find('.js_medical_prescription_is_pregnant'); - if ($target.val() == 'f') { + if ($target.val() == 'female') { $isPreg.removeClass('hidden').prop('disabled', false); } else { $isPreg.addClass('hidden').prop('disabled', true).prop('checked', false); From a3a23c816b761a8ce007f66aaa73e8846af15316 Mon Sep 17 00:00:00 2001 From: Dave Lasley Date: Tue, 18 Jul 2017 12:28:10 -0700 Subject: [PATCH 2/9] Missed a uom --- .../models/medical_prescription_order_line.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sale_stock_medical_prescription_us/models/medical_prescription_order_line.py b/sale_stock_medical_prescription_us/models/medical_prescription_order_line.py index 0866e57fa..377daf954 100644 --- a/sale_stock_medical_prescription_us/models/medical_prescription_order_line.py +++ b/sale_stock_medical_prescription_us/models/medical_prescription_order_line.py @@ -42,7 +42,7 @@ class MedicalPrescriptionOrderLine(models.Model): @api.multi def _compute_dispense_remain(self): - day_uom_id = self.env.ref('product_uom.product_uom_day') + day_uom_id = self.env.ref('medical_medication.product_uom_day') for record in self: if not record.duration_uom_id or record.duration <= 0: From 532e889939bf69e7b1f7def33cab9e8145d56f97 Mon Sep 17 00:00:00 2001 From: Dave Lasley Date: Thu, 27 Jul 2017 14:43:55 -0700 Subject: [PATCH 3/9] Remove luhn method --- medical_patient_us/models/res_partner.py | 8 -------- 1 file changed, 8 deletions(-) diff --git a/medical_patient_us/models/res_partner.py b/medical_patient_us/models/res_partner.py index 33b3dfa1a..a7e963d17 100644 --- a/medical_patient_us/models/res_partner.py +++ b/medical_patient_us/models/res_partner.py @@ -42,11 +42,3 @@ class ResPartner(models.Model): ), help='US Passport - 9 digits', ) - - @api.multi - @api.constrains('country_id', 'ref', 'type') - def _check_ref(self): - """ Implement Luhns Formula to validate social security numbers """ - for rec_id in self: - if rec_id.type == 'medical.patient' and rec_id.ref: - rec_id._luhn_constrains_helper('ref') From 5c0d796aadabb6e52f581cb115045c3520ab3f3f Mon Sep 17 00:00:00 2001 From: Dave Lasley Date: Thu, 27 Jul 2017 14:46:32 -0700 Subject: [PATCH 4/9] Remove choose prescription option --- .../views/medical_prescription_order_template.xml | 1 - 1 file changed, 1 deletion(-) diff --git a/website_sale_medical_prescription/views/medical_prescription_order_template.xml b/website_sale_medical_prescription/views/medical_prescription_order_template.xml index c3b7c9e39..bc43b3947 100644 --- a/website_sale_medical_prescription/views/medical_prescription_order_template.xml +++ b/website_sale_medical_prescription/views/medical_prescription_order_template.xml @@ -96,7 +96,6 @@ class="form-control js_medical_prescription o_website_form_input" required="required" > -