|
|
@@ -38,7 +38,7 @@ export class OrderLine extends VendureEntity implements HasCustomFields {
|
|
|
@ManyToOne(type => Asset)
|
|
|
featuredAsset: Asset;
|
|
|
|
|
|
- @OneToMany(type => OrderItem, item => item.line)
|
|
|
+ @OneToMany(type => OrderItem, item => item.line, { eager: true })
|
|
|
items: OrderItem[];
|
|
|
|
|
|
@Index()
|
|
|
@@ -52,7 +52,7 @@ export class OrderLine extends VendureEntity implements HasCustomFields {
|
|
|
* @description
|
|
|
* The price of a single unit, excluding tax and discounts.
|
|
|
*/
|
|
|
- @Calculated()
|
|
|
+ @Calculated({ relations: ['items'] })
|
|
|
get unitPrice(): number {
|
|
|
return this.firstActiveItemPropOr('unitPrice', 0);
|
|
|
}
|
|
|
@@ -61,7 +61,7 @@ export class OrderLine extends VendureEntity implements HasCustomFields {
|
|
|
* @description
|
|
|
* The price of a single unit, including tax but excluding discounts.
|
|
|
*/
|
|
|
- @Calculated()
|
|
|
+ @Calculated({ relations: ['items'] })
|
|
|
get unitPriceWithTax(): number {
|
|
|
return this.firstActiveItemPropOr('unitPriceWithTax', 0);
|
|
|
}
|
|
|
@@ -70,7 +70,7 @@ export class OrderLine extends VendureEntity implements HasCustomFields {
|
|
|
* @description
|
|
|
* Non-zero if the `unitPrice` has changed since it was initially added to Order.
|
|
|
*/
|
|
|
- @Calculated()
|
|
|
+ @Calculated({ relations: ['items'] })
|
|
|
get unitPriceChangeSinceAdded(): number {
|
|
|
const firstItem = this.activeItems[0];
|
|
|
if (!firstItem) {
|
|
|
@@ -87,7 +87,7 @@ export class OrderLine extends VendureEntity implements HasCustomFields {
|
|
|
* @description
|
|
|
* Non-zero if the `unitPriceWithTax` has changed since it was initially added to Order.
|
|
|
*/
|
|
|
- @Calculated()
|
|
|
+ @Calculated({ relations: ['items'] })
|
|
|
get unitPriceWithTaxChangeSinceAdded(): number {
|
|
|
const firstItem = this.activeItems[0];
|
|
|
if (!firstItem) {
|
|
|
@@ -109,7 +109,7 @@ export class OrderLine extends VendureEntity implements HasCustomFields {
|
|
|
* correct price to display to customers to avoid confusion
|
|
|
* about the internal handling of distributed Order-level discounts.
|
|
|
*/
|
|
|
- @Calculated()
|
|
|
+ @Calculated({ relations: ['items'] })
|
|
|
get discountedUnitPrice(): number {
|
|
|
return this.firstActiveItemPropOr('discountedUnitPrice', 0);
|
|
|
}
|
|
|
@@ -118,7 +118,7 @@ export class OrderLine extends VendureEntity implements HasCustomFields {
|
|
|
* @description
|
|
|
* The price of a single unit including discounts and tax
|
|
|
*/
|
|
|
- @Calculated()
|
|
|
+ @Calculated({ relations: ['items'] })
|
|
|
get discountedUnitPriceWithTax(): number {
|
|
|
return this.firstActiveItemPropOr('discountedUnitPriceWithTax', 0);
|
|
|
}
|
|
|
@@ -129,7 +129,7 @@ export class OrderLine extends VendureEntity implements HasCustomFields {
|
|
|
* Order-level discounts. This value is the true economic value of the OrderItem, and is used in tax
|
|
|
* and refund calculations.
|
|
|
*/
|
|
|
- @Calculated()
|
|
|
+ @Calculated({ relations: ['items'] })
|
|
|
get proratedUnitPrice(): number {
|
|
|
return this.firstActiveItemPropOr('proratedUnitPrice', 0);
|
|
|
}
|
|
|
@@ -138,17 +138,17 @@ export class OrderLine extends VendureEntity implements HasCustomFields {
|
|
|
* @description
|
|
|
* The `proratedUnitPrice` including tax.
|
|
|
*/
|
|
|
- @Calculated()
|
|
|
+ @Calculated({ relations: ['items'] })
|
|
|
get proratedUnitPriceWithTax(): number {
|
|
|
return this.firstActiveItemPropOr('proratedUnitPriceWithTax', 0);
|
|
|
}
|
|
|
|
|
|
- @Calculated()
|
|
|
+ @Calculated({ relations: ['items'] })
|
|
|
get quantity(): number {
|
|
|
return this.activeItems.length;
|
|
|
}
|
|
|
|
|
|
- @Calculated()
|
|
|
+ @Calculated({ relations: ['items'] })
|
|
|
get adjustments(): Adjustment[] {
|
|
|
return this.activeItems.reduce(
|
|
|
(adjustments, item) => [...adjustments, ...(item.adjustments || [])],
|
|
|
@@ -156,12 +156,12 @@ export class OrderLine extends VendureEntity implements HasCustomFields {
|
|
|
);
|
|
|
}
|
|
|
|
|
|
- @Calculated()
|
|
|
+ @Calculated({ relations: ['items'] })
|
|
|
get taxLines(): TaxLine[] {
|
|
|
return this.firstActiveItemPropOr('taxLines', []);
|
|
|
}
|
|
|
|
|
|
- @Calculated()
|
|
|
+ @Calculated({ relations: ['items'] })
|
|
|
get taxRate(): number {
|
|
|
return this.firstActiveItemPropOr('taxRate', 0);
|
|
|
}
|
|
|
@@ -170,7 +170,7 @@ export class OrderLine extends VendureEntity implements HasCustomFields {
|
|
|
* @description
|
|
|
* The total price of the line excluding tax and discounts.
|
|
|
*/
|
|
|
- @Calculated()
|
|
|
+ @Calculated({ relations: ['items'] })
|
|
|
get linePrice(): number {
|
|
|
return summate(this.activeItems, 'unitPrice');
|
|
|
}
|
|
|
@@ -179,7 +179,7 @@ export class OrderLine extends VendureEntity implements HasCustomFields {
|
|
|
* @description
|
|
|
* The total price of the line including tax but excluding discounts.
|
|
|
*/
|
|
|
- @Calculated()
|
|
|
+ @Calculated({ relations: ['items'] })
|
|
|
get linePriceWithTax(): number {
|
|
|
return summate(this.activeItems, 'unitPriceWithTax');
|
|
|
}
|
|
|
@@ -188,7 +188,7 @@ export class OrderLine extends VendureEntity implements HasCustomFields {
|
|
|
* @description
|
|
|
* The price of the line including discounts, excluding tax.
|
|
|
*/
|
|
|
- @Calculated()
|
|
|
+ @Calculated({ relations: ['items'] })
|
|
|
get discountedLinePrice(): number {
|
|
|
return summate(this.activeItems, 'discountedUnitPrice');
|
|
|
}
|
|
|
@@ -197,12 +197,12 @@ export class OrderLine extends VendureEntity implements HasCustomFields {
|
|
|
* @description
|
|
|
* The price of the line including discounts and tax.
|
|
|
*/
|
|
|
- @Calculated()
|
|
|
+ @Calculated({ relations: ['items'] })
|
|
|
get discountedLinePriceWithTax(): number {
|
|
|
return summate(this.activeItems, 'discountedUnitPriceWithTax');
|
|
|
}
|
|
|
|
|
|
- @Calculated()
|
|
|
+ @Calculated({ relations: ['items'] })
|
|
|
get discounts(): Discount[] {
|
|
|
const priceIncludesTax = this.items?.[0]?.listPriceIncludesTax ?? false;
|
|
|
// Group discounts together, so that it does not list a new
|
|
|
@@ -232,7 +232,7 @@ export class OrderLine extends VendureEntity implements HasCustomFields {
|
|
|
* @description
|
|
|
* The total tax on this line.
|
|
|
*/
|
|
|
- @Calculated()
|
|
|
+ @Calculated({ relations: ['items'] })
|
|
|
get lineTax(): number {
|
|
|
return summate(this.activeItems, 'unitTax');
|
|
|
}
|
|
|
@@ -243,7 +243,7 @@ export class OrderLine extends VendureEntity implements HasCustomFields {
|
|
|
* Order-level discounts. This value is the true economic value of the OrderLine, and is used in tax
|
|
|
* and refund calculations.
|
|
|
*/
|
|
|
- @Calculated()
|
|
|
+ @Calculated({ relations: ['items'] })
|
|
|
get proratedLinePrice(): number {
|
|
|
return summate(this.activeItems, 'proratedUnitPrice');
|
|
|
}
|
|
|
@@ -252,12 +252,12 @@ export class OrderLine extends VendureEntity implements HasCustomFields {
|
|
|
* @description
|
|
|
* The `proratedLinePrice` including tax.
|
|
|
*/
|
|
|
- @Calculated()
|
|
|
+ @Calculated({ relations: ['items'] })
|
|
|
get proratedLinePriceWithTax(): number {
|
|
|
return summate(this.activeItems, 'proratedUnitPriceWithTax');
|
|
|
}
|
|
|
|
|
|
- @Calculated()
|
|
|
+ @Calculated({ relations: ['items'] })
|
|
|
get proratedLineTax(): number {
|
|
|
return summate(this.activeItems, 'proratedUnitTax');
|
|
|
}
|