changeset 4818:1a062fa88cf5

task #16043: Migration to GNU Health 4.0: Migration of health_ntd and health_ntd_chagas packages
author Luis Falcon <falcon@gnuhealth.org>
date Tue, 21 Dec 2021 12:22:09 +0000
parents c0a4ebca5c4c
children eb5654be6e64
files tryton/health_ntd/__init__.py tryton/health_ntd/tryton.cfg tryton/health_ntd_chagas/__init__.py tryton/health_ntd_chagas/data/health_ntd_chagas_sequence.xml tryton/health_ntd_chagas/data/lab_test_data.xml tryton/health_ntd_chagas/health_ntd_chagas.py tryton/health_ntd_chagas/sequences.py tryton/health_ntd_chagas/tryton.cfg
diffstat 8 files changed, 116 insertions(+), 92 deletions(-) [+]
line wrap: on
line diff
--- a/tryton/health_ntd/__init__.py
+++ b/tryton/health_ntd/__init__.py
@@ -1,4 +1,3 @@
-# -*- coding: utf-8 -*-
 ##############################################################################
 #
 #    GNU Health: The Free Health and Hospital Information System
@@ -21,4 +20,4 @@
 #
 ##############################################################################
 
-from .health_ntd import *
+from . import health_ntd 
--- a/tryton/health_ntd/tryton.cfg
+++ b/tryton/health_ntd/tryton.cfg
@@ -1,5 +1,5 @@
 [tryton]
-version=3.8.0
+version=3.9.0
 depends:
     health
     health_lab
--- a/tryton/health_ntd_chagas/__init__.py
+++ b/tryton/health_ntd_chagas/__init__.py
@@ -1,4 +1,3 @@
-# -*- coding: utf-8 -*-
 ##############################################################################
 #
 #    GNU Health: The Free Health and Hospital Information System
@@ -22,11 +21,12 @@
 ##############################################################################
 
 from trytond.pool import Pool
-from .health_ntd_chagas import *
+from . import health_ntd_chagas
+from . import sequences
 
 def register():
     Pool.register(
-        ChagasDUSurvey,
-        GnuHealthSequences,
-        GnuHealthSequenceSetup,
+        health_ntd_chagas.ChagasDUSurvey,
+        sequences.GnuHealthSequences,
+        sequences.ChagasDUSurveySequence,
         module='health_ntd_chagas', type_='model')
--- a/tryton/health_ntd_chagas/data/health_ntd_chagas_sequence.xml
+++ b/tryton/health_ntd_chagas/data/health_ntd_chagas_sequence.xml
@@ -1,15 +1,13 @@
 <?xml version="1.0" encoding="utf-8"?>
 <tryton>
-    <data noupdate="0">
-
+    <data>
         <!-- Sequences for Chagas -->
-        <record id="seq_type_gnuhealth_du_survey" model="ir.sequence.type">
+        <record id="seq_type_gnuhealth_chagas_du_survey" model="ir.sequence.type">
             <field name="name">Chagas DU Survey</field>
-            <field name="code">gnuhealth.chagas_du_survey</field>
         </record>
-        <record id="seq_gnuhealth_du_survey" model="ir.sequence">
+        <record id="seq_gnuhealth_chagas_du_survey" model="ir.sequence">
             <field name="name">Chagas DU Survey</field>
-            <field name="code">gnuhealth.chagas_du_survey</field>
+            <field name="sequence_type" ref="seq_type_gnuhealth_chagas_du_survey"></field>
             <field name="prefix">CHAGAS-DU-${year}/</field>
             <field name="padding">3</field>
         </record>
--- a/tryton/health_ntd_chagas/data/lab_test_data.xml
+++ b/tryton/health_ntd_chagas/data/lab_test_data.xml
@@ -1,6 +1,6 @@
 <?xml version="1"?>
 <tryton>
-    <data skiptest="1" noupdate="0">
+    <data skiptest="1">
 
 
 <!-- BEGIN OF XENODIAGNOSIS TEST -->
@@ -10,7 +10,6 @@
         <record id="product_template_chagas_xenodiagnosis_analysischarges0" model="product.template">
             <field name="name">Chagas Xenodiagnosis Charges</field>
             <field eval="1" name="list_price"/>
-            <field eval="0" name="cost_price"/>
             <field name="default_uom" ref="product.uom_unit"/>
             <field name="type">service</field>
         </record>
@@ -50,7 +49,6 @@
         <record id="product_template_chagas_strout_analysischarges0" model="product.template">
             <field name="name">Chagas strout 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>
@@ -90,7 +88,6 @@
         <record id="product_template_chagas_bsmear_analysischarges0" model="product.template">
             <field name="name">Chagas Blood Smear 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>
@@ -129,7 +126,6 @@
         <record id="product_template_chagas_elisa_analysischarges0" model="product.template">
             <field name="name">Chagas ELISA Ig 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>
@@ -170,7 +166,6 @@
         <record id="product_template_chagas_ifa_analysischarges0" model="product.template">
             <field name="name">Chagas ifa Ig 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>
@@ -211,7 +206,6 @@
         <record id="product_template_chagas_pcr_analysischarges0" model="product.template">
             <field name="name">Chagas 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>
--- a/tryton/health_ntd_chagas/health_ntd_chagas.py
+++ b/tryton/health_ntd_chagas/health_ntd_chagas.py
@@ -1,4 +1,3 @@
-# -*- coding: utf-8 -*-
 ##############################################################################
 #
 #    GNU Health: The Free Health and Hospital Information System
@@ -29,68 +28,8 @@
 from trytond.tools.multivalue import migrate_property
 
 
-__all__ = ['GnuHealthSequences','GnuHealthSequenceSetup','ChagasDUSurvey']
+__all__ = ['ChagasDUSurvey']
 
-sequences = ['chagas_du_survey_sequence']
-
-
-class GnuHealthSequences(ModelSingleton, ModelSQL, ModelView):
-    __name__ = 'gnuhealth.sequences'
-
-    chagas_du_survey_sequence = fields.MultiValue(fields.Many2One('ir.sequence',
-        'Chagas Survey Sequence', required=True,
-        domain=[('code', '=', 'gnuhealth.chagas_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_chagas_du_survey_sequence(cls):
-        return cls.multivalue_model(
-            'chagas_du_survey_sequence').default_chagas_du_survey_sequence()
-
-
-# SEQUENCE SETUP
-class GnuHealthSequenceSetup(ModelSQL, ValueMixin):
-    'GNU Health Sequences Setup'
-    __name__ = 'gnuhealth.sequence.setup'
-
-    chagas_du_survey_sequence = fields.Many2One('ir.sequence', 
-        'Chagas DU Survey Sequence', required=True,
-        domain=[('code', '=', 'gnuhealth.chagas_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_chagas_du_survey_sequence(cls):
-        pool = Pool()
-        ModelData = pool.get('ir.model.data')
-        return ModelData.get_id(
-            'health_ntd_chagas', 'seq_gnuhealth_du_survey')
-    
-# END SEQUENCE SETUP , MIGRATION FROM FIELDS.MultiValue
 
 class ChagasDUSurvey(ModelSQL, ModelView):
     'Chagas DU Entomological Survey'
@@ -149,18 +88,19 @@
     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(
+            'chagas_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.chagas_du_survey_sequence.id)
-
+                values['name'] = cls.generate_code()
         return super(ChagasDUSurvey, cls).create(vlist)
-
new file mode 100644
--- /dev/null
+++ b/tryton/health_ntd_chagas/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
+chagas_du_survey_sequence = fields.Many2One(
+    'ir.sequence', 'Chagas DU Survey Sequence', required=True,
+    domain=[('sequence_type', '=', Id(
+        'health_ntd_chagas', 'seq_type_gnuhealth_chagas_du_survey'))])
+
+
+
+
+# GNU HEALTH SEQUENCES
+class GnuHealthSequences(ModelSingleton, ModelSQL, ModelView, MultiValueMixin):
+    'Standard Sequences for GNU Health'
+    __name__ = 'gnuhealth.sequences'
+
+    chagas_du_survey_sequence = fields.MultiValue(
+        chagas_du_survey_sequence)
+
+
+    @classmethod
+    def default_chagas_du_survey_sequence(cls, **pattern):
+        pool = Pool()
+        ModelData = pool.get('ir.model.data')
+        try:
+            return ModelData.get_id('health_ntd_chagas',
+                                    'seq_gnuhealth_chagas_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 ChagasDUSurveySequence(_ConfigurationValue, ModelSQL, ValueMixin):
+    'Chagas DU Survey Sequences setup'
+    __name__ = 'gnuhealth.sequences.chagas_du_survey_sequence'
+    chagas_du_survey_sequence = chagas_du_survey_sequence
+    _configuration_value_field = 'chagas_du_survey_sequence'
+
+    @classmethod
+    def check_xml_record(cls, records, values):
+        return True
--- a/tryton/health_ntd_chagas/tryton.cfg
+++ b/tryton/health_ntd_chagas/tryton.cfg
@@ -1,5 +1,5 @@
 [tryton]
-version=3.8.0
+version=3.9.0
 depends:
     health_ntd