Merge pull request #14076 from chdecultot/pricing_rule
Missing parentheses in price list rate determination
diff --git a/erpnext/__init__.py b/erpnext/__init__.py
index a20b21a..3eaf994 100644
--- a/erpnext/__init__.py
+++ b/erpnext/__init__.py
@@ -5,7 +5,7 @@
from erpnext.hooks import regional_overrides
from frappe.utils import getdate
-__version__ = '10.1.31'
+__version__ = '10.1.33'
def get_default_company(user=None):
'''Get default company for user'''
diff --git a/erpnext/controllers/taxes_and_totals.py b/erpnext/controllers/taxes_and_totals.py
index e968e61..a4d9dae 100644
--- a/erpnext/controllers/taxes_and_totals.py
+++ b/erpnext/controllers/taxes_and_totals.py
@@ -558,7 +558,8 @@
itemised_tax=itemised_tax,
itemised_taxable_amount=itemised_taxable_amount,
tax_accounts=tax_accounts,
- company_currency=erpnext.get_company_currency(doc.company)
+ conversion_rate=doc.conversion_rate,
+ currency=doc.currency
)
)
diff --git a/erpnext/hr/doctype/attendance/attendance.py b/erpnext/hr/doctype/attendance/attendance.py
index 458b2dd..d1809c6 100644
--- a/erpnext/hr/doctype/attendance/attendance.py
+++ b/erpnext/hr/doctype/attendance/attendance.py
@@ -20,17 +20,19 @@
set_employee_name(self)
def check_leave_record(self):
- leave_record = frappe.db.sql("""select leave_type, half_day from `tabLeave Application`
+ leave_record = frappe.db.sql("""select leave_type, half_day, half_day_date from `tabLeave Application`
where employee = %s and %s between from_date and to_date and status = 'Approved'
and docstatus = 1""", (self.employee, self.attendance_date), as_dict=True)
if leave_record:
- if leave_record[0].half_day:
- self.status = 'Half Day'
- frappe.msgprint(_("Employee {0} on Half day on {1}").format(self.employee, self.attendance_date))
- else:
- self.status = 'On Leave'
- self.leave_type = leave_record[0].leave_type
- frappe.msgprint(_("Employee {0} on Leave on {1}").format(self.employee, self.attendance_date))
+ for d in leave_record:
+ if d.half_day_date == getdate(self.attendance_date):
+ self.status = 'Half Day'
+ frappe.msgprint(_("Employee {0} on Half day on {1}").format(self.employee, self.attendance_date))
+ else:
+ self.status = 'On Leave'
+ self.leave_type = d.leave_type
+ frappe.msgprint(_("Employee {0} on Leave on {1}").format(self.employee, self.attendance_date))
+
if self.status == "On Leave" and not leave_record:
frappe.throw(_("No leave record found for employee {0} for {1}").format(self.employee, self.attendance_date))
diff --git a/erpnext/hr/doctype/leave_application/leave_application.js b/erpnext/hr/doctype/leave_application/leave_application.js
index 2eb155d..06eee61 100755
--- a/erpnext/hr/doctype/leave_application/leave_application.js
+++ b/erpnext/hr/doctype/leave_application/leave_application.js
@@ -95,6 +95,9 @@
if (!r.exc && r.message) {
frm.set_value('leave_balance', r.message);
}
+ else {
+ frm.set_value('leave_balance', "0");
+ }
}
});
}
diff --git a/erpnext/hr/doctype/leave_application/leave_application.py b/erpnext/hr/doctype/leave_application/leave_application.py
index 8d19510..4e1b54b 100755
--- a/erpnext/hr/doctype/leave_application/leave_application.py
+++ b/erpnext/hr/doctype/leave_application/leave_application.py
@@ -5,12 +5,12 @@
import frappe
from frappe import _
from frappe.utils import cint, cstr, date_diff, flt, formatdate, getdate, get_link_to_form, \
- comma_or, get_fullname
+ comma_or, get_fullname, nowdate
from erpnext.hr.utils import set_employee_name
from erpnext.hr.doctype.leave_block_list.leave_block_list import get_applicable_block_dates
from erpnext.hr.doctype.employee.employee import get_holiday_list_for_employee
from erpnext.hr.doctype.employee_leave_approver.employee_leave_approver import get_approver_list
-
+from erpnext.buying.doctype.supplier_scorecard.supplier_scorecard import daterange
class LeaveDayBlockedError(frappe.ValidationError): pass
class OverlapError(frappe.ValidationError): pass
@@ -52,6 +52,7 @@
frappe.throw(_("Only Leave Applications with status 'Approved' and 'Rejected' can be submitted"))
self.validate_back_dated_application()
+ self.update_attendance()
# notify leave applier about approval
self.notify_employee(self.status)
@@ -100,6 +101,41 @@
frappe.throw(_("Leave cannot be applied/cancelled before {0}, as leave balance has already been carry-forwarded in the future leave allocation record {1}")
.format(formatdate(future_allocation[0].from_date), future_allocation[0].name))
+ def update_attendance(self):
+ if self.status == "Approved":
+ attendance = frappe.db.sql("""select name from `tabAttendance` where employee = %s\
+ and (attendance_date between %s and %s) and docstatus < 2""",(self.employee, self.from_date, self.to_date), as_dict=1)
+
+ if attendance:
+ for d in attendance:
+ doc = frappe.get_doc("Attendance", d.name)
+ if getdate(self.half_day_date) == doc.attendance_date:
+ status = "Half Day"
+ else:
+ status = "On Leave"
+ frappe.db.sql("""update `tabAttendance` set status = %s, leave_type = %s\
+ where name = %s""",(status, self.leave_type, d.name))
+
+ elif self.from_date <= nowdate():
+ for dt in daterange(getdate(self.from_date), getdate(self.to_date)):
+ date = dt.strftime("%Y-%m-%d")
+ if not date == self.half_day_date:
+ doc = frappe.new_doc("Attendance")
+ doc.employee = self.employee
+ doc.attendance_date = date
+ doc.company = self.company
+ doc.status = "On Leave"
+ doc.leave_type = self.leave_type
+ doc.submit()
+ else:
+ doc = frappe.new_doc("Attendance")
+ doc.employee = self.employee
+ doc.attendance_date = date
+ doc.company = self.company
+ doc.status = "Half Day"
+ doc.leave_type = self.leave_type
+ doc.submit()
+
def validate_salary_processed_days(self):
if not frappe.db.get_value("Leave Type", self.leave_type, "is_lwp"):
return
@@ -436,30 +472,17 @@
and company=%s""", (department, company))
match_conditions = "and employee in (\"%s\")" % '", "'.join(department_employees)
- add_leaves(events, start, end, filter_conditions=match_conditions)
+ add_leaves(events, start, end, match_conditions=match_conditions)
-def add_leaves(events, start, end, filter_conditions=None):
- conditions = []
-
- if filter_conditions:
- conditions.append(filter_conditions)
-
- if not cint(frappe.db.get_value("HR Settings", None, "show_leaves_of_all_department_members_in_calendar")):
- from frappe.desk.reportview import build_match_conditions
- match_conditions = build_match_conditions("Leave Application")
-
- if match_conditions:
- conditions.append(match_conditions)
-
+def add_leaves(events, start, end, match_conditions=None):
query = """select name, from_date, to_date, employee_name, half_day,
status, employee, docstatus
from `tabLeave Application` where
from_date <= %(end)s and to_date >= %(start)s <= to_date
and docstatus < 2
and status!="Rejected" """
-
- if conditions:
- query += ' and '.join(conditions)
+ if match_conditions:
+ query += match_conditions
for d in frappe.db.sql(query, {"start":start, "end": end}, as_dict=True):
e = {
diff --git a/erpnext/hr/report/monthly_attendance_sheet/monthly_attendance_sheet.py b/erpnext/hr/report/monthly_attendance_sheet/monthly_attendance_sheet.py
index 698c4fb..0c338e0 100644
--- a/erpnext/hr/report/monthly_attendance_sheet/monthly_attendance_sheet.py
+++ b/erpnext/hr/report/monthly_attendance_sheet/monthly_attendance_sheet.py
@@ -22,6 +22,10 @@
holiday_map = get_holiday(holiday_list, filters["month"])
data = []
+ leave_types = frappe.db.sql("""select name from `tabLeave Type`""", as_list=True)
+ leave_list = [d[0] for d in leave_types]
+ columns.extend(leave_list)
+
for emp in sorted(att_map):
emp_det = emp_map.get(emp)
if not emp_det:
@@ -49,10 +53,35 @@
elif status == "Half Day":
total_p += 0.5
total_a += 0.5
+ total_l += 0.5
row += [total_p, total_l, total_a]
- data.append(row)
+ if not filters.get("employee"):
+ filters.update({"employee": emp})
+ conditions += " and employee = %(employee)s"
+ elif not filters.get("employee") == emp:
+ filters.update({"employee": emp})
+
+ leave_details = frappe.db.sql("""select leave_type, status, count(*) as count from `tabAttendance`\
+ where leave_type is not NULL %s group by leave_type, status""" % conditions, filters, as_dict=1)
+
+ leaves = {}
+ for d in leave_details:
+ if d.status == "Half Day":
+ d.count = d.count * 0.5
+ if d.leave_type in leaves:
+ leaves[d.leave_type] += d.count
+ else:
+ leaves[d.leave_type] = d.count
+
+ for d in leave_list:
+ if d in leaves:
+ row.append(leaves[d])
+ else:
+ row.append("0.0")
+
+ data.append(row)
return columns, data
def get_columns(filters):
diff --git a/erpnext/patches/v10_0/set_qty_in_transactions_based_on_serial_no_input.py b/erpnext/patches/v10_0/set_qty_in_transactions_based_on_serial_no_input.py
index 5dbcb1d..083b7f4 100644
--- a/erpnext/patches/v10_0/set_qty_in_transactions_based_on_serial_no_input.py
+++ b/erpnext/patches/v10_0/set_qty_in_transactions_based_on_serial_no_input.py
@@ -9,4 +9,13 @@
ss = frappe.get_doc("Stock Settings")
ss.set_qty_in_transactions_based_on_serial_no_input = 1
+
+ if ss.default_warehouse \
+ and not frappe.db.exists("Warehouse", ss.default_warehouse):
+ ss.default_warehouse = None
+
+ if ss.stock_uom and not frappe.db.exists("UOM", ss.stock_uom):
+ ss.stock_uom = None
+
+ ss.flags.ignore_mandatory = True
ss.save()
\ No newline at end of file
diff --git a/erpnext/projects/doctype/project/project.py b/erpnext/projects/doctype/project/project.py
index 979c4fc..44b0c00 100644
--- a/erpnext/projects/doctype/project/project.py
+++ b/erpnext/projects/doctype/project/project.py
@@ -75,7 +75,7 @@
sum = 0
for task in self.tasks:
if task.task_weight > 0:
- sum = sum + task.task_weight
+ sum = flt(sum + task.task_weight, task.precision('task_weight'))
if sum > 0 and sum != 1:
frappe.throw(_("Total of all task weights should be 1. Please adjust weights of all Project tasks accordingly"))
diff --git a/erpnext/public/js/controllers/transaction.js b/erpnext/public/js/controllers/transaction.js
index 4ab413b..d9bd50c 100644
--- a/erpnext/public/js/controllers/transaction.js
+++ b/erpnext/public/js/controllers/transaction.js
@@ -106,7 +106,7 @@
}
if(
- this.frm.docstatus < 2
+ this.frm.docstatus < 2
&& this.frm.fields_dict["payment_terms_template"]
&& this.frm.fields_dict["payment_schedule"]
&& this.frm.doc.payment_terms_template
@@ -1094,6 +1094,8 @@
me.in_apply_price_list = false;
}
}
+ }).always(() => {
+ me.in_apply_price_list = false;
});
},
diff --git a/erpnext/selling/doctype/customer/customer.py b/erpnext/selling/doctype/customer/customer.py
index 0ea1119..7232fad 100644
--- a/erpnext/selling/doctype/customer/customer.py
+++ b/erpnext/selling/doctype/customer/customer.py
@@ -316,7 +316,7 @@
return address
def get_customer_primary_contact(doctype, txt, searchfield, start, page_len, filters):
- customer = frappe.db.escape(filters.get('customer'))
+ customer = filters.get('customer')
return frappe.db.sql("""
select `tabContact`.name from `tabContact`, `tabDynamic Link`
where `tabContact`.name = `tabDynamic Link`.parent and `tabDynamic Link`.link_name = %(customer)s
diff --git a/erpnext/selling/report/sales_person_target_variance_item_group_wise/sales_person_target_variance_item_group_wise.py b/erpnext/selling/report/sales_person_target_variance_item_group_wise/sales_person_target_variance_item_group_wise.py
index e57636c..e7bb5b4 100644
--- a/erpnext/selling/report/sales_person_target_variance_item_group_wise/sales_person_target_variance_item_group_wise.py
+++ b/erpnext/selling/report/sales_person_target_variance_item_group_wise/sales_person_target_variance_item_group_wise.py
@@ -91,17 +91,22 @@
start_date, end_date = get_fiscal_year(fiscal_year = filters["fiscal_year"])[1:]
item_details = frappe.db.sql("""
- select
- sum(soi.stock_qty * (st.allocated_percentage/100)) as qty,
- sum(soi.base_net_amount * (st.allocated_percentage/100)) as amount,
- st.sales_person, MONTHNAME(so.transaction_date) as month_name
+ SELECT st.sales_person, MONTHNAME(so.transaction_date) as month_name,
+ CASE
+ WHEN so.status = "Closed" THEN sum(soi.delivered_qty * soi.conversion_factor * (st.allocated_percentage/100))
+ ELSE sum(soi.stock_qty * (st.allocated_percentage/100))
+ END as qty,
+ CASE
+ WHEN so.status = "Closed" THEN sum(soi.delivered_qty * soi.conversion_factor * soi.base_net_rate * (st.allocated_percentage/100))
+ ELSE soi.base_net_amount * (st.allocated_percentage/100))
+ END as amount
from
`tabSales Order Item` soi, `tabSales Order` so, `tabSales Team` st
where
soi.parent=so.name and so.docstatus=1 and st.parent=so.name
and so.transaction_date>=%s and so.transaction_date<=%s
- and exists(select name from `tabSales Person` where lft >= %s and rgt <= %s and name=st.sales_person)
- and exists(select name from `tabItem Group` where lft >= %s and rgt <= %s and name=soi.item_group)
+ and exists(SELECT name from `tabSales Person` where lft >= %s and rgt <= %s and name=st.sales_person)
+ and exists(SELECT name from `tabItem Group` where lft >= %s and rgt <= %s and name=soi.item_group)
group by
sales_person, month_name
""",
diff --git a/erpnext/selling/report/sales_person_wise_transaction_summary/sales_person_wise_transaction_summary.py b/erpnext/selling/report/sales_person_wise_transaction_summary/sales_person_wise_transaction_summary.py
index 025e740..19b6774 100644
--- a/erpnext/selling/report/sales_person_wise_transaction_summary/sales_person_wise_transaction_summary.py
+++ b/erpnext/selling/report/sales_person_wise_transaction_summary/sales_person_wise_transaction_summary.py
@@ -15,11 +15,12 @@
data = []
for d in entries:
- data.append([
- d.name, d.customer, d.territory, d.posting_date, d.item_code,
- item_details.get(d.item_code, {}).get("item_group"), item_details.get(d.item_code, {}).get("brand"),
- d.stock_qty, d.base_net_amount, d.sales_person, d.allocated_percentage, d.contribution_amt
- ])
+ if d.stock_qty > 0:
+ data.append([
+ d.name, d.customer, d.territory, d.posting_date, d.item_code,
+ item_details.get(d.item_code, {}).get("item_group"), item_details.get(d.item_code, {}).get("brand"),
+ d.stock_qty, d.base_net_amount, d.sales_person, d.allocated_percentage, d.contribution_amt
+ ])
if data:
total_row = [""]*len(data[0])
@@ -40,18 +41,34 @@
def get_entries(filters):
date_field = filters["doc_type"] == "Sales Order" and "transaction_date" or "posting_date"
+ if filters["doc_type"] == "Sales Order":
+ qty_field = "delivered_qty"
+ else:
+ qty_field = "qty"
conditions, values = get_conditions(filters, date_field)
+
entries = frappe.db.sql("""
select
dt.name, dt.customer, dt.territory, dt.%s as posting_date, dt_item.item_code,
- dt_item.stock_qty, dt_item.base_net_amount, st.sales_person, st.allocated_percentage,
- dt_item.base_net_amount*st.allocated_percentage/100 as contribution_amt
+ st.sales_person, st.allocated_percentage,
+ CASE
+ WHEN dt.status = "Closed" THEN dt_item.%s * dt_item.conversion_factor
+ ELSE dt_item.stock_qty
+ END as stock_qty,
+ CASE
+ WHEN dt.status = "Closed" THEN (dt_item.base_net_rate * dt_item.%s * dt_item.conversion_factor)
+ ELSE dt_item.base_net_amount
+ END as base_net_amount,
+ CASE
+ WHEN dt.status = "Closed" THEN ((dt_item.base_net_rate * dt_item.%s * dt_item.conversion_factor) * st.allocated_percentage/100)
+ ELSE dt_item.base_net_amount * st.allocated_percentage/100
+ END as contribution_amt
from
`tab%s` dt, `tab%s Item` dt_item, `tabSales Team` st
where
st.parent = dt.name and dt.name = dt_item.parent and st.parenttype = %s
and dt.docstatus = 1 %s order by st.sales_person, dt.name desc
- """ %(date_field, filters["doc_type"], filters["doc_type"], '%s', conditions),
+ """ %(date_field, qty_field, qty_field, qty_field, filters["doc_type"], filters["doc_type"], '%s', conditions),
tuple([filters["doc_type"]] + values), as_dict=1)
return entries
diff --git a/erpnext/stock/doctype/material_request/material_request.py b/erpnext/stock/doctype/material_request/material_request.py
index 8f0a25d..f58b40e 100644
--- a/erpnext/stock/doctype/material_request/material_request.py
+++ b/erpnext/stock/doctype/material_request/material_request.py
@@ -417,6 +417,7 @@
prod_order.material_request_item = d.name
prod_order.planned_start_date = mr.transaction_date
prod_order.company = mr.company
+ prod_order.set_production_order_operations()
prod_order.save()
production_orders.append(prod_order.name)
else:
diff --git a/erpnext/support/doctype/issue/issue.json b/erpnext/support/doctype/issue/issue.json
index d2ec7c3..923a79c 100644
--- a/erpnext/support/doctype/issue/issue.json
+++ b/erpnext/support/doctype/issue/issue.json
@@ -926,6 +926,37 @@
"set_only_once": 0,
"translatable": 0,
"unique": 0
+ },
+ {
+ "allow_bulk_edit": 0,
+ "allow_on_submit": 0,
+ "bold": 0,
+ "collapsible": 0,
+ "columns": 0,
+ "fieldname": "via_customer_portal",
+ "fieldtype": "Check",
+ "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": "Via Customer Portal",
+ "length": 0,
+ "no_copy": 0,
+ "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
}
],
"has_web_view": 0,
@@ -939,7 +970,7 @@
"issingle": 0,
"istable": 0,
"max_attachments": 0,
- "modified": "2018-04-13 13:03:14.748090",
+ "modified": "2018-05-07 05:53:20.684275",
"modified_by": "Administrator",
"module": "Support",
"name": "Issue",
diff --git a/erpnext/support/doctype/issue/issue.py b/erpnext/support/doctype/issue/issue.py
index 6a18f11..dfcc2a8 100644
--- a/erpnext/support/doctype/issue/issue.py
+++ b/erpnext/support/doctype/issue/issue.py
@@ -17,6 +17,8 @@
return "{0}: {1}".format(_(self.status), self.subject)
def validate(self):
+ if (self.get("__islocal") and self.via_customer_portal):
+ self.flags.create_communication = True
if not self.raised_by:
self.raised_by = frappe.session.user
self.update_status()
@@ -26,6 +28,12 @@
from frappe.desk.form.assign_to import clear
clear(self.doctype, self.name)
+ def on_update(self):
+ # create the communication email and remove the description
+ if (self.flags.create_communication and self.via_customer_portal):
+ self.create_communication()
+ self.flags.communication_created = None
+
def set_lead_contact(self, email_id):
import email.utils
email_id = email.utils.parseaddr(email_id)[1]
@@ -53,6 +61,26 @@
# if no date, it should be set as None and not a blank string "", as per mysql strict config
self.resolution_date = None
+ def create_communication(self):
+ communication = frappe.new_doc("Communication")
+ communication.update({
+ "communication_type": "Communication",
+ "communication_medium": "Email",
+ "sent_or_received": "Received",
+ "email_status": "Open",
+ "subject": self.subject,
+ "sender": self.raised_by,
+ "content": self.description,
+ "status": "Linked",
+ "reference_doctype": "Issue",
+ "reference_name": self.name
+ })
+ communication.ignore_permissions = True
+ communication.ignore_mandatory = True
+ communication.save()
+
+ self.db_set("description", "")
+
def get_list_context(context=None):
return {
"title": _("Issues"),
diff --git a/erpnext/support/web_form/issues/issues.json b/erpnext/support/web_form/issues/issues.json
index 264b9df..a8c7ab9 100644
--- a/erpnext/support/web_form/issues/issues.json
+++ b/erpnext/support/web_form/issues/issues.json
@@ -18,7 +18,7 @@
"is_standard": 1,
"login_required": 1,
"max_attachment_size": 0,
- "modified": "2017-07-25 22:49:10.762704",
+ "modified": "2018-05-07 05:54:22.213127",
"modified_by": "Administrator",
"module": "Support",
"name": "issues",
@@ -83,6 +83,17 @@
"max_value": 0,
"read_only": 0,
"reqd": 0
+ },
+ {
+ "default": "1",
+ "fieldname": "via_customer_portal",
+ "fieldtype": "Check",
+ "hidden": 1,
+ "label": "Via Customer Portal",
+ "max_length": 0,
+ "max_value": 0,
+ "read_only": 1,
+ "reqd": 0
}
]
}
\ No newline at end of file
diff --git a/erpnext/support/web_form/issues/issues.py b/erpnext/support/web_form/issues/issues.py
index 2334f8b..bb9197a 100644
--- a/erpnext/support/web_form/issues/issues.py
+++ b/erpnext/support/web_form/issues/issues.py
@@ -4,4 +4,5 @@
def get_context(context):
# do your magic here
- pass
+ if context.doc:
+ context.read_only = 1
\ No newline at end of file
diff --git a/erpnext/templates/includes/itemised_tax_breakup.html b/erpnext/templates/includes/itemised_tax_breakup.html
index 4162b3a..982397e 100644
--- a/erpnext/templates/includes/itemised_tax_breakup.html
+++ b/erpnext/templates/includes/itemised_tax_breakup.html
@@ -16,16 +16,16 @@
<tr>
<td>{{ item }}</td>
<td class='text-right'>
- {{ frappe.utils.fmt_money(itemised_taxable_amount.get(item), None, company_currency) }}
+ {{ frappe.utils.fmt_money(itemised_taxable_amount.get(item), None, currency) }}
</td>
{% for tax_account in tax_accounts %}
{% set tax_details = taxes.get(tax_account) %}
{% if tax_details %}
<td class='text-right'>
{% if tax_details.tax_rate or not tax_details.tax_amount %}
- ({{ tax_details.tax_rate }}%)
+ ({{ tax_details.tax_rate }}%)
{% endif %}
- {{ frappe.utils.fmt_money(tax_details.tax_amount, None, company_currency) }}
+ {{ frappe.utils.fmt_money(tax_details.tax_amount / conversion_rate, None, currency) }}
</td>
{% else %}
<td></td>