@companyio/purchasing
v0.1.6
Published
Universal purchasing package for multi-tenant CompanyIO products
Readme
@companyio/purchasing
Universal procurement for CompanyIO products. Fuel, POS, school, and retail share this package. None of them get industry columns here.
Purchasing owns purchase orders, receipts, supplier bills, supplier returns, and supplier payments.
Purchasing does not own:
- who the supplier is (
@companyio/contacts) - the ledger (
@companyio/accounting) - stock balances (
@companyio/inventory) - operating expenses (
@companyio/expenses) - customer sales (
@companyio/sales) - pumps, tanks, litres, or dips (
@companyio/fuel)
productRef stores a @companyio/catalog variant id. sourceModule, sourceType, and sourceId point at the host document. Meter readings and fuel dips do not belong here.
Install
The host owns PostgreSQL, DATABASE_URL, Prisma Client, and migrations.
pnpm exec purchasing init --schema apps/api/prisma/schema.prisma
pnpm exec purchasing statuspurchasing init appends models between // @companyio/purchasing:begin and // @companyio/purchasing:end and copies prisma/migrations/0001_purchasing_baseline when that baseline is missing. The host copy is 20260926001000_purchasing_baseline. It does not create a database and it does not run migrate. The host runs pnpm --filter @companyio/api exec prisma migrate deploy --config prisma7.config.ts. Tenant columns are main_business_id and branch_id, with no Prisma relation back to Business or Branch.
Fastify
attachPurchasing(app, {
store: createPrismaPurchasingStore(prisma),
prefix: '/api/v1/purchasing',
books: createAccountingPurchasingAdapter(accounting),
contacts: createContactsPurchasingAdapter(contacts),
inventory: {
receiptConfirmed: async (context, receipt) => {
/* call @companyio/inventory when this receipt has a location */
},
returnApproved: async (context, record) => {
/* call @companyio/inventory when this return has a location */
},
},
authenticate: async (request) => getUser(request),
getContext: (_request, user) => ({
main_business_id: user.main_business_id,
branch_id: user.branch_id,
user_id: user.id,
}),
});A confirmed receipt tells inventory what arrived (productRef, quantity, price). A draft receipt does not. Issuing a bill posts Dr purchase / Cr accounts payable. The debit account is debitAccountId on the bill, so a host can choose inventory, expense, or an asset. If it is omitted, the adapter uses the standard expense account.
Amounts are major currency units with two decimal places, using the same cent rounding as Accounting.
