2
0
mirror of https://github.com/frappe/books.git synced 2024-11-10 07:40:55 +00:00

Merge pull request #266 from 18alantom/fix-regional-changes

feat: allow regional model updates
This commit is contained in:
Alan 2021-12-01 18:46:08 +05:30 committed by GitHub
commit 14ce1e88cf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 88 additions and 44 deletions

View File

@ -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'],
};

View File

@ -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
export default function getAugmentedParty({ country }) {
const Party = cloneDeep(PartyOriginal);
if (!country) {
return Party;
}
if (country === 'India') {
Party.fields.splice(
3,
0,
{
fieldname: 'gstin',
label: 'GSTIN No.',
fieldtype: 'Data',
hidden: form => {
hidden: (form) => {
return form.gstType === 'Registered Regular' ? 0 : 1;
}
});
party.fields.splice(4, 0, {
},
},
{
fieldname: 'gstType',
label: 'GST Registration Type',
fieldtype: 'Select',
options: ['Unregistered', 'Registered Regular', 'Consumer']
options: ['Unregistered', 'Registered Regular', 'Consumer'],
}
);
Party.quickEditFields.push('gstin');
} else {
Party.fields.splice(3, 0, {
fieldname: 'taxId',
label: 'Tax ID',
fieldtype: 'Data',
});
party.fields.join();
const newParty = party;
export default newParty;
Party.quickEditFields.push('taxId');
}
return Party;
}

View 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);
}
}

View File

@ -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);
}
}

View File

@ -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,13 +100,9 @@ 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 regionalModelUpdates({ country });
await frappe.db.migrate();
}
}
function updateCompanyNameInConfig() {
let filePath = frappe.db.dbPath;