review code haravan connector and yuhtfarm haravan (vibe-kanban) - #24
Merged
Conversation
…sing several critical issues to improve its reliability and performance: 1. **Optimized Webhook Processing (`queue_job`)**: - I moved the webhook processing logic from `webhook_controller.py` into the `haravan.webhook` model. - The controller now delegates execution using Odoo's `.with_delay()` which leverages `queue_job`. This ensures that incoming webhooks return a 200 OK immediately and process payload in the background, preventing slow transactions or timeouts from breaking webhook integrations. 2. **Fixed Lexicographical Sorting Bugs**: - In both `haravan_product.py` and `haravan_order.py`, the `since_id` calculation incorrectly queried Odoo string fields (`haravan_product_id` and `haravan_order_id`) with `desc` and `asc` respectively. Because Haravan IDs are huge numbers stored as strings, ordering lexicographically causes issues (e.g. `'9'` > `'10'`). - I updated the queries to order by Odoo's internal `id desc` instead, securely fetching the most recently imported mapping to determine the correct `since_id`. 3. **Multi-Location Inventory Support**: - The stock push methods (`_upload_stock_to_haravan` in `haravan_config.py` and `_push_inventory_to_haravan` in `haravan_product.py`) were hardcoded to only pull from the first index (`mapping[0]`). - I refactored these functions to iterate over all valid location mappings assigned to a configuration so it correctly aggregates or pushes per-location inventory. 4. **Code Cleanups**: - Refactored `_get_api_url` in `haravan_config.py` to correctly utilize the globally defined `HARAVAN_API_BASE` constant instead of redefining the string internally.
…hronization functions (`sync_orders_from_haravan`, `sync_products_from_haravan`, `sync_customers_from_haravan`, and `sync_revenue_from_haravan`). Here is a summary of the critical logic bugs fixed and the structural improvements made: 1. **Decoupled Sync Timestamps (`last_sync_date`)**: - **Issue:** Previously, `haravan.config` used a single `last_sync_date` for products, orders, and customers. If orders synced first, it would advance `last_sync_date`. When products synced next, they would use the new timestamp, completely missing any products that were updated in Haravan between the previous sync cycle and the order sync. - **Fix:** Introduced separate `last_order_sync_date`, `last_product_sync_date`, and `last_customer_sync_date` fields to the model and views, ensuring independent and accurate sync cycles. 2. **Fixed Flawed Sort Order (`id desc` vs Lexicographical)**: - **Issue:** The fallback mechanism fetched the `since_id` by sorting string fields (`haravan_order_id desc`, `haravan_product_id desc`). In SQL, sorting numeric strings lexicographically evaluates "999" as greater than "1000", meaning the system frequently pulled the wrong `since_id`. - **Fix:** Updated queries to accurately sort by the internal database sequence `order="id desc"`. 3. **Corrected Incremental Sync Parameter Logic (`since_id` vs `updated_at_min`)**: - **Issue:** The sync algorithms were simultaneously querying Haravan using both `since_id` and `updated_at_min` (and using `page`), which resulted in skipped updates (e.g., if an older order was updated to "paid", its ID is lower than `since_id`, thus the API would omit it). - **Fix:** Refactored the methods to strictly prioritize `updated_at_min`. `since_id` is now exclusively used as a fallback if the sync runs for the very first time. Additionally, updated `sync_revenue` to use `updated_at_min` instead of `created_at_min` to capture orders that get fulfilled or paid later. 4. **Captured Pre-Sync Start Timestamps**: - **Issue:** The functions did not update the `last_sync_date` or updated it inaccurately at the end of execution. Any records updated in Haravan while the sync process was actively running would be permanently missed. - **Fix:** Each sync function now tracks `sync_start = fields.Datetime.now()` at the exact moment execution begins. It writes this exact timestamp to the configuration when complete, guaranteeing 100% gapless coverage during the next sync run.
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.
No description provided.