feat: Add support for managing tax inclusivity (#7943)
UI / HTTP / Workflows will come in separate PRs REF CORE-2376
This commit is contained in:
1 parent
20be64e799
commit
5544303b91
17 files changed
+970
-66
No files matched your search
@@ -3,4 +3,5 @@ export * from "./price"
|
||||
export * from "./price-list"
|
||||
export * from "./price-rule"
|
||||
export * from "./price-set"
|
||||
export * from "./price-preference"
|
||||
export * from "./pricing-context"
|
||||
@@ -0,0 +1,95 @@
|
||||
import { BaseFilterable } from "../../dal"
|
||||
|
||||
/**
|
||||
* @interface
|
||||
*
|
||||
* A price preference's data.
|
||||
*/
|
||||
export interface PricePreferenceDTO {
|
||||
/**
|
||||
* The ID of a price preference.
|
||||
*/
|
||||
id: string
|
||||
/**
|
||||
* The rule attribute for the preference
|
||||
*/
|
||||
attribute: string | null
|
||||
/**
|
||||
* The rule value for the preference
|
||||
*/
|
||||
value: string | null
|
||||
/**
|
||||
* Flag specifying whether prices for the specified rule are tax inclusive.
|
||||
*/
|
||||
is_tax_inclusive: boolean
|
||||
/**
|
||||
* When the price preference was created.
|
||||
*/
|
||||
created_at: Date
|
||||
/**
|
||||
* When the price preference was updated.
|
||||
*/
|
||||
updated_at: Date
|
||||
/**
|
||||
* When the price preference was deleted.
|
||||
*/
|
||||
deleted_at: null | Date
|
||||
}
|
||||
|
||||
export interface UpsertPricePreferenceDTO extends UpdatePricePreferenceDTO {
|
||||
/**
|
||||
* The ID of a price preference.
|
||||
*/
|
||||
id?: string
|
||||
}
|
||||
|
||||
export interface UpdatePricePreferenceDTO {
|
||||
/**
|
||||
* The rule attribute for the preference
|
||||
*/
|
||||
attribute?: string | null
|
||||
/**
|
||||
* The rule value for the preference
|
||||
*/
|
||||
value?: string | null
|
||||
/**
|
||||
* Flag specifying whether prices for the specified rule are tax inclusive.
|
||||
*/
|
||||
is_tax_inclusive?: boolean
|
||||
}
|
||||
|
||||
export interface CreatePricePreferenceDTO {
|
||||
/**
|
||||
* The rule attribute for the preference
|
||||
*/
|
||||
attribute?: string
|
||||
/**
|
||||
* The rule value for the preference
|
||||
*/
|
||||
value?: string
|
||||
/**
|
||||
* Flag specifying whether prices for the specified rule are tax inclusive.
|
||||
*/
|
||||
is_tax_inclusive?: boolean
|
||||
}
|
||||
|
||||
/**
|
||||
* @interface
|
||||
*
|
||||
* Filters to apply on prices.
|
||||
*/
|
||||
export interface FilterablePricePreferenceProps
|
||||
extends BaseFilterable<FilterablePricePreferenceProps> {
|
||||
/**
|
||||
* The IDs to filter the price preferences by.
|
||||
*/
|
||||
id?: string[]
|
||||
/**
|
||||
* Attributes to filter price preferences by.
|
||||
*/
|
||||
attribute?: string | string[]
|
||||
/**
|
||||
* Values to filter price preferences by.
|
||||
*/
|
||||
value?: string | string[]
|
||||
}
|
||||
@@ -121,6 +121,10 @@ export interface CalculatedPriceSet {
|
||||
* the calculated price is set to the original price, which doesn't belong to a price list. In that case, the value of this property is `false`.
|
||||
*/
|
||||
is_calculated_price_price_list?: boolean
|
||||
/**
|
||||
* Whether the calculated price is tax inclusive or not.
|
||||
*/
|
||||
is_calculated_price_tax_inclusive?: boolean
|
||||
/**
|
||||
* The amount of the calculated price, or `null` if there isn't a calculated price.
|
||||
*/
|
||||
@@ -131,6 +135,10 @@ export interface CalculatedPriceSet {
|
||||
* the original price will be the same as the calculated price. In that case, the value of this property is `true`.
|
||||
*/
|
||||
is_original_price_price_list?: boolean
|
||||
/**
|
||||
* Whether the original price is tax inclusive or not.
|
||||
*/
|
||||
is_original_price_tax_inclusive?: boolean
|
||||
/**
|
||||
* The amount of the original price, or `null` if there isn't a calculated price.
|
||||
*/
|
||||
|
||||
@@ -29,6 +29,13 @@ import {
|
||||
UpdatePriceSetDTO,
|
||||
UpsertPriceSetDTO,
|
||||
} from "./common"
|
||||
import {
|
||||
CreatePricePreferenceDTO,
|
||||
FilterablePricePreferenceProps,
|
||||
PricePreferenceDTO,
|
||||
UpdatePricePreferenceDTO,
|
||||
UpsertPricePreferenceDTO,
|
||||
} from "./common/price-preference"
|
||||
|
||||
/**
|
||||
* The main service interface for the Pricing Module.
|
||||
@@ -1488,4 +1495,261 @@ export interface IPricingModuleService extends IModuleService {
|
||||
* ])
|
||||
*/
|
||||
removePrices(ids: string[], sharedContext?: Context): Promise<void>
|
||||
|
||||
/**
|
||||
* This method is used to retrieve a price preference by its ID.
|
||||
*
|
||||
* @param {string} id - The ID of the price preference to retrieve.
|
||||
* @param {FindConfig<PricePreferenceDTO>} config -
|
||||
* The configurations determining how the price preference is retrieved. Its properties, such as `select` or `relations`, accept the
|
||||
* attributes or relations associated with a price preference.
|
||||
* @param {Context} sharedContext - A context used to share resources, such as transaction manager, between the application and the module.
|
||||
* @returns {Promise<PricePreferenceDTO>} The retrieved price preference.
|
||||
*
|
||||
* @example
|
||||
* A simple example that retrieves a price preference by its ID:
|
||||
*
|
||||
* ```ts
|
||||
* const pricePreference =
|
||||
* await pricingModuleService.retrievePricePreference("prpref_123")
|
||||
* ```
|
||||
*/
|
||||
retrievePricePreference(
|
||||
id: string,
|
||||
config?: FindConfig<PricePreferenceDTO>,
|
||||
sharedContext?: Context
|
||||
): Promise<PricePreferenceDTO>
|
||||
|
||||
/**
|
||||
* This method is used to retrieve a paginated list of price preferences based on optional filters and configuration.
|
||||
*
|
||||
* @param {FilterablePricePreferenceProps} filters - The filters to apply on the retrieved price lists.
|
||||
* @param {FindConfig<PricePreferenceDTO>} config -
|
||||
* The configurations determining how the price preferences are retrieved. Its properties, such as `select` or `relations`, accept the
|
||||
* attributes or relations associated with a price preference.
|
||||
* @param {Context} sharedContext - A context used to share resources, such as transaction manager, between the application and the module.
|
||||
* @returns {Promise<PricePreferenceDTO[]>} The list of price preferences.
|
||||
*
|
||||
* @example
|
||||
*
|
||||
* To retrieve a list of price preferences using their IDs:
|
||||
*
|
||||
* ```ts
|
||||
* const pricePreferences = await pricingModuleService.listPricePreferences({
|
||||
* id: ["prpref_123", "prpref_321"],
|
||||
* })
|
||||
* ```
|
||||
*
|
||||
* To specify relations that should be retrieved within the price preferences:
|
||||
*
|
||||
* By default, only the first `15` records are retrieved. You can control pagination by specifying the `skip` and `take` properties of the `config` parameter:
|
||||
*
|
||||
* ```ts
|
||||
* const pricePreferences = await pricingModuleService.listPricePreferences(
|
||||
* {
|
||||
* id: ["prpref_123", "prpref_321"],
|
||||
* },
|
||||
* {
|
||||
* take: 20,
|
||||
* skip: 2,
|
||||
* }
|
||||
* )
|
||||
* ```
|
||||
*/
|
||||
listPricePreferences(
|
||||
filters?: FilterablePricePreferenceProps,
|
||||
config?: FindConfig<PricePreferenceDTO>,
|
||||
sharedContext?: Context
|
||||
): Promise<PricePreferenceDTO[]>
|
||||
|
||||
/**
|
||||
* This method is used to create a new price preference.
|
||||
*
|
||||
* @param {CreatePricePreferenceDTO} data - The attributes of the price preference to create.
|
||||
* @param {Context} sharedContext - A context used to share resources, such as transaction manager, between the application and the module.
|
||||
* @returns {Promise<PricePreferenceDTO>} The created price preference.
|
||||
*
|
||||
* @example
|
||||
* To create a price preference with rule:
|
||||
*
|
||||
* ```ts
|
||||
* const pricePreference = await pricingModuleService.createPricePreferences({
|
||||
* attribute: 'region_id',
|
||||
* value: 'DE',
|
||||
* is_tax_inclusive: true
|
||||
* })
|
||||
* ```
|
||||
*/
|
||||
createPricePreferences(
|
||||
data: CreatePricePreferenceDTO,
|
||||
sharedContext?: Context
|
||||
): Promise<PricePreferenceDTO>
|
||||
|
||||
/**
|
||||
* This method is used to create multiple price preferences.
|
||||
*
|
||||
* @param {CreatePricePreferenceDTO[]} data - The price preferences to create.
|
||||
* @param {Context} sharedContext - A context used to share resources, such as transaction manager, between the application and the module.
|
||||
* @returns {Promise<PricePreferenceDTO[]>} The list of created price preferences.
|
||||
*
|
||||
* @example
|
||||
* const pricePreferences = await pricingModuleService.createPricePreferences([{
|
||||
* attribute: 'region_id',
|
||||
* value: 'DE',
|
||||
* is_tax_inclusive: true
|
||||
* }])
|
||||
*/
|
||||
createPricePreferences(
|
||||
data: CreatePricePreferenceDTO[],
|
||||
sharedContext?: Context
|
||||
): Promise<PricePreferenceDTO[]>
|
||||
|
||||
/**
|
||||
* This method updates existing price preferences, or creates new ones if they don't exist.
|
||||
*
|
||||
* @param {UpsertPricePreferenceDTO[]} data - The attributes to update or create for each price preference.
|
||||
* @param {Context} sharedContext - A context used to share resources, such as transaction manager, between the application and the module.
|
||||
* @returns {Promise<PricePreferenceDTO[]>} The updated and created price preferences.
|
||||
*
|
||||
* @example
|
||||
* const pricePreferences = await pricingModuleService.upsertPricePreferences([
|
||||
* {
|
||||
* id: "prpref_123",
|
||||
* attribute: 'region_id',
|
||||
* value: 'DE',
|
||||
* is_tax_inclusive: true
|
||||
* },
|
||||
* ])
|
||||
*/
|
||||
upsertPricePreferences(
|
||||
data: UpsertPricePreferenceDTO[],
|
||||
sharedContext?: Context
|
||||
): Promise<PricePreferenceDTO[]>
|
||||
|
||||
/**
|
||||
* This method updates the price preference if it exists, or creates a new ones if it doesn't.
|
||||
*
|
||||
* @param {UpsertPricePreferenceDTO} data - The attributes to update or create for the new price preference.
|
||||
* @param {Context} sharedContext - A context used to share resources, such as transaction manager, between the application and the module.
|
||||
* @returns {Promise<PricePreferenceDTO>} The updated or created price preference.
|
||||
*
|
||||
* @example
|
||||
* const pricePreference = await pricingModuleService.upsertPricePreferences(
|
||||
* {
|
||||
* id: "prpref_123",
|
||||
* attribute: 'region_id',
|
||||
* value: 'DE',
|
||||
* is_tax_inclusive: true
|
||||
* }
|
||||
* )
|
||||
*/
|
||||
upsertPricePreferences(
|
||||
data: UpsertPricePreferenceDTO,
|
||||
sharedContext?: Context
|
||||
): Promise<PricePreferenceDTO>
|
||||
|
||||
/**
|
||||
* This method is used to update a price preference.
|
||||
*
|
||||
* @param {string} id - The ID of the price preference to be updated.
|
||||
* @param {UpdatePricePreferenceDTO} data - The attributes of the price preference to be updated
|
||||
* @param {Context} sharedContext - A context used to share resources, such as transaction manager, between the application and the module.
|
||||
* @returns {Promise<PricePreferenceDTO>} The updated price preference.
|
||||
*
|
||||
* @example
|
||||
* const pricePreference = await pricingModuleService.updatePricePreferences(
|
||||
* "prpref_123",
|
||||
* {
|
||||
* is_tax_inclusive: false
|
||||
* }
|
||||
* )
|
||||
*/
|
||||
updatePricePreferences(
|
||||
id: string,
|
||||
data: UpdatePricePreferenceDTO,
|
||||
sharedContext?: Context
|
||||
): Promise<PricePreferenceDTO>
|
||||
|
||||
/**
|
||||
* This method is used to update a list of price preferences determined by the selector filters.
|
||||
*
|
||||
* @param {FilterablePricePreferenceProps} selector - The filters that will determine which price preferences will be updated.
|
||||
* @param {UpdatePricePreferenceDTO} data - The attributes to be updated on the selected price preferences
|
||||
* @param {Context} sharedContext - A context used to share resources, such as transaction manager, between the application and the module.
|
||||
* @returns {Promise<PricePreferenceDTO[]>} The updated price preferences.
|
||||
*
|
||||
* @example
|
||||
* const pricePreferences = await pricingModuleService.updatePricePreferences(
|
||||
* {
|
||||
* id: ["prpref_123", "prpref_321"],
|
||||
* },
|
||||
* {
|
||||
* is_tax_inclusive: false
|
||||
* }
|
||||
* )
|
||||
*/
|
||||
updatePricePreferences(
|
||||
selector: FilterablePricePreferenceProps,
|
||||
data: UpdatePricePreferenceDTO,
|
||||
sharedContext?: Context
|
||||
): Promise<PricePreferenceDTO[]>
|
||||
|
||||
/**
|
||||
* This method soft deletes price preferences by their IDs.
|
||||
*
|
||||
* @param {string[]} pricePreferenceIds - The IDs of the price preferences.
|
||||
* @param {SoftDeleteReturn<TReturnableLinkableKeys>} config - An object that is used to specify an entity's related entities that should be soft-deleted when the main entity is soft-deleted.
|
||||
* @param {Context} sharedContext - A context used to share resources, such as transaction manager, between the application and the module.
|
||||
* @returns {Promise<void | Record<string, string[]>>} An object that includes the IDs of related records that were also soft deleted.
|
||||
* The object's keys are the ID attribute names of the price preference entity's relations, and its value is an array of strings, each being the ID of a record associated.
|
||||
*
|
||||
* If there are no related records, the promise resolves to `void`.
|
||||
*
|
||||
* @example
|
||||
* await pricingModuleService.softDeletePricePreferences([
|
||||
* "prpref_123",
|
||||
* "prpref_321",
|
||||
* ])
|
||||
*/
|
||||
softDeletePricePreferences<TReturnableLinkableKeys extends string = string>(
|
||||
pricePreferenceIds: string[],
|
||||
config?: SoftDeleteReturn<TReturnableLinkableKeys>,
|
||||
sharedContext?: Context
|
||||
): Promise<Record<string, string[]> | void>
|
||||
|
||||
/**
|
||||
* This method restores soft deleted price preferences by their IDs.
|
||||
*
|
||||
* @param {string[]} pricePreferenceIds - The IDs of the price preferences.
|
||||
* @param {RestoreReturn<TReturnableLinkableKeys>} config - Configurations determining which relations to restore along with each of the price preferences.
|
||||
* @param {Context} sharedContext - A context used to share resources, such as transaction manager, between the application and the module.
|
||||
* @returns {Promise<void | Record<string, string[]>>} An object that includes the IDs of related records that were restored.
|
||||
* The object's keys are the ID attribute names of the price preferences entity's relations,
|
||||
* and its value is an array of strings, each being the ID of the record associated with the price preferences through this relation.
|
||||
*
|
||||
* If there are no related records restored, the promise resolves to `void`.
|
||||
*
|
||||
* @example
|
||||
* await pricingModuleService.restorePricePreferences([
|
||||
* "prpref_123",
|
||||
* "prpref_321",
|
||||
* ])
|
||||
*/
|
||||
restorePricePreferences<TReturnableLinkableKeys extends string = string>(
|
||||
pricePreferenceIds: string[],
|
||||
config?: RestoreReturn<TReturnableLinkableKeys>,
|
||||
sharedContext?: Context
|
||||
): Promise<Record<string, string[]> | void>
|
||||
|
||||
/**
|
||||
* This method deletes price preferences by their IDs.
|
||||
*
|
||||
* @param {string[]} ids - The IDs of the price preferences to delete.
|
||||
* @param {Context} sharedContext - A context used to share resources, such as transaction manager, between the application and the module.
|
||||
* @returns {Promise<void>} Resolves when the price preferences are successfully deleted.
|
||||
*
|
||||
* @example
|
||||
* await pricingModuleService.deletePricePreferences(["prpref_123", "prpref_321"])
|
||||
*/
|
||||
deletePricePreferences(ids: string[], sharedContext?: Context): Promise<void>
|
||||
}
|
||||
Reference in new issue
Block a user