mirror of
https://github.com/frappe/books.git
synced 2024-12-23 19:39:07 +00:00
c0ea8d6edc
- test manufacture stock movement
47 lines
1.0 KiB
TypeScript
47 lines
1.0 KiB
TypeScript
import { getDefaultMetaFieldValueMap } from '../../backend/helpers';
|
|
import { DatabaseManager } from '../database/manager';
|
|
|
|
async function execute(dm: DatabaseManager) {
|
|
const s = (await dm.db?.getAll('SingleValue', {
|
|
fields: ['value'],
|
|
filters: { fieldname: 'setupComplete' },
|
|
})) as { value: string }[];
|
|
|
|
if (!Number(s?.[0]?.value ?? '0')) {
|
|
return;
|
|
}
|
|
|
|
const names: Record<string, string> = {
|
|
StockMovement: 'SMOV-',
|
|
PurchaseReceipt: 'PREC-',
|
|
Shipment: 'SHPM-',
|
|
};
|
|
|
|
for (const referenceType in names) {
|
|
const name = names[referenceType];
|
|
await createNumberSeries(name, referenceType, dm);
|
|
}
|
|
}
|
|
|
|
async function createNumberSeries(
|
|
name: string,
|
|
referenceType: string,
|
|
dm: DatabaseManager
|
|
) {
|
|
const exists = await dm.db?.exists('NumberSeries', name);
|
|
if (exists) {
|
|
return;
|
|
}
|
|
|
|
await dm.db?.insert('NumberSeries', {
|
|
name,
|
|
start: 1001,
|
|
padZeros: 4,
|
|
current: 0,
|
|
referenceType,
|
|
...getDefaultMetaFieldValueMap(),
|
|
});
|
|
}
|
|
|
|
export default { execute, beforeMigrate: true };
|