public void SetOrderLinesTaxes(ref Order order)
        {
            foreach (var orderLine in order.OrderLines)
            {
                var productVariant = _productVariantService.GetProductVariantBySKU(orderLine.SKU);

                var getDefaultTaxRate    = new GetDefaultTaxRate(_session);
                var productPricingMethod = new ProductPricingMethod(new TaxSettings
                {
                    PriceLoadingMethod   = PriceLoadingMethod.IncludingTax,
                    TaxCalculationMethod = TaxCalculationMethod.Individual,
                    TaxesEnabled         = true
                }, getDefaultTaxRate);

                var taxRate = productVariant == null || productVariant.TaxRate == null
                    ? getDefaultTaxRate.Get()
                    : productVariant.TaxRate;

                var taxRatePercentage = taxRate == null ? 0 : taxRate.Percentage;
                var tax = productPricingMethod.GetTax(orderLine.UnitPrice, taxRatePercentage, 0m, 0m);

                orderLine.UnitPricePreTax = orderLine.UnitPrice - tax;
                orderLine.PricePreTax     = orderLine.UnitPricePreTax * orderLine.Quantity;
                orderLine.Tax             = orderLine.Price - orderLine.PricePreTax;
                orderLine.TaxRate         = _getProductVariantTaxRatePercentage.GetTaxRatePercentage(productVariant);
            }
            order.Subtotal = order.OrderLines.Sum(line => line.UnitPricePreTax * line.Quantity);
            order.Tax      = order.OrderLines.Sum(line => line.Tax);
        }
Beispiel #2
0
        public void Get_ShouldReturnTaxRate()
        {
            var taxRate = new TaxRate {
                Percentage = 10, IsDefault = true, Name = "GLOBAL", Code = "GL"
            };

            Session.Transact(session => session.Save(taxRate));

            TaxRate result = _getDefaultTaxRate.Get();

            result.Should().NotBeNull();
            result.Should().Be(taxRate);
        }