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
8 changes: 4 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ on:
pull_request:

concurrency:
group: develop-sa_ecom-${{ github.event.number }}
group: develop-ls_shop-${{ github.event.number }}
cancel-in-progress: true

jobs:
Expand Down Expand Up @@ -90,15 +90,15 @@ jobs:
- name: Install
working-directory: /home/runner/frappe-bench
run: |
bench get-app sa_ecom $GITHUB_WORKSPACE
bench get-app ls_shop $GITHUB_WORKSPACE
bench setup requirements --dev
bench get-app erpnext
bench get-app payments
bench get-app webshop
bench new-site --db-root-password root --admin-password admin test_site
bench --site test_site install-app erpnext
bench --site test_site install-app webshop
bench --site test_site install-app sa_ecom
bench --site test_site install-app ls_shop
bench build
env:
CI: 'Yes'
Expand All @@ -107,6 +107,6 @@ jobs:
working-directory: /home/runner/frappe-bench
run: |
bench --site test_site set-config allow_tests true
bench --site test_site run-tests --app sa_ecom
bench --site test_site run-tests --app ls_shop
env:
TYPE: server
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,5 @@ jspm_packages/

# Aider AI Chat
.aider*

ls_shop/public/css/tailwind.css
60 changes: 5 additions & 55 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,22 +1,4 @@
exclude: 'node_modules|.git'
default_stages: [pre-commit]
fail_fast: false


repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v5.0.0
hooks:
- id: trailing-whitespace
files: "ls_shop.*"
exclude: ".*json$|.*txt$|.*csv|.*md|.*svg"
- id: check-merge-conflict
- id: check-ast
- id: check-json
- id: check-toml
- id: check-yaml
- id: debug-statements

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.8.1
hooks:
Expand All @@ -30,40 +12,8 @@ repos:
- id: ruff-format
name: "Run ruff formatter"

- repo: https://github.com/pre-commit/mirrors-prettier
rev: v2.7.1
hooks:
- id: prettier
types_or: [javascript, vue, scss]
# Ignore any files that might contain jinja / bundles
exclude: |
(?x)^(
ls_shop/public/dist/.*|
.*node_modules.*|
.*boilerplate.*|
ls_shop/templates/includes/.*|
ls_shop/public/js/lib/.*
)$


- repo: https://github.com/pre-commit/mirrors-eslint
rev: v8.44.0
hooks:
- id: eslint
types_or: [javascript]
args: ['--quiet']
# Ignore any files that might contain jinja / bundles
exclude: |
(?x)^(
ls_shop/public/dist/.*|
cypress/.*|
.*node_modules.*|
.*boilerplate.*|
ls_shop/templates/includes/.*|
ls_shop/public/js/lib/.*
)$

ci:
autoupdate_schedule: weekly
skip: []
submodules: false
- repo: https://github.com/biomejs/pre-commit
rev: "v0.1.0" # Use the sha / tag you want to point at
hooks:
- id: biome-check
additional_dependencies: ["@biomejs/biome@1.4.1"]
30 changes: 30 additions & 0 deletions biome.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"$schema": "https://biomejs.dev/schemas/1.9.4/schema.json",
"vcs": {
"enabled": false,
"clientKind": "git",
"useIgnoreFile": false
},
"files": {
"ignoreUnknown": false,
"ignore": ["public/js/vendor/**/*"]
},
"formatter": {
"enabled": true,
"indentStyle": "tab"
},
"organizeImports": {
"enabled": true
},
"linter": {
"enabled": true,
"rules": {
"recommended": true
}
},
"javascript": {
"formatter": {
"quoteStyle": "single"
}
}
}
27 changes: 27 additions & 0 deletions commitlint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
module.exports = {
parserPreset: 'conventional-changelog-conventionalcommits',
rules: {
'subject-empty': [2, 'never'],
'type-case': [2, 'always', 'lower-case'],
'type-empty': [2, 'never'],
'type-enum': [
2,
'always',
[
'build',
'chore',
'ci',
'docs',
'feat',
'fix',
'perf',
'refactor',
'revert',
'style',
'test',
'deprecate', // deprecation decision
'wip',
],
],
},
};
12 changes: 3 additions & 9 deletions ls_shop/api/cart.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,11 @@
@frappe.whitelist(allow_guest=True)
def get_detail_for_cart_items(items):
stock_data = {}
warehouse = frappe.get_cached_value(
"Lifestyle Settings", "Lifestyle Settings", "ecommerce_warehouse"
)
warehouse = frappe.get_cached_value("Lifestyle Settings", "Lifestyle Settings", "ecommerce_warehouse")
default_price_list = frappe.get_cached_value(
"Lifestyle Settings", "Lifestyle Settings", "default_price_list"
)
sale_price_list = frappe.get_cached_value(
"Lifestyle Settings", "Lifestyle Settings", "sale_price_list"
)
sale_price_list = frappe.get_cached_value("Lifestyle Settings", "Lifestyle Settings", "sale_price_list")
default_price = 0
sale_price = 0
for entry in items:
Expand Down Expand Up @@ -61,9 +57,7 @@ def get_detail_for_cart_items(items):
@frappe.whitelist(allow_guest=True)
def validate_cart_stock(items):
errors = []
warehouse = frappe.get_cached_value(
"Lifestyle Settings", "Lifestyle Settings", "ecommerce_warehouse"
)
warehouse = frappe.get_cached_value("Lifestyle Settings", "Lifestyle Settings", "ecommerce_warehouse")
for entry in items:
item_code = entry.get("variant", {}).get("item_code")
item_name = entry.get("item", {}).get("display_name")
Expand Down
56 changes: 14 additions & 42 deletions ls_shop/api/payments.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@ class PaymentMode(StrEnum):
@frappe.whitelist()
def initiate_checkout_with_mode(payment_mode: PaymentMode):
lifestyle_settings = frappe.get_cached_doc("Lifestyle Settings")
if payment_mode not in set(PaymentMode) or not lifestyle_settings.get(
f"{payment_mode}_enabled"
):
if payment_mode not in set(PaymentMode) or not lifestyle_settings.get(f"{payment_mode}_enabled"):
frappe.throw(frappe._("Please select a valid payment mode."))

quotation = _get_cart_quotation()
Expand All @@ -47,9 +45,7 @@ def initiate_checkout_with_mode(payment_mode: PaymentMode):
{
"doctype": "Telr Payment Request",
"amount": quotation.rounded_total,
"currency_code": "SAR"
if frappe.conf.developer_mode
else quotation.currency,
"currency_code": "SAR" if frappe.conf.developer_mode else quotation.currency,
"ref_doctype": quotation.doctype,
"ref_docname": quotation.name,
"customer_ref": quotation.party_name,
Expand All @@ -66,9 +62,7 @@ def initiate_checkout_with_mode(payment_mode: PaymentMode):
{
"doctype": "Tabby Payment Request",
"amount": quotation.rounded_total,
"currency_code": "SAR"
if frappe.conf.developer_mode
else quotation.currency,
"currency_code": "SAR" if frappe.conf.developer_mode else quotation.currency,
"ref_doctype": quotation.doctype,
"ref_docname": quotation.name,
"customer_ref": quotation.party_name,
Expand All @@ -93,9 +87,7 @@ def generate_quotation_for_cart(cart: dict):

def get_quotation_for_cart(cart: dict):
unsaved_quotation_doc = _get_cart_quotation()
sale_price_list = frappe.get_cached_value(
"Lifestyle Settings", "Lifestyle Settings", "sale_price_list"
)
sale_price_list = frappe.get_cached_value("Lifestyle Settings", "Lifestyle Settings", "sale_price_list")
ecommerce_warehouse = frappe.get_cached_value(
"Lifestyle Settings", "Lifestyle Settings", "ecommerce_warehouse"
)
Expand All @@ -119,9 +111,7 @@ def get_quotation_for_cart(cart: dict):


def set_charges(quotation):
shipping_rule = frappe.get_cached_value(
"Lifestyle Settings", "Lifestyle Settings", "shipping_rule"
)
shipping_rule = frappe.get_cached_value("Lifestyle Settings", "Lifestyle Settings", "shipping_rule")
if shipping_rule:
quotation.shipping_rule = shipping_rule
quotation.run_method("apply_shipping_rule")
Expand All @@ -130,9 +120,7 @@ def set_charges(quotation):

def set_cod_charges(quotation):
cod_charges_applicable_below, cod_charge = get_cod_configuration()
account_head = frappe.get_cached_value(
"Lifestyle Settings", "Lifestyle Settings", "charge_account_head"
)
account_head = frappe.get_cached_value("Lifestyle Settings", "Lifestyle Settings", "charge_account_head")
if not cod_charges_applicable_below or not cod_charge:
return
if cod_charges_applicable_below < quotation.rounded_total:
Expand Down Expand Up @@ -224,23 +212,17 @@ def confirm_payment(payment_mode: PaymentMode, reference_id: str):

if payment_request.status == "Paid":
quote_name = payment_request.ref_docname
submit_quotation_and_create_order(
quote_name, payment_mode, payment_request.telr_order_ref
)
submit_quotation_and_create_order(quote_name, payment_mode, payment_request.telr_order_ref)
return payment_request

if payment_mode == PaymentMode.TABBY:
payment_request = frappe.get_doc(
"Tabby Payment Request", {"tabby_payment_id": reference_id}
)
payment_request = frappe.get_doc("Tabby Payment Request", {"tabby_payment_id": reference_id})
payment_request.sync_status()

if payment_request.status == "AUTHORIZED":
quote_name = payment_request.ref_docname
payment_request.capture_payment()
submit_quotation_and_create_order(
quote_name, payment_mode, payment_request.tabby_order_ref
)
submit_quotation_and_create_order(quote_name, payment_mode, payment_request.tabby_order_ref)

return payment_request

Expand All @@ -257,23 +239,17 @@ def submit_quotation_and_create_order(

so = _make_sales_order(quote_name, ignore_permissions=True)
so.custom_ecommerce_payment_mode = (
payment_mode.title()
if not payment_mode == payment_mode.COD
else payment_mode.upper()
payment_mode.title() if not payment_mode == payment_mode.COD else payment_mode.upper()
)
so.flags.ignore_permissions = True
so.insert()

if payment_mode != payment_mode.COD:
so.submit()
payment_request_doctype = (
"Telr Payment Request"
if payment_mode == PaymentMode.TELR
else "Tabby Payment Request"
)
payment_order_ref_field = (
"telr_order_ref" if payment_mode == PaymentMode.TELR else "tabby_order_ref"
"Telr Payment Request" if payment_mode == PaymentMode.TELR else "Tabby Payment Request"
)
payment_order_ref_field = "telr_order_ref" if payment_mode == PaymentMode.TELR else "tabby_order_ref"
payment_request = frappe.get_doc(
payment_request_doctype, {payment_order_ref_field: payment_reference}
)
Expand All @@ -282,9 +258,7 @@ def submit_quotation_and_create_order(
payment_request.ref_doctype = "Sales Order"
payment_request.save()
frappe.set_user("Administrator")
pe = get_payment_entry(
"Sales Order", so.name, reference_date=frappe.utils.today()
)
pe = get_payment_entry("Sales Order", so.name, reference_date=frappe.utils.today())
pe.flags.ignore_permissions = True
pe.mode_of_payment = payment_mode.title()
pe.reference_no = payment_reference
Expand All @@ -297,9 +271,7 @@ def apply_coupon_code(applied_code):
quotation = True
if not applied_code:
frappe.throw(frappe._("Please enter a coupon code"))
coupon_name = frappe.db.get_value(
"Coupon Code", {"coupon_code": applied_code}, "name"
)
coupon_name = frappe.db.get_value("Coupon Code", {"coupon_code": applied_code}, "name")
if not coupon_name:
frappe.throw(frappe._("Please enter a valid coupon code"))
validate_coupon_code(coupon_name)
Expand Down
10 changes: 2 additions & 8 deletions ls_shop/api/return.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,7 @@ def return_items(sales_order_id, items):
)

if not return_dn.items:
frappe.throw(
frappe._(
"None of the items to return were found in the original Delivery Note."
)
)
frappe.throw(frappe._("None of the items to return were found in the original Delivery Note."))

return_dn.insert(ignore_permissions=True)

Expand Down Expand Up @@ -95,9 +91,7 @@ def get_returned_items(sales_order_id):

returned_draft_item_codes = [item.item_code for item in returned_items_in_draft]

is_fully_returned = all(
item_code in returned_item_codes for item_code in ordered_item_codes
)
is_fully_returned = all(item_code in returned_item_codes for item_code in ordered_item_codes)
partially_returned = len(returned_item_codes) > 0 and not is_fully_returned

return {
Expand Down
8 changes: 2 additions & 6 deletions ls_shop/api/translation.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@

@frappe.whitelist(allow_guest=True)
def get_translations():
translations = frappe.db.get_all(
"Translation", fields=["language", "source_text", "translated_text"]
)
translations = frappe.db.get_all("Translation", fields=["language", "source_text", "translated_text"])

translation_dict = {}

Expand All @@ -17,8 +15,6 @@ def get_translations():
if lang not in translation_dict:
translation_dict[lang] = {}
for i in range(min(len(source_texts), len(translated_texts))):
translation_dict[lang][source_texts[i].strip()] = translated_texts[
i
].strip()
translation_dict[lang][source_texts[i].strip()] = translated_texts[i].strip()

return translation_dict
Loading