Mercurial > hgweb > health
changeset 4875:1450878cb7f1
task #16043: Migration to GNU Health 4.0: Migrate and cleanup health_insurance
| author | Luis Falcon <falcon@gnuhealth.org> |
|---|---|
| date | Sat, 15 Jan 2022 09:49:50 +0000 |
| parents | df3ca2fbe9af |
| children | b32ff7e2b86f |
| files | tryton/health_insurance/__init__.py tryton/health_insurance/data/messages/messages.xml tryton/health_insurance/exceptions.py tryton/health_insurance/health_insurance.py tryton/health_insurance/tryton.cfg |
| diffstat | 5 files changed, 66 insertions(+), 45 deletions(-) [+] |
line wrap: on
line diff
--- a/tryton/health_insurance/__init__.py +++ b/tryton/health_insurance/__init__.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- ############################################################################## # # GNU Health: The Free Health and Hospital Information System @@ -25,16 +24,16 @@ ############################################################################## from trytond.pool import Pool -from .health_insurance import * -from .wizard import * +from . import health_insurance +from . import wizard def register(): Pool.register( - InsurancePlanProductPolicy, - InsurancePlan, - HealthService, + health_insurance.InsurancePlanProductPolicy, + health_insurance.InsurancePlan, + health_insurance.HealthService, module='health_insurance', type_='model') Pool.register( - CreateServiceInvoice, + wizard.wizard_health_insurance.CreateServiceInvoice, module='health_services', type_='wizard')
new file mode 100644 --- /dev/null +++ b/tryton/health_insurance/data/messages/messages.xml @@ -0,0 +1,13 @@ +<?xml version="1.0"?> +<!-- This file is part of GNU Health. The COPYRIGHT file at the top level of +this repository contains the full copyright notices and license terms. --> +<tryton> + <data grouped="1"> + <record model="ir.message" id="msg_pct_out_of_range"> + <field name="text">Percentage out of range [0-100]</field> + </record> + <record model="ir.message" id="msg_discount_without_element"> + <field name="text">You need to associate a product or category to the discount</field> + </record> + </data> +</tryton>
new file mode 100644 --- /dev/null +++ b/tryton/health_insurance/exceptions.py @@ -0,0 +1,14 @@ +# This file is part of GNU Health. The COPYRIGHT file at the top level of +# this repository contains the full copyright notices and license terms. +from trytond.exceptions import UserError, UserWarning +from trytond.model.exceptions import ValidationError + + +class DisctountPctOutOfRange(ValidationError): + pass + + +class DiscountWithoutElement(ValidationError): + pass + +
--- a/tryton/health_insurance/health_insurance.py +++ b/tryton/health_insurance/health_insurance.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- ############################################################################## # # GNU Health: The Free Health and Hospital Information System @@ -21,30 +20,30 @@ # ############################################################################## -from trytond.model import ModelView, ModelSQL, ModelSingleton, fields -from datetime import datetime -from trytond.pool import Pool -from trytond.transaction import Transaction -from trytond.pyson import Eval, Not, Bool, PYSONEncoder, Equal, And, Or, If +from trytond.model import ModelView, ModelSQL, fields +from trytond.pyson import Eval +from trytond.i18n import gettext +from .exceptions import (DisctountPctOutOfRange, DiscountWithoutElement) -__all__ = ['InsurancePlanProductPolicy','InsurancePlan','HealthService'] + +__all__ = ['InsurancePlanProductPolicy', 'InsurancePlan', 'HealthService'] class InsurancePlanProductPolicy(ModelSQL, ModelView): 'Policy associated to the product on the insurance plan' __name__ = "gnuhealth.insurance.plan.product.policy" - plan = fields.Many2One('gnuhealth.insurance.plan', + plan = fields.Many2One( + 'gnuhealth.insurance.plan', 'Plan', required=True) - product = fields.Many2One('product.product', - 'Product', ) + product = fields.Many2One('product.product', 'Product') - product_category = fields.Many2One('product.category', - 'Category', ) - - discount = fields.Float('Discount', digits=(3,2), + product_category = fields.Many2One('product.category', 'Category') + + discount = fields.Float( + 'Discount', digits=(3, 2), help="Discount in Percentage", required=True) @classmethod @@ -56,46 +55,41 @@ def validate_discount(self): if (self.discount < 0 or self.discount > 100): - self.raise_user_error('discount_pct_out_of_range') + raise DisctountPctOutOfRange( + gettext('health_insurance.msg_pct_out_of_range') + ) def validate_policy_elements(self): if (not self.product and not self.product_category): - self.raise_user_error('discount_need_and_element') - - @classmethod - def __setup__(cls): - super(InsurancePlanProductPolicy, cls).__setup__() - - cls._error_messages.update({ - 'discount_pct_out_of_range': - 'Percentage out of range [0-100]', - 'discount_need_and_element': - 'You need a product or category', - }) + raise DiscountWithoutElement( + gettext('health_insurance.msg_discount_without_element') + ) class InsurancePlan(ModelSQL, ModelView): __name__ = "gnuhealth.insurance.plan" _rec_name = 'name' - product_policy = fields.One2Many('gnuhealth.insurance.plan.product.policy', - 'plan','Policy') + product_policy = fields.One2Many( + 'gnuhealth.insurance.plan.product.policy', + 'plan', 'Policy') + class HealthService(ModelSQL, ModelView): __name__ = 'gnuhealth.health_service' - insurance_holder = fields.Many2One('party.party','Insurance Holder', + insurance_holder = fields.Many2One( + 'party.party', 'Insurance Holder', help="Insurance Policy Holder") - insurance_plan = fields.Many2One('gnuhealth.insurance', - 'Plan', - domain=[('name', '=', Eval('insurance_holder'))], - depends=['insurance_holder']) + insurance_plan = fields.Many2One( + 'gnuhealth.insurance', + 'Plan', + domain=[('name', '=', Eval('insurance_holder'))], + depends=['insurance_holder']) - - # Set the insurance holder upon entering the + # Set the insurance holder upon entering the patient @fields.depends('patient') def on_change_patient(self): - insurance_holder=None if self.patient: self.insurance_holder = self.patient.name
