Skip to content

Commit

Permalink
Merge branch 'staging-fixes' into staging
Browse files Browse the repository at this point in the history
  • Loading branch information
codingCoffee committed Oct 4, 2018
2 parents a7ae06e + 5ae3445 commit c6eac7c
Show file tree
Hide file tree
Showing 103 changed files with 11,358 additions and 9,669 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__ = '10.1.54'
__version__ = '10.1.55'

def get_default_company(user=None):
'''Get default company for user'''
Expand Down
8 changes: 4 additions & 4 deletions erpnext/accounts/deferred_revenue.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ def validate_service_stop_date(doc):
def convert_deferred_expense_to_expense(start_date=None, end_date=None):
# check for the purchase invoice for which GL entries has to be done
invoices = frappe.db.sql_list('''
select parent from `tabPurchase Invoice Item` where service_start_date<=%s and service_end_date>=%s
and enable_deferred_expense = 1 and docstatus = 1
select distinct parent from `tabPurchase Invoice Item` where service_start_date<=%s and service_end_date>=%s
and enable_deferred_expense = 1 and docstatus = 1 and ifnull(amount, 0) > 0
''', (end_date or today(), start_date or add_months(today(), -1)))

# For each invoice, book deferred expense
Expand All @@ -47,8 +47,8 @@ def convert_deferred_expense_to_expense(start_date=None, end_date=None):
def convert_deferred_revenue_to_income(start_date=None, end_date=None):
# check for the sales invoice for which GL entries has to be done
invoices = frappe.db.sql_list('''
select parent from `tabSales Invoice Item` where service_start_date<=%s and service_end_date>=%s
and enable_deferred_revenue = 1 and docstatus = 1
select distinct parent from `tabSales Invoice Item` where service_start_date<=%s and service_end_date>=%s
and enable_deferred_revenue = 1 and docstatus = 1 and ifnull(amount, 0) > 0
''', (end_date or today(), start_date or add_months(today(), -1)))

# For each invoice, book deferred revenue
Expand Down
6 changes: 5 additions & 1 deletion erpnext/accounts/doctype/cost_center/cost_center.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ def before_rename(self, olddn, newdn, merge=False):
# Validate properties before merging
super(CostCenter, self).before_rename(olddn, new_cost_center, merge, "is_group")
if not merge:
from erpnext.accounts.doctype.account.account import get_name_with_number
new_cost_center = get_name_with_number(new_cost_center, self.cost_center_number)

return new_cost_center
Expand Down Expand Up @@ -89,3 +88,8 @@ def after_rename(self, olddn, newdn, merge=False):

def on_doctype_update():
frappe.db.add_index("Cost Center", ["lft", "rgt"])

def get_name_with_number(new_account, account_number):
if account_number and not new_account[0].isdigit():
new_account = account_number + " - " + new_account
return new_account
57 changes: 37 additions & 20 deletions erpnext/accounts/doctype/payment_entry/payment_entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,24 @@ frappe.ui.form.on('Payment Entry', {
}
}
});

frm.set_query("party_type", function() {
return{
"filters": {
"name": ["in", Object.keys(frappe.boot.party_account_types)],
}
}
});

frm.set_query("contact_person", function() {
if (frm.doc.party) {
return {
query: 'frappe.contacts.doctype.contact.contact.contact_query',
filters: {
link_doctype: frm.doc.party_type,
link_name: frm.doc.party
}
};
}
});
frm.set_query("paid_to", function() {
var account_types = in_list(["Receive", "Internal Transfer"], frm.doc.payment_type) ?
["Bank", "Cash"] : [frappe.boot.party_account_types[frm.doc.party_type]];
Expand Down Expand Up @@ -114,6 +123,11 @@ frappe.ui.form.on('Payment Entry', {
frm.events.set_dynamic_labels(frm);
},

contact_person: function(frm) {
frm.set_value("contact_email", "");
erpnext.utils.get_contact_details(frm);
},

hide_unhide_fields: function(frm) {
var company_currency = frm.doc.company? frappe.get_doc(":Company", frm.doc.company).default_currency: "";

Expand Down Expand Up @@ -146,7 +160,7 @@ frappe.ui.form.on('Payment Entry', {
frm.toggle_display("set_exchange_gain_loss",
(frm.doc.paid_amount && frm.doc.received_amount && frm.doc.difference_amount &&
((frm.doc.paid_from_account_currency != company_currency ||
frm.doc.paid_to_account_currency != company_currency) &&
frm.doc.paid_to_account_currency != company_currency) &&
frm.doc.paid_from_account_currency != frm.doc.paid_to_account_currency)));

frm.refresh_fields();
Expand Down Expand Up @@ -208,7 +222,7 @@ frappe.ui.form.on('Payment Entry', {
});
} else {
if(frm.doc.party) {
frm.events.party(frm);
frm.events.party(frm);
}

if(frm.doc.mode_of_payment) {
Expand All @@ -230,13 +244,16 @@ frappe.ui.form.on('Payment Entry', {
},

party: function(frm) {
if (frm.doc.contact_email || frm.doc.contact_person) {
frm.set_value("contact_email", "");
frm.set_value("contact_person", "");
}
if(frm.doc.payment_type && frm.doc.party_type && frm.doc.party) {
if(!frm.doc.posting_date) {
frappe.msgprint(__("Please select Posting Date before selecting Party"))
frm.set_value("party", "");
return ;
}

frm.set_party_account_based_on_party = true;

return frappe.call({
Expand Down Expand Up @@ -302,7 +319,7 @@ frappe.ui.form.on('Payment Entry', {
frm.set_value("target_exchange_rate", frm.doc.source_exchange_rate);
}
frm.set_value("received_amount", frm.doc.paid_amount);

} else {
frm.events.received_amount(frm);
}
Expand Down Expand Up @@ -350,7 +367,7 @@ frappe.ui.form.on('Payment Entry', {
]);
}
}
});
});
}
},

Expand Down Expand Up @@ -402,7 +419,7 @@ frappe.ui.form.on('Payment Entry', {
}
})
},

posting_date: function(frm) {
frm.events.paid_from_account_currency(frm);
},
Expand All @@ -415,7 +432,7 @@ frappe.ui.form.on('Payment Entry', {
frm.set_value("target_exchange_rate", frm.doc.source_exchange_rate);
frm.set_value("base_received_amount", frm.doc.base_paid_amount);
}

frm.events.set_unallocated_amount(frm);
}

Expand All @@ -425,17 +442,17 @@ frappe.ui.form.on('Payment Entry', {

target_exchange_rate: function(frm) {
frm.set_paid_amount_based_on_received_amount = true;

if (frm.doc.received_amount) {
frm.set_value("base_received_amount",
flt(frm.doc.received_amount) * flt(frm.doc.target_exchange_rate));
if(!frm.doc.source_exchange_rate &&

if(!frm.doc.source_exchange_rate &&
(frm.doc.paid_from_account_currency == frm.doc.paid_to_account_currency)) {
frm.set_value("source_exchange_rate", frm.doc.target_exchange_rate);
frm.set_value("base_paid_amount", frm.doc.base_received_amount);
}

frm.events.set_unallocated_amount(frm);
}
frm.set_paid_amount_based_on_received_amount = false;
Expand Down Expand Up @@ -468,22 +485,22 @@ frappe.ui.form.on('Payment Entry', {
frm.events.allocate_party_amount_against_ref_docs(frm, frm.doc.received_amount);
else
frm.events.set_unallocated_amount(frm);

frm.set_paid_amount_based_on_received_amount = false;
},

reset_received_amount: function(frm) {
if(!frm.set_paid_amount_based_on_received_amount &&
(frm.doc.paid_from_account_currency == frm.doc.paid_to_account_currency)) {

frm.set_value("received_amount", frm.doc.paid_amount);

if(frm.doc.source_exchange_rate) {
frm.set_value("target_exchange_rate", frm.doc.source_exchange_rate);
}
frm.set_value("base_received_amount", frm.doc.base_paid_amount);
}

if(frm.doc.payment_type == "Receive")
frm.events.allocate_party_amount_against_ref_docs(frm, frm.doc.paid_amount);
else
Expand Down Expand Up @@ -549,7 +566,7 @@ frappe.ui.form.on('Payment Entry', {
(frm.doc.payment_type=="Receive" && frm.doc.party_type=="Customer") ||
(frm.doc.payment_type=="Pay" && frm.doc.party_type=="Supplier") ||
(frm.doc.payment_type=="Pay" && frm.doc.party_type=="Employee") ||
(frm.doc.payment_type=="Receive" && frm.doc.party_type=="Student")
(frm.doc.payment_type=="Receive" && frm.doc.party_type=="Student")
) {
if(total_positive_outstanding > total_negative_outstanding)
frm.set_value("paid_amount",
Expand Down Expand Up @@ -694,7 +711,7 @@ frappe.ui.form.on('Payment Entry', {
frm.set_value("unallocated_amount", unallocated_amount);
frm.trigger("set_difference_amount");
},

set_difference_amount: function(frm) {
var difference_amount = 0;
var base_unallocated_amount = flt(frm.doc.unallocated_amount) *
Expand Down Expand Up @@ -753,7 +770,7 @@ frappe.ui.form.on('Payment Entry', {
frappe.msgprint(__("Row #{0}: Reference Document Type must be one of Purchase Order, Purchase Invoice or Journal Entry", [row.idx]));
return false;
}

if(frm.doc.party_type=="Employee" &&
!in_list(["Expense Claim", "Journal Entry"], row.reference_doctype)
) {
Expand Down
70 changes: 69 additions & 1 deletion erpnext/accounts/doctype/payment_entry/payment_entry.json
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,40 @@
"translatable": 0,
"unique": 0
},
{
"allow_bulk_edit": 0,
"allow_in_quick_entry": 0,
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"columns": 0,
"depends_on": "party",
"fieldname": "contact_person",
"fieldtype": "Link",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_global_search": 0,
"in_list_view": 0,
"in_standard_filter": 0,
"label": "Contact",
"length": 0,
"no_copy": 0,
"options": "Contact",
"permlevel": 0,
"precision": "",
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
"remember_last_selected_value": 0,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"translatable": 0,
"unique": 0
},
{
"allow_bulk_edit": 0,
"allow_in_quick_entry": 0,
Expand Down Expand Up @@ -441,6 +475,40 @@
"translatable": 0,
"unique": 0
},
{
"allow_bulk_edit": 0,
"allow_in_quick_entry": 0,
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"columns": 0,
"depends_on": "contact_person",
"fieldname": "contact_email",
"fieldtype": "Data",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_global_search": 0,
"in_list_view": 0,
"in_standard_filter": 0,
"label": "Email",
"length": 0,
"no_copy": 0,
"options": "Email",
"permlevel": 0,
"precision": "",
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 1,
"remember_last_selected_value": 0,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"translatable": 0,
"unique": 0
},
{
"allow_bulk_edit": 0,
"allow_in_quick_entry": 0,
Expand Down Expand Up @@ -1972,7 +2040,7 @@
"issingle": 0,
"istable": 0,
"max_attachments": 0,
"modified": "2018-09-11 15:44:28.647566",
"modified": "2018-09-25 14:38:48.312629",
"modified_by": "Administrator",
"module": "Accounts",
"name": "Payment Entry",
Expand Down
8 changes: 4 additions & 4 deletions erpnext/accounts/doctype/payment_entry/payment_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,12 +299,12 @@ def set_unallocated_amount(self):
if self.payment_type == "Receive" \
and self.base_total_allocated_amount < self.base_received_amount + total_deductions \
and self.total_allocated_amount < self.paid_amount + (total_deductions / self.source_exchange_rate):
self.unallocated_amount = (self.base_received_amount + total_deductions -
self.unallocated_amount = (self.base_received_amount + total_deductions -
self.base_total_allocated_amount) / self.source_exchange_rate
elif self.payment_type == "Pay" \
and self.base_total_allocated_amount < (self.base_paid_amount - total_deductions) \
and self.total_allocated_amount < self.received_amount + (total_deductions / self.target_exchange_rate):
self.unallocated_amount = (self.base_paid_amount - (total_deductions +
self.unallocated_amount = (self.base_paid_amount - (total_deductions +
self.base_total_allocated_amount)) / self.target_exchange_rate

def set_difference_amount(self):
Expand Down Expand Up @@ -790,7 +790,6 @@ def get_reference_details(reference_doctype, reference_name, party_account_curre
@frappe.whitelist()
def get_payment_entry(dt, dn, party_amount=None, bank_account=None, bank_amount=None):
doc = frappe.get_doc(dt, dn)

if dt in ("Sales Order", "Purchase Order") and flt(doc.per_billed, 2) > 0:
frappe.throw(_("Can only make payment against unbilled {0}").format(dt))

Expand Down Expand Up @@ -877,7 +876,8 @@ def get_payment_entry(dt, dn, party_amount=None, bank_account=None, bank_amount=
pe.mode_of_payment = doc.get("mode_of_payment")
pe.party_type = party_type
pe.party = doc.get(scrub(party_type))

pe.contact_person = doc.get("contact_person")
pe.contact_email = doc.get("contact_email")
pe.ensure_supplier_is_not_blocked()

pe.paid_from = party_account if payment_type=="Receive" else bank.account
Expand Down
12 changes: 12 additions & 0 deletions erpnext/accounts/doctype/pricing_rule/pricing_rule.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,18 @@ frappe.ui.form.on('Pricing Rule', {
};
},

onload: function(frm) {
if(frm.doc.__islocal && !frm.doc.applicable_for && (frm.doc.customer || frm.doc.supplier)) {
if(frm.doc.customer) {
frm.doc.applicable_for = "Customer";
frm.doc.selling = 1
} else {
frm.doc.applicable_for = "Supplier";
frm.doc.buying = 1
}
}
},

refresh: function(frm) {
var help_content =
`<table class="table table-bordered" style="background-color: #f9f9f9;">
Expand Down
10 changes: 10 additions & 0 deletions erpnext/accounts/doctype/pricing_rule/pricing_rule.py
Original file line number Diff line number Diff line change
Expand Up @@ -384,3 +384,13 @@ def set_transaction_type(args):
args.transaction_type = "selling"
else:
args.transaction_type = "buying"

@frappe.whitelist()
def make_pricing_rule(doctype, docname):
doc = frappe.new_doc("Pricing Rule")
doc.applicable_for = doctype
doc.set(frappe.scrub(doctype), docname)
doc.selling = 1 if doctype == "Customer" else 0
doc.buying = 1 if doctype == "Supplier" else 0

return doc

0 comments on commit c6eac7c

Please sign in to comment.