Mercurial > hgweb > health
changeset 4819:eb5654be6e64
GNU Health - Tasks: task #16043, Migration to GNU Health 4.0: Migrate health_ntd_dengue
| author | Luis Falcon <falcon@gnuhealth.org> |
|---|---|
| date | Tue, 21 Dec 2021 12:52:04 +0000 |
| parents | 1a062fa88cf5 |
| children | 64917af212cf |
| files | tryton/health_ntd_dengue/__init__.py tryton/health_ntd_dengue/data/health_ntd_dengue_sequence.xml tryton/health_ntd_dengue/data/lab_test_data.xml tryton/health_ntd_dengue/health_ntd_dengue.py tryton/health_ntd_dengue/sequences.py tryton/health_ntd_dengue/tryton.cfg |
| diffstat | 6 files changed, 114 insertions(+), 84 deletions(-) [+] |
line wrap: on
line diff
--- a/tryton/health_ntd_dengue/__init__.py +++ b/tryton/health_ntd_dengue/__init__.py @@ -22,11 +22,12 @@ ############################################################################## from trytond.pool import Pool -from .health_ntd_dengue import * +from . import health_ntd_dengue +from . import sequences def register(): Pool.register( - DengueDUSurvey, - GnuHealthSequences, - GnuHealthSequenceSetup, + health_ntd_dengue.DengueDUSurvey, + sequences.GnuHealthSequences, + sequences.DengueDUSurveySequence, module='health_ntd_dengue', type_='model')
--- a/tryton/health_ntd_dengue/data/health_ntd_dengue_sequence.xml +++ b/tryton/health_ntd_dengue/data/health_ntd_dengue_sequence.xml @@ -3,13 +3,12 @@ <data noupdate="0"> <!-- Sequences for Dengue --> - <record id="seq_type_gnuhealth_du_survey" model="ir.sequence.type"> + <record id="seq_type_gnuhealth_dengue_du_survey" model="ir.sequence.type"> <field name="name">Dengue DU Survey</field> - <field name="code">gnuhealth.dengue_du_survey</field> </record> - <record id="seq_gnuhealth_du_survey" model="ir.sequence"> + <record id="seq_gnuhealth_dengue_du_survey" model="ir.sequence"> <field name="name">Dengue DU Survey</field> - <field name="code">gnuhealth.dengue_du_survey</field> + <field name="sequence_type" ref="seq_type_gnuhealth_dengue_du_survey"></field> <field name="prefix">DENGUE-DU-${year}/</field> <field name="padding">3</field> </record>
--- a/tryton/health_ntd_dengue/data/lab_test_data.xml +++ b/tryton/health_ntd_dengue/data/lab_test_data.xml @@ -11,7 +11,6 @@ <record id="product_template_dengue_elisa_igm_analysischarges0" model="product.template"> <field name="name">Dengue ELISA MAC Ig-M Charges</field> <field eval="1" name="list_price"/> - <field eval="0.0" name="cost_price"/> <field name="default_uom" ref="product.uom_unit"/> <field name="type">service</field> </record> @@ -48,7 +47,6 @@ <record id="product_template_dengue_elisa_igg_analysischarges0" model="product.template"> <field name="name">Dengue IgG Charges</field> <field eval="1" name="list_price"/> - <field eval="0.0" name="cost_price"/> <field name="default_uom" ref="product.uom_unit"/> <field name="type">service</field> </record> @@ -84,7 +82,6 @@ <record id="product_template_dengue_pcr_analysischarges0" model="product.template"> <field name="name">Dengue PCR Charges</field> <field eval="1" name="list_price"/> - <field eval="0.0" name="cost_price"/> <field name="default_uom" ref="product.uom_unit"/> <field name="type">service</field> </record> @@ -120,7 +117,6 @@ <record id="product_template_dengue_prnt_analysischarges0" model="product.template"> <field name="name">Dengue PRNT Charges</field> <field eval="1" name="list_price"/> - <field eval="0.0" name="cost_price"/> <field name="default_uom" ref="product.uom_unit"/> <field name="type">service</field> </record>
--- a/tryton/health_ntd_dengue/health_ntd_dengue.py +++ b/tryton/health_ntd_dengue/health_ntd_dengue.py @@ -30,70 +30,7 @@ -__all__ = ['GnuHealthSequences', 'GnuHealthSequenceSetup', 'DengueDUSurvey'] - -sequences = ['dengue_du_survey_sequence'] - - -class GnuHealthSequences(ModelSingleton, ModelSQL, ModelView): - __name__ = 'gnuhealth.sequences' - - dengue_du_survey_sequence = fields.MultiValue(fields.Many2One( - 'ir.sequence', - 'Dengue Survey Sequence', required=True, - domain=[('code', '=', 'gnuhealth.dengue_du_survey')])) - - @classmethod - def multivalue_model(cls, field): - pool = Pool() - - if field in sequences: - return pool.get('gnuhealth.sequence.setup') - return super(GnuHealthSequences, cls).multivalue_model(field) - - - @classmethod - def default_dengue_du_survey_sequence(cls): - return cls.multivalue_model( - 'dengue_du_survey_sequence').default_dengue_du_survey_sequence() - - -# SEQUENCE SETUP -class GnuHealthSequenceSetup(ModelSQL, ValueMixin): - 'GNU Health Sequences Setup' - __name__ = 'gnuhealth.sequence.setup' - - dengue_du_survey_sequence = fields.Many2One('ir.sequence', - 'Dengue DU Survey Sequence', required=True, - domain=[('code', '=', 'gnuhealth.dengue_du_survey')]) - - @classmethod - def __register__(cls, module_name): - TableHandler = backend.get('TableHandler') - exist = TableHandler.table_exist(cls._table) - - super(GnuHealthSequenceSetup, cls).__register__(module_name) - - if not exist: - cls._migrate_MultiValue([], [], []) - - @classmethod - def _migrate_property(cls, field_names, value_names, fields): - field_names.extend(sequences) - value_names.extend(sequences) - migrate_property( - 'gnuhealth.sequences', field_names, cls, value_names, - fields=fields) - - @classmethod - def default_dengue_du_survey_sequence(cls): - pool = Pool() - ModelData = pool.get('ir.model.data') - return ModelData.get_id( - 'health_ntd_dengue', 'seq_gnuhealth_du_survey') - -# END SEQUENCE SETUP , MIGRATION FROM FIELDS.MultiValue - +__all__ = ['DengueDUSurvey'] class DengueDUSurvey(ModelSQL, ModelView): 'Dengue DU Survey' @@ -164,16 +101,20 @@ def default_survey_date(): return datetime.now() + + @classmethod + def generate_code(cls, **pattern): + Config = Pool().get('gnuhealth.sequences') + config = Config(1) + sequence = config.get_multivalue( + 'dengue_du_survey_sequence', **pattern) + if sequence: + return sequence.get() + @classmethod def create(cls, vlist): - Sequence = Pool().get('ir.sequence') - Config = Pool().get('gnuhealth.sequences') - vlist = [x.copy() for x in vlist] for values in vlist: if not values.get('name'): - config = Config(1) - values['name'] = Sequence.get_id( - config.dengue_du_survey_sequence.id) - + values['name'] = cls.generate_code() return super(DengueDUSurvey, cls).create(vlist)
new file mode 100644 --- /dev/null +++ b/tryton/health_ntd_dengue/sequences.py @@ -0,0 +1,93 @@ +############################################################################## +# +# GNU Health HMIS: The Free Health and Hospital Information System +# Copyright (C) 2008-2021 Luis Falcon <falcon@gnuhealth.org> +# Copyright (C) 2011-2021 GNU Solidario <health@gnusolidario.org> +# +# The GNU Health HMIS component is part of the GNU Health project +# www.gnuhealth.org +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. +# +############################################################################## + +# GNU Health HMIS sequences for this package + +from trytond.model import (ModelView, ModelSingleton, ModelSQL, + ValueMixin, MultiValueMixin, fields) +from trytond import backend +from trytond.pyson import Id +from trytond.pool import Pool +from trytond.tools.multivalue import migrate_property + +# Sequences +dengue_du_survey_sequence = fields.Many2One( + 'ir.sequence', 'Dengue DU Survey Sequence', required=True, + domain=[('sequence_type', '=', Id( + 'health_ntd_dengue', 'seq_type_gnuhealth_dengue_du_survey'))]) + + + + +# GNU HEALTH SEQUENCES +class GnuHealthSequences(ModelSingleton, ModelSQL, ModelView, MultiValueMixin): + 'Standard Sequences for GNU Health' + __name__ = 'gnuhealth.sequences' + + dengue_du_survey_sequence = fields.MultiValue( + dengue_du_survey_sequence) + + + @classmethod + def default_dengue_du_survey_sequence(cls, **pattern): + pool = Pool() + ModelData = pool.get('ir.model.data') + try: + return ModelData.get_id('health_ntd_dengue', + 'seq_gnuhealth_dengue_du_survey') + except KeyError: + return None + + +class _ConfigurationValue(ModelSQL): + + _configuration_value_field = None + + @classmethod + def __register__(cls, module_name): + exist = backend.TableHandler.table_exist(cls._table) + + super(_ConfigurationValue, cls).__register__(module_name) + + if not exist: + cls._migrate_property([], [], []) + + @classmethod + def _migrate_property(cls, field_names, value_names, fields): + field_names.append(cls._configuration_value_field) + value_names.append(cls._configuration_value_field) + migrate_property( + 'gnuhealth.sequences', field_names, cls, value_names, + fields=fields) + + +class DengueDUSurveySequence(_ConfigurationValue, ModelSQL, ValueMixin): + 'Dengue DU Survey Sequences setup' + __name__ = 'gnuhealth.sequences.dengue_du_survey_sequence' + dengue_du_survey_sequence = dengue_du_survey_sequence + _configuration_value_field = 'dengue_du_survey_sequence' + + @classmethod + def check_xml_record(cls, records, values): + return True
