# HG changeset patch # User Luis Falcon # Date 1507055332 -3600 # Node ID 212a70f45984d494343b9dedf9ea5b5c8ab4d59b # Parent 130b9c272d55a26ec4c4821764d20e0f84ae516d health_services: Fix bug #52160: Issues related to invoice type and domain when creating the service invoice diff --git a/tryton/health_insurance/wizard/wizard_health_insurance.py b/tryton/health_insurance/wizard/wizard_health_insurance.py --- a/tryton/health_insurance/wizard/wizard_health_insurance.py +++ b/tryton/health_insurance/wizard/wizard_health_insurance.py @@ -91,9 +91,10 @@ invoice_data = {} invoice_data['description'] = service.desc invoice_data['party'] = party.id - invoice_data['type'] = 'out_invoice' + invoice_data['type'] = 'out' invoice_data['invoice_date'] = datetime.date.today() invoice_data['account'] = party.account_receivable.id + invoice_data['company'] = service.company.id ctx = {} sale_price_list = None @@ -156,18 +157,19 @@ discount = \ self.discount_policy(service.insurance_plan, \ line.product) - - if 'value' in list(discount.keys()): - if discount['value']: - if (discount['type'] == 'pct'): - unit_price *= (1 - - decimal.Decimal(discount['value'])/100) - - # Add a remark on the description discount - str_disc = str(discount['value']) + '%' - desc = line.desc + " (Discnt " + \ - str (str_disc) + ")" - + + if discount: + if 'value' in list(discount.keys()): + if discount['value']: + if (discount['type'] == 'pct'): + unit_price *= (1 - + decimal.Decimal(discount['value'])/100) + + # Add a remark on the description discount + str_disc = str(discount['value']) + '%' + desc = line.desc + " (Discnt " + \ + str (str_disc) + ")" + invoice_lines.append(('create', [{ 'origin': str(line), 'product': line.product.id, diff --git a/tryton/health_services/health_services.py b/tryton/health_services/health_services.py --- a/tryton/health_services/health_services.py +++ b/tryton/health_services/health_services.py @@ -23,6 +23,7 @@ ############################################################################## import datetime from trytond.model import ModelView, ModelSQL, fields, ModelSingleton, Unique +from trytond.transaction import Transaction from trytond.pyson import Eval, Equal from trytond.pool import Pool @@ -53,6 +54,7 @@ 'Patient', required=True, states=STATES) institution = fields.Many2One('gnuhealth.institution', 'Institution') + company = fields.Many2One('company.company', 'Company') service_date = fields.Date('Date') service_line = fields.One2Many('gnuhealth.health_service.line', @@ -85,6 +87,10 @@ return 'draft' @staticmethod + def default_company(): + return Transaction().context.get('company') + + @staticmethod def default_service_date(): return datetime.date.today() diff --git a/tryton/health_services/view/gnuhealth_health_service.xml b/tryton/health_services/view/gnuhealth_health_service.xml --- a/tryton/health_services/view/gnuhealth_health_service.xml +++ b/tryton/health_services/view/gnuhealth_health_service.xml @@ -1,6 +1,6 @@
- + diff --git a/tryton/health_services/wizard/wizard_health_services.py b/tryton/health_services/wizard/wizard_health_services.py --- a/tryton/health_services/wizard/wizard_health_services.py +++ b/tryton/health_services/wizard/wizard_health_services.py @@ -81,9 +81,10 @@ invoice_data = {} invoice_data['description'] = service.desc invoice_data['party'] = party.id - invoice_data['type'] = 'out_invoice' + invoice_data['type'] = 'out' invoice_data['invoice_date'] = datetime.date.today() invoice_data['account'] = party.account_receivable.id + invoice_data['company'] = service.company.id ctx = {} sale_price_list = None