1515from typing import Any , Dict , List , Optional
1616from dataclasses import dataclass , field
1717
18+ from ..common .constants import (
19+ ODATA_TYPE_LOCALIZED_LABEL ,
20+ ODATA_TYPE_LABEL ,
21+ ODATA_TYPE_LOOKUP_ATTRIBUTE ,
22+ ODATA_TYPE_ONE_TO_MANY_RELATIONSHIP ,
23+ ODATA_TYPE_MANY_TO_MANY_RELATIONSHIP ,
24+ )
25+
1826
1927@dataclass
2028class LocalizedLabel :
@@ -35,9 +43,21 @@ class LocalizedLabel:
3543 additional_properties : Optional [Dict [str , Any ]] = None
3644
3745 def to_dict (self ) -> Dict [str , Any ]:
38- """Convert to Web API JSON format."""
46+ """
47+ Convert to Web API JSON format.
48+
49+ Example::
50+
51+ >>> label = LocalizedLabel(label="Account", language_code=1033)
52+ >>> label.to_dict()
53+ {
54+ '@odata.type': 'Microsoft.Dynamics.CRM.LocalizedLabel',
55+ 'Label': 'Account',
56+ 'LanguageCode': 1033
57+ }
58+ """
3959 result = {
40- "@odata.type" : "Microsoft.Dynamics.CRM.LocalizedLabel" ,
60+ "@odata.type" : ODATA_TYPE_LOCALIZED_LABEL ,
4161 "Label" : self .label ,
4262 "LanguageCode" : self .language_code ,
4363 }
@@ -65,9 +85,23 @@ class Label:
6585 additional_properties : Optional [Dict [str , Any ]] = None
6686
6787 def to_dict (self ) -> Dict [str , Any ]:
68- """Convert to Web API JSON format."""
88+ """
89+ Convert to Web API JSON format.
90+
91+ Example::
92+
93+ >>> label = Label(localized_labels=[LocalizedLabel("Account", 1033)])
94+ >>> label.to_dict()
95+ {
96+ '@odata.type': 'Microsoft.Dynamics.CRM.Label',
97+ 'LocalizedLabels': [
98+ {'@odata.type': '...', 'Label': 'Account', 'LanguageCode': 1033}
99+ ],
100+ 'UserLocalizedLabel': {'@odata.type': '...', 'Label': 'Account', ...}
101+ }
102+ """
69103 result = {
70- "@odata.type" : "Microsoft.Dynamics.CRM.Label" ,
104+ "@odata.type" : ODATA_TYPE_LABEL ,
71105 "LocalizedLabels" : [ll .to_dict () for ll in self .localized_labels ],
72106 }
73107 # Use explicit user_localized_label, or default to first localized label
@@ -118,7 +152,22 @@ class CascadeConfiguration:
118152 additional_properties : Optional [Dict [str , Any ]] = None
119153
120154 def to_dict (self ) -> Dict [str , Any ]:
121- """Convert to Web API JSON format."""
155+ """
156+ Convert to Web API JSON format.
157+
158+ Example::
159+
160+ >>> config = CascadeConfiguration(delete="Cascade", assign="NoCascade")
161+ >>> config.to_dict()
162+ {
163+ 'Assign': 'NoCascade',
164+ 'Delete': 'Cascade',
165+ 'Merge': 'NoCascade',
166+ 'Reparent': 'NoCascade',
167+ 'Share': 'NoCascade',
168+ 'Unshare': 'NoCascade'
169+ }
170+ """
122171 result = {
123172 "Assign" : self .assign ,
124173 "Delete" : self .delete ,
@@ -163,7 +212,15 @@ class AssociatedMenuConfiguration:
163212 additional_properties : Optional [Dict [str , Any ]] = None
164213
165214 def to_dict (self ) -> Dict [str , Any ]:
166- """Convert to Web API JSON format."""
215+ """
216+ Convert to Web API JSON format.
217+
218+ Example::
219+
220+ >>> menu = AssociatedMenuConfiguration(behavior="UseLabel", group="Details")
221+ >>> menu.to_dict()
222+ {'Behavior': 'UseLabel', 'Group': 'Details', 'Order': 10000}
223+ """
167224 result = {
168225 "Behavior" : self .behavior ,
169226 "Group" : self .group ,
@@ -209,9 +266,27 @@ class LookupAttributeMetadata:
209266 additional_properties : Optional [Dict [str , Any ]] = None
210267
211268 def to_dict (self ) -> Dict [str , Any ]:
212- """Convert to Web API JSON format."""
269+ """
270+ Convert to Web API JSON format.
271+
272+ Example::
273+
274+ >>> lookup = LookupAttributeMetadata(
275+ ... schema_name="new_AccountId",
276+ ... display_name=Label([LocalizedLabel("Account", 1033)])
277+ ... )
278+ >>> lookup.to_dict()
279+ {
280+ '@odata.type': 'Microsoft.Dynamics.CRM.LookupAttributeMetadata',
281+ 'SchemaName': 'new_AccountId',
282+ 'AttributeType': 'Lookup',
283+ 'AttributeTypeName': {'Value': 'LookupType'},
284+ 'DisplayName': {...},
285+ 'RequiredLevel': {'Value': 'None', 'CanBeChanged': True, ...}
286+ }
287+ """
213288 result = {
214- "@odata.type" : "Microsoft.Dynamics.CRM.LookupAttributeMetadata" ,
289+ "@odata.type" : ODATA_TYPE_LOOKUP_ATTRIBUTE ,
215290 "SchemaName" : self .schema_name ,
216291 "AttributeType" : "Lookup" ,
217292 "AttributeTypeName" : {"Value" : "LookupType" },
@@ -265,9 +340,29 @@ class OneToManyRelationshipMetadata:
265340 additional_properties : Optional [Dict [str , Any ]] = None
266341
267342 def to_dict (self ) -> Dict [str , Any ]:
268- """Convert to Web API JSON format."""
343+ """
344+ Convert to Web API JSON format.
345+
346+ Example::
347+
348+ >>> rel = OneToManyRelationshipMetadata(
349+ ... schema_name="new_account_orders",
350+ ... referenced_entity="account",
351+ ... referencing_entity="new_order",
352+ ... referenced_attribute="accountid"
353+ ... )
354+ >>> rel.to_dict()
355+ {
356+ '@odata.type': 'Microsoft.Dynamics.CRM.OneToManyRelationshipMetadata',
357+ 'SchemaName': 'new_account_orders',
358+ 'ReferencedEntity': 'account',
359+ 'ReferencingEntity': 'new_order',
360+ 'ReferencedAttribute': 'accountid',
361+ 'CascadeConfiguration': {...}
362+ }
363+ """
269364 result = {
270- "@odata.type" : "Microsoft.Dynamics.CRM.OneToManyRelationshipMetadata" ,
365+ "@odata.type" : ODATA_TYPE_ONE_TO_MANY_RELATIONSHIP ,
271366 "SchemaName" : self .schema_name ,
272367 "ReferencedEntity" : self .referenced_entity ,
273368 "ReferencingEntity" : self .referencing_entity ,
@@ -317,11 +412,29 @@ class ManyToManyRelationshipMetadata:
317412 additional_properties : Optional [Dict [str , Any ]] = None
318413
319414 def to_dict (self ) -> Dict [str , Any ]:
320- """Convert to Web API JSON format."""
415+ """
416+ Convert to Web API JSON format.
417+
418+ Example::
419+
420+ >>> rel = ManyToManyRelationshipMetadata(
421+ ... schema_name="new_account_contact",
422+ ... entity1_logical_name="account",
423+ ... entity2_logical_name="contact"
424+ ... )
425+ >>> rel.to_dict()
426+ {
427+ '@odata.type': 'Microsoft.Dynamics.CRM.ManyToManyRelationshipMetadata',
428+ 'SchemaName': 'new_account_contact',
429+ 'Entity1LogicalName': 'account',
430+ 'Entity2LogicalName': 'contact',
431+ 'IntersectEntityName': 'new_account_contact'
432+ }
433+ """
321434 # IntersectEntityName is required - use provided value or default to schema_name
322435 intersect_name = self .intersect_entity_name or self .schema_name
323436 result = {
324- "@odata.type" : "Microsoft.Dynamics.CRM.ManyToManyRelationshipMetadata" ,
437+ "@odata.type" : ODATA_TYPE_MANY_TO_MANY_RELATIONSHIP ,
325438 "SchemaName" : self .schema_name ,
326439 "Entity1LogicalName" : self .entity1_logical_name ,
327440 "Entity2LogicalName" : self .entity2_logical_name ,
0 commit comments