2
0
mirror of https://github.com/frappe/books.git synced 2024-11-10 07:40:55 +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

1
dist/js/bundle.js vendored
View File

@ -2741,6 +2741,7 @@ var account_client = {
List: AccountList List: AccountList
}; };
// start server
client.start({ client.start({
server: 'localhost:8000', server: 'localhost:8000',
container: document.querySelector('.wrapper'), container: document.querySelector('.wrapper'),

View File

@ -1,7 +1,7 @@
{ {
"name": "Account", "name": "Account",
"doctype": "DocType", "doctype": "DocType",
"issingle": 0, "is_single": 0,
"keyword_fields": [ "keyword_fields": [
"name", "name",
"account_type" "account_type"
@ -17,7 +17,7 @@
"fieldname": "parent_account", "fieldname": "parent_account",
"label": "Parent Account", "label": "Parent Account",
"fieldtype": "Link", "fieldtype": "Link",
"options": "Account" "target": "Account"
}, },
{ {
"fieldname": "account_type", "fieldname": "account_type",

View File

@ -1,7 +1,7 @@
{ {
"name": "Customer", "name": "Customer",
"doctype": "DocType", "doctype": "DocType",
"issingle": 0, "is_single": 0,
"istable": 0, "istable": 0,
"keyword_fields": [ "keyword_fields": [
"name" "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", "name": "Item",
"doctype": "DocType", "doctype": "DocType",
"issingle": 0, "is_single": 0,
"keyword_fields": [ "keyword_fields": [
"name", "name",
"description" "description"