Updated schemas.

This commit is contained in:
Tom Butcher 2025-12-13 22:35:01 +00:00
parent aa931c8f96
commit 787e8f6a9c
2 changed files with 6 additions and 13 deletions

View File

@ -62,7 +62,9 @@ orderItemSchema.statics.recalculate = async function (orderItem, user) {
model: purchaseOrderModel,
id: orderId,
updateData: {
cost: { net: totalAmount, gross: totalAmountWithTax },
totalAmount: parseFloat(totalAmount),
totalAmountWithTax: parseFloat(totalAmountWithTax),
totalTaxAmount: parseFloat(totalAmountWithTax - totalAmount),
},
user,
});

View File

@ -2,21 +2,12 @@ import mongoose from 'mongoose';
import { generateId } from '../../utils.js';
const { Schema } = mongoose;
const itemSchema = new Schema({
itemType: { type: String, required: true },
item: { type: Schema.Types.ObjectId, refPath: 'items.itemType', required: true },
quantity: { type: Number, required: true },
itemCost: { type: Number, required: true },
totalCost: { type: Number, required: true },
totalCostWithTax: { type: Number, required: true },
taxRate: { type: Schema.Types.ObjectId, ref: 'taxRate', required: false },
});
const purchaseOrderSchema = new Schema(
{
_reference: { type: String, default: () => generateId()() },
cost: { net: { type: Number, required: true }, gross: { type: Number, required: true } },
items: [itemSchema],
totalAmount: { type: Number, required: true },
totalAmountWithTax: { type: Number, required: true },
totalTaxAmount: { type: Number, required: true },
timestamp: { type: Date, default: Date.now },
vendor: { type: Schema.Types.ObjectId, ref: 'vendor', required: true },
state: {