Files
wekan/models/workload.js
T
Lauri Ojansivu d88662d69c PSA: expenses, fixed fees and retainers, time approval, cost rates and margin, quotes, utilization and skills.
Budget and billing gains what a professional services automation system
has on top of time and invoices:

- Expenses (travel, accommodation, meals, materials, subcontracting,
  software, other) with a markup, billable or not, on a card and a person.
  They spend the budget at their cost and go on the next invoice of their
  period at their charge, once; voiding or crediting frees them.
- Fixed fees billed once from their day (milestones, fixed prices) and
  monthly retainers to their end. Which occurrences are billed is read from
  the standing invoices' lines. "Bill time by the hour" off makes a board a
  fixed price: its invoices carry fees and expenses only.
- Approving time: with it on only approved time is invoiced; board admins
  approve or send back the waiting entries, the card's Time popup shows the
  decision, and approved time can no longer be removed by its logger.
- A cost per hour on a rate, the board's cost (hours at cost rates and
  expenses), unbilled work in progress and the margin.
- Quotes (QUO-YYYY-NNNN) of the work still to do and the fees not billed,
  valid for the invoicer's days, draft -> sent -> accepted or declined;
  accepting can make the quote the budget; PDF, SVG, Excel and CSV.
- The board's customer, filled in on invoices and quotes.

Workload gains billable utilization against working time with a target, and
skills with levels: a placeholder that needs a skill lists who could do it,
the most free hours first.

Two bugs found on the way: crediting an invoice failed on a real database,
because the invoice schema did not allow the status "credited" (a test now
checks every status the server writes against the schema); and the workload
report ignored everybody's own working time, because capacityOf validated
the stored document with its _id and userId and fell back to the default.

58 new strings are translated in every language. Lower-confidence
translations: chr, dz, bo, csb, cv, bua, ay, ff, fj, gn, gv, haw, ig, iu,
kl, kw, ks, kok, hsb, lg, lld, nah, nap, scn, sc, rup, rm, qu, se, sah, nd,
ss, nso, ny, sn, rn, rw, om, so, sm, mi, mg, pap, la, mai, or_IN, sd, ps,
my, tig, tlh, wal, zgh, vo, ve-PP, uz-AR, tpi, wa and wo.

Thanks to xet7 !
2026-11-21 22:19:45 +02:00

81 lines
4.1 KiB
JavaScript

// Workload and capacity planning (docs/Features/Workload/Workload.md): the
// collections the Workload page plans with. Every write goes through a method
// in server/workload.js, which checks who may make it, and nothing here is
// published: the page asks the server for a computed report instead, so the
// cards of every board in a report never reach the browser.
import { Meteor } from 'meteor/meteor';
import { Mongo } from 'meteor/mongo';
import { createdAtAutoValue, modifiedAtAutoValue } from '/models/lib/schemaTimestamps';
const { SimpleSchema } = require('/imports/simpleSchema');
// One person's working time: hours a week, work percent, working days.
export const WorkloadCapacities = new Mongo.Collection('workloadCapacities');
WorkloadCapacities.attachSchema(new SimpleSchema({
userId: { type: String },
hoursPerWeek: { type: Number, min: 0, max: 168 },
workPercent: { type: Number, min: 0, max: 100 },
workingDays: { type: Array },
'workingDays.$': { type: Number, min: 1, max: 7 },
// Skills, each a name and a level 1 to 5 (models/lib/workload.js).
skills: { type: Array, optional: true },
'skills.$': { type: Object },
'skills.$.name': { type: String, max: 50 },
'skills.$.level': { type: Number, min: 1, max: 5 },
// The share of the working time meant to be billable.
utilizationTarget: { type: Number, optional: true, min: 0, max: 100 },
createdAt: { type: Date, optional: true, autoValue: createdAtAutoValue },
modifiedAt: { type: Date, optional: true, autoValue: modifiedAtAutoValue },
}));
// Leave and absences of one person, both days inclusive. The type and the note
// are shown only to that person and to administrators (server/workload.js):
// to everybody else an absence is only "not available".
export const WorkloadAbsences = new Mongo.Collection('workloadAbsences');
WorkloadAbsences.attachSchema(new SimpleSchema({
userId: { type: String },
start: { type: String, regEx: /^\d{4}-\d\d-\d\d$/ },
end: { type: String, regEx: /^\d{4}-\d\d-\d\d$/ },
type: { type: String, allowedValues: ['vacation', 'sick', 'holiday', 'training', 'other'] },
note: { type: String, optional: true, max: 200 },
createdBy: { type: String, optional: true },
createdAt: { type: Date, optional: true, autoValue: createdAtAutoValue },
modifiedAt: { type: Date, optional: true, autoValue: modifiedAtAutoValue },
}));
// Public holidays, set in Admin Panel: a day off for everyone.
export const WorkloadHolidays = new Mongo.Collection('workloadHolidays');
WorkloadHolidays.attachSchema(new SimpleSchema({
date: { type: String, regEx: /^\d{4}-\d\d-\d\d$/ },
name: { type: String, optional: true, max: 100 },
createdBy: { type: String, optional: true },
createdAt: { type: Date, optional: true, autoValue: createdAtAutoValue },
modifiedAt: { type: Date, optional: true, autoValue: modifiedAtAutoValue },
}));
// Allocations: a person's share of their time on a board for a period - or,
// with no person, a placeholder for a role the board will need.
export const WorkloadAllocations = new Mongo.Collection('workloadAllocations');
WorkloadAllocations.attachSchema(new SimpleSchema({
boardId: { type: String },
userId: { type: String, optional: true },
roleName: { type: String, optional: true, max: 100 },
start: { type: String, regEx: /^\d{4}-\d\d-\d\d$/ },
end: { type: String, regEx: /^\d{4}-\d\d-\d\d$/ },
percent: { type: Number, min: 1, max: 100 },
headcount: { type: Number, min: 1, max: 100, optional: true },
// The skill a placeholder needs, and its lowest level.
skill: { type: String, optional: true, max: 50 },
skillLevel: { type: Number, optional: true, min: 1, max: 5 },
createdBy: { type: String, optional: true },
createdAt: { type: Date, optional: true, autoValue: createdAtAutoValue },
modifiedAt: { type: Date, optional: true, autoValue: modifiedAtAutoValue },
}));
// No client writes, to any of them: the methods are the only way in.
if (Meteor.isServer) {
for (const collection of [WorkloadCapacities, WorkloadAbsences, WorkloadHolidays, WorkloadAllocations]) {
collection.deny({ insert: () => true, update: () => true, remove: () => true });
}
}