diff options
author | Trygve Laugstøl <trygvis@inamo.no> | 2019-05-14 21:29:04 +0200 |
---|---|---|
committer | Trygve Laugstøl <trygvis@inamo.no> | 2019-05-14 21:29:04 +0200 |
commit | b9da2d88e21e5edda04e928352b45d203147be26 (patch) | |
tree | 2b62b862abe546d87e016a45e2df74d3ea7ba7a4 /src/ee/part/__init__.py | |
parent | ee62dd01720c8481599a717d067014164af7e096 (diff) | |
download | ee-python-b9da2d88e21e5edda04e928352b45d203147be26.tar.gz ee-python-b9da2d88e21e5edda04e928352b45d203147be26.tar.bz2 ee-python-b9da2d88e21e5edda04e928352b45d203147be26.tar.xz ee-python-b9da2d88e21e5edda04e928352b45d203147be26.zip |
ee.xsd:
o Removing distributor info, wasn't useful.
o Removing part type, using a fact instead.
part-search-list:
o Putting in some smart rules about values for parts. Might be too smart
for its own good.
o Removing duplication checking, that is up to the searcher to decide.
Diffstat (limited to 'src/ee/part/__init__.py')
-rw-r--r-- | src/ee/part/__init__.py | 25 |
1 files changed, 16 insertions, 9 deletions
diff --git a/src/ee/part/__init__.py b/src/ee/part/__init__.py index 996eeff..43e4cfa 100644 --- a/src/ee/part/__init__.py +++ b/src/ee/part/__init__.py @@ -1,5 +1,5 @@ from pathlib import Path -from typing import List, MutableMapping, Optional, Iterator, Union +from typing import List, Optional, Iterator, Union from ee import EeException from ee.money import Money @@ -43,6 +43,12 @@ class PartNumber(Reference): def to_xml(self): return types.PartNumber(value=self.value) + def __eq__(self, other): + return self.value == other.value + + def __hash__(self): + return hash(self.value) + class SupplierPartNumber(Reference): def __init__(self, value: str): @@ -51,6 +57,12 @@ class SupplierPartNumber(Reference): def to_xml(self): return types.SupplierPartNumber(value=self.value) + def __eq__(self, other): + return self.value == other.value + + def __hash__(self): + return hash(self.value) + class ReferenceList(object): def __init__(self, part_uri): @@ -296,6 +308,9 @@ class Part(object): def find_fact(self, key: str) -> Optional[types.Fact]: return next((f for f in self.get_facts() if f.keyProp == key), None) + def remove_fact(self, key): + self.xml.factsProp.fact = [f for f in self.xml.factsProp.fact if f.keyProp != key] + class Facts(object): def __init__(self, part): @@ -331,7 +346,6 @@ class Assembly(object): class PartDb(object): def __init__(self): self.parts: List[Entry] = [] - self.pn_index: MutableMapping[str, Entry] = {} self.new_entries = 0 self._assembly: Optional[Assembly] = None @@ -342,9 +356,6 @@ class PartDb(object): e = Entry(new, part) self.parts.append(e) - if e.pn: - self.pn_index[e.pn] = e - if e.new: self.new_entries = self.new_entries + 1 @@ -355,10 +366,6 @@ class PartDb(object): def size(self) -> int: return len(self.parts) - def find_by_pn(self, pn: str) -> Optional[types.Part]: - entry = self.pn_index.get(pn, None) - return entry.part if entry else None - @property def has_assembly(self): return self._assembly is not None |