Merge branch 'hotfix' into hotfix-lead-import-fix

This commit is contained in:
Saurabh
2019-05-13 12:07:33 +05:30
committed by GitHub
12 changed files with 3077 additions and 2899 deletions

View File

@@ -42,15 +42,14 @@ frappe.ui.form.on('Account', {
// show / hide convert buttons // show / hide convert buttons
frm.trigger('add_toolbar_buttons'); frm.trigger('add_toolbar_buttons');
} }
frm.add_custom_button(__('Update Account Name / Number'), function () { if (frm.has_perm('write')) {
frm.trigger("update_account_number"); frm.add_custom_button(__('Update Account Name / Number'), function () {
}); frm.trigger("update_account_number");
} });
frm.add_custom_button(__('Merge Account'), function () {
if(!frm.doc.__islocal) { frm.trigger("merge_account");
frm.add_custom_button(__('Merge Account'), function () { });
frm.trigger("merge_account"); }
});
} }
}, },
account_type: function (frm) { account_type: function (frm) {

View File

@@ -268,7 +268,7 @@ def update_account_number(name, account_name, account_number=None):
new_name = get_account_autoname(account_number, account_name, account.company) new_name = get_account_autoname(account_number, account_name, account.company)
if name != new_name: if name != new_name:
frappe.rename_doc("Account", name, new_name, ignore_permissions=1) frappe.rename_doc("Account", name, new_name, force=1)
return new_name return new_name
@frappe.whitelist() @frappe.whitelist()
@@ -287,7 +287,7 @@ def merge_account(old, new, is_group, root_type, company):
frappe.db.set_value("Account", new, "parent_account", frappe.db.set_value("Account", new, "parent_account",
frappe.db.get_value("Account", old, "parent_account")) frappe.db.get_value("Account", old, "parent_account"))
frappe.rename_doc("Account", old, new, merge=1, ignore_permissions=1) frappe.rename_doc("Account", old, new, merge=1, force=1)
return new return new

View File

@@ -121,7 +121,7 @@
"bold": 0, "bold": 0,
"collapsible": 0, "collapsible": 0,
"columns": 0, "columns": 0,
"default": "Settled", "default": "Pending",
"fetch_if_empty": 0, "fetch_if_empty": 0,
"fieldname": "status", "fieldname": "status",
"fieldtype": "Select", "fieldtype": "Select",
@@ -755,7 +755,7 @@
"issingle": 0, "issingle": 0,
"istable": 0, "istable": 0,
"max_attachments": 0, "max_attachments": 0,
"modified": "2019-04-26 14:32:16.437813", "modified": "2019-05-11 05:27:55.244721",
"modified_by": "Administrator", "modified_by": "Administrator",
"module": "Accounts", "module": "Accounts",
"name": "Bank Transaction", "name": "Bank Transaction",

View File

@@ -36,6 +36,10 @@ class BankTransaction(StatusUpdater):
frappe.db.set_value(self.doctype, self.name, "allocated_amount", 0) frappe.db.set_value(self.doctype, self.name, "allocated_amount", 0)
frappe.db.set_value(self.doctype, self.name, "unallocated_amount", abs(flt(self.credit) - flt(self.debit))) frappe.db.set_value(self.doctype, self.name, "unallocated_amount", abs(flt(self.credit) - flt(self.debit)))
amount = self.debit or self.credit
if amount == self.allocated_amount:
frappe.db.set_value(self.doctype, self.name, "status", "Reconciled")
self.reload() self.reload()
def clear_linked_payment_entries(self): def clear_linked_payment_entries(self):

View File

@@ -39,7 +39,9 @@ def add_payment_to_transaction(transaction, payment_entry, gl_entry):
"payment_entry": payment_entry.name, "payment_entry": payment_entry.name,
"allocated_amount": allocated_amount "allocated_amount": allocated_amount
}) })
transaction.save() transaction.save()
transaction.update_allocations()
@frappe.whitelist() @frappe.whitelist()
def get_linked_payments(bank_transaction): def get_linked_payments(bank_transaction):
@@ -56,7 +58,11 @@ def get_linked_payments(bank_transaction):
return check_amount_vs_description(amount_matching, description_matching) return check_amount_vs_description(amount_matching, description_matching)
elif description_matching: elif description_matching:
return sorted(description_matching, key = lambda x: x["posting_date"], reverse=True) description_matching = filter(lambda x: not x.get('clearance_date'), description_matching)
if not description_matching:
return []
return sorted(list(description_matching), key = lambda x: x["posting_date"], reverse=True)
else: else:
return [] return []
@@ -97,7 +103,8 @@ def check_matching_amount(bank_account, company, transaction):
journal_entries = frappe.db.sql(""" journal_entries = frappe.db.sql("""
SELECT SELECT
'Journal Entry' as doctype, je.name, je.posting_date, je.cheque_no as reference_no, 'Journal Entry' as doctype, je.name, je.posting_date, je.cheque_no as reference_no,
je.pay_to_recd_from as party, je.cheque_date as reference_date, jea.credit_in_account_currency as paid_amount jea.account_currency as currency, je.pay_to_recd_from as party, je.cheque_date as reference_date,
jea.credit_in_account_currency as paid_amount
FROM FROM
`tabJournal Entry Account` as jea `tabJournal Entry Account` as jea
JOIN JOIN
@@ -107,12 +114,17 @@ def check_matching_amount(bank_account, company, transaction):
WHERE WHERE
(je.clearance_date is null or je.clearance_date='0000-00-00') (je.clearance_date is null or je.clearance_date='0000-00-00')
AND AND
jea.account = %s jea.account = %(bank_account)s
AND AND
jea.credit_in_account_currency like %s jea.credit_in_account_currency like %(txt)s
AND AND
je.docstatus = 1 je.docstatus = 1
""", (bank_account, amount), as_dict=True) """, {
'bank_account': bank_account,
'txt': '%%%s%%' % amount
}, as_dict=True, debug=1)
frappe.errprint(journal_entries)
if transaction.credit > 0: if transaction.credit > 0:
sales_invoices = frappe.db.sql(""" sales_invoices = frappe.db.sql("""
@@ -213,9 +225,14 @@ def get_matching_descriptions_data(company, transaction):
company_currency = get_company_currency(company) company_currency = get_company_currency(company)
for key, value in iteritems(links): for key, value in iteritems(links):
if key == "Payment Entry": if key == "Payment Entry":
data.extend(frappe.get_all("Payment Entry", filters=[["name", "in", value]], fields=["'Payment Entry' as doctype", "posting_date", "party", "reference_no", "reference_date", "paid_amount", "paid_to_account_currency as currency"])) data.extend(frappe.get_all("Payment Entry", filters=[["name", "in", value]],
fields=["'Payment Entry' as doctype", "posting_date", "party", "reference_no",
"reference_date", "paid_amount", "paid_to_account_currency as currency", "clearance_date"]))
if key == "Journal Entry": if key == "Journal Entry":
journal_entries = frappe.get_all("Journal Entry", filters=[["name", "in", value]], fields=["name", "'Journal Entry' as doctype", "posting_date", "pay_to_recd_from as party", "cheque_no as reference_no", "cheque_date as reference_date", "total_credit as paid_amount"]) journal_entries = frappe.get_all("Journal Entry", filters=[["name", "in", value]],
fields=["name", "'Journal Entry' as doctype", "posting_date",
"pay_to_recd_from as party", "cheque_no as reference_no", "cheque_date as reference_date",
"total_credit as paid_amount", "clearance_date"])
for journal_entry in journal_entries: for journal_entry in journal_entries:
journal_entry_accounts = frappe.get_all("Journal Entry Account", filters={"parenttype": journal_entry["doctype"], "parent": journal_entry["name"]}, fields=["account_currency"]) journal_entry_accounts = frappe.get_all("Journal Entry Account", filters={"parenttype": journal_entry["doctype"], "parent": journal_entry["name"]}, fields=["account_currency"])
journal_entry["currency"] = journal_entry_accounts[0]["account_currency"] if journal_entry_accounts else company_currency journal_entry["currency"] = journal_entry_accounts[0]["account_currency"] if journal_entry_accounts else company_currency
@@ -236,6 +253,9 @@ def check_amount_vs_description(amount_matching, description_matching):
if description_matching: if description_matching:
for am_match in amount_matching: for am_match in amount_matching:
for des_match in description_matching: for des_match in description_matching:
if des_match.get("clearance_date"):
continue
if am_match["party"] == des_match["party"]: if am_match["party"] == des_match["party"]:
if am_match not in result: if am_match not in result:
result.append(am_match) result.append(am_match)

View File

@@ -4,6 +4,12 @@
frappe.query_reports["Inactive Sales Items"] = { frappe.query_reports["Inactive Sales Items"] = {
"filters": [ "filters": [
{
fieldname: "territory",
label: __("Territory"),
fieldtype: "Link",
options: "Territory"
},
{ {
fieldname: "item", fieldname: "item",
label: __("Item"), label: __("Item"),

View File

@@ -7,13 +7,11 @@ from frappe.utils import getdate, add_days, today, cint
from frappe import _ from frappe import _
def execute(filters=None): def execute(filters=None):
columns = get_columns() columns = get_columns()
data = get_data(filters) data = get_data(filters)
return columns, data return columns, data
def get_columns(): def get_columns():
columns = [ columns = [
{ {
"fieldname": "territory", "fieldname": "territory",
@@ -74,36 +72,37 @@ def get_columns():
def get_data(filters): def get_data(filters):
data = [] data = []
items = get_items(filters) items = get_items(filters)
territories = get_territories(filters)
sales_invoice_data = get_sales_details(filters) sales_invoice_data = get_sales_details(filters)
for item in items: for territory in territories:
row = { for item in items:
row = {
"territory": territory.name,
"item_group": item.item_group, "item_group": item.item_group,
"item": item.name, "item": item.name,
"item_name": item.item_name "item_name": item.item_name
} }
if sales_invoice_data.get(item.name): if sales_invoice_data.get((territory.name,item.name)):
item_obj = sales_invoice_data[item.name] item_obj = sales_invoice_data[(territory.name,item.name)]
if item_obj.days_since_last_order > cint(filters['days']): if item_obj.days_since_last_order > cint(filters['days']):
row.update({ row.update({
"territory": item_obj.territory, "territory": item_obj.territory,
"customer": item_obj.customer, "customer": item_obj.customer,
"last_order_date": item_obj.last_order_date, "last_order_date": item_obj.last_order_date,
"qty": item_obj.qty, "qty": item_obj.qty,
"days_since_last_order": item_obj.days_since_last_order "days_since_last_order": item_obj.days_since_last_order
}) })
data.append(row) data.append(row)
return data return data
def get_sales_details(filters): def get_sales_details(filters):
data = [] data = []
item_details_map = {} item_details_map = {}
@@ -118,12 +117,21 @@ def get_sales_details(filters):
.format(date_field = date_field, doctype = filters['based_on']), as_dict=1) .format(date_field = date_field, doctype = filters['based_on']), as_dict=1)
for d in sales_data: for d in sales_data:
item_details_map.setdefault(d.item_name, d) item_details_map.setdefault((d.territory,d.item_name), d)
return item_details_map return item_details_map
def get_items(filters): def get_territories(filters):
filter_dict = {}
if filters.get("territory"):
filter_dict.update({'name': filters['territory']})
territories = frappe.get_all("Territory", fields=["name"], filters=filter_dict)
return territories
def get_items(filters):
filters_dict = { filters_dict = {
"disabled": 0, "disabled": 0,
"is_stock_item": 1 "is_stock_item": 1

View File

@@ -167,7 +167,7 @@ def make_quotation(source_name, target_doc=None):
{"Lead": { {"Lead": {
"doctype": "Quotation", "doctype": "Quotation",
"field_map": { "field_map": {
"name": "lead" "name": "party_name"
} }
}}, target_doc) }}, target_doc)
target_doc.quotation_to = "Lead" target_doc.quotation_to = "Lead"

View File

@@ -598,4 +598,5 @@ erpnext.patches.v11_1.set_salary_details_submittable
erpnext.patches.v11_1.rename_depends_on_lwp erpnext.patches.v11_1.rename_depends_on_lwp
erpnext.patches.v11_1.set_missing_title_for_quotation erpnext.patches.v11_1.set_missing_title_for_quotation
execute:frappe.delete_doc("Report", "Inactive Items") execute:frappe.delete_doc("Report", "Inactive Items")
erpnext.patches.v11_1.delete_scheduling_tool erpnext.patches.v11_1.delete_scheduling_tool
erpnext.patches.v11_1.update_bank_transaction_status

View File

@@ -0,0 +1,15 @@
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
# License: GNU General Public License v3. See license.txt
from __future__ import unicode_literals
import frappe
def execute():
frappe.reload_doc("accounts", "doctype", "bank_transaction")
frappe.db.sql(""" UPDATE `tabBank Transaction`
SET status = 'Reconciled'
WHERE
status = 'Settled' and (debit = allocated_amount or credit = allocated_amount)
and ifnull(allocated_amount, 0) > 0
""")

File diff suppressed because it is too large Load Diff

View File

@@ -3,7 +3,7 @@
from __future__ import unicode_literals from __future__ import unicode_literals
import frappe, erpnext import frappe, erpnext
from frappe.utils import cint from frappe.utils import cint, nowdate
from frappe import throw, _ from frappe import throw, _
from frappe.utils.nestedset import NestedSet from frappe.utils.nestedset import NestedSet
from erpnext.stock import get_warehouse_account from erpnext.stock import get_warehouse_account
@@ -140,7 +140,7 @@ class Warehouse(NestedSet):
@frappe.whitelist() @frappe.whitelist()
def get_children(doctype, parent=None, company=None, is_root=False): def get_children(doctype, parent=None, company=None, is_root=False):
from erpnext.stock.utils import get_stock_value_from_bin from erpnext.stock.utils import get_stock_value_on
if is_root: if is_root:
parent = "" parent = ""
@@ -156,7 +156,7 @@ def get_children(doctype, parent=None, company=None, is_root=False):
# return warehouses # return warehouses
for wh in warehouses: for wh in warehouses:
wh["balance"] = get_stock_value_from_bin(warehouse=wh.value) wh["balance"] = get_stock_value_on(warehouse=wh.value, posting_date=nowdate())
if company: if company:
wh["company_currency"] = frappe.db.get_value('Company', company, 'default_currency') wh["company_currency"] = frappe.db.get_value('Company', company, 'default_currency')
return warehouses return warehouses