changeset 5161:227cc26317f7

health_: Fix bug #62598: Payment term search stops in party
author Luis Falcon <falcon@gnuhealth.org>
date Wed, 08 Jun 2022 18:54:20 +0100
parents 180cc7a9d84b
children caa01afaaaeb
files tryton/health_services/wizard/wizard_health_services.py
diffstat 1 files changed, 11 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/tryton/health_services/wizard/wizard_health_services.py
+++ b/tryton/health_services/wizard/wizard_health_services.py
@@ -129,12 +129,20 @@
             invoice_data['invoice_address'] = party_address.id
             invoice_data['reference'] = service.name
 
-            if not party.customer_payment_term:
+            """ Look for the payment term in the following order:
+                * Party
+                * Default payment term in accounting config
+                * Raise an error if there is no payment term
+            """
+            if (party.customer_payment_term):
+                invoice_data['payment_term'] = party.customer_payment_term.id
+            elif (acct_config.default_customer_payment_term):
+                invoice_data['payment_term'] = \
+                    acct_config.default_customer_payment_term.id
+            else:
                 raise NoPaymentTerm(
                     gettext('health_service.msg_no_payment_term'))
 
-            invoice_data['payment_term'] = party.customer_payment_term.id
-
             # Invoice Lines
             seq = 0
             invoice_lines = []