2
0
mirror of https://github.com/frappe/books.git synced 2024-11-10 15:50:56 +00:00
books/model/index.js
2018-06-15 21:12:02 +05:30

72 lines
1.9 KiB
JavaScript

const deepmerge = require('deepmerge');
module.exports = {
extend: (base, target, options = {}) => {
base = deepmerge({}, base);
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: [
{
fieldname: 'name', fieldtype: 'Data', required: 1
}
],
parentFields: [
{
fieldname: 'owner', fieldtype: 'Data', required: 1
},
{
fieldname: 'modifiedBy', fieldtype: 'Data', required: 1
},
{
fieldname: 'creation', fieldtype: 'Datetime', required: 1
},
{
fieldname: 'modified', fieldtype: 'Datetime', required: 1
},
{
fieldname: 'keywords', fieldtype: 'Text'
}
],
childFields: [
{
fieldname: 'idx', fieldtype: 'Int', required: 1
},
{
fieldname: 'parent', fieldtype: 'Data', required: 1
},
{
fieldname: 'parenttype', fieldtype: 'Data', required: 1
},
{
fieldname: 'parentfield', fieldtype: 'Data', required: 1
}
],
treeFields: [
{
fieldname: 'lft', fieldtype: 'Int'
},
{
fieldname: 'rgt', fieldtype: 'Int'
}
]
};