Repository: tefra/xsdata

Issue:
New substitution group code opportunities
What is the reason that the new substitution group code generates:

```
class JourneysInFrameRelStructure(ContainmentAggregationStructure):
    class Meta:
        name = "journeysInFrame_RelStructure"

    choice: List[
        Union[
            VehicleJourney,
            DatedVehicleJourney,
            NormalDatedVehicleJourney,
            ServiceJourney,
            DatedServiceJourney,
            DeadRun,
            SpecialService,
            TemplateServiceJourney,
        ]
    ] = field(
```

<xsd:element name="VehicleJourney" abstract="false" substitutionGroup="VehicleJourney_" id="VehicleJourney">
<xsd:element name="DeadRun" abstract="false" substitutionGroup="VehicleJourney_">
<xsd:element name="DatedVehicleJourney" abstract="false" substitutionGroup="Journey_">
<xsd:element name="NormalDatedVehicleJourney" abstract="false" substitutionGroup="Journey_">
<xsd:element name="ServiceJourney" abstract="false" substitutionGroup="VehicleJourney_">
<xsd:element name="DatedServiceJourney" abstract="false" substitutionGroup="ServiceJourney_">
<xsd:element name="DeadRun" abstract="false" substitutionGroup="VehicleJourney_">
<xsd:element name="DatedSpecialService" abstract="false" substitutionGroup="Journey_">
<xsd:element name="TemplateServiceJourney" abstract="false" substitutionGroup="ServiceJourney_">

But misses the opportunities to make the choice named "Journey_" (being the most abstract type).

Is this due the the choice being?
```
                                <xsd:choice maxOccurs="unbounded">
                                        <xsd:element ref="VehicleJourney"/>
                                        <xsd:element ref="DatedVehicleJourney"/>
                                        <xsd:element ref="NormalDatedVehicleJourney"/>
                                        <xsd:element ref="ServiceJourney"/>
                                        <xsd:element ref="DatedServiceJourney"/>
                                        <xsd:element ref="DeadRun"/>
                                        <xsd:element ref="SpecialService"/>
                                        <xsd:element ref="TemplateServiceJourney">
                                                <xsd:annotation>
                                                        <xsd:documentation>A VEHICLE JOURNEY with a set of frequencies that may be used to represent a set of similar journeys differing only by their time of departure.</xsd:documentation>
                                                </xsd:annotation>
                                        </xsd:element>
                                </xsd:choice>
```

Instead of something like this?
```
                                <xsd:sequence>
                                        <xsd:element ref="Journey_" maxOccurs="unbounded"/>
                                </xsd:sequence>
```

Discussion:
sonarcloud[bot]: ## [![Quality Gate Passed](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/QualityGateBadge/qg-passed-20px.png 'Quality Gate Passed')](https://sonarcloud.io/dashboard?id=tefra_xsdata&pullRequest=905) **Quality Gate passed**  
Kudos, no new issues were introduced!

[0 New issues](https://sonarcloud.io/project/issues?id=tefra_xsdata&pullRequest=905&resolved=false&inNewCodePeriod=true)  
[0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=tefra_xsdata&pullRequest=905&resolved=false&inNewCodePeriod=true)  
No data about Coverage  
[0.0% Duplication on New Code](https://sonarcloud.io/component_measures?id=tefra_xsdata&pullRequest=905&metric=new_duplicated_lines_density&view=list)  
  
[See analysis details on SonarCloud](https://sonarcloud.io/dashboard?id=tefra_xsdata&pullRequest=905)


codecov[bot]: ## [Codecov](https://app.codecov.io/gh/tefra/xsdata/pull/905?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Chris+Tsou) Report
All modified and coverable lines are covered by tests :white_check_mark:
> Comparison is base [(`fa05d61`)](https://app.codecov.io/gh/tefra/xsdata/commit/fa05d61338a5beb06caf8438383bed0b9070ee26?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Chris+Tsou) 100.00% compared to head [(`bec3902`)](https://app.codecov.io/gh/tefra/xsdata/pull/905?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Chris+Tsou) 100.00%.


<details><summary>Additional details and impacted files</summary>


```diff
@@            Coverage Diff            @@
##              main      #905   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          105       105           
  Lines         8728      8728           
  Branches      2067      2067           
=========================================
  Hits          8728      8728           
```



</details>

[:umbrella: View full report in Codecov by Sentry](https://app.codecov.io/gh/tefra/xsdata/pull/905?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Chris+Tsou).   
:loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Chris+Tsou).


Patch:
diff --git a/xsdata/codegen/handlers/create_compound_fields.py b/xsdata/codegen/handlers/create_compound_fields.py
index 0cc943a8..df7271b0 100644
--- a/xsdata/codegen/handlers/create_compound_fields.py
+++ b/xsdata/codegen/handlers/create_compound_fields.py
@@ -121,7 +121,7 @@ class CreateCompoundFields(RelativeHandlerInterface):
     def choose_name(
         self, target: Class, names: List[str], substitutions: List[str]
     ) -> str:
-        if self.config.use_substitution_groups and substitutions:
+        if self.config.use_substitution_groups and len(names) == len(substitutions):
             names = substitutions
 
         names = collections.unique_sequence(names)


Test patch:
diff --git a/tests/codegen/handlers/test_create_compound_fields.py b/tests/codegen/handlers/test_create_compound_fields.py
index b96fe285..ff56e338 100644
--- a/tests/codegen/handlers/test_create_compound_fields.py
+++ b/tests/codegen/handlers/test_create_compound_fields.py
@@ -170,6 +170,9 @@ class CreateCompoundFieldsTests(FactoryTestCase):
         actual = self.processor.choose_name(target, ["a", "b", "c"], ["d", "e", "f"])
         self.assertEqual("d_Or_e_Or_f", actual)
 
+        actual = self.processor.choose_name(target, ["a", "b", "c"], ["d", "f"])
+        self.assertEqual("a_Or_b_Or_c", actual)
+
     def test_build_reserved_names(self):
         base = ClassFactory.create(
             attrs=[