Skip to content

Commit

Permalink
Merge pull request #4 from alyf-de/improve-periods
Browse files Browse the repository at this point in the history
  • Loading branch information
barredterra authored Sep 14, 2024
2 parents 629a6be + fafc39b commit 799d24b
Show file tree
Hide file tree
Showing 11 changed files with 417 additions and 63 deletions.
37 changes: 37 additions & 0 deletions .github/helper/install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/bin/bash

set -e

cd ~ || exit

sudo apt update && sudo apt install redis-server libcups2-dev

pip install frappe-bench

git clone https://github.com/frappe/frappe --branch version-15 --depth 1
bench init --skip-assets --frappe-path ~/frappe --python "$(which python)" frappe-bench

mysql --host 127.0.0.1 --port 3306 -u root -proot -e "SET GLOBAL character_set_server = 'utf8mb4'"
mysql --host 127.0.0.1 --port 3306 -u root -proot -e "SET GLOBAL collation_server = 'utf8mb4_unicode_ci'"

mysql --host 127.0.0.1 --port 3306 -u root -proot -e "CREATE USER 'test_frappe'@'localhost' IDENTIFIED BY 'test_frappe'"
mysql --host 127.0.0.1 --port 3306 -u root -proot -e "CREATE DATABASE test_frappe"
mysql --host 127.0.0.1 --port 3306 -u root -proot -e "GRANT ALL PRIVILEGES ON \`test_frappe\`.* TO 'test_frappe'@'localhost'"

mysql --host 127.0.0.1 --port 3306 -u root -proot -e "FLUSH PRIVILEGES"

cd ~/frappe-bench || exit

sed -i 's/watch:/# watch:/g' Procfile
sed -i 's/schedule:/# schedule:/g' Procfile
sed -i 's/socketio:/# socketio:/g' Procfile
sed -i 's/redis_socketio:/# redis_socketio:/g' Procfile

bench get-app payments --branch version-15
bench get-app erpnext --branch version-15
bench get-app simple_subscription "${GITHUB_WORKSPACE}"

bench start &> bench_run_logs.txt &
bench new-site --db-root-password root --admin-password admin test_site --install-app erpnext
bench --site test_site install-app simple_subscription
bench setup requirements --dev
36 changes: 8 additions & 28 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,12 @@ name: "CodeQL"

on:
push:
branches: [ version-13 ]
branches: [ version-* ]
pull_request:
# The branches below must be a subset of the branches above
branches: [ version-13 ]
schedule:
- cron: '34 13 * * 0'

jobs:
analyze:
name: Analyze
name: Analyze (${{ matrix.language }})
runs-on: ubuntu-latest
permissions:
actions: read
Expand All @@ -32,39 +28,23 @@ jobs:
strategy:
fail-fast: false
matrix:
language: [ 'javascript', 'python' ]
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ]
# Learn more about CodeQL language support at https://git.io/codeql-language-support
language: [ 'javascript-typescript', 'python' ]

steps:
- name: Checkout repository
uses: actions/checkout@v2
uses: actions/checkout@v4

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v1
uses: github/codeql-action/init@v3
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
# By default, queries listed here will override any specified in a config file.
# Prefix the list here with "+" to use these queries and those in the config file.
# queries: ./path/to/local/query, your-org/your-repo/queries@main

# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
uses: github/codeql-action/autobuild@v1

# ℹ️ Command-line programs to run using the OS shell.
# 📚 https://git.io/JvXDl

# ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
# and modify them (or add more) to build your code if your project
# uses a compiled language

#- run: |
# make bootstrap
# make release

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v1
uses: github/codeql-action/analyze@v3
with:
category: "/language:${{matrix.language}}"
89 changes: 89 additions & 0 deletions .github/workflows/server-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@

name: Server

on:
push:
branches:
- version-14
- version-15
pull_request:

concurrency:
group: version-15-simple_subscription-${{ github.event.number }}
cancel-in-progress: true

jobs:
tests:
name: Unit Tests
runs-on: ubuntu-latest
timeout-minutes: 60
env:
NODE_ENV: "production"

strategy:
fail-fast: false

services:
mariadb:
image: mariadb:10.6
env:
MYSQL_ROOT_PASSWORD: root
ports:
- 3306:3306
options: --health-cmd="mysqladmin ping" --health-interval=5s --health-timeout=2s --health-retries=3

steps:
- name: Clone
uses: actions/checkout@v4

- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: '3.11'

- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: 18
check-latest: true

- name: Add to Hosts
run: |
echo "127.0.0.1 test_site" | sudo tee -a /etc/hosts
- name: Cache pip
uses: actions/cache@v3
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('**/*requirements.txt', '**/pyproject.toml', '**/setup.py', '**/setup.cfg') }}
restore-keys: |
${{ runner.os }}-pip-
${{ runner.os }}-
- name: Get yarn cache directory path
id: yarn-cache-dir-path
run: 'echo "::set-output name=dir::$(yarn cache dir)"'

- uses: actions/cache@v3
id: yarn-cache
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
- name: Install
run: |
bash ${GITHUB_WORKSPACE}/.github/helper/install.sh
- name: Run Tests
working-directory: /home/runner/frappe-bench
run: |
bench --site test_site set-config allow_tests true
bench --site test_site run-tests --app simple_subscription
env:
TYPE: server

- name: Show bench output
if: ${{ always() }}
run: cat ~/frappe-bench/bench_start.log || true
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ Easy setup: existing **Subscriptions** get copied from ERPNext (you have to canc
1. Create a new **Simple Subscription**
2. Select a _Customer_
3. Set a _Start Date_
4. Select if billing is based on _calendar months_ or _Start Date_
5. Select if billing is supposed to happen _at the beginning of period_ or _after end of period_
4. Select a _Frequency_
5. Add items to the table
6. Select a _Sales Taxes and Charges Template_
Expand All @@ -16,8 +18,8 @@ Easy setup: existing **Subscriptions** get copied from ERPNext (you have to canc

- Submit a **Simple Subscription** to start generating invoices.

- New invoices will automatically be generated on the first day of a period, for the previous period.
- If you need an invoice immediately, click the button "Create last {Monthly / Quarterly / Yearly} invoice".
- New invoices for the current period will automatically be generated once per day if they don't yet exist
- If you need an invoice immediately, click the button "Create current {Monthly / Quarterly / Yearly} invoice".

- Mark a **Simple Subscription** as _disabled_ to stop generating invoices.
- Duplicate a disabled **Simple Subscription** to change any values.
2 changes: 1 addition & 1 deletion simple_subscription/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@
# Testing
# -------

# before_tests = "simple_subscription.install.before_tests"
before_tests = "simple_subscription.utils.before_tests"

# Overriding Methods
# ------------------------------
Expand Down
4 changes: 2 additions & 2 deletions simple_subscription/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from frappe.custom.doctype.property_setter.property_setter import make_property_setter
from simple_subscription.simple_subscription.doctype.simple_subscription.simple_subscription import (
Frequency,
get_first_day_of_period
get_calendar_period
)


Expand Down Expand Up @@ -52,7 +52,7 @@ def create_simple_subscription(
):
simple_subscription = frappe.new_doc("Simple Subscription")
simple_subscription.customer = customer
simple_subscription.start_date = get_first_day_of_period(date.today(), frequency)
simple_subscription.start_date, _ = get_calendar_period(date.today(), frequency)
simple_subscription.frequency = frequency.name
simple_subscription.extend("items", items)
simple_subscription.taxes_and_charges = taxes_and_charges
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ frappe.ui.form.on("Simple Subscription", {
null,
"Frequency of Subscription"
);
frm.add_custom_button(__("Create last {0} invoice", [translated_frequency]), () =>
frm.add_custom_button(__("Create current {0} invoice", [translated_frequency]), () =>
frappe.call({
method:
"simple_subscription.simple_subscription.doctype.simple_subscription.simple_subscription.create_invoice_for_previous_period",
"simple_subscription.simple_subscription.doctype.simple_subscription.simple_subscription.create_current_invoice",
args: {
subscription_name: frm.doc.name,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
"customer_name",
"column_break_3",
"start_date",
"period_type",
"billing_time",
"frequency",
"disabled",
"section_break_5",
Expand Down Expand Up @@ -95,6 +97,20 @@
"fieldtype": "Link",
"label": "Company",
"options": "Company"
},
{
"default": "after end of period",
"fieldname": "billing_time",
"fieldtype": "Select",
"label": "Billing Time",
"options": "at beginning of period\nafter end of period"
},
{
"default": "calendar months",
"fieldname": "period_type",
"fieldtype": "Select",
"label": "Billing Period is based on",
"options": "calendar months\nstart date"
}
],
"is_submittable": 1,
Expand All @@ -104,7 +120,7 @@
"link_fieldname": "simple_subscription"
}
],
"modified": "2024-07-30 12:12:07.652994",
"modified": "2024-08-20 20:19:15.055024",
"modified_by": "Administrator",
"module": "Simple Subscription",
"name": "Simple Subscription",
Expand Down
Loading

0 comments on commit 799d24b

Please sign in to comment.