From 0bd1706e2bfb2f98e123e1f83d2192a41e5685e0 Mon Sep 17 00:00:00 2001 From: 18alantom <2.alan.tom@gmail.com> Date: Tue, 8 Mar 2022 12:13:29 +0530 Subject: [PATCH 1/8] feat: add reference to number series doc --- .../doctype/NumberSeries/NumberSeries.js | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/frappe/models/doctype/NumberSeries/NumberSeries.js b/frappe/models/doctype/NumberSeries/NumberSeries.js index 379e48ad..ecd85748 100644 --- a/frappe/models/doctype/NumberSeries/NumberSeries.js +++ b/frappe/models/doctype/NumberSeries/NumberSeries.js @@ -1,5 +1,18 @@ const { t } = require('frappe'); +const referenceTypeMap = { + SalesInvoice: t`Invoice`, + PurchaseInvoice: t`Bill`, + Payment: t`Payment`, + JournalEntry: t`Journal Entry`, + Quotation: t`Quotation`, + SalesOrder: t`SalesOrder`, + Fulfillment: t`Fulfillment`, + PurchaseOrder: t`PurchaseOrder`, + PurchaseReceipt: t`PurchaseReceipt`, + '-': t`None`, +}; + module.exports = { name: 'NumberSeries', documentClass: require('./NumberSeriesDocument.js'), @@ -14,11 +27,28 @@ module.exports = { fieldtype: 'Data', required: 1, }, + { + fieldname: 'referenceType', + label: t`Reference Type`, + fieldtype: 'Select', + options: Object.keys(referenceTypeMap), + map: referenceTypeMap, + default: '-', + required: 1, + }, + { + fieldname: 'start', + label: t`Start`, + fieldtype: 'Int', + default: 1001, + required: 1, + }, { fieldname: 'current', label: t`Current`, fieldtype: 'Int', required: 1, + readOnly: 1, }, ], }; From c9631c27a6d51baaabee3bcb120bed4ac71e7edf Mon Sep 17 00:00:00 2001 From: 18alantom <2.alan.tom@gmail.com> Date: Tue, 8 Mar 2022 12:14:05 +0530 Subject: [PATCH 2/8] feat: add numberSeries field to docs --- frappe/utils/consts.js | 13 ++++++++++++- models/doctype/Fulfillment/Fulfillment.js | 12 ++++++++++++ models/doctype/JournalEntry/JournalEntry.js | 12 ++++++++++++ models/doctype/Payment/Payment.js | 13 +++++++++++++ models/doctype/PurchaseInvoice/PurchaseInvoice.js | 12 ++++++++++++ models/doctype/PurchaseOrder/PurchaseOrder.js | 12 ++++++++++++ models/doctype/PurchaseReceipt/PurchaseReceipt.js | 12 ++++++++++++ models/doctype/Quotation/Quotation.js | 12 ++++++++++++ models/doctype/SalesInvoice/SalesInvoice.js | 12 ++++++++++++ models/doctype/SalesOrder/SalesOrder.js | 12 ++++++++++++ 10 files changed, 121 insertions(+), 1 deletion(-) diff --git a/frappe/utils/consts.js b/frappe/utils/consts.js index 7b30b826..88e741fa 100644 --- a/frappe/utils/consts.js +++ b/frappe/utils/consts.js @@ -1,4 +1,15 @@ export const DEFAULT_INTERNAL_PRECISION = 11; export const DEFAULT_DISPLAY_PRECISION = 2; export const DEFAULT_LOCALE = 'en-IN'; -export const DEFAULT_LANGUAGE = 'English'; \ No newline at end of file +export const DEFAULT_LANGUAGE = 'English'; +export const DEFAULT_NUMBER_SERIES = { + SalesInvoice: 'SINV-', + PurchaseInvoice: 'PINV-', + Payment: 'PAY-', + JournalEntry: 'JV-', + Quotation: 'QTN-', + SalesOrder: 'SO-', + Fulfillment: 'OF-', + PurchaseOrder: 'PO-', + PurchaseReceipt: 'PREC-', +}; diff --git a/models/doctype/Fulfillment/Fulfillment.js b/models/doctype/Fulfillment/Fulfillment.js index 6a6ebe40..7fbb7ec2 100644 --- a/models/doctype/Fulfillment/Fulfillment.js +++ b/models/doctype/Fulfillment/Fulfillment.js @@ -1,5 +1,6 @@ import { t } from 'frappe'; import model from 'frappe/model'; +import { DEFAULT_NUMBER_SERIES } from '../../../frappe/utils/consts'; import Quotation from '../Quotation/Quotation'; export default model.extend(Quotation, { @@ -11,5 +12,16 @@ export default model.extend(Quotation, { fieldname: 'items', childtype: 'FulfillmentItem', }, + { + fieldname: 'numberSeries', + label: t`Number Series`, + fieldtype: 'Link', + target: 'NumberSeries', + required: 1, + getFilters: () => { + return { referenceType: 'Fulfillment' }; + }, + default: DEFAULT_NUMBER_SERIES['FulFillment'], + }, ], }); diff --git a/models/doctype/JournalEntry/JournalEntry.js b/models/doctype/JournalEntry/JournalEntry.js index 07f8d482..e7302113 100644 --- a/models/doctype/JournalEntry/JournalEntry.js +++ b/models/doctype/JournalEntry/JournalEntry.js @@ -1,6 +1,7 @@ import { t } from 'frappe'; import { DateTime } from 'luxon'; import { ledgerLink } from '../../../accounting/utils'; +import { DEFAULT_NUMBER_SERIES } from '../../../frappe/utils/consts'; export default { label: t`Journal Entry`, @@ -72,6 +73,17 @@ export default { default: 0, readOnly: 1, }, + { + fieldname: 'numberSeries', + label: t`Number Series`, + fieldtype: 'Link', + target: 'NumberSeries', + required: 1, + getFilters: () => { + return { referenceType: 'JournalEntry' }; + }, + default: DEFAULT_NUMBER_SERIES['JournalEntry'], + }, ], actions: [ledgerLink], }; diff --git a/models/doctype/Payment/Payment.js b/models/doctype/Payment/Payment.js index dcb8eee4..c376c585 100644 --- a/models/doctype/Payment/Payment.js +++ b/models/doctype/Payment/Payment.js @@ -1,5 +1,6 @@ import frappe, { t } from 'frappe'; import utils from '../../../accounting/utils'; +import { DEFAULT_NUMBER_SERIES } from '../../../frappe/utils/consts'; export default { name: 'Payment', @@ -81,6 +82,17 @@ export default { } }, }, + { + fieldname: 'numberSeries', + label: t`Number Series`, + fieldtype: 'Link', + target: 'NumberSeries', + required: 1, + getFilters: () => { + return { referenceType: 'Payment' }; + }, + default: DEFAULT_NUMBER_SERIES['Payment'], + }, { fieldname: 'paymentMethod', label: t`Payment Method`, @@ -162,6 +174,7 @@ export default { ], quickEditFields: [ + 'numberSeries', 'party', 'date', 'paymentMethod', diff --git a/models/doctype/PurchaseInvoice/PurchaseInvoice.js b/models/doctype/PurchaseInvoice/PurchaseInvoice.js index 34c9c17a..c67832e7 100644 --- a/models/doctype/PurchaseInvoice/PurchaseInvoice.js +++ b/models/doctype/PurchaseInvoice/PurchaseInvoice.js @@ -1,4 +1,5 @@ import { t } from 'frappe'; +import { DEFAULT_NUMBER_SERIES } from '../../../frappe/utils/consts'; import InvoiceTemplate from '../SalesInvoice/InvoiceTemplate.vue'; import { getActions } from '../Transaction/Transaction'; import PurchaseInvoice from './PurchaseInvoiceDocument'; @@ -134,6 +135,17 @@ export default { default: 0, readOnly: 1, }, + { + fieldname: 'numberSeries', + label: t`Number Series`, + fieldtype: 'Link', + target: 'NumberSeries', + required: 1, + getFilters: () => { + return { referenceType: 'PurchaseInvoice' }; + }, + default: DEFAULT_NUMBER_SERIES['PurchaseInvoice'], + }, ], actions: getActions('PurchaseInvoice'), diff --git a/models/doctype/PurchaseOrder/PurchaseOrder.js b/models/doctype/PurchaseOrder/PurchaseOrder.js index 15f54151..a47960d9 100644 --- a/models/doctype/PurchaseOrder/PurchaseOrder.js +++ b/models/doctype/PurchaseOrder/PurchaseOrder.js @@ -1,5 +1,6 @@ import { t } from 'frappe'; import model from 'frappe/model'; +import { DEFAULT_NUMBER_SERIES } from '../../../frappe/utils/consts'; import PurchaseInvoice from '../PurchaseInvoice/PurchaseInvoice'; export default model.extend( @@ -13,6 +14,17 @@ export default model.extend( fieldname: 'items', childtype: 'PurchaseOrderItem', }, + { + fieldname: 'numberSeries', + label: t`Number Series`, + fieldtype: 'Link', + target: 'NumberSeries', + required: 1, + getFilters: () => { + return { referenceType: 'PurchaseOrder' }; + }, + default: DEFAULT_NUMBER_SERIES['PurchaseOrder'], + }, ], }, { diff --git a/models/doctype/PurchaseReceipt/PurchaseReceipt.js b/models/doctype/PurchaseReceipt/PurchaseReceipt.js index 984d9455..d3c31ee7 100644 --- a/models/doctype/PurchaseReceipt/PurchaseReceipt.js +++ b/models/doctype/PurchaseReceipt/PurchaseReceipt.js @@ -1,5 +1,6 @@ import { t } from 'frappe'; import model from 'frappe/model'; +import { DEFAULT_NUMBER_SERIES } from '../../../frappe/utils/consts'; import PurchaseOrder from '../PurchaseOrder/PurchaseOrder'; export default model.extend(PurchaseOrder, { @@ -11,5 +12,16 @@ export default model.extend(PurchaseOrder, { fieldname: 'items', childtype: 'PurchaseReceiptItem', }, + { + fieldname: 'numberSeries', + label: t`Number Series`, + fieldtype: 'Link', + target: 'NumberSeries', + required: 1, + getFilters: () => { + return { referenceType: 'PurchaseReceipt' }; + }, + default: DEFAULT_NUMBER_SERIES['PurchaseReceipt'], + }, ], }); diff --git a/models/doctype/Quotation/Quotation.js b/models/doctype/Quotation/Quotation.js index cf506b61..d2401a63 100644 --- a/models/doctype/Quotation/Quotation.js +++ b/models/doctype/Quotation/Quotation.js @@ -1,5 +1,6 @@ import { t } from 'frappe'; import model from 'frappe/model'; +import { DEFAULT_NUMBER_SERIES } from '../../../frappe/utils/consts'; import SalesInvoice from '../SalesInvoice/SalesInvoice'; const Quotation = model.extend( @@ -13,6 +14,17 @@ const Quotation = model.extend( fieldname: 'items', childtype: 'QuotationItem', }, + { + fieldname: 'numberSeries', + label: t`Number Series`, + fieldtype: 'Link', + target: 'NumberSeries', + required: 1, + getFilters: () => { + return { referenceType: 'Quotation' }; + }, + default: DEFAULT_NUMBER_SERIES['Quotation'], + }, ], links: [], }, diff --git a/models/doctype/SalesInvoice/SalesInvoice.js b/models/doctype/SalesInvoice/SalesInvoice.js index 072c19e5..91318cbf 100644 --- a/models/doctype/SalesInvoice/SalesInvoice.js +++ b/models/doctype/SalesInvoice/SalesInvoice.js @@ -1,4 +1,5 @@ import { t } from 'frappe'; +import { DEFAULT_NUMBER_SERIES } from '../../../frappe/utils/consts'; import { getActions } from '../Transaction/Transaction'; import InvoiceTemplate from './InvoiceTemplate.vue'; import SalesInvoice from './SalesInvoiceDocument'; @@ -134,6 +135,17 @@ export default { default: 0, readOnly: 1, }, + { + fieldname: 'numberSeries', + label: t`Number Series`, + fieldtype: 'Link', + target: 'NumberSeries', + required: 1, + getFilters: () => { + return { referenceType: 'SalesInvoice' }; + }, + default: DEFAULT_NUMBER_SERIES['SalesInvoice'], + }, ], actions: getActions('SalesInvoice'), diff --git a/models/doctype/SalesOrder/SalesOrder.js b/models/doctype/SalesOrder/SalesOrder.js index 551e8433..b8ed2eb6 100644 --- a/models/doctype/SalesOrder/SalesOrder.js +++ b/models/doctype/SalesOrder/SalesOrder.js @@ -1,5 +1,6 @@ import { t } from 'frappe'; import model from 'frappe/model'; +import { DEFAULT_NUMBER_SERIES } from '../../../frappe/utils/consts'; import Quotation from '../Quotation/Quotation'; export default model.extend(Quotation, { @@ -11,5 +12,16 @@ export default model.extend(Quotation, { fieldname: 'items', childtype: 'SalesOrderItem', }, + { + fieldname: 'numberSeries', + label: t`Number Series`, + fieldtype: 'Link', + target: 'NumberSeries', + required: 1, + getFilters: () => { + return { referenceType: 'SalesOrder' }; + }, + default: DEFAULT_NUMBER_SERIES['SalesOrder'], + }, ], }); From 454a2f5a95c17d41afb258bced4d08fdc0063fe7 Mon Sep 17 00:00:00 2001 From: 18alantom <2.alan.tom@gmail.com> Date: Tue, 8 Mar 2022 12:16:18 +0530 Subject: [PATCH 3/8] feat: update number series with references --- patches/0.3.2/moveNumberSeriesFromSettings.js | 16 ++++++++++++++ patches/patches.json | 5 +++++ src/utils.js | 11 ++++++++++ tsconfig.json | 22 +++++-------------- 4 files changed, 38 insertions(+), 16 deletions(-) create mode 100644 patches/0.3.2/moveNumberSeriesFromSettings.js diff --git a/patches/0.3.2/moveNumberSeriesFromSettings.js b/patches/0.3.2/moveNumberSeriesFromSettings.js new file mode 100644 index 00000000..fc3f3aeb --- /dev/null +++ b/patches/0.3.2/moveNumberSeriesFromSettings.js @@ -0,0 +1,16 @@ +import { invertMap } from '@/utils'; +import frappe from 'frappe'; +import { DEFAULT_NUMBER_SERIES } from 'frappe/utils/consts'; + +async function setReferencesOnNumberSeries() { + const map = invertMap(DEFAULT_NUMBER_SERIES); + const rows = await frappe.db.knex('NumberSeries'); + for (const row of rows) { + row.referenceType = map[row.name]; + } + await frappe.db.prestigeTheTable('NumberSeries', rows); +} + +export default async function execute() { + await setReferencesOnNumberSeries(); +} diff --git a/patches/patches.json b/patches/patches.json index e450d707..27a912ad 100644 --- a/patches/patches.json +++ b/patches/patches.json @@ -8,5 +8,10 @@ "version": "0.0.4", "fileName": "convertCurrencyToStrings", "beforeMigrate": true + }, + { + "version": "0.3.2", + "fileName": "moveNumberSeriesFromSettings", + "beforeMigrate": false } ] diff --git a/src/utils.js b/src/utils.js index 40693498..a4c1c84c 100644 --- a/src/utils.js +++ b/src/utils.js @@ -536,3 +536,14 @@ export function getCOAList() { } return frappe.temp.coaList; } + +export function invertMap(map) { + const keys = Object.keys(map); + const inverted = {}; + for (const key of keys) { + const val = map[key]; + inverted[val] = key; + } + + return inverted; +} diff --git a/tsconfig.json b/tsconfig.json index 95703ad7..be28c3f3 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -12,20 +12,11 @@ "allowSyntheticDefaultImports": true, "sourceMap": true, "baseUrl": ".", - "types": [ - "webpack-env" - ], + "types": ["webpack-env"], "paths": { - "@/*": [ - "src/*" - ] + "@/*": ["src/*"] }, - "lib": [ - "esnext", - "dom", - "dom.iterable", - "scripthost" - ] + "lib": ["esnext", "dom", "dom.iterable", "scripthost"] }, "include": [ "src/**/*.ts", @@ -38,11 +29,10 @@ "frappe/**/*.ts", "models/**/*.ts", "patches/**/*.ts", + "patches/**/*.js", "reports/**/*.ts", "accounting/**/*.ts", - "accounting/**/*.ts", + "accounting/**/*.ts" ], - "exclude": [ - "node_modules" - ] + "exclude": ["node_modules"] } From 2de72153e49fbed672d5c50f1e983c71046afed1 Mon Sep 17 00:00:00 2001 From: 18alantom <2.alan.tom@gmail.com> Date: Tue, 8 Mar 2022 13:13:04 +0530 Subject: [PATCH 4/8] feat: add number series to the forms --- .../doctype/NumberSeries/NumberSeries.js | 23 +++++++++++----- src/components/Controls/Link.vue | 23 ++++++++++------ src/pages/InvoiceForm.vue | 26 ++++++++++++------- src/pages/JournalEntryForm.vue | 24 ++++++++++++----- 4 files changed, 65 insertions(+), 31 deletions(-) diff --git a/frappe/models/doctype/NumberSeries/NumberSeries.js b/frappe/models/doctype/NumberSeries/NumberSeries.js index ecd85748..ba1a42e7 100644 --- a/frappe/models/doctype/NumberSeries/NumberSeries.js +++ b/frappe/models/doctype/NumberSeries/NumberSeries.js @@ -27,6 +27,20 @@ module.exports = { fieldtype: 'Data', required: 1, }, + { + fieldname: 'start', + label: t`Start`, + fieldtype: 'Int', + default: 1001, + required: 1, + }, + { + fieldname: 'padZeros', + label: t`Pad Zeros`, + fieldtype: 'Int', + default: 4, + required: 1, + }, { fieldname: 'referenceType', label: t`Reference Type`, @@ -35,13 +49,7 @@ module.exports = { map: referenceTypeMap, default: '-', required: 1, - }, - { - fieldname: 'start', - label: t`Start`, - fieldtype: 'Int', - default: 1001, - required: 1, + readOnly: 1, }, { fieldname: 'current', @@ -51,4 +59,5 @@ module.exports = { readOnly: 1, }, ], + quickEditFields: ['start', 'padZeros', 'referenceType'], }; diff --git a/src/components/Controls/Link.vue b/src/components/Controls/Link.vue index 48062836..b9203848 100644 --- a/src/components/Controls/Link.vue +++ b/src/components/Controls/Link.vue @@ -1,10 +1,9 @@