Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
revant committed Jun 2, 2016
2 parents 2499617 + efd9424 commit 84381b3
Show file tree
Hide file tree
Showing 5 changed files with 182 additions and 4 deletions.
2 changes: 1 addition & 1 deletion kiratplastics_erpnext/__version__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
from __future__ import unicode_literals
__version__ = "1.0.11"
__version__ = "1.1.0"

4 changes: 2 additions & 2 deletions kiratplastics_erpnext/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@
app_icon = "octicon octicon-file-directory"
app_color = "grey"
app_email = "[email protected]"
app_version = "1.0.11"
app_version = "1.1.0"
app_license = "GPL v3"

# Includes in <head>
# ------------------

# include js, css files in header of desk.html
# app_include_css = "/assets/kiratplastics_erpnext/css/kiratplastics_erpnext.css"
# app_include_js = "/assets/kiratplastics_erpnext/js/kiratplastics_erpnext.js"
app_include_js = "/assets/kiratplastics_erpnext/js/kp_si.js"

# include js, css files in header of web template
# web_include_css = "/assets/kiratplastics_erpnext/css/kiratplastics_erpnext.css"
Expand Down
5 changes: 5 additions & 0 deletions kiratplastics_erpnext/public/build.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"js/kp_si.js": [
"public/js/kp_si.js"
]
}
173 changes: 173 additions & 0 deletions kiratplastics_erpnext/public/js/kp_si.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
//Kirat Plastics Script

var excise_account;
var zero_price_list;

function get_company_account(frm) {
frappe.call({
method: "kiratplastics_erpnext.kirat_plastics_erpnext.doctype.kp_settings.kp_settings.get_ep_account",
args: {
"company": frm.doc.company
},
callback: function(r) {
excise_account = r.message; //excise_account is a global variable.
}
});
}

function get_zero_price_list(frm) {
frappe.call({
method: "kiratplastics_erpnext.kirat_plastics_erpnext.doctype.kp_settings.kp_settings.get_zero_price_list",
args: {},
callback: function(r) {
zero_price_list = r.message; //zero_price_list is a global variable
}
});
}

function set_excise_chapter_filter(frm) {
//Set query filter
frm.set_query("kirat_excise_chapter_head", function() {
return {
"filters": {
"is_group": "No"
}
};
});
}

function make_taxes_unsortable(frm) {
frm.page.body.find('[data-fieldname="taxes"] [data-idx] .data-row').removeClass('sortable-handle');
}

function calculate_excise_duty_amount(item) {
var item_price;
var item_price_for_excise_calc;

if (item.price_list_rate != 0) {
item_price = item.price_list_rate;
} else {
item_price = item.rate;
}
//Deprecated: 160521: Calculate excise rate ONLY with excise price.
//It WILL be entered manually for each item.
// if (item.kirat_excise_price != 0) {
// item_price_for_excise_calc = item.kirat_excise_price;
// } else {
// item_price_for_excise_calc = item_price; //Price list rate or rate.
// }
item_price_for_excise_calc = item.kirat_excise_price;

var excise_duty_amt = (item.qty * item_price_for_excise_calc) * (item.kirat_excise_duty_rate / 100);
item.kirat_excise_duty_amt = excise_duty_amt;
item.kirat_total_amt_with_excise = item.amount + excise_duty_amt;
}

function inject_excise_row_and_append_taxes(frm) {

//Calculate total excise amount for all items
var items = frm.doc.items;
var total_ed = 0.0;
var total_ea = 0.0; //Total Amount with Excise.

//Inject total as zero for Sample and Challan.
// if (frm.doc.kirat_invoice_type == "Invoice for Sample" | frm.doc.kirat_invoice_type == "Challan") {
// total_ed = 0.0;
// total_ea = 0.0;
// } else {
// for (var i = 0; i <items.length; i++) {
// total_ed += items[i].kirat_excise_duty_amt;
// total_ea += items[i].kirat_total_amt_with_excise;
// }
// }

if (frm.doc.kirat_invoice_type == "Challan") {
total_ed = 0.0;
total_ea = 0.0;
} else {
for (var i = 0; i <items.length; i++) {
total_ed += items[i].kirat_excise_duty_amt;
total_ea += items[i].kirat_total_amt_with_excise;
}
}

//Set total fields in Doc
frm.set_value("kirat_excise_payable_total", total_ed);
frm.set_value("kirat_amount_with_excise_total", total_ea);

var taxes_temp = frm.doc.taxes;

//Find and delete Excise rows from taxes_temp;
if (taxes_temp) {
var taxes_temp_temp = taxes_temp; //!Removing elements from array while iterating over it may be hazardous.

for(var i = 0; i <= taxes_temp_temp.length - 1; i++) {
if (taxes_temp_temp[i].description.indexOf("Excise") > -1) {
taxes_temp.splice(i, 1);
}
}
}

//Clear the taxes table.
frm.clear_table("taxes");

//Inject Excise row as first row.
var si = locals['Sales Invoice'][si];
var ed = frappe.model.add_child(frm.doc,'Sales Taxes and Charges','taxes');
//ed.account_head = "Excise Payable - KPPL";
ed.account_head = excise_account; //1
ed.charge_type = "Actual";
ed.description = "Excise Duty Payable";
ed.tax_amount = total_ed;

if (!taxes_temp) { return; } //to prevent taxes_temp nullref in for loop.

for (var i = 0; i < taxes_temp.length; i++) {
var tr = frappe.model.add_child(frm.doc,'Sales Taxes and Charges','taxes');
tr.account_head = taxes_temp[i].account_head;
tr.description = taxes_temp[i].description;

if (taxes_temp[i].charge_type != "Actual") {
tr.charge_type = "On Previous Row Total";
tr.row_id = 1;
tr.rate = taxes_temp[i].rate;
} else {
tr.charge_type = taxes_temp[i].charge_type;
tr.tax_amount = taxes_temp[i].tax_amount;
}
}
}

function set_item_filter_query(frm) {
frm.set_query("item_code", "items", function() {
return {
query: "kiratplastics_erpnext.kirat_plastics_erpnext.kp_api.kp_sinv_item_query",
filters: {
"cust_name": frm.doc.customer,
"excise_chapter": frm.doc.kirat_excise_chapter_head
}
};
});
}

function set_customer_readonly(frm) {
if (frm.doc.items) {
frm.set_df_property("customer", "read_only", (frm.doc.items.length > 0));
}
}
function set_chapter_head_readonly(frm) {
if (frm.doc.items) {
frm.set_df_property("kirat_excise_chapter_head", "read_only", (frm.doc.items.length > 0));
}
}
function set_invoice_type_and_series_readonly(frm) {
if (frm.doc.items) {
frm.set_df_property("kirat_invoice_type", "read_only", (frm.doc.items.length > 0));
frm.set_df_property("naming_series", "read_only", (frm.doc.items.length > 0));
}
}
function set_excise_price_readonly(frm) {
//frm.set_df_property("kirat_excise_price", "read_only", (frm.doc.kirat_invoice_type != "Supplementary Invoice"));
var df = frappe.meta.get_docfield("Sales Invoice Item","kirat_excise_price", cur_frm.doc.name);
df.read_only = (frm.doc.kirat_invoice_type != "Supplementary Invoice");
}
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from setuptools import setup, find_packages
from pip.req import parse_requirements

version = '1.0.11'
version = '1.1.0'
requirements = parse_requirements("requirements.txt", session="")

setup(
Expand Down

0 comments on commit 84381b3

Please sign in to comment.