def add_product(self, cname, pname, price_name, price):
""" Add product to list
:param str cname: Category name
:param str pname: Product name
:param str price_name: Price name
:param float price: Price value
"""
name = "{} ({}) - {}".format(pname, price_name, cname)
for product in self.products:
if product['name'] == name:
product['price'] += price
product['price'] = product['price']
product['count'] += 1
product['widget'].setText(0, str(product['count']))
product['widget'].setText(2, str(round(product['price'], 2)))
break
else:
product = {
'name': name,
'price': price,
'count': 1,
'category': cname,
'product': pname,
'price_name': price_name,
'deletable': False if pname == settings.ECOCUP_NAME else True,
}
widget = QtWidgets.QTreeWidgetItem(['1', name, str(price)])
self.addTopLevelItem(widget)
product['widget'] = widget
self.products.append(product)
self.update_total()
评论列表
文章目录