mirror of
https://github.com/frappe/books.git
synced 2024-12-23 11:29:03 +00:00
add number series
This commit is contained in:
parent
2a2f1fb6f3
commit
66b3dc6dc7
@ -296,7 +296,7 @@ class sqliteDatabase {
|
|||||||
this.conn.run(query, params, (err) => {
|
this.conn.run(query, params, (err) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
if (debug) {
|
if (debug) {
|
||||||
console.error(err);
|
console.log(err);
|
||||||
}
|
}
|
||||||
reject(err);
|
reject(err);
|
||||||
} else {
|
} else {
|
||||||
|
@ -91,10 +91,12 @@ class TableControl extends BaseControl {
|
|||||||
primary_label: frappe._('Submit'),
|
primary_label: frappe._('Submit'),
|
||||||
primary_action: (modal) => {
|
primary_action: (modal) => {
|
||||||
this.datatable.cellmanager.submitEditing();
|
this.datatable.cellmanager.submitEditing();
|
||||||
this.datatable.cellmanager.deactivateEditing();
|
|
||||||
modal.hide();
|
modal.hide();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
this.text_modal.$modal.on('hidden.bs.modal', () => {
|
||||||
|
this.datatable.cellmanager.deactivateEditing();
|
||||||
|
})
|
||||||
|
|
||||||
return this.get_control(field, this.text_modal.get_body());
|
return this.get_control(field, this.text_modal.get_body());
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,20 @@
|
|||||||
|
const frappe = require('frappejs');
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
async get_series_next(prefix) {
|
||||||
|
let series;
|
||||||
|
try {
|
||||||
|
series = await frappe.get_doc('Number Series', prefix);
|
||||||
|
} catch (e) {
|
||||||
|
if (!e.status_code || e.status_code !== 404) {
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
series = frappe.new_doc({doctype: 'Number Series', name: prefix, current: 0});
|
||||||
|
await series.insert();
|
||||||
|
}
|
||||||
|
let next = await series.next()
|
||||||
|
return prefix + next;
|
||||||
|
},
|
||||||
common_fields: [
|
common_fields: [
|
||||||
{
|
{
|
||||||
fieldname: 'name', fieldtype: 'Data', reqd: 1
|
fieldname: 'name', fieldtype: 'Data', reqd: 1
|
||||||
|
24
models/doctype/number_series/number_series.js
Normal file
24
models/doctype/number_series/number_series.js
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
const BaseMeta = require('frappejs/model/meta');
|
||||||
|
const BaseDocument = require('frappejs/model/document');
|
||||||
|
|
||||||
|
class NumberSeriesMeta extends BaseMeta {
|
||||||
|
setup_meta() {
|
||||||
|
Object.assign(this, require('./number_series.json'));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class NumberSeries extends BaseDocument {
|
||||||
|
async next() {
|
||||||
|
if (this.current===null || this.current===undefined) {
|
||||||
|
this.current = 0;
|
||||||
|
}
|
||||||
|
this.current++;
|
||||||
|
await this.update();
|
||||||
|
return this.current;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
Document: NumberSeries,
|
||||||
|
Meta: NumberSeriesMeta
|
||||||
|
};
|
21
models/doctype/number_series/number_series.json
Normal file
21
models/doctype/number_series/number_series.json
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
{
|
||||||
|
"name": "Number Series",
|
||||||
|
"doctype": "DocType",
|
||||||
|
"is_single": 0,
|
||||||
|
"is_child": 0,
|
||||||
|
"keyword_fields": [],
|
||||||
|
"fields": [
|
||||||
|
{
|
||||||
|
"fieldname": "name",
|
||||||
|
"label": "Name",
|
||||||
|
"fieldtype": "Data",
|
||||||
|
"reqd": 1
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldname": "current",
|
||||||
|
"label": "Current",
|
||||||
|
"fieldtype": "Int",
|
||||||
|
"reqd": 1
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
16
tests/test_number_series.js
Normal file
16
tests/test_number_series.js
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
const assert = require('assert');
|
||||||
|
const frappe = require('frappejs');
|
||||||
|
const helpers = require('./helpers');
|
||||||
|
|
||||||
|
describe('Document', () => {
|
||||||
|
before(async function() {
|
||||||
|
await helpers.init_sqlite();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should start a series and get next value', async () => {
|
||||||
|
frappe.db.delete('Number Series', 'test-series-')
|
||||||
|
assert.equal(await frappe.model.get_series_next('test-series-'), 'test-series-1');
|
||||||
|
assert.equal(await frappe.model.get_series_next('test-series-'), 'test-series-2');
|
||||||
|
assert.equal(await frappe.model.get_series_next('test-series-'), 'test-series-3');
|
||||||
|
});
|
||||||
|
});
|
Loading…
Reference in New Issue
Block a user