2
0
mirror of https://github.com/frappe/books.git synced 2024-11-08 14:50:56 +00:00

added invoice models

This commit is contained in:
Rushabh Mehta 2018-01-31 18:52:50 +05:30
parent cd5461722e
commit 76f3f669d3
8 changed files with 125 additions and 9 deletions

11
dist/js/bundle.js vendored
View File

@ -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'),

View File

@ -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",

View File

@ -1,7 +1,7 @@
{
"name": "Customer",
"doctype": "DocType",
"issingle": 0,
"is_single": 0,
"istable": 0,
"keyword_fields": [
"name"

View File

@ -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
};

View File

@ -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
}
]
}

View File

@ -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
};

View File

@ -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"
}
]
}

View File

@ -1,7 +1,7 @@
{
"name": "Item",
"doctype": "DocType",
"issingle": 0,
"is_single": 0,
"keyword_fields": [
"name",
"description"