我正在尝试添加 return 0 以防方程式的最终结果为 None 以防万一: TypeError: unsupported operand type(s) for *: 'NoneType' and 'decimal.Decimal' 但它对我不起作用。
这样做的原因是没有。售出数量可以为零,因此它返回类型错误。
这是功能:
def designer_total_discount_price(self):
total_sold_discount = self.count_sold * self.discount_price
return 0 if total_sold_discount is None else total_sold_discount
def designer_total_price(self):
total_sold_regular = self.count_sold * self.price
return 0 if total_sold_regular is None else total_sold_regular
def designer_total(self):
if self.discount_price:
return self.designer_total_discount_price()
return self.designer_total_price()
def get_designer_final(self):
return self.designer_total() * self.designer_profit
汪汪一只猫
相关分类