django-bom 1.252__py3-none-any.whl → 1.258__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
bom/helpers.py CHANGED
@@ -1,13 +1,16 @@
1
1
  from bom import constants
2
2
  from bom.models import (
3
3
  Assembly,
4
- AssemblySubparts,
5
4
  Manufacturer,
6
5
  ManufacturerPart,
7
6
  Organization,
8
7
  Part,
9
8
  PartClass,
10
9
  PartRevision,
10
+ QuantityOfMeasure,
11
+ UnitDefinition,
12
+ PartRevisionProperty,
13
+ PartRevisionPropertyDefinition,
11
14
  Seller,
12
15
  SellerPart,
13
16
  Subpart,
@@ -64,14 +67,86 @@ def create_a_fake_assembly_with_subpart(part_revision, reference="D4", count=4):
64
67
  return assy
65
68
 
66
69
 
67
- def create_a_fake_part_revision(part, assembly, description="Brown dog", revision="1"):
70
+ def create_some_fake_quantities_of_measure(organization=None):
71
+ qom_each, _ = QuantityOfMeasure.objects.get_or_create(name='Each')
72
+ qom_volt, _ = QuantityOfMeasure.objects.get_or_create(name='Voltage')
73
+ qom_custom = None
74
+ if organization is not None:
75
+ qom_custom, _ = QuantityOfMeasure.objects.get_or_create(name='Custom', organization=organization)
76
+ return qom_each, qom_volt, qom_custom
77
+
78
+
79
+ def create_some_fake_unit_definitions(organization=None):
80
+ qom_each, qom_volt, qom_custom = create_some_fake_quantities_of_measure(organization)
81
+ v, _ = UnitDefinition.objects.get_or_create(name='Volts', symbol='V', quantity_of_measure=qom_volt,
82
+ base_multiplier=1.0)
83
+ mv, _ = UnitDefinition.objects.get_or_create(name='Millivolts', symbol='mV', quantity_of_measure=qom_volt,
84
+ base_multiplier=0.001)
85
+ uv, _ = UnitDefinition.objects.get_or_create(name='Microvolts', symbol='uV', quantity_of_measure=qom_volt,
86
+ base_multiplier=0.000001)
87
+ kv, _ = UnitDefinition.objects.get_or_create(name='Kilovolts', symbol='kV', quantity_of_measure=qom_volt,
88
+ base_multiplier=1000)
89
+ sv = None
90
+ if organization is not None:
91
+ sv, _ = UnitDefinition.objects.get_or_create(name='Supervolts', symbol='SV', quantity_of_measure=qom_custom,
92
+ base_multiplier=1000000)
93
+ return v, mv, uv, kv, sv
94
+
95
+
96
+ def create_some_fake_part_revision_property_definitions(organization=None, some_required=True, part_class=None):
97
+ qom_each, qom_volt, qom_custom = create_some_fake_quantities_of_measure(organization)
98
+ sheen, _ = PartRevisionPropertyDefinition.objects.get_or_create(name='Sheen', code='sheen',
99
+ type=constants.PART_REVISION_PROPERTY_TYPE_STRING,
100
+ quantity_of_measure=None,
101
+ defaults={'required': some_required})
102
+ voltage, _ = PartRevisionPropertyDefinition.objects.get_or_create(name='Voltage', code='voltage',
103
+ type=constants.PART_REVISION_PROPERTY_TYPE_DECIMAL,
104
+ quantity_of_measure=qom_volt,
105
+ defaults={'required': some_required})
106
+ max_voltage, _ = PartRevisionPropertyDefinition.objects.get_or_create(name='Max Voltage', code='max_voltage',
107
+ type=constants.PART_REVISION_PROPERTY_TYPE_DECIMAL,
108
+ required=False, quantity_of_measure=qom_volt)
109
+ count, _ = PartRevisionPropertyDefinition.objects.get_or_create(name='Count', code='count',
110
+ type=constants.PART_REVISION_PROPERTY_TYPE_DECIMAL,
111
+ required=False, quantity_of_measure=qom_each)
112
+
113
+ defs = [sheen, voltage, max_voltage, count]
114
+
115
+ custom = None
116
+ if organization is not None:
117
+ custom, _ = PartRevisionPropertyDefinition.objects.get_or_create(name='Custom', code='custom',
118
+ type=constants.PART_REVISION_PROPERTY_TYPE_BOOLEAN,
119
+ required=False, quantity_of_measure=qom_custom)
120
+ defs.append(custom)
121
+
122
+ if part_class is not None:
123
+ part_class.property_definitions.add(*defs)
124
+
125
+ return sheen, voltage, max_voltage, count, custom
126
+
127
+
128
+ def create_a_fake_part_revision(part, assembly, description="Brown dog", revision="1", some_required_definitions=True):
68
129
  pch, created = PartRevision.objects.get_or_create(part=part, revision=revision, defaults={
69
130
  'description': description,
70
131
  'revision': revision,
71
- 'attribute': "Voltage",
72
- 'value': "3.3",
73
132
  'assembly': assembly,
74
133
  })
134
+
135
+ organization = part.organization
136
+ part_class = part.number_class if part else None
137
+ _, voltage, max_voltage, count, custom = create_some_fake_part_revision_property_definitions(organization,
138
+ some_required_definitions,
139
+ part_class=part_class)
140
+ v, mv, _, _, sv = create_some_fake_unit_definitions(organization)
141
+
142
+ PartRevisionProperty.objects.get_or_create(part_revision=pch, property_definition=voltage, unit_definition=v,
143
+ value_raw=".01")
144
+ PartRevisionProperty.objects.get_or_create(part_revision=pch, property_definition=max_voltage, unit_definition=v,
145
+ value_raw="3.5")
146
+ PartRevisionProperty.objects.get_or_create(part_revision=pch, property_definition=count, value_raw="5.2")
147
+ PartRevisionProperty.objects.get_or_create(part_revision=pch, property_definition=custom, unit_definition=sv,
148
+ value_raw="True")
149
+
75
150
  return pch
76
151
 
77
152