Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions .github/workflows/pre-commit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Pre-commit

on:
pull_request:
workflow_dispatch:

permissions:
contents: read

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
pre-commit:
name: 'Run pre-commit (all files)'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.10'
cache: pip
- name: Install pre-commit
run: pip install pre-commit
- name: Run pre-commit
env:
SKIP: frappe-semgrep-rules,full-repository-check
run: pre-commit run --all-files --show-diff-on-failure --color=always
34 changes: 0 additions & 34 deletions .github/workflows/release.yml

This file was deleted.

32 changes: 29 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
exclude: 'node_modules|.git|frappe-semgrep-rules'
exclude: '^(node_modules/|frappe-semgrep-rules/|[.]vscode/|.*/node_modules/)'
default_stages: [pre-commit]
default_install_hook_types: [pre-commit, commit-msg]
default_install_hook_types: [pre-commit, commit-msg, pre-push]
fail_fast: false

repos:
Expand All @@ -18,20 +18,37 @@ repos:
- id: check-toml
- id: check-yaml
- id: debug-statements
- id: no-commit-to-branch
args:
- --branch
- main
- --branch
- master
- --branch
- production
- --branch
- version-14
- --branch
- version-15
- --branch
- version-16

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.11.0
hooks:
- id: ruff
name: "Run ruff import sorter"
args: ["--select=I", "--fix"]
files: '^csf_tz/.*\.py$'

- id: ruff
name: "Run ruff linter"
args: ["--fix"]
files: '^csf_tz/.*\.py$'

- id: ruff-format
name: "Run ruff formatter"
files: '^csf_tz/.*\.py$'

- repo: local
hooks:
Expand All @@ -45,6 +62,15 @@ repos:
pass_filenames: true
require_serial: true

- id: full-repository-check
name: "Full repository check before push"
entry: bash -c 'if command -v pre-commit >/dev/null 2>&1; then exec pre-commit run --all-files --hook-stage pre-commit --show-diff-on-failure --color=always; else exec python3 -m pre_commit run --all-files --hook-stage pre-commit --show-diff-on-failure --color=always; fi'
language: system
stages: [pre-push]
pass_filenames: false
always_run: true
verbose: true

- repo: https://github.com/alessandrojcm/commitlint-pre-commit-hook
rev: v9.22.0
hooks:
Expand All @@ -54,5 +80,5 @@ repos:

ci:
autoupdate_schedule: weekly
skip: [frappe-semgrep-rules]
skip: [frappe-semgrep-rules, full-repository-check]
submodules: false
22 changes: 0 additions & 22 deletions .releaserc.json

This file was deleted.

32 changes: 31 additions & 1 deletion csf_tz/vfd_support/sales_invoice.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,37 @@ def get_item_inclusive_amount(item):

@erpnext.allow_regional
def get_itemised_tax_breakup_data(doc):
return get_itemised_tax(doc)
itemised_tax = get_itemised_tax(doc)
return itemised_tax


def get_itemised_tax(doc, with_tax_account=False):
itemised_tax = {}
for row in doc.get("_item_wise_tax_details") or []:
item = row.get("item")
tax = row.get("tax")
if not item or not tax:
continue
if getattr(tax, "category", None) and tax.category == "Valuation":
continue

item_code = item.item_code or item.item_name
tax_info = itemised_tax.setdefault(item_code, frappe._dict()).setdefault(
tax.description, frappe._dict(tax_rate=flt(row.rate), tax_amount=0.0)
)
tax_info.tax_amount += flt(row.amount)

if with_tax_account:
tax_info.tax_account = tax.account_head

return itemised_tax


def get_rounded_tax_amount(itemised_tax, precision):
# Rounding based on tax_amount precision
for taxes in itemised_tax.values():
for tax_account in taxes:
taxes[tax_account]["tax_amount"] = flt(taxes[tax_account]["tax_amount"], precision)


def remove_special_characters(text):
Expand Down
5 changes: 5 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ dependencies = [
"selcom-apigw-client",
]

[project.optional-dependencies]
dev = [
"pre-commit",
]

[build-system]
requires = ["flit_core >=3.4,<4"]
build-backend = "flit_core.buildapi"
Expand Down
16 changes: 16 additions & 0 deletions scripts/setup-git-hooks.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/usr/bin/env bash
set -euo pipefail

cd "$(dirname "${BASH_SOURCE[0]}")/.."

if ! command -v pre-commit >/dev/null 2>&1; then
if command -v uv >/dev/null 2>&1; then
uv tool install pre-commit
elif command -v pipx >/dev/null 2>&1; then
pipx install pre-commit
else
pip install --user pre-commit
fi
fi

pre-commit install --install-hooks --overwrite
Loading