2
0
mirror of https://github.com/frappe/books.git synced 2025-01-24 15:48:25 +00:00
books/model/index.js

72 lines
1.9 KiB
JavaScript
Raw Normal View History

2018-04-26 15:50:46 +05:30
const deepmerge = require('deepmerge');
2018-01-12 17:55:07 +05:30
module.exports = {
2018-04-26 15:50:46 +05:30
extend: (base, target, options = {}) => {
base = deepmerge({}, base);
2018-04-26 15:50:46 +05:30
const fieldsToMerge = (target.fields || []).map(df => df.fieldname);
const fieldsToRemove = options.skipFields || [];
base.fields = base.fields
.filter(df => !fieldsToRemove.includes(df.fieldname))
.map(df => {
if (fieldsToMerge.includes(df.fieldname)) {
return deepmerge(df, target.fields.find(tdf => tdf.fieldname === df.fieldname));
}
return df;
});
const overrideProps = options.overrideProps || [];
for (let prop of overrideProps) {
if (base.hasOwnProperty(prop)) {
delete base[prop];
}
}
return deepmerge(base, target);
},
commonFields: [
2018-01-12 17:55:07 +05:30
{
2018-02-09 18:25:55 +05:30
fieldname: 'name', fieldtype: 'Data', required: 1
2018-01-31 18:26:21 +05:30
}
2018-01-31 18:34:46 +05:30
],
parentFields: [
2018-01-12 17:55:07 +05:30
{
2018-02-20 19:41:44 +05:30
fieldname: 'owner', fieldtype: 'Data', required: 1
2018-01-12 17:55:07 +05:30
},
{
2018-03-29 19:58:56 +05:30
fieldname: 'modifiedBy', fieldtype: 'Data', required: 1
2018-01-12 17:55:07 +05:30
},
{
2018-02-09 18:25:55 +05:30
fieldname: 'creation', fieldtype: 'Datetime', required: 1
2018-01-12 17:55:07 +05:30
},
{
2018-02-09 18:25:55 +05:30
fieldname: 'modified', fieldtype: 'Datetime', required: 1
2018-01-12 17:55:07 +05:30
},
{
fieldname: 'keywords', fieldtype: 'Text'
}
],
childFields: [
2018-01-12 17:55:07 +05:30
{
2018-02-09 18:25:55 +05:30
fieldname: 'idx', fieldtype: 'Int', required: 1
2018-01-12 17:55:07 +05:30
},
{
2018-02-09 18:25:55 +05:30
fieldname: 'parent', fieldtype: 'Data', required: 1
2018-01-12 17:55:07 +05:30
},
{
2018-02-20 19:41:44 +05:30
fieldname: 'parenttype', fieldtype: 'Data', required: 1
2018-01-12 17:55:07 +05:30
},
{
2018-02-09 18:25:55 +05:30
fieldname: 'parentfield', fieldtype: 'Data', required: 1
2018-01-12 17:55:07 +05:30
}
2018-04-18 12:18:24 +05:30
],
treeFields: [
{
2018-05-08 15:36:19 +05:30
fieldname: 'lft', fieldtype: 'Int'
2018-04-18 12:18:24 +05:30
},
{
2018-05-08 15:36:19 +05:30
fieldname: 'rgt', fieldtype: 'Int'
2018-04-18 12:18:24 +05:30
}
2018-01-12 17:55:07 +05:30
]
2018-04-18 12:18:24 +05:30
};