mirror of
https://github.com/frappe/books.git
synced 2024-11-09 23:30:56 +00:00
feat: allow regional model updates
This commit is contained in:
parent
209e8bf7ec
commit
3f69d7fcc5
@ -4,6 +4,7 @@ import { _ } from 'frappejs/utils';
|
||||
export default {
|
||||
name: 'Party',
|
||||
label: 'Party',
|
||||
regional: 1,
|
||||
keywordFields: ['name'],
|
||||
fields: [
|
||||
{
|
||||
@ -99,22 +100,7 @@ export default {
|
||||
}
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldname: 'gstin',
|
||||
label: 'GSTIN No.',
|
||||
fieldtype: 'Data',
|
||||
hidden: (form) => {
|
||||
return form.gstType === 'Registered Regular' ? 0 : 1;
|
||||
},
|
||||
},
|
||||
],
|
||||
|
||||
quickEditFields: [
|
||||
'email',
|
||||
'phone',
|
||||
'address',
|
||||
'defaultAccount',
|
||||
'currency',
|
||||
'gstin',
|
||||
],
|
||||
quickEditFields: ['email', 'phone', 'address', 'defaultAccount', 'currency'],
|
||||
};
|
||||
|
@ -1,21 +1,39 @@
|
||||
import party from './Party';
|
||||
import { cloneDeep } from 'lodash';
|
||||
import PartyOriginal from './Party';
|
||||
|
||||
party.fields.splice(3, 0, {
|
||||
//insert at 3rd position
|
||||
fieldname: 'gstin',
|
||||
label: 'GSTIN No.',
|
||||
fieldtype: 'Data',
|
||||
hidden: form => {
|
||||
return form.gstType === 'Registered Regular' ? 0 : 1;
|
||||
export default function getAugmentedParty({ country }) {
|
||||
const Party = cloneDeep(PartyOriginal);
|
||||
if (!country) {
|
||||
return Party;
|
||||
}
|
||||
});
|
||||
party.fields.splice(4, 0, {
|
||||
fieldname: 'gstType',
|
||||
label: 'GST Registration Type',
|
||||
fieldtype: 'Select',
|
||||
options: ['Unregistered', 'Registered Regular', 'Consumer']
|
||||
});
|
||||
party.fields.join();
|
||||
const newParty = party;
|
||||
|
||||
export default newParty;
|
||||
if (country === 'India') {
|
||||
Party.fields.splice(
|
||||
3,
|
||||
0,
|
||||
{
|
||||
fieldname: 'gstin',
|
||||
label: 'GSTIN No.',
|
||||
fieldtype: 'Data',
|
||||
hidden: (form) => {
|
||||
return form.gstType === 'Registered Regular' ? 0 : 1;
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldname: 'gstType',
|
||||
label: 'GST Registration Type',
|
||||
fieldtype: 'Select',
|
||||
options: ['Unregistered', 'Registered Regular', 'Consumer'],
|
||||
}
|
||||
);
|
||||
Party.quickEditFields.push('gstin');
|
||||
} else {
|
||||
Party.fields.splice(3, 0, {
|
||||
fieldname: 'taxId',
|
||||
label: 'Tax ID',
|
||||
fieldtype: 'Data',
|
||||
});
|
||||
Party.quickEditFields.push('taxId');
|
||||
}
|
||||
return Party;
|
||||
}
|
||||
|
19
models/regionalModelUpdates.js
Normal file
19
models/regionalModelUpdates.js
Normal file
@ -0,0 +1,19 @@
|
||||
import frappe from 'frappejs';
|
||||
|
||||
async function setAugmentedModel(model, regionalInfo) {
|
||||
const getAugmentedModel = (
|
||||
await import('./doctype/' + model + '/RegionalChanges')
|
||||
).default;
|
||||
frappe.models[model] = getAugmentedModel(regionalInfo);
|
||||
frappe.models[model].augmented = 1;
|
||||
}
|
||||
|
||||
export default async function regionalModelUpdates(regionalInfo) {
|
||||
for (let model in frappe.models) {
|
||||
const { regional, basedOn, augmented } = frappe.models[model];
|
||||
if (!regional || basedOn || augmented) {
|
||||
continue;
|
||||
}
|
||||
await setAugmentedModel(model, regionalInfo);
|
||||
}
|
||||
}
|
@ -3,6 +3,8 @@ import { ipcRenderer } from 'electron';
|
||||
import { _ } from 'frappejs';
|
||||
import SQLiteDatabase from 'frappejs/backends/sqlite';
|
||||
import fs from 'fs';
|
||||
import models from '../models';
|
||||
import regionalModelUpdates from '../models/regionalModelUpdates';
|
||||
import postStart from '../server/postStart';
|
||||
import { IPC_ACTIONS } from './messages';
|
||||
import migrate from './migrate';
|
||||
@ -36,6 +38,18 @@ export async function createNewDatabase() {
|
||||
return filePath;
|
||||
}
|
||||
|
||||
async function runRegionalModelUpdates() {
|
||||
if (!(await frappe.db.knex.schema.hasTable('SingleValue'))) {
|
||||
return;
|
||||
}
|
||||
|
||||
const { country, setupComplete } = await frappe.db.getSingle(
|
||||
'AccountingSettings'
|
||||
);
|
||||
if (!parseInt(setupComplete)) return;
|
||||
await regionalModelUpdates({ country });
|
||||
}
|
||||
|
||||
export async function connectToLocalDatabase(filePath) {
|
||||
if (!filePath) {
|
||||
return false;
|
||||
@ -52,6 +66,12 @@ export async function connectToLocalDatabase(filePath) {
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
await runRegionalModelUpdates();
|
||||
} catch (error) {
|
||||
console.error('regional model updates failed', error);
|
||||
}
|
||||
|
||||
await migrate();
|
||||
await postStart();
|
||||
|
||||
@ -75,7 +95,7 @@ export async function connectToLocalDatabase(filePath) {
|
||||
|
||||
export function purgeCache(purgeAll = false) {
|
||||
const filterFunction = purgeAll
|
||||
? (d) => true
|
||||
? () => true
|
||||
: (d) => frappe.docs[d][d] instanceof frappe.BaseMeta;
|
||||
|
||||
Object.keys(frappe.docs)
|
||||
@ -84,4 +104,9 @@ export function purgeCache(purgeAll = false) {
|
||||
frappe.removeFromCache(d, d);
|
||||
delete frappe[d];
|
||||
});
|
||||
|
||||
if (purgeAll) {
|
||||
delete frappe.db;
|
||||
frappe.initializeAndRegister(models, true);
|
||||
}
|
||||
}
|
||||
|
@ -1,8 +1,8 @@
|
||||
import config from '@/config';
|
||||
import frappe from 'frappejs';
|
||||
import countryList from '~/fixtures/countryInfo.json';
|
||||
import generateTaxes from '../../../models/doctype/Tax/RegionalChanges';
|
||||
import { getCountryCOA } from '../../../accounting/importCOA';
|
||||
import config from '@/config';
|
||||
import generateTaxes from '../../../models/doctype/Tax/RegionalEntries';
|
||||
import regionalModelUpdates from '../../../models/regionalModelUpdates';
|
||||
|
||||
export default async function setupCompany(setupWizardValues) {
|
||||
const {
|
||||
@ -100,12 +100,8 @@ async function setupChartOfAccounts(bankName, country) {
|
||||
|
||||
async function setupRegionalChanges(country) {
|
||||
await generateTaxes(country);
|
||||
if (country === 'India') {
|
||||
frappe.models.Party = (
|
||||
await import('../../../models/doctype/Party/RegionalChanges')
|
||||
).default;
|
||||
await frappe.db.migrate();
|
||||
}
|
||||
await regionalModelUpdates({ country });
|
||||
await frappe.db.migrate();
|
||||
}
|
||||
|
||||
function updateCompanyNameInConfig() {
|
||||
|
Loading…
Reference in New Issue
Block a user