Merge branch 'develop' into fix-#23231

This commit is contained in:
Saqib Ansari 2022-03-09 11:08:45 +05:30 committed by GitHub
commit e6666609e3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 89 additions and 60 deletions

View File

@ -68,6 +68,28 @@ frappe.ui.form.on('Asset Repair', {
});
frappe.ui.form.on('Asset Repair Consumed Item', {
item_code: function(frm, cdt, cdn) {
var item = locals[cdt][cdn];
let item_args = {
'item_code': item.item_code,
'warehouse': frm.doc.warehouse,
'qty': item.consumed_quantity,
'serial_no': item.serial_no,
'company': frm.doc.company
};
frappe.call({
method: 'erpnext.stock.utils.get_incoming_rate',
args: {
args: item_args
},
callback: function(r) {
frappe.model.set_value(cdt, cdn, 'valuation_rate', r.message);
}
});
},
consumed_quantity: function(frm, cdt, cdn) {
var row = locals[cdt][cdn];
frappe.model.set_value(cdt, cdn, 'total_value', row.consumed_quantity * row.valuation_rate);

View File

@ -13,12 +13,10 @@
],
"fields": [
{
"fetch_from": "item.valuation_rate",
"fieldname": "valuation_rate",
"fieldtype": "Currency",
"in_list_view": 1,
"label": "Valuation Rate",
"read_only": 1
"label": "Valuation Rate"
},
{
"fieldname": "consumed_quantity",
@ -49,7 +47,7 @@
"index_web_pages_for_search": 1,
"istable": 1,
"links": [],
"modified": "2021-11-11 18:23:00.492483",
"modified": "2022-02-08 17:37:20.028290",
"modified_by": "Administrator",
"module": "Assets",
"name": "Asset Repair Consumed Item",

View File

@ -1,10 +1,9 @@
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors and Contributors
# See license.txt
import unittest
import frappe
from frappe.utils import add_days, get_first_day, getdate, nowdate
from frappe.tests.utils import FrappeTestCase
from frappe.utils import add_days, get_first_day, getdate, now_datetime, nowdate
from erpnext.hr.doctype.attendance.attendance import (
get_month_map,
@ -16,7 +15,7 @@ from erpnext.hr.doctype.leave_application.test_leave_application import get_firs
test_records = frappe.get_test_records('Attendance')
class TestAttendance(unittest.TestCase):
class TestAttendance(FrappeTestCase):
def test_mark_absent(self):
employee = make_employee("test_mark_absent@example.com")
date = nowdate()
@ -74,12 +73,14 @@ class TestAttendance(unittest.TestCase):
self.assertNotIn(first_sunday, unmarked_days)
def test_unmarked_days_as_per_joining_and_relieving_dates(self):
first_day = get_first_day(getdate())
now = now_datetime()
previous_month = now.month - 1
first_day = now.replace(day=1).replace(month=previous_month).date()
doj = add_days(first_day, 1)
relieving_date = add_days(first_day, 5)
employee = make_employee('test_unmarked_days_as_per_doj@example.com', date_of_joining=doj,
date_of_relieving=relieving_date)
relieving_date=relieving_date)
frappe.db.delete('Attendance', {'employee': employee})
attendance_date = add_days(first_day, 2)
@ -104,4 +105,4 @@ def get_month_name(date):
month_number = date.month
for month, number in get_month_map().items():
if number == month_number:
return month
return month

View File

@ -4,6 +4,7 @@
import frappe
from frappe import _
from frappe.query_builder.functions import Max, Min, Sum
from frappe.utils import (
add_days,
cint,
@ -567,28 +568,39 @@ def get_leave_balance_on(employee, leave_type, date, to_date=None, consider_all_
return get_remaining_leaves(allocation, leaves_taken, date, expiry)
def get_leave_allocation_records(employee, date, leave_type=None):
''' returns the total allocated leaves and carry forwarded leaves based on ledger entries '''
"""Returns the total allocated leaves and carry forwarded leaves based on ledger entries"""
Ledger = frappe.qb.DocType("Leave Ledger Entry")
conditions = ("and leave_type='%s'" % leave_type) if leave_type else ""
allocation_details = frappe.db.sql("""
SELECT
SUM(CASE WHEN is_carry_forward = 1 THEN leaves ELSE 0 END) as cf_leaves,
SUM(CASE WHEN is_carry_forward = 0 THEN leaves ELSE 0 END) as new_leaves,
MIN(from_date) as from_date,
MAX(to_date) as to_date,
leave_type
FROM `tabLeave Ledger Entry`
WHERE
from_date <= %(date)s
AND to_date >= %(date)s
AND docstatus=1
AND transaction_type="Leave Allocation"
AND employee=%(employee)s
AND is_expired=0
AND is_lwp=0
{0}
GROUP BY employee, leave_type
""".format(conditions), dict(date=date, employee=employee), as_dict=1) #nosec
cf_leave_case = frappe.qb.terms.Case().when(Ledger.is_carry_forward == "1", Ledger.leaves).else_(0)
sum_cf_leaves = Sum(cf_leave_case).as_("cf_leaves")
new_leaves_case = frappe.qb.terms.Case().when(Ledger.is_carry_forward == "0", Ledger.leaves).else_(0)
sum_new_leaves = Sum(new_leaves_case).as_("new_leaves")
query = (
frappe.qb.from_(Ledger)
.select(
sum_cf_leaves,
sum_new_leaves,
Min(Ledger.from_date).as_("from_date"),
Max(Ledger.to_date).as_("to_date"),
Ledger.leave_type
).where(
(Ledger.from_date <= date)
& (Ledger.to_date >= date)
& (Ledger.docstatus == 1)
& (Ledger.transaction_type == "Leave Allocation")
& (Ledger.employee == employee)
& (Ledger.is_expired == 0)
& (Ledger.is_lwp == 0)
)
)
if leave_type:
query = query.where((Ledger.leave_type == leave_type))
query = query.groupby(Ledger.employee, Ledger.leave_type)
allocation_details = query.run(as_dict=True)
allocated_leaves = frappe._dict()
for d in allocation_details:

View File

@ -792,4 +792,4 @@ def get_first_sunday(holiday_list):
order by holiday_date
""", (holiday_list, month_start_date, month_end_date))[0][0]
return first_sunday
return first_sunday

View File

@ -1,6 +1,5 @@
import unittest
import frappe
from frappe.tests.utils import FrappeTestCase
from frappe.utils import add_days, getdate
from erpnext.hr.doctype.employee.test_employee import make_employee
@ -12,7 +11,7 @@ from erpnext.projects.doctype.timesheet.timesheet import make_salary_slip, make_
from erpnext.projects.report.project_profitability.project_profitability import execute
class TestProjectProfitability(unittest.TestCase):
class TestProjectProfitability(FrappeTestCase):
def setUp(self):
frappe.db.sql('delete from `tabTimesheet`')
emp = make_employee('test_employee_9@salary.com', company='_Test Company')
@ -67,6 +66,3 @@ class TestProjectProfitability(unittest.TestCase):
fractional_cost = self.salary_slip.base_gross_pay * utilization
self.assertEqual(fractional_cost, row.fractional_cost)
def tearDown(self):
frappe.db.rollback()

View File

@ -156,24 +156,24 @@ def get_data(filters):
customer_record = customer_details.get(record.customer)
item_record = item_details.get(record.item_code)
row = {
"item_code": record.item_code,
"item_name": item_record.item_name,
"item_group": item_record.item_group,
"description": record.description,
"quantity": record.qty,
"uom": record.uom,
"rate": record.base_rate,
"amount": record.base_amount,
"sales_order": record.name,
"transaction_date": record.transaction_date,
"customer": record.customer,
"customer_name": customer_record.customer_name,
"customer_group": customer_record.customer_group,
"territory": record.territory,
"project": record.project,
"delivered_quantity": flt(record.delivered_qty),
"billed_amount": flt(record.billed_amt),
"company": record.company
"item_code": record.get('item_code'),
"item_name": item_record.get('item_name'),
"item_group": item_record.get('item_group'),
"description": record.get('description'),
"quantity": record.get('qty'),
"uom": record.get('uom'),
"rate": record.get('base_rate'),
"amount": record.get('base_amount'),
"sales_order": record.get('name'),
"transaction_date": record.get('transaction_date'),
"customer": record.get('customer'),
"customer_name": customer_record.get('customer_name'),
"customer_group": customer_record.get('customer_group'),
"territory": record.get('territory'),
"project": record.get('project'),
"delivered_quantity": flt(record.get('delivered_qty')),
"billed_amount": flt(record.get('billed_amt')),
"company": record.get('company')
}
data.append(row)

View File

@ -272,9 +272,9 @@ def get_available_item_locations_for_batched_item(item_code, from_warehouses, re
and IFNULL(batch.`expiry_date`, '2200-01-01') > %(today)s
{warehouse_condition}
GROUP BY
`warehouse`,
`batch_no`,
`item_code`
sle.`warehouse`,
sle.`batch_no`,
sle.`item_code`
HAVING `qty` > 0
ORDER BY IFNULL(batch.`expiry_date`, '2200-01-01'), batch.`creation`
""".format(warehouse_condition=warehouse_condition), { #nosec