diff --git a/dist/js/bundle.js b/dist/js/bundle.js index ca0796b1..71692006 100644 --- a/dist/js/bundle.js +++ b/dist/js/bundle.js @@ -1240,14 +1240,14 @@ var router = class Router { }; var observable = class Observable { - constructor() { - this._handlers = {}; - } + constructor() { + this._handlers = {}; + } on(event, fn) { if (!this._handlers[event]) { - this._handlers[event] = []; - } + this._handlers[event] = []; + } this._handlers[event].push(fn); } @@ -2741,6 +2741,7 @@ var account_client = { List: AccountList }; +// start server client.start({ server: 'localhost:8000', container: document.querySelector('.wrapper'), diff --git a/models/doctype/account/account.json b/models/doctype/account/account.json index ecad766b..cb8a86fe 100644 --- a/models/doctype/account/account.json +++ b/models/doctype/account/account.json @@ -1,7 +1,7 @@ { "name": "Account", "doctype": "DocType", - "issingle": 0, + "is_single": 0, "keyword_fields": [ "name", "account_type" @@ -17,7 +17,7 @@ "fieldname": "parent_account", "label": "Parent Account", "fieldtype": "Link", - "options": "Account" + "target": "Account" }, { "fieldname": "account_type", diff --git a/models/doctype/customer/customer.json b/models/doctype/customer/customer.json index 2c6f09e2..f1e68fd9 100644 --- a/models/doctype/customer/customer.json +++ b/models/doctype/customer/customer.json @@ -1,7 +1,7 @@ { "name": "Customer", "doctype": "DocType", - "issingle": 0, + "is_single": 0, "istable": 0, "keyword_fields": [ "name" diff --git a/models/doctype/invoice/invoice.js b/models/doctype/invoice/invoice.js new file mode 100644 index 00000000..951a747f --- /dev/null +++ b/models/doctype/invoice/invoice.js @@ -0,0 +1,27 @@ +const BaseMeta = require('frappejs/model/meta'); +const BaseDocument = require('frappejs/model/document'); + +class InvoiceMeta extends BaseMeta { + setup_meta() { + Object.assign(this, require('./invoice.json')); + } +} + +class Invoice extends BaseDocument { + setup() { + this.add_handler('validate'); + } + + validate() { + this.total = this.get_total(); + } + + get_total() { + return this.items.map(d => d.amount).reduce((a, b) => a + b, 0); + } +} + +module.exports = { + Document: Invoice, + Meta: InvoiceMeta +}; \ No newline at end of file diff --git a/models/doctype/invoice/invoice.json b/models/doctype/invoice/invoice.json new file mode 100644 index 00000000..2ec20ab9 --- /dev/null +++ b/models/doctype/invoice/invoice.json @@ -0,0 +1,30 @@ +{ + "name": "Invoice", + "doctype": "DocType", + "is_single": 0, + "istable": 0, + "keyword_fields": [], + "fields": [ + { + "fieldname": "customer", + "label": "Customer", + "fieldtype": "Link", + "target": "Customer", + "reqd": 1 + }, + { + "fieldname": "items", + "label": "Items", + "fieldtype": "Table", + "childtype": "Invoice Item", + "reqd": 1 + }, + { + "fieldname": "total", + "label": "Total", + "fieldtype": "Currency", + "formula": "doc.get_total()", + "reqd": 1 + } + ] +} \ No newline at end of file diff --git a/models/doctype/invoice_item/invoice_item.js b/models/doctype/invoice_item/invoice_item.js new file mode 100644 index 00000000..62fb348b --- /dev/null +++ b/models/doctype/invoice_item/invoice_item.js @@ -0,0 +1,16 @@ +const BaseMeta = require('frappejs/model/meta'); +const BaseDocument = require('frappejs/model/document'); + +class InvoiceItemMeta extends BaseMeta { + setup_meta() { + Object.assign(this, require('./invoice_item.json')); + } +} + +class InvoiceItem extends BaseDocument { +} + +module.exports = { + Document: InvoiceItem, + Meta: InvoiceItemMeta +}; \ No newline at end of file diff --git a/models/doctype/invoice_item/invoice_item.json b/models/doctype/invoice_item/invoice_item.json new file mode 100644 index 00000000..3ec56fc7 --- /dev/null +++ b/models/doctype/invoice_item/invoice_item.json @@ -0,0 +1,42 @@ +{ + "name": "Invoice Item", + "doctype": "DocType", + "is_single": 0, + "is_child": 1, + "keyword_fields": [], + "fields": [ + { + "fieldname": "item", + "label": "Item", + "fieldtype": "Link", + "options": "Item", + "reqd": 1 + }, + { + "fieldname": "description", + "label": "Description", + "fieldtype": "Text", + "fetch": "item.description", + "reqd": 1 + }, + { + "fieldname": "quantity", + "label": "Quantity", + "fieldtype": "Float", + "reqd": 1 + }, + { + "fieldname": "rate", + "label": "Rate", + "fieldtype": "Currency", + "reqd": 1 + }, + { + "fieldname": "amount", + "label": "Amount", + "fieldtype": "Currency", + "readonly": 1, + "formula": "doc.quantity * doc.rate" + } + ] +} \ No newline at end of file diff --git a/models/doctype/item/item.json b/models/doctype/item/item.json index 36100b79..11329750 100644 --- a/models/doctype/item/item.json +++ b/models/doctype/item/item.json @@ -1,7 +1,7 @@ { "name": "Item", "doctype": "DocType", - "issingle": 0, + "is_single": 0, "keyword_fields": [ "name", "description"