Odoo to PostgreSQL Sync Backend — Python, SQLAlchemy, Docker - #17
Open
Mohammad77416 wants to merge 2 commits into
Open
Odoo to PostgreSQL Sync Backend — Python, SQLAlchemy, Docker#17Mohammad77416 wants to merge 2 commits into
Mohammad77416 wants to merge 2 commits into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
توضیح مختصر راهحل
این پروژه یک Backend با Python پیادهسازی میکند که اطلاعات Contacts،
Products، Sale Orders و Sale Order Lines را از Odoo (از طریق XML-RPC)
دریافت کرده، به مدل داخلی تبدیل میکند، و در PostgreSQL ذخیره میکند.
معماری بهصورت لایهای طراحی شده:
سیستم کاملاً Idempotent است (اجرای مکرر دادهی تکراری نمیسازد)، خطای هر
رکورد بهصورت مجزا مدیریت میشود (بدون توقف کل فرآیند)، و شامل Retry
Mechanism، Structured Logging (Database + File + Standard Output)،
Incremental Sync و Graceful Shutdown است.
نحوه اجرای پروژه
راهنمای کامل و قدمبهقدم (شامل روش Docker و روش دستی) در
docs/USER_DOCUMENTATION.mdموجود است.خلاصه:
سپس یک دیتابیس Odoo (نام:
sync_test) از طریقhttp://localhost:8069ساخته و اپ Sales نصب میشود (این تنها مرحلهی دستی است، چون Odoo تازهنصبشده
هیچ دیتابیسی ندارد). سپس:
نحوه اجرای تستها
docker compose exec app pytest -v۲۴ Unit Test (Mapper، Repository، Service Layer، Retry) با استفاده از
pytestوunittest.mockنوشته شده که بدون نیاز به Odoo یا PostgreSQLواقعی اجرا میشوند (از SQLite در حافظه استفاده میکنند). برای مشاهدهی
Test Coverage:
docker compose exec app pytest --cov=src --cov-report=term-missingتصمیمات مهم معماری
جزئیات کامل در
docs/TECHNICAL_DOCUMENTATION.mdموجود است. مهمترین تصمیمات:
odoo_idقبل از insert (سطح اپلیکیشن) +UNIQUE constraintرویodoo_id(سطح دیتابیس).session.begin_nested()): خطای یک رکوردفقط تغییرات همان رکورد را rollback میکند، نه کل Transaction — پردازش
رکوردهای بعدی ادامه پیدا میکند.
SessionوOdooClientاز بیرون بهRepository/Service تزریق میشوند؛ این امر تستنویسی با Mock را ساده کرده.
BaseMapper,BaseRepository,BaseSyncServiceقرارداد مشترک تعریف میکنند و افزودن Entity جدید راساده میکنند.
ConnectionError,OSError)با Exponential Backoff تلاش مجدد میشوند؛ خطاهای منطقی/برنامهنویسی
(
ValueError,TypeError, ...) هرگز retry نمیشوند.write_dateدر Odoo و آخرینزمان Sync موفق ثبتشده در جدول
sync_runs.محدودیتهای شناختهشده
پشتیبانی میشود).
دانسته شده) و به همین دلیل با تنها یک
docker compose upبهطور کاملخودکار نمیشود؛ سرویس
appپس از بالا آمدن، Migration را خودکار اجرامیکند و برای اجرای Sync واقعی از
docker compose exec app ...استفادهمیشود.
وجود دارد (برای اجرای تکی/زمانبندیشده مشکلی ایجاد نمیکند).
واقعی در پایپلاین CI) به دلیل محدودیت زمانی نوشته نشده و اسکریپتهای
scripts/test_*.pyاین نقش را بهصورت دستی ایفا میکنند.