fixed bug where some items were missed in the basic configurations (concho incorrectly assumes that the quatity of each item was 1)

This commit is contained in:
Guillaume Raffy 2023-03-13 15:12:17 +01:00
parent 0a59fd5f23
commit 1e93d89169
2 changed files with 16 additions and 2 deletions

View File

@ -363,7 +363,7 @@ class Config():
def get_price(self): def get_price(self):
price = self.configurator.chassis.price price = self.configurator.chassis.price
print(self.cpu.uid, self.configurator.chassis.price, self.configurator.get_item_price(self.cpu.uid), self.ram_price)
price += self.num_servers * self.num_cpu_per_server * self.configurator.get_item_price(self.cpu.uid) + self.ram_price price += self.num_servers * self.num_cpu_per_server * self.configurator.get_item_price(self.cpu.uid) + self.ram_price
assert price > 0.0 assert price > 0.0
return price return price

View File

@ -32,6 +32,12 @@ def parse_cpu_label(label: str) -> str:
assert False, 'unhandled label : %s' % label assert False, 'unhandled label : %s' % label
def hpe_product_get_attr(hpe_product_node: dict, attr_name: str) -> str:
for attr_node in hpe_product_node['attributes']:
if attr_node['id'] == attr_name:
return attr_node['value']
class HpeCatalogParser(): class HpeCatalogParser():
def __init__(self, hpe_catalog: dict): def __init__(self, hpe_catalog: dict):
@ -40,9 +46,16 @@ class HpeCatalogParser():
def get_base_price(self): def get_base_price(self):
base_price = 0.0 base_price = 0.0
for component_db in self.hpe_catalog: for component_db in self.hpe_catalog:
print('component %s' % component_db['id'])
for item_node in component_db['products']: for item_node in component_db['products']:
if item_node['selected']: if item_node['selected']:
base_price += float(item_node['price']) quantity = 1
# quantity_as_str = item_node['selectedQuantity']
quantity_as_str = hpe_product_get_attr(item_node, 'selectedQty')
if quantity_as_str:
quantity = int(quantity_as_str)
print('HpeCatalogParser.get_base_price : adding %d * %f (%s)' % (quantity, item_node['price'], item_node['desc']))
base_price += float(item_node['price']) * quantity
return base_price return base_price
def parse_proc_change_options(self): def parse_proc_change_options(self):
@ -365,6 +378,7 @@ class HpeConfiguratorParser():
one_cpu_price = configurator.get_item_price(configurator.base_config.cpu.uid) one_cpu_price = configurator.get_item_price(configurator.base_config.cpu.uid)
ram_price = configurator.base_config.ram_price ram_price = configurator.base_config.ram_price
print('HpeConfiguratorParser.parse : chassis_id=%s cpu.uid = %s, base_price=%f, ram_price=%f' % (chassis_id, configurator.base_config.cpu.uid, base_price, ram_price))
configurator.chassis.price = base_price - configurator.base_config.num_cpus * one_cpu_price - ram_price configurator.chassis.price = base_price - configurator.base_config.num_cpus * one_cpu_price - ram_price