mirror of
https://github.com/frappe/books.git
synced 2024-11-08 14:50:56 +00:00
chore: rename getNewDoc, newDoc
- delete irrelevant tests
This commit is contained in:
parent
dc5d705a52
commit
82709165a4
@ -25,7 +25,7 @@ async function importAccounts(children, parentAccount, rootType, rootAccount) {
|
||||
const { accountType, accountNumber } = child;
|
||||
const accountName = getAccountName(rootName, accountNumber);
|
||||
const isGroup = identifyIsGroup(child);
|
||||
const doc = frappe.newDoc({
|
||||
const doc = frappe.getNewDoc({
|
||||
doctype: 'Account',
|
||||
name: accountName,
|
||||
parentAccount,
|
||||
|
@ -145,7 +145,7 @@ export default class LedgerPosting {
|
||||
|
||||
async insertEntries() {
|
||||
for (let entry of this.entries) {
|
||||
let entryDoc = frappe.newDoc({
|
||||
let entryDoc = frappe.getNewDoc({
|
||||
doctype: 'AccountingLedgerEntry',
|
||||
});
|
||||
Object.assign(entryDoc, entry);
|
||||
|
@ -2,6 +2,7 @@ import frappe from 'frappe';
|
||||
import Observable from 'frappe/utils/observable';
|
||||
import Knex from 'knex';
|
||||
import CacheManager from '../utils/cacheManager';
|
||||
import { getRandomString } from '../utils/index';
|
||||
|
||||
export default class Database extends Observable {
|
||||
constructor() {
|
||||
@ -49,7 +50,7 @@ export default class Database extends Observable {
|
||||
if (await this.singleExists(doctype)) {
|
||||
const singleValues = await this.getSingleFieldsToInsert(doctype);
|
||||
singleValues.forEach(({ fieldname, value }) => {
|
||||
let singleValue = frappe.newDoc({
|
||||
let singleValue = frappe.getNewDoc({
|
||||
doctype: 'SingleValue',
|
||||
parent: doctype,
|
||||
fieldname,
|
||||
@ -429,7 +430,7 @@ export default class Database extends Observable {
|
||||
let fields = this.getValidFields(doctype);
|
||||
|
||||
if (!doc.name) {
|
||||
doc.name = frappe.getRandomString();
|
||||
doc.name = getRandomString();
|
||||
}
|
||||
|
||||
let formattedDoc = this.getFormattedDoc(fields, doc);
|
||||
@ -509,7 +510,7 @@ export default class Database extends Observable {
|
||||
for (let field of meta.getValidFields({ withChildren: false })) {
|
||||
let value = doc[field.fieldname];
|
||||
if (value != null) {
|
||||
let singleValue = frappe.newDoc({
|
||||
let singleValue = frappe.getNewDoc({
|
||||
doctype: 'SingleValue',
|
||||
parent: doctype,
|
||||
fieldname: field.fieldname,
|
||||
@ -540,7 +541,7 @@ export default class Database extends Observable {
|
||||
|
||||
prepareChild(parenttype, parent, child, field, idx) {
|
||||
if (!child.name) {
|
||||
child.name = frappe.getRandomString();
|
||||
child.name = getRandomString();
|
||||
}
|
||||
child.parent = parent;
|
||||
child.parenttype = parenttype;
|
||||
|
160
frappe/index.js
160
frappe/index.js
@ -15,7 +15,6 @@ class Frappe {
|
||||
t = t;
|
||||
T = T;
|
||||
format = format;
|
||||
getRandomString = getRandomString;
|
||||
|
||||
errors = errors;
|
||||
isElectron = false;
|
||||
@ -36,6 +35,67 @@ class Frappe {
|
||||
this.registerModels(customModels);
|
||||
}
|
||||
|
||||
init(force) {
|
||||
if (this._initialized && !force) return;
|
||||
|
||||
// Initialize Globals
|
||||
this.metaCache = {};
|
||||
this.models = {};
|
||||
|
||||
this.methods = {};
|
||||
this.errorLog = [];
|
||||
|
||||
// temp params while calling routes
|
||||
this.temp = {};
|
||||
|
||||
this.docs = new Observable();
|
||||
this.events = new Observable();
|
||||
this._initialized = true;
|
||||
}
|
||||
|
||||
registerModels(models) {
|
||||
// register models from app/models/index.js
|
||||
for (let doctype in models) {
|
||||
let metaDefinition = models[doctype];
|
||||
if (!metaDefinition.name) {
|
||||
throw new Error(`Name is mandatory for ${doctype}`);
|
||||
}
|
||||
if (metaDefinition.name !== doctype) {
|
||||
throw new Error(
|
||||
`Model name mismatch for ${doctype}: ${metaDefinition.name}`
|
||||
);
|
||||
}
|
||||
let fieldnames = (metaDefinition.fields || [])
|
||||
.map((df) => df.fieldname)
|
||||
.sort();
|
||||
let duplicateFieldnames = getDuplicates(fieldnames);
|
||||
if (duplicateFieldnames.length > 0) {
|
||||
throw new Error(
|
||||
`Duplicate fields in ${doctype}: ${duplicateFieldnames.join(', ')}`
|
||||
);
|
||||
}
|
||||
|
||||
this.models[doctype] = metaDefinition;
|
||||
}
|
||||
}
|
||||
|
||||
registerMethod({ method, handler }) {
|
||||
this.methods[method] = handler;
|
||||
if (this.app) {
|
||||
// add to router if client-server
|
||||
this.app.post(
|
||||
`/api/method/${method}`,
|
||||
asyncHandler(async function (request, response) {
|
||||
let data = await handler(request.body);
|
||||
if (data === undefined) {
|
||||
data = {};
|
||||
}
|
||||
return response.json(data);
|
||||
})
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
async initializeMoneyMaker(currency) {
|
||||
currency ??= 'XXX';
|
||||
|
||||
@ -82,50 +142,6 @@ class Frappe {
|
||||
});
|
||||
}
|
||||
|
||||
init(force) {
|
||||
if (this._initialized && !force) return;
|
||||
|
||||
// Initialize Globals
|
||||
this.metaCache = {};
|
||||
this.models = {};
|
||||
|
||||
this.methods = {};
|
||||
this.errorLog = [];
|
||||
|
||||
// temp params while calling routes
|
||||
this.temp = {};
|
||||
|
||||
this.docs = new Observable();
|
||||
this.events = new Observable();
|
||||
this._initialized = true;
|
||||
}
|
||||
|
||||
registerModels(models) {
|
||||
// register models from app/models/index.js
|
||||
for (let doctype in models) {
|
||||
let metaDefinition = models[doctype];
|
||||
if (!metaDefinition.name) {
|
||||
throw new Error(`Name is mandatory for ${doctype}`);
|
||||
}
|
||||
if (metaDefinition.name !== doctype) {
|
||||
throw new Error(
|
||||
`Model name mismatch for ${doctype}: ${metaDefinition.name}`
|
||||
);
|
||||
}
|
||||
let fieldnames = (metaDefinition.fields || [])
|
||||
.map((df) => df.fieldname)
|
||||
.sort();
|
||||
let duplicateFieldnames = getDuplicates(fieldnames);
|
||||
if (duplicateFieldnames.length > 0) {
|
||||
throw new Error(
|
||||
`Duplicate fields in ${doctype}: ${duplicateFieldnames.join(', ')}`
|
||||
);
|
||||
}
|
||||
|
||||
this.models[doctype] = metaDefinition;
|
||||
}
|
||||
}
|
||||
|
||||
getModels(filterFunction) {
|
||||
let models = [];
|
||||
for (let doctype in this.models) {
|
||||
@ -134,29 +150,6 @@ class Frappe {
|
||||
return filterFunction ? models.filter(filterFunction) : models;
|
||||
}
|
||||
|
||||
// del
|
||||
registerView(view, name, module) {
|
||||
if (!this.views[view]) this.views[view] = {};
|
||||
this.views[view][name] = module;
|
||||
}
|
||||
|
||||
registerMethod({ method, handler }) {
|
||||
this.methods[method] = handler;
|
||||
if (this.app) {
|
||||
// add to router if client-server
|
||||
this.app.post(
|
||||
`/api/method/${method}`,
|
||||
asyncHandler(async function (request, response) {
|
||||
let data = await handler(request.body);
|
||||
if (data === undefined) {
|
||||
data = {};
|
||||
}
|
||||
return response.json(data);
|
||||
})
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
async call({ method, args }) {
|
||||
if (this.isServer) {
|
||||
if (this.methods[method]) {
|
||||
@ -263,7 +256,7 @@ class Frappe {
|
||||
}
|
||||
|
||||
async getDuplicate(doc) {
|
||||
const newDoc = await this.getNewDoc(doc.doctype);
|
||||
const newDoc = await this.getEmptyDoc(doc.doctype);
|
||||
for (let field of this.getMeta(doc.doctype).getValidFields()) {
|
||||
if (['name', 'submitted'].includes(field.fieldname)) continue;
|
||||
if (field.fieldtype === 'Table') {
|
||||
@ -279,37 +272,26 @@ class Frappe {
|
||||
return newDoc;
|
||||
}
|
||||
|
||||
getNewDoc(doctype, cacheDoc = true) {
|
||||
let doc = this.newDoc({ doctype: doctype });
|
||||
getEmptyDoc(doctype, cacheDoc = true) {
|
||||
let doc = this.getNewDoc({ doctype: doctype });
|
||||
doc._notInserted = true;
|
||||
doc.name = frappe.getRandomString();
|
||||
doc.name = getRandomString();
|
||||
|
||||
if (cacheDoc) {
|
||||
this.addToCache(doc);
|
||||
}
|
||||
|
||||
return doc;
|
||||
}
|
||||
|
||||
async newCustomDoc(fields) {
|
||||
let doc = new this.Document({ isCustom: 1, fields });
|
||||
doc._notInserted = true;
|
||||
doc.name = this.getRandomString();
|
||||
this.addToCache(doc);
|
||||
return doc;
|
||||
}
|
||||
|
||||
createMeta(fields) {
|
||||
let meta = new this.Meta({ isCustom: 1, fields });
|
||||
return meta;
|
||||
}
|
||||
|
||||
newDoc(data) {
|
||||
getNewDoc(data) {
|
||||
let doc = new (this.getDocumentClass(data.doctype))(data);
|
||||
doc.setDefaults();
|
||||
return doc;
|
||||
}
|
||||
|
||||
async insert(data) {
|
||||
return await this.newDoc(data).insert();
|
||||
createMeta(fields) {
|
||||
return new this.Meta({ isCustom: 1, fields });
|
||||
}
|
||||
|
||||
async syncDoc(data) {
|
||||
@ -319,7 +301,7 @@ class Frappe {
|
||||
Object.assign(doc, data);
|
||||
await doc.update();
|
||||
} else {
|
||||
doc = this.newDoc(data);
|
||||
doc = this.getNewDoc(data);
|
||||
await doc.insert();
|
||||
}
|
||||
}
|
||||
|
@ -3,7 +3,7 @@ import { Verb } from '@/telemetry/types';
|
||||
import frappe from 'frappe';
|
||||
import Observable from 'frappe/utils/observable';
|
||||
import { DEFAULT_INTERNAL_PRECISION } from '../utils/consts';
|
||||
import { isPesa } from '../utils/index';
|
||||
import { getRandomString, isPesa } from '../utils/index';
|
||||
import { setName } from './naming';
|
||||
|
||||
export default class Document extends Observable {
|
||||
@ -190,7 +190,7 @@ export default class Document extends Observable {
|
||||
}
|
||||
|
||||
if (!data.name) {
|
||||
data.name = frappe.getRandomString();
|
||||
data.name = getRandomString();
|
||||
}
|
||||
|
||||
const childDoc = new Document(data);
|
||||
@ -335,7 +335,7 @@ export default class Document extends Observable {
|
||||
updateModified() {
|
||||
if (frappe.isServer) {
|
||||
let now = new Date().toISOString();
|
||||
this.modifiedBy = frappe.auth.session.user
|
||||
this.modifiedBy = frappe.auth.session.user;
|
||||
this.modified = now;
|
||||
}
|
||||
}
|
||||
@ -741,7 +741,7 @@ export default class Document extends Observable {
|
||||
updateMap.name = updateMap.name + ' CPY';
|
||||
}
|
||||
|
||||
const doc = frappe.getNewDoc(this.doctype, false);
|
||||
const doc = frappe.getEmptyDoc(this.doctype, false);
|
||||
await doc.set(updateMap);
|
||||
await doc.insert();
|
||||
}
|
||||
|
@ -2,7 +2,7 @@ import frappe from 'frappe';
|
||||
import { getRandomString } from 'frappe/utils';
|
||||
|
||||
export async function isNameAutoSet(doctype) {
|
||||
const doc = frappe.getNewDoc(doctype);
|
||||
const doc = frappe.getEmptyDoc(doctype);
|
||||
if (doc.meta.naming === 'autoincrement') {
|
||||
return true;
|
||||
}
|
||||
@ -108,7 +108,7 @@ export async function createNumberSeries(prefix, referenceType, start = 1001) {
|
||||
return;
|
||||
}
|
||||
|
||||
const series = frappe.newDoc({
|
||||
const series = frappe.getNewDoc({
|
||||
doctype: 'NumberSeries',
|
||||
name: prefix,
|
||||
start,
|
||||
|
@ -17,7 +17,7 @@ export default async function runPatches(patchList) {
|
||||
async function runPatch({ patchName, patchFunction }) {
|
||||
try {
|
||||
await patchFunction();
|
||||
const patchRun = frappe.getNewDoc('PatchRun');
|
||||
const patchRun = frappe.getEmptyDoc('PatchRun');
|
||||
patchRun.name = patchName;
|
||||
await patchRun.insert();
|
||||
} catch (error) {
|
||||
|
@ -140,7 +140,7 @@ export default {
|
||||
label: t`New Invoice`,
|
||||
condition: (doc) => !doc.isNew(),
|
||||
action: async (doc, router) => {
|
||||
const invoice = await frappe.getNewDoc('SalesInvoice');
|
||||
const invoice = await frappe.getEmptyDoc('SalesInvoice');
|
||||
invoice.append('items', {
|
||||
item: doc.name,
|
||||
rate: doc.rate,
|
||||
@ -153,7 +153,7 @@ export default {
|
||||
label: t`New Bill`,
|
||||
condition: (doc) => !doc.isNew(),
|
||||
action: async (doc, router) => {
|
||||
const invoice = await frappe.getNewDoc('PurchaseInvoice');
|
||||
const invoice = await frappe.getEmptyDoc('PurchaseInvoice');
|
||||
invoice.append('items', {
|
||||
item: doc.name,
|
||||
rate: doc.rate,
|
||||
|
@ -15,7 +15,7 @@ export default {
|
||||
label: t`Create Invoice`,
|
||||
condition: (doc) => !doc.isNew(),
|
||||
action: async (customer) => {
|
||||
let doc = await frappe.getNewDoc('SalesInvoice');
|
||||
let doc = await frappe.getEmptyDoc('SalesInvoice');
|
||||
router.push({
|
||||
path: `/edit/SalesInvoice/${doc.name}`,
|
||||
query: {
|
||||
|
@ -15,7 +15,7 @@ export default {
|
||||
label: t`Create Bill`,
|
||||
condition: (doc) => !doc.isNew(),
|
||||
action: async (supplier) => {
|
||||
let doc = await frappe.getNewDoc('PurchaseInvoice');
|
||||
let doc = await frappe.getEmptyDoc('PurchaseInvoice');
|
||||
router.push({
|
||||
path: `/edit/PurchaseInvoice/${doc.name}`,
|
||||
query: {
|
||||
|
@ -8,7 +8,7 @@ export default async function generateTaxes(country) {
|
||||
'Exempt-GST': [0],
|
||||
'Exempt-IGST': [0],
|
||||
};
|
||||
let newTax = await frappe.getNewDoc('Tax');
|
||||
let newTax = await frappe.getEmptyDoc('Tax');
|
||||
|
||||
for (const type of Object.keys(GSTs)) {
|
||||
for (const percent of GSTs[type]) {
|
||||
|
@ -33,7 +33,7 @@ export function getActions(doctype) {
|
||||
label: t`Make Payment`,
|
||||
condition: (doc) => doc.submitted && doc.outstandingAmount > 0,
|
||||
action: async function makePayment(doc) {
|
||||
let payment = await frappe.getNewDoc('Payment');
|
||||
let payment = await frappe.getEmptyDoc('Payment');
|
||||
payment.once('afterInsert', async () => {
|
||||
await payment.submit();
|
||||
});
|
||||
|
@ -1,3 +1,8 @@
|
||||
import Badge from '@/components/Badge';
|
||||
import { openQuickEdit } from '@/utils';
|
||||
import frappe, { t } from 'frappe';
|
||||
import { markRaw } from 'vue';
|
||||
import AutoComplete from './AutoComplete';
|
||||
<script>
|
||||
import Badge from '@/components/Badge';
|
||||
import { openQuickEdit } from '@/utils';
|
||||
@ -103,7 +108,7 @@ export default {
|
||||
},
|
||||
async openNewDoc() {
|
||||
let doctype = this.df.target;
|
||||
let doc = await frappe.getNewDoc(doctype);
|
||||
let doc = await frappe.getEmptyDoc(doctype);
|
||||
let filters = await this.getFilters();
|
||||
openQuickEdit({
|
||||
doctype,
|
||||
|
@ -20,7 +20,7 @@
|
||||
<div class="p-3">
|
||||
<template v-if="filters.length">
|
||||
<div
|
||||
:key="filter.fieldname + frappe.getRandomString()"
|
||||
:key="filter.fieldname + getRandomString()"
|
||||
v-for="(filter, i) in filters"
|
||||
class="flex items-center justify-between text-base"
|
||||
:class="i !== 0 && 'mt-2'"
|
||||
@ -117,6 +117,7 @@
|
||||
|
||||
<script>
|
||||
import { t } from 'frappe';
|
||||
import { getRandomString } from 'frappe/utils';
|
||||
import Button from './Button';
|
||||
import FormControl from './Controls/FormControl';
|
||||
import Icon from './Icon';
|
||||
@ -152,6 +153,9 @@ export default {
|
||||
this.addNewFilter();
|
||||
},
|
||||
methods: {
|
||||
getRandomString() {
|
||||
return getRandomString();
|
||||
},
|
||||
addNewFilter() {
|
||||
let df = this.fields[0];
|
||||
this.addFilter(df.fieldname, 'like', '');
|
||||
|
@ -1,3 +1,7 @@
|
||||
import Button from '@/components/Button';
|
||||
import FormControl from '@/components/Controls/FormControl';
|
||||
import frappe from 'frappe';
|
||||
import { getErrorMessage, handleErrorWithDialog } from '../errorHandling';
|
||||
<template>
|
||||
<div class="text-sm" :class="{ 'border-t': !noBorder }">
|
||||
<template v-for="df in formFields">
|
||||
@ -220,7 +224,7 @@ let TwoColumnForm = {
|
||||
|
||||
this.inlineEditField = df;
|
||||
if (!this.doc[df.fieldname]) {
|
||||
this.inlineEditDoc = await frappe.getNewDoc(df.target);
|
||||
this.inlineEditDoc = await frappe.getEmptyDoc(df.target);
|
||||
this.inlineEditDoc.once('afterInsert', () => {
|
||||
this.onChangeCommon(df, this.inlineEditDoc.name);
|
||||
});
|
||||
|
@ -382,7 +382,7 @@ export class Importer {
|
||||
delete docObj[key];
|
||||
}
|
||||
|
||||
const doc: Doc = frappe.getNewDoc(this.doctype, false);
|
||||
const doc: Doc = frappe.getEmptyDoc(this.doctype, false);
|
||||
try {
|
||||
await this.makeEntry(doc, docObj);
|
||||
entriesMade += 1;
|
||||
|
@ -1,3 +1,9 @@
|
||||
import PageHeader from '@/components/PageHeader';
|
||||
import SearchBar from '@/components/SearchBar';
|
||||
import { openQuickEdit } from '@/utils';
|
||||
import frappe from 'frappe';
|
||||
import { nextTick } from 'vue';
|
||||
import { handleErrorWithDialog } from '../errorHandling';
|
||||
<template>
|
||||
<div class="flex flex-col overflow-y-hidden">
|
||||
<PageHeader>
|
||||
@ -240,7 +246,7 @@ export default {
|
||||
this.insertingAccount = true;
|
||||
|
||||
accountName = accountName.trim();
|
||||
let account = await frappe.getNewDoc('Account');
|
||||
let account = await frappe.getEmptyDoc('Account');
|
||||
try {
|
||||
let { name, rootType, accountType } = parentAccount;
|
||||
await account.set({
|
||||
|
@ -74,6 +74,7 @@ import frappe, { t } from 'frappe';
|
||||
import { getDatesAndPeriodicity } from './getDatesAndPeriodicity';
|
||||
import PeriodSelector from './PeriodSelector';
|
||||
import SectionHeader from './SectionHeader';
|
||||
|
||||
export default {
|
||||
name: 'UnpaidInvoices',
|
||||
components: {
|
||||
@ -143,7 +144,7 @@ export default {
|
||||
this.invoices = await Promise.all(promises);
|
||||
},
|
||||
async newInvoice(invoice) {
|
||||
let doc = await frappe.getNewDoc(invoice.doctype);
|
||||
let doc = await frappe.getEmptyDoc(invoice.doctype);
|
||||
routeTo(`/edit/${invoice.doctype}/${doc.name}`);
|
||||
},
|
||||
},
|
||||
|
@ -1,3 +1,11 @@
|
||||
import Button from '@/components/Button';
|
||||
import FilterDropdown from '@/components/FilterDropdown';
|
||||
import PageHeader from '@/components/PageHeader';
|
||||
import SearchBar from '@/components/SearchBar';
|
||||
import { routeTo } from '@/utils';
|
||||
import frappe from 'frappe';
|
||||
import List from './List';
|
||||
import listConfigs from './listConfig';
|
||||
<template>
|
||||
<div class="flex flex-col">
|
||||
<PageHeader>
|
||||
@ -63,7 +71,7 @@ export default {
|
||||
methods: {
|
||||
async makeNewDoc() {
|
||||
const doctype = this.listConfig.doctype;
|
||||
const doc = await frappe.getNewDoc(doctype);
|
||||
const doc = await frappe.getEmptyDoc(doctype);
|
||||
if (this.listConfig.filters) {
|
||||
doc.set(this.listConfig.filters);
|
||||
}
|
||||
|
@ -1,3 +1,20 @@
|
||||
import FormControl from '@/components/Controls/FormControl';
|
||||
import LanguageSelector from '@/components/Controls/LanguageSelector.vue';
|
||||
import Popover from '@/components/Popover';
|
||||
import TwoColumnForm from '@/components/TwoColumnForm';
|
||||
import config from '@/config';
|
||||
import { connectToLocalDatabase, purgeCache } from '@/initialization';
|
||||
import { IPC_MESSAGES } from '@/messages';
|
||||
import { setLanguageMap, showMessageDialog } from '@/utils';
|
||||
import { ipcRenderer } from 'electron';
|
||||
import frappe from 'frappe';
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
import {
|
||||
getErrorMessage, handleErrorWithDialog, showErrorDialog
|
||||
} from '../../errorHandling';
|
||||
import setupCompany from './setupCompany';
|
||||
import Slide from './Slide.vue';
|
||||
<template>
|
||||
<div>
|
||||
<Slide
|
||||
@ -137,7 +154,7 @@ export default {
|
||||
this.index = 1;
|
||||
}
|
||||
|
||||
this.doc = await frappe.newDoc({ doctype: 'SetupWizard' });
|
||||
this.doc = await frappe.getNewDoc({ doctype: 'SetupWizard' });
|
||||
this.doc.on('change', () => {
|
||||
this.valuesFilled = this.allValuesFilled();
|
||||
});
|
||||
|
@ -154,7 +154,7 @@ async function checkAndCreateDoc(docObject) {
|
||||
return;
|
||||
}
|
||||
|
||||
const doc = await frappe.newDoc(docObject);
|
||||
const doc = await frappe.getNewDoc(docObject);
|
||||
return doc.insert();
|
||||
}
|
||||
|
||||
|
@ -1,56 +0,0 @@
|
||||
import assert from 'assert';
|
||||
import frappe from 'frappe';
|
||||
import helpers from 'frappe/tests/helpers';
|
||||
import models from '../models';
|
||||
|
||||
async function makeFixtures() {
|
||||
if (!(await frappe.db.exists('Party', 'Test Customer'))) {
|
||||
await frappe.insert({doctype:'Party', name:'Test Customer'})
|
||||
await frappe.insert({doctype:'Item', name:'Test Item 1', description:'Test Item Description 1', unit:'No', rate: 100})
|
||||
await frappe.insert({doctype:'Item', name:'Test Item 2', description:'Test Item Description 2', unit:'No', rate: 200})
|
||||
await frappe.insert({doctype:'Account', name:'GST', parentAccount: 'Liabilities'});
|
||||
await frappe.insert({doctype:'Tax', name:'GST',
|
||||
details: [{account: 'GST', rate:10}]
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
describe('Invoice', () => {
|
||||
before(async function() {
|
||||
await helpers.initSqlite({models: models});
|
||||
await makeFixtures();
|
||||
});
|
||||
|
||||
it('show create an invoice', async () => {
|
||||
let invoice = await frappe.insert({
|
||||
doctype:'Invoice',
|
||||
customer: 'Test Customer',
|
||||
items: [
|
||||
{item: 'Test Item 1', quantity: 5},
|
||||
{item: 'Test Item 2', quantity: 7},
|
||||
]
|
||||
});
|
||||
|
||||
assert.equal(invoice.items[0].amount, 500);
|
||||
assert.equal(invoice.items[1].amount, 1400);
|
||||
assert.equal(invoice.netTotal, 1900);
|
||||
});
|
||||
|
||||
it('show create an invoice with tax', async () => {
|
||||
let invoice = await frappe.insert({
|
||||
doctype:'Invoice',
|
||||
customer: 'Test Customer',
|
||||
items: [
|
||||
{item: 'Test Item 1', quantity: 5, tax: 'GST'},
|
||||
{item: 'Test Item 2', quantity: 7, tax: 'GST'},
|
||||
]
|
||||
});
|
||||
|
||||
assert.equal(invoice.items[0].amount, 500);
|
||||
assert.equal(invoice.items[1].amount, 1400);
|
||||
assert.equal(invoice.netTotal, 1900);
|
||||
assert.equal(invoice.taxes[0].amount, 190);
|
||||
assert.equal(invoice.grandTotal, 2090);
|
||||
});
|
||||
|
||||
});
|
Loading…
Reference in New Issue
Block a user