From 27d67a33e5c61cc29751eae36c4e85ddff059fcc Mon Sep 17 00:00:00 2001 From: Mildred Ki'Lya Date: Tue, 16 Jan 2024 23:46:01 +0100 Subject: [PATCH 1/2] fix: #808 Payment referenceType NULL due to bad migration --- backend/patches/index.ts | 6 ++++++ backend/patches/setPaymentReferenceType.ts | 9 +++++++++ 2 files changed, 15 insertions(+) create mode 100644 backend/patches/setPaymentReferenceType.ts diff --git a/backend/patches/index.ts b/backend/patches/index.ts index 9dee78bb..5d59c1d9 100644 --- a/backend/patches/index.ts +++ b/backend/patches/index.ts @@ -4,6 +4,7 @@ import createInventoryNumberSeries from './createInventoryNumberSeries'; import fixRoundOffAccount from './fixRoundOffAccount'; import testPatch from './testPatch'; import updateSchemas from './updateSchemas'; +import setPaymentReferenceType from './setPaymentReferenceType'; export default [ { name: 'testPatch', version: '0.5.0-beta.0', patch: testPatch }, @@ -28,4 +29,9 @@ export default [ version: '0.6.6-beta.0', patch: createInventoryNumberSeries, }, + { + name: 'setPaymentReferenceType', + version: '0.21.0', + patch: setPaymentReferenceType, + }, ] as Patch[]; diff --git a/backend/patches/setPaymentReferenceType.ts b/backend/patches/setPaymentReferenceType.ts new file mode 100644 index 00000000..a141e201 --- /dev/null +++ b/backend/patches/setPaymentReferenceType.ts @@ -0,0 +1,9 @@ +import { DatabaseManager } from '../database/manager'; + +async function execute(dm: DatabaseManager) { + await dm.db!.knex!('Payment') + .where({ referenceType: null }) + .update({ referenceType: 'SalesInvoice' }); +} + +export default { execute, beforeMigrate: true }; From dcbfa9f1c5deb235c764f141220af562bf919b17 Mon Sep 17 00:00:00 2001 From: Mildred Ki'Lya Date: Fri, 19 Jan 2024 23:23:03 +0100 Subject: [PATCH 2/2] fix: setPaymentReferenceType patch for payments for versions >0.18 <0.20 --- backend/patches/setPaymentReferenceType.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/backend/patches/setPaymentReferenceType.ts b/backend/patches/setPaymentReferenceType.ts index a141e201..70f57b01 100644 --- a/backend/patches/setPaymentReferenceType.ts +++ b/backend/patches/setPaymentReferenceType.ts @@ -2,7 +2,10 @@ import { DatabaseManager } from '../database/manager'; async function execute(dm: DatabaseManager) { await dm.db!.knex!('Payment') - .where({ referenceType: null }) + .where({ referenceType: null, paymentType: 'Pay' }) + .update({ referenceType: 'PurchaseInvoice' }); + await dm.db!.knex!('Payment') + .where({ referenceType: null, paymentType: 'Receive' }) .update({ referenceType: 'SalesInvoice' }); }