Skip to content

Commit

Permalink
Merge pull request #2726 from frappe/version-15-hotfix
Browse files Browse the repository at this point in the history
chore: release v15
  • Loading branch information
asmitahase authored Jan 31, 2025
2 parents fcf42f2 + e363886 commit 1fd9942
Show file tree
Hide file tree
Showing 15 changed files with 334 additions and 25 deletions.
5 changes: 5 additions & 0 deletions .github/helper/apps.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[
{"url": "https://github.com/frappe/erpnext","branch": "version-15"},
{"url": "https://github.com/frappe/payments","branch": "version-15"},
{"url": "https://github.com/frappe/hrms","branch": "version-15"}
]
66 changes: 66 additions & 0 deletions .github/workflows/build_image.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
name: Build Container Image
on:
release:
types: [published]
workflow_dispatch:
push:
branches:
- version-15
tags:
- "*"
jobs:
build:
name: Build
runs-on: ubuntu-latest

strategy:
matrix:
arch: [amd64, arm64]

permissions:
packages: write

steps:
- name: Checkout Entire Repository
uses: actions/checkout@v4

- name: Set up QEMU
uses: docker/setup-qemu-action@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
with:
platforms: linux/${{ matrix.arch }}
- name: Login to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Set Branch
run: |
export APPS_JSON_PATH='${{ github.workspace }}/.github/helper/apps.json'
echo "APPS_JSON_BASE64=$(cat $APPS_JSON_PATH | base64 -w 0)" >> $GITHUB_ENV
echo "FRAPPE_BRANCH=version-15" >> $GITHUB_ENV
- name: Set Image Tag
run: |
echo "IMAGE_TAG=stable" >> $GITHUB_ENV
- uses: actions/checkout@v4
with:
repository: frappe/frappe_docker
path: builds

- name: Build and push
uses: docker/build-push-action@v6
with:
push: true
context: builds
file: builds/images/layered/Containerfile
tags: >
ghcr.io/${{ github.repository }}:${{ github.ref_name }},
ghcr.io/${{ github.repository }}:${{ env.IMAGE_TAG }}
build-args: |
"FRAPPE_BRANCH=${{ env.FRAPPE_BRANCH }}"
"APPS_JSON_BASE64=${{ env.APPS_JSON_BASE64 }}"
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ jobs:
CAPTURE_COVERAGE: ${{ github.event_name != 'pull_request' }}

- name: Upload coverage data
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
if: github.event_name != 'pull_request'
with:
name: coverage-${{ matrix.container }}
Expand All @@ -131,7 +131,7 @@ jobs:
uses: actions/checkout@v2

- name: Download artifacts
uses: actions/download-artifact@v3
uses: actions/download-artifact@v4

- name: Upload coverage data
uses: codecov/codecov-action@v2
Expand Down
1 change: 1 addition & 0 deletions hrms/hr/doctype/employee_advance/employee_advance.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ frappe.ui.form.on("Employee Advance", {
posting_date: frm.doc.posting_date,
paid_amount: frm.doc.paid_amount,
claimed_amount: frm.doc.claimed_amount,
return_amount: frm.doc.return_amount,
},
callback: function (r) {
const doclist = frappe.model.sync(r.message);
Expand Down
4 changes: 2 additions & 2 deletions hrms/hr/doctype/employee_advance/employee_advance.json
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@
},
{
"allow_on_submit": 1,
"description": "Amount returned by the employee after the advance is paid",
"description": "Amount scheduled for deduction via salary",
"fieldname": "return_amount",
"fieldtype": "Currency",
"label": "Returned Amount",
Expand Down Expand Up @@ -241,7 +241,7 @@
],
"is_submittable": 1,
"links": [],
"modified": "2024-04-12 13:53:55.442187",
"modified": "2025-01-29 12:05:13.623633",
"modified_by": "Administrator",
"module": "HR",
"name": "Employee Advance",
Expand Down
11 changes: 8 additions & 3 deletions hrms/hr/doctype/employee_advance/test_employee_advance.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
make_bank_entry,
make_return_entry,
)
from hrms.hr.doctype.expense_claim.expense_claim import get_advances
from hrms.hr.doctype.expense_claim.expense_claim import get_advances, get_allocation_amount
from hrms.hr.doctype.expense_claim.test_expense_claim import (
get_payable_account,
make_expense_claim,
Expand Down Expand Up @@ -353,7 +353,11 @@ def get_advances_for_claim(claim, advance_name, amount=None):
if amount:
allocated_amount = amount
else:
allocated_amount = flt(entry.paid_amount) - flt(entry.claimed_amount)
allocated_amount = get_allocation_amount(
paid_amount=entry.paid_amount,
claimed_amount=entry.claimed_amount,
return_amount=entry.return_amount,
)

claim.append(
"advances",
Expand All @@ -362,7 +366,8 @@ def get_advances_for_claim(claim, advance_name, amount=None):
"posting_date": entry.posting_date,
"advance_account": entry.advance_account,
"advance_paid": entry.paid_amount,
"unclaimed_amount": allocated_amount,
"return_amount": entry.return_amount,
"unclaimed_amount": entry.paid_amount - entry.claimed_amount,
"allocated_amount": allocated_amount,
},
)
Expand Down
25 changes: 19 additions & 6 deletions hrms/hr/doctype/expense_claim/expense_claim.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,9 @@ frappe.ui.form.on("Expense Claim", {
update_employee_advance_claimed_amount: function (frm) {
let amount_to_be_allocated = frm.doc.grand_total;
$.each(frm.doc.advances || [], function (i, advance) {
if (amount_to_be_allocated >= advance.unclaimed_amount) {
advance.allocated_amount = frm.doc.advances[i].unclaimed_amount;
if (amount_to_be_allocated >= advance.unclaimed_amount - advance.return_amount) {
advance.allocated_amount =
frm.doc.advances[i].unclaimed_amount - frm.doc.advances[i].return_amount;
amount_to_be_allocated -= advance.allocated_amount;
} else {
advance.allocated_amount = amount_to_be_allocated;
Expand All @@ -212,7 +213,6 @@ frappe.ui.form.on("Expense Claim", {
frm.refresh_field("advances");
});
},

make_payment_entry: function (frm) {
let method = "hrms.overrides.employee_payment_entry.get_payment_entry_for_employee";
if (frm.doc.__onload && frm.doc.__onload.make_payment_via_journal_entry) {
Expand Down Expand Up @@ -317,7 +317,12 @@ frappe.ui.form.on("Expense Claim", {
row.advance_account = d.advance_account;
row.advance_paid = d.paid_amount;
row.unclaimed_amount = flt(d.paid_amount) - flt(d.claimed_amount);
row.allocated_amount = 0;
row.return_amount = flt(d.return_amount);
row.allocated_amount = get_allocation_amount(
flt(d.paid_amount),
flt(d.claimed_amount),
flt(d.return_amount),
);
});
refresh_field("advances");
}
Expand Down Expand Up @@ -393,8 +398,12 @@ frappe.ui.form.on("Expense Claim Advance", {
child.advance_paid = r.message[0].paid_amount;
child.unclaimed_amount =
flt(r.message[0].paid_amount) - flt(r.message[0].claimed_amount);
child.allocated_amount =
flt(r.message[0].paid_amount) - flt(r.message[0].claimed_amount);
child.return_amount = flt(r.message[0].return_amount);
child.allocated_amount = get_allocation_amount(
flt(r.message[0].paid_amount),
flt(r.message[0].claimed_amount),
flt(r.message[0].return_amount),
);
frm.trigger("calculate_grand_total");
refresh_field("advances");
}
Expand Down Expand Up @@ -440,3 +449,7 @@ frappe.ui.form.on("Expense Taxes and Charges", {
frm.trigger("calculate_total_tax", cdt, cdn);
},
});

function get_allocation_amount(paid_amount, claimed_amount, return_amount) {
return paid_amount - (claimed_amount + return_amount);
}
30 changes: 26 additions & 4 deletions hrms/hr/doctype/expense_claim/expense_claim.py
Original file line number Diff line number Diff line change
Expand Up @@ -339,15 +339,17 @@ def validate_advances(self):
ref_doc = frappe.db.get_value(
"Employee Advance",
d.employee_advance,
["posting_date", "paid_amount", "claimed_amount", "advance_account"],
["posting_date", "paid_amount", "claimed_amount", "return_amount", "advance_account"],
as_dict=1,
)
d.posting_date = ref_doc.posting_date
d.advance_account = ref_doc.advance_account
d.advance_paid = ref_doc.paid_amount
d.unclaimed_amount = flt(ref_doc.paid_amount) - flt(ref_doc.claimed_amount)

if d.allocated_amount and flt(d.allocated_amount) > flt(d.unclaimed_amount):
if d.allocated_amount and flt(d.allocated_amount) > (
flt(d.unclaimed_amount) - flt(d.return_amount)
):
frappe.throw(
_("Row {0}# Allocated amount {1} cannot be greater than unclaimed amount {2}").format(
d.idx, d.allocated_amount, d.unclaimed_amount
Expand Down Expand Up @@ -511,6 +513,7 @@ def get_advances(employee, advance_id=None):
advance.posting_date,
advance.paid_amount,
advance.claimed_amount,
advance.return_amount,
advance.advance_account,
)

Expand All @@ -529,7 +532,7 @@ def get_advances(employee, advance_id=None):

@frappe.whitelist()
def get_expense_claim(
employee_name, company, employee_advance_name, posting_date, paid_amount, claimed_amount
employee_name, company, employee_advance_name, posting_date, paid_amount, claimed_amount, return_amount
):
default_payable_account = frappe.get_cached_value(
"Company", company, "default_expense_claim_payable_account"
Expand All @@ -549,7 +552,10 @@ def get_expense_claim(
"posting_date": posting_date,
"advance_paid": flt(paid_amount),
"unclaimed_amount": flt(paid_amount) - flt(claimed_amount),
"allocated_amount": flt(paid_amount) - flt(claimed_amount),
"allocated_amount": get_allocation_amount(
paid_amount=(paid_amount), claimed_amount=(claimed_amount), return_amount=(return_amount)
),
"return_amount": flt(return_amount),
},
)

Expand Down Expand Up @@ -606,3 +612,19 @@ def make_expense_claim_for_delivery_trip(source_name, target_doc=None):
)

return doc


# // amke below fucntion reusable basef on wht is passed, if only unclaimed and return_amt is pased, return unclaimed - returne_amt else paid_amount - (claimed_amount + return_amount)
# @frappe.whitelist()
# def get_allocation_amount(paid_amount, claimed_amount, return_amount):
# return paid_amount - (claimed_amount + return_amount)


@frappe.whitelist()
def get_allocation_amount(paid_amount=None, claimed_amount=None, return_amount=None, unclaimed_amount=None):
if unclaimed_amount is not None and return_amount is not None:
return flt(unclaimed_amount) - flt(return_amount)
elif paid_amount is not None and claimed_amount is not None and return_amount is not None:
return flt(paid_amount) - (flt(claimed_amount) + flt(return_amount))
else:
frappe.throw(_("Invalid parameters provided. Please pass the required arguments."))
58 changes: 58 additions & 0 deletions hrms/hr/doctype/expense_claim/test_expense_claim.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,64 @@ def test_expense_claim_partially_paid_via_advance(self):
self.assertEqual(claim.total_amount_reimbursed, 500)
self.assertEqual(claim.status, "Paid")

def test_expense_claim_with_deducted_returned_advance(self):
from hrms.hr.doctype.employee_advance.test_employee_advance import (
create_return_through_additional_salary,
get_advances_for_claim,
make_employee_advance,
make_journal_entry_for_advance,
)
from hrms.hr.doctype.expense_claim.expense_claim import get_allocation_amount
from hrms.payroll.doctype.salary_component.test_salary_component import create_salary_component
from hrms.payroll.doctype.salary_structure.test_salary_structure import make_salary_structure

# create employee and employee advance
employee_name = make_employee("[email protected]", "_Test Company")
advance = make_employee_advance(employee_name, {"repay_unclaimed_amount_from_salary": 1})
journal_entry = make_journal_entry_for_advance(advance)
journal_entry.submit()
advance.reload()

# set up salary components and structure
create_salary_component("Advance Salary - Deduction", type="Deduction")
make_salary_structure(
"Test Additional Salary for Advance Return",
"Monthly",
employee=employee_name,
company="_Test Company",
)

# create additional salary for advance return
additional_salary = create_return_through_additional_salary(advance)
additional_salary.salary_component = "Advance Salary - Deduction"
additional_salary.payroll_date = nowdate()
additional_salary.amount = 400
additional_salary.insert()
additional_salary.submit()
advance.reload()

self.assertEqual(advance.return_amount, 400)

# create an expense claim
payable_account = get_payable_account("_Test Company")
claim = make_expense_claim(
payable_account, 200, 200, "_Test Company", "Travel Expenses - _TC", do_not_submit=True
)

# link advance to the claim
claim = get_advances_for_claim(claim, advance.name, amount=200)
claim.save()
claim.submit()

# verify the allocation amount
advance = claim.advances[0]
self.assertEqual(
get_allocation_amount(
unclaimed_amount=advance.unclaimed_amount, return_amount=advance.return_amount
),
600,
)

def test_expense_claim_gl_entry(self):
payable_account = get_payable_account(company_name)
taxes = generate_taxes()
Expand Down
11 changes: 10 additions & 1 deletion hrms/hr/doctype/expense_claim_advance/expense_claim_advance.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"advance_paid",
"column_break_4",
"unclaimed_amount",
"return_amount",
"allocated_amount",
"advance_account"
],
Expand Down Expand Up @@ -84,11 +85,19 @@
{
"fieldname": "column_break_4",
"fieldtype": "Column Break"
},
{
"depends_on": "return_amount",
"fieldname": "return_amount",
"fieldtype": "Currency",
"label": "Returned Amount",
"options": "Company:company:default_currency",
"read_only": 1
}
],
"istable": 1,
"links": [],
"modified": "2021-11-22 16:33:58.515819",
"modified": "2025-01-29 15:22:37.971097",
"modified_by": "Administrator",
"module": "HR",
"name": "Expense Claim Advance",
Expand Down
9 changes: 8 additions & 1 deletion hrms/hr/doctype/hr_settings/hr_settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"leave_status_notification_template",
"leave_approver_mandatory_in_leave_application",
"restrict_backdated_leave_application",
"prevent_self_leave_approval",
"role_allowed_to_create_backdated_leave_application",
"column_break_29",
"expense_approver_mandatory_in_expense_claim",
Expand Down Expand Up @@ -329,13 +330,19 @@
"fieldname": "unlink_payment_on_cancellation_of_employee_advance",
"fieldtype": "Check",
"label": " Unlink Payment on Cancellation of Employee Advance"
},
{
"default": "0",
"fieldname": "prevent_self_leave_approval",
"fieldtype": "Check",
"label": "Prevent self approval for leaves even if user has permissions"
}
],
"icon": "fa fa-cog",
"idx": 1,
"issingle": 1,
"links": [],
"modified": "2024-09-29 12:49:16.175079",
"modified": "2025-01-30 12:41:22.594071",
"modified_by": "Administrator",
"module": "HR",
"name": "HR Settings",
Expand Down
Loading

0 comments on commit 1fd9942

Please sign in to comment.