Skip to content

Commit

Permalink
Merge branch 'version-12-hotfix' into version-12
Browse files Browse the repository at this point in the history
  • Loading branch information
sahil28297 committed Jul 30, 2019
2 parents d800f99 + 403968b commit de1ecee
Show file tree
Hide file tree
Showing 37 changed files with 772 additions and 1,687 deletions.
2 changes: 1 addition & 1 deletion erpnext/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from erpnext.hooks import regional_overrides
from frappe.utils import getdate

__version__ = '12.0.2'
__version__ = '12.0.3'

def get_default_company(user=None):
'''Get default company for user'''
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,49 +4,63 @@
frappe.ui.form.on('Accounting Dimension', {

refresh: function(frm) {
if (!frm.is_new()) {
frm.add_custom_button(__('Show {0}', [frm.doc.document_type]), function () {
frappe.set_route("List", frm.doc.document_type);
});
}

frm.set_query('document_type', () => {
return {
filters: {
name: ['not in', ['Accounting Dimension', 'Project', 'Cost Center']]
name: ['not in', ['Accounting Dimension', 'Project', 'Cost Center', 'Accounting Dimension Detail']]
}
};
});

let button = frm.doc.disabled ? "Enable" : "Disable";
if (!frm.is_new()) {
frm.add_custom_button(__('Show {0}', [frm.doc.document_type]), function () {
frappe.set_route("List", frm.doc.document_type);
});

let button = frm.doc.disabled ? "Enable" : "Disable";

frm.add_custom_button(__(button), function() {
frm.add_custom_button(__(button), function() {

frm.set_value('disabled', 1 - frm.doc.disabled);
frm.set_value('disabled', 1 - frm.doc.disabled);

frappe.call({
method: "erpnext.accounts.doctype.accounting_dimension.accounting_dimension.disable_dimension",
args: {
doc: frm.doc
},
freeze: true,
callback: function(r) {
let message = frm.doc.disabled ? "Dimension Disabled" : "Dimension Enabled";
frm.save();
frappe.show_alert({message:__(message), indicator:'green'});
}
frappe.call({
method: "erpnext.accounts.doctype.accounting_dimension.accounting_dimension.disable_dimension",
args: {
doc: frm.doc
},
freeze: true,
callback: function(r) {
let message = frm.doc.disabled ? "Dimension Disabled" : "Dimension Enabled";
frm.save();
frappe.show_alert({message:__(message), indicator:'green'});
}
});
});
});
}
},

document_type: function(frm) {

frm.set_value('label', frm.doc.document_type);
frm.set_value('fieldname', frappe.model.scrub(frm.doc.document_type));

if (frm.is_new()){
let row = frappe.model.add_child(frm.doc, "Accounting Dimension Detail", "dimension_defaults");
row.reference_document = frm.doc.document_type;
frm.refresh_fields("dimension_defaults");
}

frappe.db.get_value('Accounting Dimension', {'document_type': frm.doc.document_type}, 'document_type', (r) => {
if (r && r.document_type) {
frm.set_df_property('document_type', 'description', "Document type is already set as dimension");
}
});
},
});

frappe.ui.form.on('Accounting Dimension Detail', {
dimension_defaults_add: function(frm, cdt, cdn) {
let row = locals[cdt][cdn];
row.reference_document = frm.doc.document_type;
}
});
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
{
"_comments": "[]",
"_liked_by": "[]",
"autoname": "field:label",
"creation": "2019-05-04 18:13:37.002352",
"doctype": "DocType",
Expand All @@ -9,8 +7,7 @@
"document_type",
"label",
"fieldname",
"mandatory_for_bs",
"mandatory_for_pl",
"dimension_defaults",
"disabled"
],
"fields": [
Expand Down Expand Up @@ -43,19 +40,13 @@
"read_only": 1
},
{
"default": "0",
"fieldname": "mandatory_for_bs",
"fieldtype": "Check",
"label": "Mandatory For Balance Sheet"
},
{
"default": "0",
"fieldname": "mandatory_for_pl",
"fieldtype": "Check",
"label": "Mandatory For Profit and Loss Account"
"fieldname": "dimension_defaults",
"fieldtype": "Table",
"label": "Dimension Defaults",
"options": "Accounting Dimension Detail"
}
],
"modified": "2019-07-14 17:25:01.307948",
"modified": "2019-07-17 16:49:31.134385",
"modified_by": "Administrator",
"module": "Accounts",
"name": "Accounting Dimension",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,13 @@ def delete_accounting_dimension(doc):

frappe.db.sql("""
DELETE FROM `tabCustom Field`
WHERE fieldname = %s
WHERE fieldname = %s
AND dt IN (%s)""" % #nosec
('%s', ', '.join(['%s']* len(doclist))), tuple([doc.fieldname] + doclist))

frappe.db.sql("""
DELETE FROM `tabProperty Setter`
WHERE field_name = %s
WHERE field_name = %s
AND doc_type IN (%s)""" % #nosec
('%s', ', '.join(['%s']* len(doclist))), tuple([doc.fieldname] + doclist))

Expand Down Expand Up @@ -150,14 +150,40 @@ def get_doctypes_with_dimensions():
"Purchase Order Item", "Journal Entry Account", "Material Request Item", "Delivery Note Item", "Purchase Receipt Item",
"Stock Entry Detail", "Payment Entry Deduction", "Sales Taxes and Charges", "Purchase Taxes and Charges", "Shipping Rule",
"Landed Cost Item", "Asset Value Adjustment", "Loyalty Program", "Fee Schedule", "Fee Structure", "Stock Reconciliation",
"Travel Request", "Fees", "POS Profile"]
"Travel Request", "Fees", "POS Profile", "Opening Invoice Creation Tool", "Opening Invoice Creation Tool Item", "Subscription",
"Subscription Plan"]

return doclist

def get_accounting_dimensions(as_list=True):
accounting_dimensions = frappe.get_all("Accounting Dimension", fields=["label", "fieldname", "mandatory_for_pl", "mandatory_for_bs", "disabled"], filters={"disabled": 0})
accounting_dimensions = frappe.get_all("Accounting Dimension", fields=["label", "fieldname", "disabled"])

if as_list:
return [d.fieldname for d in accounting_dimensions]
else:
return accounting_dimensions

def get_checks_for_pl_and_bs_accounts():
dimensions = frappe.db.sql("""SELECT p.label, p.disabled, p.fieldname, c.company, c.mandatory_for_pl, c.mandatory_for_bs
FROM `tabAccounting Dimension`p ,`tabAccounting Dimension Detail` c
WHERE p.name = c.parent""", as_dict=1)

return dimensions

@frappe.whitelist()
def get_dimension_filters():
dimension_filters = frappe.db.sql("""
SELECT label, fieldname, document_type
FROM `tabAccounting Dimension`
WHERE disabled = 0
""", as_dict=1)

default_dimensions = frappe.db.sql("""SELECT parent, company, default_dimension
FROM `tabAccounting Dimension Detail`""", as_dict=1)

default_dimensions_map = {}
for dimension in default_dimensions:
default_dimensions_map.setdefault(dimension['company'], {})
default_dimensions_map[dimension['company']][dimension['parent']] = dimension['default_dimension']

return dimension_filters, default_dimensions_map
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,20 @@ def setUp(self):
dimension1 = frappe.get_doc({
"doctype": "Accounting Dimension",
"document_type": "Location",
"mandatory_for_pl": 1
}).insert()
})

dimension1.append("dimension_defaults", {
"company": "_Test Company",
"reference_document": "Location",
"default_dimension": "Block 1",
"mandatory_for_bs": 1
})

dimension1.insert()
dimension1.save()
else:
dimension1 = frappe.get_doc("Accounting Dimension", "Location")
dimension1.disabled = 0
dimension1.mandatory_for_pl = 1
dimension1.save()

def test_dimension_against_sales_invoice(self):
Expand Down Expand Up @@ -100,7 +108,6 @@ def disable_dimension():
dimension1.save()

dimension2 = frappe.get_doc("Accounting Dimension", "Location")
dimension2.mandatory_for_pl = 0
dimension2.disabled = 1
dimension2.save()

Expand Down
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
{
"creation": "2019-07-16 17:53:18.718831",
"doctype": "DocType",
"editable_grid": 1,
"engine": "InnoDB",
"field_order": [
"company",
"reference_document",
"default_dimension",
"mandatory_for_bs",
"mandatory_for_pl"
],
"fields": [
{
"columns": 2,
"fieldname": "company",
"fieldtype": "Link",
"in_list_view": 1,
"label": "Company",
"options": "Company",
"reqd": 1
},
{
"fieldname": "reference_document",
"fieldtype": "Link",
"hidden": 1,
"label": "Reference Document",
"options": "DocType",
"read_only": 1
},
{
"columns": 2,
"fieldname": "default_dimension",
"fieldtype": "Dynamic Link",
"in_list_view": 1,
"label": "Default Dimension",
"options": "reference_document",
"reqd": 1
},
{
"columns": 3,
"default": "0",
"fieldname": "mandatory_for_bs",
"fieldtype": "Check",
"in_list_view": 1,
"label": "Mandatory For Balance Sheet"
},
{
"columns": 3,
"default": "0",
"fieldname": "mandatory_for_pl",
"fieldtype": "Check",
"in_list_view": 1,
"label": "Mandatory For Profit and Loss Account"
}
],
"istable": 1,
"modified": "2019-07-17 23:34:33.026883",
"modified_by": "Administrator",
"module": "Accounts",
"name": "Accounting Dimension Detail",
"owner": "Administrator",
"permissions": [],
"sort_field": "modified",
"sort_order": "DESC",
"track_changes": 1
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# -*- coding: utf-8 -*-
# Copyright (c) 2019, Frappe Technologies Pvt. Ltd. and contributors
# For license information, please see license.txt

from __future__ import unicode_literals
# import frappe
from frappe.model.document import Document

class AccountingDimensionDetail(Document):
pass
14 changes: 11 additions & 3 deletions erpnext/accounts/doctype/bank_transaction/bank_transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def update_allocations(self):
def clear_linked_payment_entries(self):
for payment_entry in self.payment_entries:
allocated_amount = get_total_allocated_amount(payment_entry)
paid_amount = get_paid_amount(payment_entry)
paid_amount = get_paid_amount(payment_entry, self.currency)

if paid_amount and allocated_amount:
if flt(allocated_amount[0]["allocated_amount"]) > flt(paid_amount):
Expand Down Expand Up @@ -80,9 +80,17 @@ def get_total_allocated_amount(payment_entry):
AND
bt.docstatus = 1""", (payment_entry.payment_document, payment_entry.payment_entry), as_dict=True)

def get_paid_amount(payment_entry):
def get_paid_amount(payment_entry, currency):
if payment_entry.payment_document in ["Payment Entry", "Sales Invoice", "Purchase Invoice"]:
return frappe.db.get_value(payment_entry.payment_document, payment_entry.payment_entry, "paid_amount")

paid_amount_field = "paid_amount"
if payment_entry.payment_document == 'Payment Entry':
doc = frappe.get_doc("Payment Entry", payment_entry.payment_entry)
paid_amount_field = ("base_paid_amount"
if doc.paid_to_account_currency == currency else "paid_amount")

return frappe.db.get_value(payment_entry.payment_document,
payment_entry.payment_entry, paid_amount_field)

elif payment_entry.payment_document == "Journal Entry":
return frappe.db.get_value(payment_entry.payment_document, payment_entry.payment_entry, "total_credit")
Expand Down
8 changes: 4 additions & 4 deletions erpnext/accounts/doctype/gl_entry/gl_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from erpnext.accounts.utils import get_account_currency
from erpnext.accounts.utils import get_fiscal_year
from erpnext.exceptions import InvalidAccountCurrency
from erpnext.accounts.doctype.accounting_dimension.accounting_dimension import get_accounting_dimensions
from erpnext.accounts.doctype.accounting_dimension.accounting_dimension import get_checks_for_pl_and_bs_accounts

exclude_from_linked_with = True
class GLEntry(Document):
Expand Down Expand Up @@ -86,16 +86,16 @@ def validate_dimensions_for_pl_and_bs(self):

account_type = frappe.db.get_value("Account", self.account, "report_type")

for dimension in get_accounting_dimensions(as_list=False):
for dimension in get_checks_for_pl_and_bs_accounts():

if account_type == "Profit and Loss" \
and dimension.mandatory_for_pl and not dimension.disabled:
and self.company == dimension.company and dimension.mandatory_for_pl and not dimension.disabled:
if not self.get(dimension.fieldname):
frappe.throw(_("Accounting Dimension <b>{0}</b> is required for 'Profit and Loss' account {1}.")
.format(dimension.label, self.account))

if account_type == "Balance Sheet" \
and dimension.mandatory_for_bs and not dimension.disabled:
and self.company == dimension.company and dimension.mandatory_for_bs and not dimension.disabled:
if not self.get(dimension.fieldname):
frappe.throw(_("Accounting Dimension <b>{0}</b> is required for 'Balance Sheet' account {1}.")
.format(dimension.label, self.account))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@
"print_hide": 1
},
{
"collapsible": 1,
"fieldname": "accounting_dimensions_section",
"fieldtype": "Section Break",
"label": "Accounting Dimensions"
Expand All @@ -269,12 +270,13 @@
],
"idx": 1,
"istable": 1,
"modified": "2019-05-25 22:14:02.715509",
"modified": "2019-07-16 17:12:08.238334",
"modified_by": "Administrator",
"module": "Accounts",
"name": "Journal Entry Account",
"owner": "Administrator",
"permissions": [],
"sort_field": "modified",
"sort_order": "DESC",
"track_changes": 1
}
Loading

0 comments on commit de1ecee

Please sign in to comment.