Skip to content

Commit

Permalink
Merge pull request #424 from frappe/minor-fixes-two
Browse files Browse the repository at this point in the history
fix: a bunch of minor issues
  • Loading branch information
18alantom authored Jul 26, 2022
2 parents 5f86634 + c8f5c01 commit 8c7088d
Show file tree
Hide file tree
Showing 10 changed files with 122 additions and 42 deletions.
2 changes: 1 addition & 1 deletion fyo/model/doc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ export class Doc extends Observable<DocValue | Doc[]> {
}

if (filterComputed) {
fields = this.schema.fields.filter((f) => !f.computed);
fields = fields.filter((f) => !f.computed);
}

const data: DocValueMap = {};
Expand Down
40 changes: 37 additions & 3 deletions main/registerIpcMainActionListeners.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { app, dialog, ipcMain } from 'electron';
import { autoUpdater } from 'electron-updater';
import { autoUpdater, UpdateInfo } from 'electron-updater';
import fs from 'fs/promises';
import path from 'path';
import databaseManager from '../backend/database/manager';
Expand All @@ -15,6 +15,40 @@ import {
} from './helpers';
import { saveHtmlAsPdf } from './saveHtmlAsPdf';

autoUpdater.autoDownload = false;

autoUpdater.on('error', (error) => {
dialog.showErrorBox(
'Update Error: ',
error == null ? 'unknown' : (error.stack || error).toString()
);
});

autoUpdater.on('update-available', async (info: UpdateInfo) => {
const currentVersion = app.getVersion();
const nextVersion = info.version;
const isCurrentBeta = currentVersion.includes('beta');
const isNextBeta = nextVersion.includes('beta');

let downloadUpdate = true;
if (!isCurrentBeta && isNextBeta) {
const option = await dialog.showMessageBox({
type: 'info',
title: `Update Frappe Books?`,
message: `Download version ${nextVersion}?`,
buttons: ['Yes', 'No'],
});

downloadUpdate = option.response === 0;
}

if (!downloadUpdate) {
return;
}

await autoUpdater.downloadUpdate();
});

export default function registerIpcMainActionListeners(main: Main) {
ipcMain.handle(IPC_ACTIONS.GET_OPEN_FILEPATH, async (event, options) => {
return await dialog.showOpenDialog(main.mainWindow!, options);
Expand Down Expand Up @@ -51,9 +85,9 @@ export default function registerIpcMainActionListeners(main: Main) {
sendError(bodyJson);
});

ipcMain.handle(IPC_ACTIONS.CHECK_FOR_UPDATES, () => {
ipcMain.handle(IPC_ACTIONS.CHECK_FOR_UPDATES, async () => {
if (!main.isDevelopment && !main.checkedForUpdate) {
autoUpdater.checkForUpdates();
await autoUpdater.checkForUpdates();
main.checkedForUpdate = true;
}
});
Expand Down
4 changes: 3 additions & 1 deletion reports/AccountReport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,9 @@ function pruneAccountTree(accountTree: AccountTree) {
}

for (const root of Object.keys(accountTree)) {
accountTree[root].children = getPrunedChildren(accountTree[root].children!);
accountTree[root].children = getPrunedChildren(
accountTree[root].children ?? []
);
}
}

Expand Down
51 changes: 46 additions & 5 deletions reports/ProfitAndLoss/ProfitAndLoss.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,21 +74,65 @@ export class ProfitAndLoss extends AccountReport {
async getReportDataFromRows(
incomeRows: ReportData,
expenseRows: ReportData,
incomeRoot: AccountTreeNode,
expenseRoot: AccountTreeNode
incomeRoot: AccountTreeNode | undefined,
expenseRoot: AccountTreeNode | undefined
): Promise<ReportData> {
if (incomeRoot && !expenseRoot) {
return await this.getIncomeOrExpenseRows(
incomeRoot,
incomeRows,
t`Total Income (Credit)`
);
}

if (expenseRoot && !incomeRoot) {
return await this.getIncomeOrExpenseRows(
expenseRoot,
expenseRows,
t`Total Income (Credit)`
);
}

if (!incomeRoot || !expenseRoot) {
return [];
}

return await this.getIncomeAndExpenseRows(
incomeRows,
expenseRows,
incomeRoot,
expenseRoot
);
}

async getIncomeOrExpenseRows(
root: AccountTreeNode,
rows: ReportData,
totalRowName: string
): Promise<ReportData> {
const total = await this.getTotalNode(root, totalRowName);
const totalRow = this.getRowFromAccountListNode(total);

return [rows, totalRow].flat();
}

async getIncomeAndExpenseRows(
incomeRows: ReportData,
expenseRows: ReportData,
incomeRoot: AccountTreeNode,
expenseRoot: AccountTreeNode
) {
const totalIncome = await this.getTotalNode(
incomeRoot,
t`Total Income (Credit)`
);
const totalIncomeRow = this.getRowFromAccountListNode(totalIncome);

const totalExpense = await this.getTotalNode(
expenseRoot,
t`Total Expense (Debit)`
);
const totalExpenseRow = this.getRowFromAccountListNode(totalExpense);

const totalValueMap: ValueMap = new Map();
for (const key of totalIncome.valueMap!.keys()) {
Expand All @@ -103,9 +147,6 @@ export class ProfitAndLoss extends AccountReport {
level: 0,
} as AccountListNode;

const totalIncomeRow = this.getRowFromAccountListNode(totalIncome);
const totalExpenseRow = this.getRowFromAccountListNode(totalExpense);

const totalProfitRow = this.getRowFromAccountListNode(totalProfit);
totalProfitRow.cells.forEach((c) => {
c.bold = true;
Expand Down
1 change: 0 additions & 1 deletion src/components/FilterDropdown.vue
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,6 @@ export default {
this.filters = this.filters.filter((f) => f !== filter);
},
setFilter(filters, implicit) {
console.log(filters);
this.filters = [];
Object.keys(filters).map((fieldname) => {
Expand Down
15 changes: 5 additions & 10 deletions src/components/PageHeader.vue
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
<template>
<div
class="
px-4
flex
justify-between
window-drag
items-center
h-row-largest
flex-shrink-0
"
:class="border ? 'border-b' : ''"
class="px-4 flex justify-between items-center h-row-largest flex-shrink-0"
:class="[
border ? 'border-b' : '',
platform !== 'Windows' ? 'window-drag' : '',
]"
>
<h1 class="text-xl font-semibold select-none" v-if="title">
{{ title }}
Expand Down
4 changes: 3 additions & 1 deletion src/pages/Settings/Settings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,11 @@ export default {
},
setActiveTab() {
const { tab } = this.$route.query;
const index = this.tabs.findIndex((i) => i.key === tab || 'Invoice');
const index = this.tabs.findIndex((i) => i.key === tab);
if (index !== -1) {
this.activeTab = index;
} else {
this.activeTab = 0;
}
},
getIconComponent(tab) {
Expand Down
5 changes: 4 additions & 1 deletion src/pages/SetupWizard/SetupWizard.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
<template>
<div class="flex-1 bg-gray-25 flex justify-center items-center window-drag">
<div
class="flex-1 bg-gray-25 flex justify-center items-center window-drag"
:class="{ 'window-drag': platform !== 'Windows' }"
>
<!-- Setup Wizard Slide -->
<Slide
:primary-disabled="!valuesFilled || loading"
Expand Down
34 changes: 19 additions & 15 deletions src/renderer/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,35 +1,39 @@
import { Directive } from 'vue';

const instances: OutsideClickCallback[] = [];
type OutsideClickCallback = (e: Event) => void;
const instanceMap: Map<HTMLElement, OutsideClickCallback> = new Map();

export const outsideClickDirective: Directive<
HTMLElement,
OutsideClickCallback
> = {
beforeMount(el, binding) {
el.dataset.outsideClickIndex = String(instances.length);

const fn = binding.value;
const click = function (e: Event) {
onDocumentClick(e, el, fn);
const clickHandler = function (e: Event) {
onDocumentClick(e, el, binding.value);
};

document.addEventListener('click', click);
instances.push(click);
removeHandlerIfPresent(el);
instanceMap.set(el, clickHandler);
document.addEventListener('click', clickHandler);
},
unmounted(el) {
const index = parseInt(el.dataset.outsideClickIndex ?? '0');
const handler = instances[index];
document.addEventListener('click', handler);
instances.splice(index, 1);
removeHandlerIfPresent(el);
},
};

function onDocumentClick(e: Event, el: HTMLElement, fn: OutsideClickCallback) {
const target = e.target;
const target = e.target as Node;
if (el !== target && !el.contains(target)) {
fn?.(e);
}
}

if (el !== target && !el.contains(target as Node)) {
fn(e);
function removeHandlerIfPresent(el: HTMLElement) {
const clickHandler = instanceMap.get(el);
if (!clickHandler) {
return;
}

instanceMap.delete(el);
document.removeEventListener('click', clickHandler);
}
8 changes: 4 additions & 4 deletions src/utils/getStartedConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ export function getGetStartedConfig() {
key: 'Add Customers',
label: t`Add Customers`,
icon: 'customer',
description: t`Add a few customers to create your first invoice`,
description: t`Add a few customers to create your first sales invoice`,
action: () => routeTo(`/list/Party/role/Customer/${t`Customers`}`),
fieldname: 'customerCreated',
documentation:
Expand All @@ -104,7 +104,7 @@ export function getGetStartedConfig() {
key: 'Create Sales Invoice',
label: t`Create Sales Invoice`,
icon: 'sales-invoice',
description: t`Create your first invoice and mail it to your customer`,
description: t`Create your first sales invoice for the created customer`,
action: () => routeTo('/list/SalesInvoice'),
fieldname: 'invoiceCreated',
documentation:
Expand All @@ -129,15 +129,15 @@ export function getGetStartedConfig() {
key: 'Add Suppliers',
label: t`Add Suppliers`,
icon: 'supplier',
description: t`Add a few suppliers to create your first bill`,
description: t`Add a few suppliers to create your first purchase invoice`,
action: () => routeTo(`/list/Party/role/Supplier/${t`Suppliers`}`),
fieldname: 'supplierCreated',
},
{
key: 'Create Purchase Invoice',
label: t`Create Purchase Invoice`,
icon: 'purchase-invoice',
description: t`Create your first bill and mail it to your supplier`,
description: t`Create your first purchase invoice from the created supplier`,
action: () => routeTo('/list/PurchaseInvoice'),
fieldname: 'billCreated',
documentation:
Expand Down

0 comments on commit 8c7088d

Please sign in to comment.