Skip to content

Commit

Permalink
Add UOMs back (+4 squashed commits)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Ted Salmon authored and lasley committed Jul 10, 2017
1 parent 5f20e7a commit b27fb30
Show file tree
Hide file tree
Showing 13 changed files with 128 additions and 57 deletions.
3 changes: 3 additions & 0 deletions medical_medicament_us/models/medical_medicament_ndc.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,6 @@ class MedicalMedicamentNdc(models.Model):
comodel_name='medical.medicament',
required=True,
)
active = fields.Boolean(
default=True,
)
22 changes: 21 additions & 1 deletion medical_medicament_us/views/medical_medicament_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,27 @@
</group>
<group string="Identifiers">
<field name="gcn_id" context="{'default_medicament_ids': [(4, id)]}" />
<field name="ndc_ids" context="{'default_medicament_id': id}" />
<field name="ndc_ids" context="{'default_medicament_id': id}">
<form string="NDC">
<button name="toggle_active"
type="object"
class="oe_stat_button"
icon="fa-archive"
>
<field name="active"
widget="boolean_button"
options='{"terminology": "archive"}'
/>
</button>
<group>
<field name="name" />
<field name="manufacturer_id" />
</group>
<group>
<field name="medicament_id" />
</group>
</form>
</field>
</group>
</page>
</xpath>
Expand Down
3 changes: 2 additions & 1 deletion medical_medication/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
26 changes: 7 additions & 19 deletions medical_medication/data/product_uom.xml
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,16 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright 2016 LasLabs Inc.
License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). -->

<odoo>
<odoo noupdate="1">

<!-- Volume -->
<record id="product_uom_litre" model="product.uom">
<field name="name">Litre(s)</field>
<field name="category_id" ref="product.product_uom_categ_vol"/>
<field name="uom_type">reference</field>
<field name="factor">1.0</field>
</record>
<record id="product_uom_ml" model="product.uom">
<field name="name">mL</field>
<field name="category_id" ref="product.product_uom_categ_vol"/>
Expand All @@ -37,43 +28,40 @@
</record>

<!-- Time -->
<record id="product_uom_categ_time" model="product.uom.categ">
<field name="name">Time</field>
</record>
<record id="product_uom_hour" model="product.uom">
<field name="name">Hour(s)</field>
<field name="factor" eval="24"/>
<field name="category_id" ref="product_uom_categ_time"/>
<field name="category_id" ref="product_uom_category_time"/>
<field name="uom_type">smaller</field>
</record>
<record id="product_uom_minute" model="product.uom">
<field name="name">Minute(s)</field>
<field name="factor" eval="1440"/>
<field name="category_id" ref="product_uom_categ_time"/>
<field name="category_id" ref="product_uom_category_time"/>
<field name="uom_type">smaller</field>
</record>
<record id="product_uom_day" model="product.uom">
<field name="name">Day(s)</field>
<field name="factor">1.0</field>
<field name="category_id" ref="product_uom_categ_time"/>
<field name="category_id" ref="product_uom_category_time"/>
<field name="uom_type">reference</field>
</record>
<record id="product_uom_month" model="product.uom">
<field name="name">Month(s)</field>
<field name="factor_inv" eval="30.4375"/>
<field name="category_id" ref="product_uom_categ_time"/>
<field name="category_id" ref="product_uom_category_time"/>
<field name="uom_type">bigger</field>
</record>
<record id="product_uom_year" model="product.uom">
<field name="name">Year(s)</field>
<field name="factor_inv" eval="365.25"/>
<field name="category_id" ref="product_uom_categ_time"/>
<field name="category_id" ref="product_uom_category_time"/>
<field name="uom_type">bigger</field>
</record>
<record id="product_uom_indef" model="product.uom">
<field name="name">Indefinitely</field>
<field name="factor_inv" eval="40000"/>
<field name="category_id" ref="product_uom_categ_time"/>
<field name="category_id" ref="product_uom_category_time"/>
<field name="uom_type">bigger</field>
</record>

Expand Down
8 changes: 8 additions & 0 deletions medical_medication/data/product_uom_categ.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo noupdate="1">

<record id="product_uom_category_time" model="product.uom.categ">
<field name="name">Time</field>
</record>

</odoo>
1 change: 0 additions & 1 deletion medical_patient_disease/models/medical_patient_disease.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion medical_patient_us/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
'category': 'Medical',
'website': 'https://laslabs.com',
'licence': 'AGPL-3',
'installable': False,
'installable': True,
'auto_install': False,
'depends': [
'medical',
Expand Down
1 change: 1 addition & 0 deletions oca_dependencies.txt
Original file line number Diff line number Diff line change
@@ -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
88 changes: 56 additions & 32 deletions sale_stock_medical_prescription/models/sale_order_line.py
Original file line number Diff line number Diff line change
@@ -1,89 +1,113 @@
# -*- 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,
compute='_compute_dispense_qty',
)

@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
Expand All @@ -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
1 change: 1 addition & 0 deletions sale_stock_medical_prescription_us/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
from . import procurement_order
from . import medical_prescription_order_line
from . import res_company
from . import sale_order_line
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
26 changes: 26 additions & 0 deletions sale_stock_medical_prescription_us/models/sale_order_line.py
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit b27fb30

Please sign in to comment.