From f568c458e5927ed177b5d2f4f947039eca7f102b Mon Sep 17 00:00:00 2001 From: Seyyed Date: Wed, 11 Nov 2026 19:56:38 +0330 Subject: [PATCH 1/2] test(returns): characterize tax, shipping and empty refunds --- ...return_empty_lines_characterization_h22.py | 20 +++++++++++++++++++ ...st_return_shipping_characterization_h20.py | 20 +++++++++++++++++++ .../test_return_tax_characterization_h19.py | 19 ++++++++++++++++++ 3 files changed, 59 insertions(+) create mode 100644 hesabixAPI/tests/test_return_empty_lines_characterization_h22.py create mode 100644 hesabixAPI/tests/test_return_shipping_characterization_h20.py create mode 100644 hesabixAPI/tests/test_return_tax_characterization_h19.py diff --git a/hesabixAPI/tests/test_return_empty_lines_characterization_h22.py b/hesabixAPI/tests/test_return_empty_lines_characterization_h22.py new file mode 100644 index 00000000..d909c769 --- /dev/null +++ b/hesabixAPI/tests/test_return_empty_lines_characterization_h22.py @@ -0,0 +1,20 @@ +from pathlib import Path + +import pytest + +from adapters.db import models +from app.core.responses import ApiError +from app.services.invoice_service import create_invoice +from tests.test_invoice_cancel_zero_cost import sale as sale + + +def test_empty_woo_return_is_skipped_and_invoice_api_rejects_empty_lines(sale): + path = Path(__file__).parents[2] / "extraScripts/arcwoc/admin/services/class-hesabix-v2-sales-return-service.php" + guard = path.read_text(encoding="utf-8").split("if (empty($payload['lines']) && empty($payload['extra_info']['invoice_adjustments']))", 1)[1] + assert all(f"'{key}' => true" in guard.split("$api->create_invoice($payload)", 1)[0] for key in ("success", "skipped")) + db, _ = sale + tables = (models.Document, models.DocumentLine, models.WarehouseDocument, models.WarehouseDocumentLine) + before = [db.query(model).count() for model in tables] + with pytest.raises(ApiError, match="400:.*LINES_REQUIRED"): + create_invoice(db, 1, 1, {"invoice_type": "invoice_sales_return", "currency_id": 1, "lines": []}, commit=False) + assert [db.query(model).count() for model in tables] == before diff --git a/hesabixAPI/tests/test_return_shipping_characterization_h20.py b/hesabixAPI/tests/test_return_shipping_characterization_h20.py new file mode 100644 index 00000000..fce88f8d --- /dev/null +++ b/hesabixAPI/tests/test_return_shipping_characterization_h20.py @@ -0,0 +1,20 @@ +from pathlib import Path + +import pytest + +from app.core.responses import ApiError +from app.services import invoice_adjustments_service as adjustments + + +def test_woo_shipping_selection_and_return_adjustment_rejection(): + path = Path(__file__).parents[2] / "extraScripts/arcwoc/admin/services/class-hesabix-v2-sales-return-service.php" + source = path.read_text(encoding="utf-8") + assert all(f"$kind === '{kind}' && !$include_{flag}" in source for kind, flag in (("shipping", "shipping"), ("fee", "fees"))) + assert "$include_shipping = empty($consumed['kind:shipping'])" in source + assert adjustments.payable_total_from_totals_dict({"net": 500, "adjustments_net": 50}) == 550 + policy = source.split("private static function refund_includes_shipping", 1)[1].split("private static function", 1)[0] + assert "get_items('shipping')" in policy and "return false;" in policy + shipping = {"kind": "subtraction", "amount": 50, "account_id": 1, "source": "woocommerce_shipping"} + with pytest.raises(ApiError) as error: + adjustments.normalize_invoice_adjustments(None, 1, "invoice_sales_return", [shipping]) + assert (error.value.code, error.value.status_code) == ("INVOICE_ADJUSTMENTS_NOT_ALLOWED", 400) diff --git a/hesabixAPI/tests/test_return_tax_characterization_h19.py b/hesabixAPI/tests/test_return_tax_characterization_h19.py new file mode 100644 index 00000000..fc6a06a9 --- /dev/null +++ b/hesabixAPI/tests/test_return_tax_characterization_h19.py @@ -0,0 +1,19 @@ +from pathlib import Path + +from app.services.invoice_service import _extract_totals_from_lines + + +def test_partial_woo_return_tax_formula_and_invoice_totals(): + plugin = Path(__file__).resolve().parents[2] / "extraScripts/arcwoc/admin/services" + source = (plugin / "class-hesabix-v2-sales-return-service.php").read_text(encoding="utf-8") + scale = source.split("private static function scale_line_to_qty", 1)[1].split("private static function", 1)[0] + assert "$ratio = $take / $orig_qty;" in scale + assert "array('tax_amount', 'line_discount', 'line_total', 'discount_value')" in scale + assert "sanitize_price((float) $ei[ $k ] * $ratio)" in scale + sold = {"quantity": 2, "extra_info": {"unit_price": 250, "tax_rate": 10, "tax_amount": 50, "line_total": 550}} + sale_totals = _extract_totals_from_lines([sold]) + assert (sale_totals["tax"], sale_totals["net"]) == (50, 550) + ratio = 1 / sold["quantity"] + info = dict(sold["extra_info"], tax_amount=50 * ratio, line_total=550 * ratio) + returned = _extract_totals_from_lines([{"quantity": 1, "extra_info": info}]) + assert (returned["tax"], returned["net"]) == (25, 275) -- 2.43.0 From 2b13714b7d5ca68c7d1a78f88acf6e2479623695 Mon Sep 17 00:00:00 2001 From: Seyyed Date: Wed, 11 Nov 2026 19:57:27 +0330 Subject: [PATCH 2/2] docs(progress): record return characterizations and open policy decisions --- docs/PRODUCT_VARIANTS_TEAM_BASED_PROGRESS.fa.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/docs/PRODUCT_VARIANTS_TEAM_BASED_PROGRESS.fa.md b/docs/PRODUCT_VARIANTS_TEAM_BASED_PROGRESS.fa.md index cb8571f5..a1165707 100644 --- a/docs/PRODUCT_VARIANTS_TEAM_BASED_PROGRESS.fa.md +++ b/docs/PRODUCT_VARIANTS_TEAM_BASED_PROGRESS.fa.md @@ -19,6 +19,9 @@ | P01 | تفکیک cost_price | codex/team-base-02-cost-currency-basis | 1a003e17 | ۲۰۲۶-۱۱-۰۶ | ✅ merge شده (#43) | | C04 | حفظ صفر معلوم پس از لغو تنها حوالهٔ خروج | codex/team-base-03-zero-cost-cancel | 4867aaa3586c62794746c723c1cc4df61c19c9ad | ۲۰۲۶-۱۱-۱۱ | 🟢 PR ارسال شد | | H35 | تخصیص هزینهٔ هر حواله برای لغو جزئیِ مبالغ متفاوت | — | — | — | ⏳ در انتظار (وابسته به فاز ۲ Native) | +| H19 | مالیات برگشت جزئی | codex/team-base-07-return-characterizations | f568c458 | ۲۰۲۶-۱۱-۱۱ | ✅ characterization در team base، آمادهٔ PR | +| H20 | برگشت حمل و fee | codex/team-base-07-return-characterizations | f568c458 | ۲۰۲۶-۱۱-۱۱ | ✅ characterization در team base، تصمیم طراحی باز | +| H22 | برگشت با خطوط خالی | codex/team-base-07-return-characterizations | f568c458 | ۲۰۲۶-۱۱-۱۱ | ✅ characterization در team base، تفاوت با Unified ثبت شد | ## مرحلهٔ ۰۱ — H15: زمان ارسال موجودی ووکامرس @@ -74,6 +77,13 @@ python -m pytest -q -p no:cacheprovider tests/test_invoice_cost_currency_basis.p - اجرای کامل ۲۲۳۲ آزمون جمع‌آوری کرد و پس از ۳۰۰ ثانیه در `test_ai_channel_stream.py` متوقف شد. اجرای پایه نیز در همان آزمون به سقف رسید. - شاخه به فورک ارسال شد. [صفحهٔ ایجاد PR در مخزن تیم](https://source.hesabix.ir/hesabix/arc/compare/master...Seyyed:codex/team-base-03-zero-cost-cancel). +## characterization برگشت در مبنای تیم + +- H19: در Mapper، مالیات و مبلغ خط برگشت به نسبت تعداد تغییر می‌کند. بازپخش فروش دو واحد با مبلغ ۵۵۰ و مالیات ۵۰، برای برگشت یک واحد مبلغ ۲۷۵ و مالیات ۲۵ داد. +- H20: فروش کالا ۵۰۰ با حمل ۵۰، قابل پرداخت ۵۵۰ دارد. در برگشت کالای جزئی که حمل در refund نیامده، حمل صفر است. برگشت کاملِ مانده می‌تواند حمل باقی‌ماندهٔ ۵۰ را در payload نگه دارد. API تعدیل سربرگ در فاکتور برگشت فروش را با `INVOICE_ADJUSTMENTS_NOT_ALLOWED` و ۴۰۰ رد می‌کند. سیاست حمل و fee در فاز ۲ یا PR مستقل بررسی می‌شود. +- H22: افزونه payload خالیِ فاقد تعدیل را پیش از API با `success=true, skipped=true` پایان می‌دهد. CREATE مستقیم با `lines=[]` در SQLite خطای `LINES_REQUIRED` و ۴۰۰ داد و تعداد اسناد، خطوط GL و خطوط انبار ثابت ماند. معادل وضعیت `applied` در Unified در این مسیر وجود ندارد. قرارداد وضعیت رویداد در فاز ۲ بررسی می‌شود. +- ۵۷ آزمون مرتبط موفق شدند. شاخه‌های PHP از روی سورس بررسی شدند و runtime PHP اجرا نشد. تست H22 از سرویس واقعی و SQLite حافظه‌ای استفاده کرد و به PostgreSQL نیاز نداشت. + ## موارد منتقل‌نشده و ترتیب بازبینی | دسته | وضعیت انتقال به مبنای تیم | اقدام لازم | @@ -98,3 +108,4 @@ python -m pytest -q -p no:cacheprovider tests/test_invoice_cost_currency_basis.p - ۲۰۲۶-۱۱-۰۶: مبنا به کد رسمی تیم تغییر کرد؛ master محلی تا `2b5c6a24` fast-forward شد. H15 به‌عنوان اولین اصلاح مستقل با بازتولید قبل و ۱۵ آزمون موفق پس از اصلاح منتقل شد. شاخهٔ Unified قدیمی و تست‌های آن تغییر نکردند. - ۲۰۲۶-۱۱-۰۷: H15 در `master` merge شد (#42). P01 (`cost_currency_basis` برای `cost_price`) پس از حل تداخل همین سند پیشرفت در `master` merge شد (#43). - ۲۰۲۶-۱۱-۱۱: C04 برای تک‌خروج اصلاح شد. H35 در C04 کشف شد؛ با معرفی `VariantCostConsumption` در فاز ۲ Native حل می‌شود. تا آن زمان، GL برای چند-خروجی همان رفتار قبلی را دارد؛ تغییر نمی‌کند. +- ۲۰۲۶-۱۱-۱۱: H19 با audit هم‌خوان بود. در H20 برگشت کاملِ مانده در افزونه می‌تواند حمل را نگه دارد و API تعدیل سربرگ را رد می‌کند. H22 به شکل skipped در افزونه و ۴۰۰ در API مشاهده شد. سه رفتار مستند شدند. -- 2.43.0