Skip to content

[ADD] currency_rate_update_BI: Add Bank Indonesia currency rate provider#215

Open
hitrosol wants to merge 2 commits into
OCA:16.0from
solusiaglis:16.0-add-currency_rate_update_BI
Open

[ADD] currency_rate_update_BI: Add Bank Indonesia currency rate provider#215
hitrosol wants to merge 2 commits into
OCA:16.0from
solusiaglis:16.0-add-currency_rate_update_BI

Conversation

@hitrosol

Copy link
Copy Markdown

Not sure if I should propose this to repo currency or l10n-indonesia.

Add new currency rate provider for Bank Indonesia (BI) Kurs Transaksi. This provider fetches official exchange rates from BI's webservice for 19 major currencies against IDR.

Features:

  • Support for BI Kurs Transaksi webservice (getSubKursLokal3)
  • Handles 19 currencies published by Bank Indonesia
  • Calculates cross-rates for non-IDR base currencies
  • Proper XML parsing of BI's SOAP DataSet response

Technical details:

  • Fetches buy/sell rates and computes middle rate
  • Handles nominal units (e.g., 100 for JPY)
  • Supports both IDR and foreign base currencies
  • Implements proper error handling and logging

@hitrosol hitrosol force-pushed the 16.0-add-currency_rate_update_BI branch 2 times, most recently from 6bc5064 to 6e2eba2 Compare February 11, 2026 02:53
Add new currency rate provider for Bank Indonesia (BI) Kurs Transaksi.
This provider fetches official exchange rates from BI's webservice for
19 major currencies against IDR.

Features:
- Support for BI Kurs Transaksi webservice (getSubKursLokal3)
- Handles 19 currencies published by Bank Indonesia
- Calculates cross-rates for non-IDR base currencies
- Proper XML parsing of BI's SOAP DataSet response

Technical details:
- Fetches buy/sell rates and computes middle rate
- Handles nominal units (e.g., 100 for JPY)
- Supports both IDR and foreign base currencies
- Implements proper error handling and logging
@hitrosol hitrosol force-pushed the 16.0-add-currency_rate_update_BI branch from 6e2eba2 to de89bf3 Compare February 11, 2026 02:58
@nurinayati

Copy link
Copy Markdown

LGTM

@nurinayati nurinayati left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Working OK and no issue

@pedrobaeza

Copy link
Copy Markdown
Member

As this is something specific of Indonesia, it should go into l10n-indonesia, not here.

When company base currency is USD (or any foreign currency supported
by BI), users can now select and get IDR exchange rates.
@hitrosol

Copy link
Copy Markdown
Author

@nurinayati There is improvement or fix to use this module to download the ex. rate for non IDR base currency. I will move this to l10n-Indonesia after this

Dear @pedrobaeza, the l10n-indonesia repository has not been active for several years. Our company is planning to develop several additional modules in that repository. Would it be possible to assign me as a maintainer of that repository?

Thanks

@pedrobaeza

Copy link
Copy Markdown
Member

Please do the request at https://github.com/OCA/repo-maintainer-conf, and I think it can be possible if no other maintainers.

@marcos-mendez marcos-mendez left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Automated Review -- Tests Failed

1. Root Cause

The test failure is due to a database connection error (Connection to the database failed) during the Odoo server startup. This indicates that the test environment is misconfigured or the database is unreachable, not a problem in the module code itself.

2. Suggested Fix

No code fix is needed for the test failure — this is an infrastructure or test environment issue. However, to prevent such failures in the future:

  • Ensure the test database is correctly initialized and accessible.
  • Verify that the runboat configuration in the PR's CI setup properly sets up the database connection.

3. Additional Code Issues

  • Missing __all__ in __init__.py: The currency_rate_update_BI/__init__.py file does not define __all__, which is a best practice for explicit imports.

    • File: currency_rate_update_BI/__init__.py
    • Suggestion: Add __all__ = ['post_init_hook', 'models'] for clarity and consistency.
  • Insecure use of urlopen in _fetch_bi_rates: The code uses urlopen without SSL context validation, which may be insecure.

    • File: currency_rate_update_BI/models/res_currency_rate_provider_BI.py
    • Suggestion: Add contextlib.closing or use urllib.request.urlopen with a proper SSL context for production use (though this is a low-priority improvement for now).
  • Potential KeyError in _convert_foreign_base_rates: If base_currency is not present in rates for a given date, the loop continues, but this may silently skip valid entries.

    • File: currency_rate_update_BI/models/res_currency_rate_provider_BI.py
    • Lines: 220–229
    • Suggestion: Log a warning or raise an error if base currency is missing, to ensure data integrity.

4. Test Improvements

To better test this module, add the following test cases using OCA patterns:

Test Cases:

  1. Test post_init_hook:

    • Type: SavepointCase
    • Purpose: Ensure stale res_currency_rate records are removed correctly.
    • Coverage:
      • Create a company with a base currency.
      • Insert stale rate records.
      • Run post_init_hook.
      • Assert stale records are deleted.
  2. Test _get_supported_currencies:

    • Type: TransactionCase
    • Purpose: Validate that supported currencies are returned correctly.
    • Coverage:
      • Set base currency to IDR.
      • Assert BI_SUPPORTED_CURRENCIES are returned.
      • Set base currency to USD.
      • Assert ["USD", "IDR"] are returned.
  3. Test _fetch_bi_rates with mocked HTTP response:

    • Type: TransactionCase
    • Purpose: Ensure proper handling of network errors and XML parsing.
    • Coverage:
      • Mock urlopen to simulate connection failure.
      • Assert UserError is raised.
      • Mock valid XML response.
      • Assert rates are parsed correctly.
  4. Test _convert_bi_rates_to_odoo:

    • Type: TransactionCase
    • Purpose: Validate conversion logic for both IDR and foreign base currencies.
    • Coverage:
      • Test IDR base case.
      • Test foreign base case (e.g., USD).
      • Test unsupported base currency → UserError.

OCA Testing Patterns:

  • Use @tagged('post_install', 'standard') for tests that require installation hooks.
  • Use TransactionCase for tests that involve data creation and modification.
  • Use SavepointCase for tests that require rollback of database changes (e.g., post_init_hook).

These tests will ensure the module behaves correctly under various conditions and edge cases.


⏰ This PR has been open for 32 days.

Every ignored PR is a contributor who might not come back. Review time matters. (OCA Aging Report)


Reciprocal Review Request

Hi everyone! I found some test failures on this PR and left detailed feedback above. I am happy to discuss or help debug. In the meantime, if any of you get a chance, I would appreciate a look at my open PR(s):

My open PRs across OCA:

Reviewing each other's work helps the whole community move forward. Thank you!


Environment via OCA Neural Reviewer: Minikube + K8s Job + oca-ci/py3.10-odoo16.0 | Odoo 16.0
Automated review by OCA Neural Reviewer + qwen3-coder:30b

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants