Skip to content

Commit

Permalink
Merge branch 'develop' into einv-qrcode-btn
Browse files Browse the repository at this point in the history
  • Loading branch information
nextchamp-saqib authored May 9, 2022
2 parents 3adc90e + ebbe27c commit f5f8888
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 121 deletions.
2 changes: 1 addition & 1 deletion erpnext/accounts/report/pos_register/pos_register.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def get_pos_entries(filters, group_by_field):
"""
SELECT
p.posting_date, p.name as pos_invoice, p.pos_profile,
p.owner, p.base_grand_total as grand_total, p.base_paid_amount as paid_amount,
p.owner, p.base_grand_total as grand_total, p.base_paid_amount - p.change_amount as paid_amount,
p.customer, p.is_return {select_mop_field}
FROM
`tabPOS Invoice` p {from_sales_invoice_payment}
Expand Down
2 changes: 1 addition & 1 deletion erpnext/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
app_logo_url = "/assets/erpnext/images/erpnext-logo.svg"


develop_version = "13.x.x-develop"
develop_version = "14.x.x-develop"

app_include_js = "erpnext.bundle.js"
app_include_css = "erpnext.bundle.css"
Expand Down
9 changes: 0 additions & 9 deletions erpnext/hr/doctype/leave_allocation/leave_allocation.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,6 @@ frappe.ui.form.on("Leave Allocation", {
});
}
}

// make new leaves allocated field read only if allocation is created via leave policy assignment
// and leave type is earned leave, since these leaves would be allocated via the scheduler
if (frm.doc.leave_policy_assignment) {
frappe.db.get_value("Leave Type", frm.doc.leave_type, "is_earned_leave", (r) => {
if (r && cint(r.is_earned_leave))
frm.set_df_property("new_leaves_allocated", "read_only", 1);
});
}
},

expire_allocation: function(frm) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -745,15 +745,15 @@ def test_earned_leaves_creation(self):

i = 0
while i < 14:
allocate_earned_leaves(ignore_duplicates=True)
allocate_earned_leaves()
i += 1
self.assertEqual(get_leave_balance_on(employee.name, leave_type, nowdate()), 6)

# validate earned leaves creation without maximum leaves
frappe.db.set_value("Leave Type", leave_type, "max_leaves_allowed", 0)
i = 0
while i < 6:
allocate_earned_leaves(ignore_duplicates=True)
allocate_earned_leaves()
i += 1
self.assertEqual(get_leave_balance_on(employee.name, leave_type, nowdate()), 9)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import unittest

import frappe
from frappe.tests.utils import FrappeTestCase
from frappe.utils import add_days, add_months, get_first_day, get_last_day, getdate

from erpnext.hr.doctype.leave_application.test_leave_application import (
Expand All @@ -18,7 +19,7 @@
test_dependencies = ["Employee"]


class TestLeavePolicyAssignment(unittest.TestCase):
class TestLeavePolicyAssignment(FrappeTestCase):
def setUp(self):
for doctype in [
"Leave Period",
Expand All @@ -39,6 +40,9 @@ def test_grant_leaves(self):
leave_policy = create_leave_policy()
leave_policy.submit()

self.employee.date_of_joining = get_first_day(leave_period.from_date)
self.employee.save()

data = {
"assignment_based_on": "Leave Period",
"leave_policy": leave_policy.name,
Expand Down Expand Up @@ -188,19 +192,6 @@ def test_earned_leave_alloc_for_passed_months_on_month_end_based_on_leave_period
)
self.assertEqual(leaves_allocated, 3)

# if the daily job is not completed yet, there is another check present
# to ensure leave is not already allocated to avoid duplication
from erpnext.hr.utils import allocate_earned_leaves

allocate_earned_leaves()

leaves_allocated = frappe.db.get_value(
"Leave Allocation",
{"leave_policy_assignment": leave_policy_assignments[0]},
"total_leaves_allocated",
)
self.assertEqual(leaves_allocated, 3)

def test_earned_leave_alloc_for_passed_months_with_cf_leaves_based_on_leave_period(self):
from erpnext.hr.doctype.leave_allocation.test_leave_allocation import create_leave_allocation

Expand Down Expand Up @@ -242,20 +233,6 @@ def test_earned_leave_alloc_for_passed_months_with_cf_leaves_based_on_leave_peri
self.assertEqual(details.unused_leaves, 5)
self.assertEqual(details.total_leaves_allocated, 7)

# if the daily job is not completed yet, there is another check present
# to ensure leave is not already allocated to avoid duplication
from erpnext.hr.utils import is_earned_leave_already_allocated

frappe.flags.current_date = get_last_day(getdate())

allocation = frappe.get_doc("Leave Allocation", details.name)
# 1 leave is still pending to be allocated, irrespective of carry forwarded leaves
self.assertFalse(
is_earned_leave_already_allocated(
allocation, leave_policy.leave_policy_details[0].annual_allocation
)
)

def test_earned_leave_alloc_for_passed_months_based_on_joining_date(self):
# tests leave alloc for earned leaves for assignment based on joining date in policy assignment
leave_type = create_earned_leave_type("Test Earned Leave")
Expand Down Expand Up @@ -288,19 +265,6 @@ def test_earned_leave_alloc_for_passed_months_based_on_joining_date(self):
self.assertEqual(effective_from, self.employee.date_of_joining)
self.assertEqual(leaves_allocated, 3)

# to ensure leave is not already allocated to avoid duplication
from erpnext.hr.utils import allocate_earned_leaves

frappe.flags.current_date = get_last_day(getdate())
allocate_earned_leaves()

leaves_allocated = frappe.db.get_value(
"Leave Allocation",
{"leave_policy_assignment": leave_policy_assignments[0]},
"total_leaves_allocated",
)
self.assertEqual(leaves_allocated, 3)

def test_grant_leaves_on_doj_for_earned_leaves_based_on_leave_period(self):
# tests leave alloc based on leave period for earned leaves with "based on doj" configuration in leave type
leave_period, leave_policy = setup_leave_period_and_policy(
Expand Down Expand Up @@ -330,20 +294,6 @@ def test_grant_leaves_on_doj_for_earned_leaves_based_on_leave_period(self):
)
self.assertEqual(leaves_allocated, 3)

# if the daily job is not completed yet, there is another check present
# to ensure leave is not already allocated to avoid duplication
from erpnext.hr.utils import allocate_earned_leaves

frappe.flags.current_date = get_first_day(getdate())
allocate_earned_leaves()

leaves_allocated = frappe.db.get_value(
"Leave Allocation",
{"leave_policy_assignment": leave_policy_assignments[0]},
"total_leaves_allocated",
)
self.assertEqual(leaves_allocated, 3)

def test_grant_leaves_on_doj_for_earned_leaves_based_on_joining_date(self):
# tests leave alloc based on joining date for earned leaves with "based on doj" configuration in leave type
leave_type = create_earned_leave_type("Test Earned Leave", based_on_doj=True)
Expand Down Expand Up @@ -377,21 +327,7 @@ def test_grant_leaves_on_doj_for_earned_leaves_based_on_joining_date(self):
self.assertEqual(effective_from, self.employee.date_of_joining)
self.assertEqual(leaves_allocated, 3)

# to ensure leave is not already allocated to avoid duplication
from erpnext.hr.utils import allocate_earned_leaves

frappe.flags.current_date = get_first_day(getdate())
allocate_earned_leaves()

leaves_allocated = frappe.db.get_value(
"Leave Allocation",
{"leave_policy_assignment": leave_policy_assignments[0]},
"total_leaves_allocated",
)
self.assertEqual(leaves_allocated, 3)

def tearDown(self):
frappe.db.rollback()
frappe.db.set_value("Employee", self.employee.name, "date_of_joining", self.original_doj)
frappe.flags.current_date = None

Expand Down
33 changes: 14 additions & 19 deletions erpnext/hr/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ def generate_leave_encashment():
create_leave_encashment(leave_allocation=leave_allocation)


def allocate_earned_leaves(ignore_duplicates=False):
def allocate_earned_leaves():
"""Allocate earned leaves to Employees"""
e_leave_types = get_earned_leaves()
today = getdate()
Expand Down Expand Up @@ -305,14 +305,10 @@ def allocate_earned_leaves(ignore_duplicates=False):
if check_effective_date(
from_date, today, e_leave_type.earned_leave_frequency, e_leave_type.based_on_date_of_joining
):
update_previous_leave_allocation(
allocation, annual_allocation, e_leave_type, ignore_duplicates
)
update_previous_leave_allocation(allocation, annual_allocation, e_leave_type)


def update_previous_leave_allocation(
allocation, annual_allocation, e_leave_type, ignore_duplicates=False
):
def update_previous_leave_allocation(allocation, annual_allocation, e_leave_type):
earned_leaves = get_monthly_earned_leave(
annual_allocation, e_leave_type.earned_leave_frequency, e_leave_type.rounding
)
Expand All @@ -326,20 +322,19 @@ def update_previous_leave_allocation(
if new_allocation != allocation.total_leaves_allocated:
today_date = today()

if ignore_duplicates or not is_earned_leave_already_allocated(allocation, annual_allocation):
allocation.db_set("total_leaves_allocated", new_allocation, update_modified=False)
create_additional_leave_ledger_entry(allocation, earned_leaves, today_date)
allocation.db_set("total_leaves_allocated", new_allocation, update_modified=False)
create_additional_leave_ledger_entry(allocation, earned_leaves, today_date)

if e_leave_type.based_on_date_of_joining:
text = _("allocated {0} leave(s) via scheduler on {1} based on the date of joining").format(
frappe.bold(earned_leaves), frappe.bold(formatdate(today_date))
)
else:
text = _("allocated {0} leave(s) via scheduler on {1}").format(
frappe.bold(earned_leaves), frappe.bold(formatdate(today_date))
)
if e_leave_type.based_on_date_of_joining:
text = _("allocated {0} leave(s) via scheduler on {1} based on the date of joining").format(
frappe.bold(earned_leaves), frappe.bold(formatdate(today_date))
)
else:
text = _("allocated {0} leave(s) via scheduler on {1}").format(
frappe.bold(earned_leaves), frappe.bold(formatdate(today_date))
)

allocation.add_comment(comment_type="Info", text=text)
allocation.add_comment(comment_type="Info", text=text)


def get_monthly_earned_leave(annual_leaves, frequency, rounding):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,17 @@ def _execute(filters=None):
added_item = []
for d in item_list:
if (d.parent, d.item_code) not in added_item:
row = [d.gst_hsn_code, d.description, d.stock_uom, d.stock_qty]
row = [d.gst_hsn_code, d.description, d.stock_uom, d.stock_qty, d.tax_rate]
total_tax = 0
for tax in tax_columns:
item_tax = itemised_tax.get((d.parent, d.item_code), {}).get(tax, {})
total_tax += flt(item_tax.get("tax_amount", 0))

row += [d.base_net_amount + total_tax]
row += [d.base_net_amount]

for tax in tax_columns:
item_tax = itemised_tax.get((d.parent, d.item_code), {}).get(tax, {})
row += [item_tax.get("tax_amount", 0)]

data.append(row)
added_item.append((d.parent, d.item_code))
if data:
Expand All @@ -64,6 +62,7 @@ def get_columns():
{"fieldname": "description", "label": _("Description"), "fieldtype": "Data", "width": 300},
{"fieldname": "stock_uom", "label": _("Stock UOM"), "fieldtype": "Data", "width": 100},
{"fieldname": "stock_qty", "label": _("Stock Qty"), "fieldtype": "Float", "width": 90},
{"fieldname": "tax_rate", "label": _("Tax Rate"), "fieldtype": "Data", "width": 90},
{"fieldname": "total_amount", "label": _("Total Amount"), "fieldtype": "Currency", "width": 120},
{
"fieldname": "taxable_amount",
Expand Down Expand Up @@ -106,16 +105,25 @@ def get_items(filters):
sum(`tabSales Invoice Item`.stock_qty) as stock_qty,
sum(`tabSales Invoice Item`.base_net_amount) as base_net_amount,
sum(`tabSales Invoice Item`.base_price_list_rate) as base_price_list_rate,
`tabSales Invoice Item`.parent, `tabSales Invoice Item`.item_code,
`tabGST HSN Code`.description
from `tabSales Invoice`, `tabSales Invoice Item`, `tabGST HSN Code`
where `tabSales Invoice`.name = `tabSales Invoice Item`.parent
`tabSales Invoice Item`.parent,
`tabSales Invoice Item`.item_code,
`tabGST HSN Code`.description,
json_extract(`tabSales Taxes and Charges`.item_wise_tax_detail,
concat('$."' , `tabSales Invoice Item`.item_code, '"[0]')) * count(distinct `tabSales Taxes and Charges`.name) as tax_rate
from
`tabSales Invoice`,
`tabSales Invoice Item`,
`tabGST HSN Code`,
`tabSales Taxes and Charges`
where
`tabSales Invoice`.name = `tabSales Invoice Item`.parent
and `tabSales Taxes and Charges`.parent = `tabSales Invoice`.name
and `tabSales Invoice`.docstatus = 1
and `tabSales Invoice Item`.gst_hsn_code is not NULL
and `tabSales Invoice Item`.gst_hsn_code = `tabGST HSN Code`.name %s %s
group by
`tabSales Invoice Item`.parent, `tabSales Invoice Item`.item_code
`tabSales Invoice Item`.parent,
`tabSales Invoice Item`.item_code
"""
% (conditions, match_conditions),
filters,
Expand Down Expand Up @@ -213,15 +221,16 @@ def get_merged_data(columns, data):
result = []

for row in data:
merged_hsn_dict.setdefault(row[0], {})
key = row[0] + "-" + str(row[4])
merged_hsn_dict.setdefault(key, {})
for i, d in enumerate(columns):
if d["fieldtype"] not in ("Int", "Float", "Currency"):
merged_hsn_dict[row[0]][d["fieldname"]] = row[i]
merged_hsn_dict[key][d["fieldname"]] = row[i]
else:
if merged_hsn_dict.get(row[0], {}).get(d["fieldname"], ""):
merged_hsn_dict[row[0]][d["fieldname"]] += row[i]
if merged_hsn_dict.get(key, {}).get(d["fieldname"], ""):
merged_hsn_dict[key][d["fieldname"]] += row[i]
else:
merged_hsn_dict[row[0]][d["fieldname"]] = row[i]
merged_hsn_dict[key][d["fieldname"]] = row[i]

for key, value in merged_hsn_dict.items():
result.append(value)
Expand All @@ -240,7 +249,7 @@ def get_json(filters, report_name, data):

fp = "%02d%s" % (getdate(filters["to_date"]).month, getdate(filters["to_date"]).year)

gst_json = {"version": "GST2.3.4", "hash": "hash", "gstin": gstin, "fp": fp}
gst_json = {"version": "GST3.0.3", "hash": "hash", "gstin": gstin, "fp": fp}

gst_json["hsn"] = {"data": get_hsn_wise_json_data(filters, report_data)}

Expand Down Expand Up @@ -271,7 +280,7 @@ def get_hsn_wise_json_data(filters, report_data):
"desc": hsn.get("description"),
"uqc": hsn.get("stock_uom").upper(),
"qty": hsn.get("stock_qty"),
"val": flt(hsn.get("total_amount"), 2),
"rt": flt(hsn.get("tax_rate"), 2),
"txval": flt(hsn.get("taxable_amount", 2)),
"iamt": 0.0,
"camt": 0.0,
Expand Down
12 changes: 8 additions & 4 deletions erpnext/selling/page/point_of_sale/pos_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -479,16 +479,20 @@ erpnext.PointOfSale.Controller = class {
frappe.dom.freeze();
this.frm = this.get_new_frm(this.frm);
this.frm.doc.items = [];
const res = await frappe.call({
return frappe.call({
method: "erpnext.accounts.doctype.pos_invoice.pos_invoice.make_sales_return",
args: {
'source_name': doc.name,
'target_doc': this.frm.doc
},
callback: (r) => {
frappe.model.sync(r.message);
frappe.get_doc(r.message.doctype, r.message.name).__run_link_triggers = false;
this.set_pos_profile_data().then(() => {
frappe.dom.unfreeze();
});
}
});
frappe.model.sync(res.message);
await this.set_pos_profile_data();
frappe.dom.unfreeze();
}

set_pos_profile_data() {
Expand Down

0 comments on commit f5f8888

Please sign in to comment.