not round price

This commit is contained in:
morteza-mortezai
2025-12-10 16:57:57 +03:30
parent b8065bf53e
commit 0ce2fea56d
@@ -67,11 +67,11 @@ const productVariantSchema = new Schema<IProductVariant>(
productVariantSchema.pre("save", function (next) {
if (this.price) {
if (this.price.retailPrice) {
this.price.retailPrice = Math.round(this.price.retailPrice / 10000) * 10000;
this.price.retailPrice = Number(this.price.retailPrice);
const sellingPrice =
this.price.discount_percent > 0 ? this.price.retailPrice * ((100 - this.price.discount_percent) / 100) : this.price.retailPrice;
this.price.selling_price = Math.round(sellingPrice / 10000) * 10000;
this.price.selling_price = Number(sellingPrice);
}
}
@@ -84,15 +84,15 @@ productVariantSchema.pre(["findOneAndUpdate", "updateOne", "updateMany"], functi
// ensure price object exists in the update object
if (update.price && update.price.retailPrice !== undefined) {
const retailPrice = Math.round(update.price.retailPrice / 10000) * 10000;
const discountPercent = Math.round(update.price.discount_percent) || 0;
const retailPrice = Number(update.price.retailPrice);
const discountPercent = update.price.discount_percent || 0;
// calculate selling price based on retailPrice and discount_percent
const sellingPrice = discountPercent > 0 ? retailPrice * ((100 - discountPercent) / 100) : retailPrice;
// set the calculated selling price in the update object
update.price.retailPrice = retailPrice;
update.price.selling_price = Math.round(sellingPrice / 10000) * 10000;
update.price.selling_price = Number(sellingPrice);
update.price.discount_percent = discountPercent;
}