fix(medusa): Add tax inclusive flag to return lines from line item (#2909)
This commit is contained in:
1 parent
90d774f563
commit
eda26f6e81
4 files changed
+135
-30
No files matched your search
@@ -2,20 +2,23 @@ import { MedusaError } from "medusa-core-utils"
|
||||
import { EntityManager, In } from "typeorm"
|
||||
import { DeepPartial } from "typeorm/common/DeepPartial"
|
||||
|
||||
import { CartRepository } from "../repositories/cart"
|
||||
import { LineItemRepository } from "../repositories/line-item"
|
||||
import { LineItemTaxLineRepository } from "../repositories/line-item-tax-line"
|
||||
import { TransactionBaseService } from "../interfaces"
|
||||
import OrderEditingFeatureFlag from "../loaders/feature-flags/order-editing"
|
||||
import TaxInclusivePricingFeatureFlag from "../loaders/feature-flags/tax-inclusive-pricing"
|
||||
import {
|
||||
LineItem,
|
||||
LineItemAdjustment,
|
||||
LineItemTaxLine,
|
||||
ProductVariant,
|
||||
} from "../models"
|
||||
import { CartRepository } from "../repositories/cart"
|
||||
import { LineItemRepository } from "../repositories/line-item"
|
||||
import { LineItemTaxLineRepository } from "../repositories/line-item-tax-line"
|
||||
import { FindConfig, Selector } from "../types/common"
|
||||
import { GenerateInputData, GenerateLineItemContext } from "../types/line-item"
|
||||
import { ProductVariantPricing } from "../types/pricing"
|
||||
import { buildQuery, isString, setMetadata } from "../utils"
|
||||
import { FlagRouter } from "../utils/flag-router"
|
||||
import LineItemAdjustmentService from "./line-item-adjustment"
|
||||
import OrderEditingFeatureFlag from "../loaders/feature-flags/order-editing"
|
||||
import TaxInclusivePricingFeatureFlag from "../loaders/feature-flags/tax-inclusive-pricing"
|
||||
import {
|
||||
PricingService,
|
||||
ProductService,
|
||||
@@ -23,10 +26,7 @@ import {
|
||||
RegionService,
|
||||
TaxProviderService,
|
||||
} from "./index"
|
||||
import { buildQuery, isString, setMetadata } from "../utils"
|
||||
import { TransactionBaseService } from "../interfaces"
|
||||
import { GenerateInputData, GenerateLineItemContext } from "../types/line-item"
|
||||
import { ProductVariantPricing } from "../types/pricing"
|
||||
import LineItemAdjustmentService from "./line-item-adjustment"
|
||||
|
||||
type InjectedDependencies = {
|
||||
manager: EntityManager
|
||||
@@ -159,6 +159,7 @@ class LineItemService extends TransactionBaseService {
|
||||
unit_price: -1 * lineItem.unit_price,
|
||||
quantity: lineItem.return_item.quantity,
|
||||
allow_discounts: lineItem.allow_discounts,
|
||||
includes_tax: !!lineItem.includes_tax,
|
||||
tax_lines: lineItem.tax_lines.map((taxLine) => {
|
||||
return itemTaxLineRepo.create({
|
||||
name: taxLine.name,
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { isDefined, MedusaError } from "medusa-core-utils"
|
||||
import { EntityManager } from "typeorm"
|
||||
import {
|
||||
ITaxCalculationStrategy,
|
||||
TaxCalculationContext,
|
||||
@@ -25,14 +26,10 @@ import {
|
||||
LineDiscountAmount,
|
||||
SubtotalOptions,
|
||||
} from "../types/totals"
|
||||
import {
|
||||
TaxProviderService,
|
||||
NewTotalsService,
|
||||
} from "./index"
|
||||
import { EntityManager } from "typeorm"
|
||||
import { NewTotalsService, TaxProviderService } from "./index"
|
||||
|
||||
import { calculatePriceTaxAmount } from "../utils"
|
||||
import TaxInclusivePricingFeatureFlag from "../loaders/feature-flags/tax-inclusive-pricing"
|
||||
import { calculatePriceTaxAmount } from "../utils"
|
||||
import { FlagRouter } from "../utils/flag-router"
|
||||
|
||||
type ShippingMethodTotals = {
|
||||
@@ -806,7 +803,7 @@ class TotalsService extends TransactionBaseService {
|
||||
|
||||
// Tax Information
|
||||
if (options.include_tax) {
|
||||
// When we have an order with a nulled or undefined tax rate we know that it is an
|
||||
// When we have an order with a tax rate we know that it is an
|
||||
// order from the old tax system. The following is a backward compat
|
||||
// calculation.
|
||||
if (isOrder(cartOrOrder) && cartOrOrder.tax_rate != null) {
|
||||
@@ -979,14 +976,11 @@ class TotalsService extends TransactionBaseService {
|
||||
giftCardable = subtotal - discountTotal
|
||||
}
|
||||
|
||||
return await this.newTotalsService_.getGiftCardTotals(
|
||||
giftCardable,
|
||||
{
|
||||
region: cartOrOrder.region,
|
||||
giftCards: cartOrOrder.gift_cards || [],
|
||||
giftCardTransactions: cartOrOrder['gift_card_transactions'] || []
|
||||
}
|
||||
)
|
||||
return await this.newTotalsService_.getGiftCardTotals(giftCardable, {
|
||||
region: cartOrOrder.region,
|
||||
giftCards: cartOrOrder.gift_cards || [],
|
||||
giftCardTransactions: cartOrOrder["gift_card_transactions"] || [],
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in new issue
Block a user