def test_sum_values_without_including_rounding_error(): total = sum([Value(7.8, 7), Value(0.97, 7)]) assert total.vat == 0.62 assert total.brutto == 9.39 total = Value(20.75, 7) assert total.brutto == 22.2 assert total.vat == 1.45
def local_platform_owner_platform_fee(self) -> Value: total_platform_fees = Decimal(str(self.total_platform_fees.netto)) local_platform_fee_share = total_platform_fees * ( Decimal("1") - self.setting.central_share / Decimal("100")) local_platform_fee_share = local_platform_fee_share.quantize( Decimal(".01"), "ROUND_HALF_UP") return Value(local_platform_fee_share, self.setting.platform_fee_vat)
def central_logistic_delivery_fee(self) -> Value: value = self.transport_insurance return Value( value.quantize(Decimal(".01"), "ROUND_HALF_UP"), self.setting.mc_swiss_delivery_fee_vat, )
def calculate_gross_value_of_items(calc_items): items_values = [item.value for item in calc_items] items_values = sorted(items_values, key=lambda item: item.vat_rate) gross = Decimal("0") for vat_rate, lines_by_vat_rate in itertools.groupby( items_values, lambda item_value: item_value.vat_rate): sum_net_value = sum(value.netto for value in lines_by_vat_rate) total_value = Value(sum_net_value, vat_rate) gross += Decimal(str(total_value.brutto)) return gross
def _vat_breakdown(self, obj): items_values = [] for cart_item in obj.cart_items: items_values.append(cart_item.price) items_values.append(cart_item._delivery_fee()) items_values.append(cart_item.buyer_platform_fee) items_values.append(cart_item.container_deposit) items_values = sorted(items_values, key=lambda item: item.vat_rate) vat_mounts_by_rates = {} for vat_rate, items_for_vat_rate in itertools.groupby( items_values, lambda item: item.vat_rate): sum_net_value = sum(value.netto for value in items_for_vat_rate) total_value = Value(sum_net_value, vat_rate) vat_mounts_by_rates[float(vat_rate)] = total_value.vat total_vat_amount = sum(list(vat_mounts_by_rates.values())) total_vat_amount = round_float(total_vat_amount) return vat_mounts_by_rates, total_vat_amount
def sum_of_seller_platform_fees(self) -> Value: sum_of_seller_fees = sum( seller_fee for seller_fee in self.seller_platform_fees.values()) return Value(sum_of_seller_fees, self.setting.platform_fee_vat)
def buyer_platform_fee(self) -> Value: value = (Decimal(str(self.price.netto)) * self.buyer.buyer_platform_fee_rate / Decimal("100")) platform_fee = value.quantize(Decimal(".01"), "ROUND_HALF_UP") return Value(float(platform_fee), self.setting.platform_fee_vat)
def price(self): return Value(self.quantity * self.product_price * self.amount, self.product_vat)
def container_deposit(self) -> Value: return Value(self.container_deposit_net, self.setting.deposit_vat)
def _delivery_fee(self) -> Value: if self.is_central_logistic_delivery: return self.central_logistic_delivery_fee elif self.is_seller_delivery: return self.seller_delivery_fee return Value(0)
def seller_delivery_fee(self) -> Value: return Value( self.product_delivery_charge, self.setting.mc_swiss_delivery_fee_vat, )
def value(self): return Value( Decimal(self.price) * Decimal(self.count) * Decimal(self.amount), # endPrice - front Decimal(self.vat), )
def get_price_value(line): return Value( Decimal(line["price"]) * Decimal(line["count"]) * Decimal(line.get("amount", 1)), Decimal(line["vat_rate"]), )