mirror of
https://github.com/frappe/books.git
synced 2024-09-20 03:29:00 +00:00
fix: knex queries
This commit is contained in:
parent
3d0e91d3f5
commit
5ad858ede7
@ -1,5 +1,5 @@
|
|||||||
import BaseDocument from 'frappejs/model/document';
|
|
||||||
import frappe from 'frappejs';
|
import frappe from 'frappejs';
|
||||||
|
import BaseDocument from 'frappejs/model/document';
|
||||||
|
|
||||||
export default class PartyServer extends BaseDocument {
|
export default class PartyServer extends BaseDocument {
|
||||||
beforeInsert() {
|
beforeInsert() {
|
||||||
@ -8,8 +8,8 @@ export default class PartyServer extends BaseDocument {
|
|||||||
method: 'show-dialog',
|
method: 'show-dialog',
|
||||||
args: {
|
args: {
|
||||||
title: 'Invalid Entry',
|
title: 'Invalid Entry',
|
||||||
message: 'Select a single party type.'
|
message: 'Select a single party type.',
|
||||||
}
|
},
|
||||||
});
|
});
|
||||||
throw new Error();
|
throw new Error();
|
||||||
}
|
}
|
||||||
@ -23,14 +23,18 @@ export default class PartyServer extends BaseDocument {
|
|||||||
let isCustomer = this.customer;
|
let isCustomer = this.customer;
|
||||||
let doctype = isCustomer ? 'SalesInvoice' : 'PurchaseInvoice';
|
let doctype = isCustomer ? 'SalesInvoice' : 'PurchaseInvoice';
|
||||||
let partyField = isCustomer ? 'customer' : 'supplier';
|
let partyField = isCustomer ? 'customer' : 'supplier';
|
||||||
let { totalOutstanding } = await frappe.db.knex
|
|
||||||
.sum({ totalOutstanding: 'outstandingAmount' })
|
const outstandingAmounts = await frappe.db.knex
|
||||||
|
.select('outstandingAmount')
|
||||||
.from(doctype)
|
.from(doctype)
|
||||||
.where('submitted', 1)
|
.where('submitted', 1)
|
||||||
.andWhere(partyField, this.name)
|
.andWhere(partyField, this.name);
|
||||||
.first();
|
|
||||||
|
|
||||||
await this.set('outstandingAmount', this.round(totalOutstanding));
|
const totalOutstanding = outstandingAmounts
|
||||||
|
.map(({ outstandingAmount }) => frappe.pesa(outstandingAmount))
|
||||||
|
.reduce((a, b) => a.add(b), frappe.pesa(0));
|
||||||
|
|
||||||
|
await this.set('outstandingAmount', totalOutstanding);
|
||||||
await this.update();
|
await this.update();
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
@ -84,9 +84,10 @@ export default {
|
|||||||
.select('name')
|
.select('name')
|
||||||
.from('Account')
|
.from('Account')
|
||||||
.where('rootType', 'Expense');
|
.where('rootType', 'Expense');
|
||||||
|
|
||||||
let topExpenses = await frappe.db.knex
|
let topExpenses = await frappe.db.knex
|
||||||
.select({
|
.select({
|
||||||
total: frappe.db.knex.raw('sum(??) - sum(??)', ['debit', 'credit']),
|
total: frappe.db.knex.raw('sum(cast(?? as real)) - sum(cast(?? as real))', ['debit', 'credit']),
|
||||||
})
|
})
|
||||||
.select('account')
|
.select('account')
|
||||||
.from('AccountingLedgerEntry')
|
.from('AccountingLedgerEntry')
|
||||||
|
Loading…
Reference in New Issue
Block a user