Skip to content

[IMP] account_payment_pro: add amount_exact field to preserve full decimal precision#1016

Closed
rov-adhoc wants to merge 1 commit intoingadhoc:18.0from
adhoc-dev:18.0-h-112064-rov
Closed

[IMP] account_payment_pro: add amount_exact field to preserve full decimal precision#1016
rov-adhoc wants to merge 1 commit intoingadhoc:18.0from
adhoc-dev:18.0-h-112064-rov

Conversation

@rov-adhoc
Copy link
Copy Markdown
Contributor

When the payment amount is stored in the Monetary field, it gets rounded to the currency's decimal places. This causes precision loss during currency conversions (e.g. ARS → USD → ARS) where intermediate values lose significant decimals.

Add amount_exact (Float, digits=0) to store the unrounded amount value. This field is automatically synced via create/write overrides and used in:

  • _compute_amount_company_currency: convert using exact amount
  • _onchange_currency_recompute_amount: reconvert using exact amount when the journal currency changes

Also add previous_currency_id to properly track the old currency across consecutive onchange calls without relying on _origin.

Copilot AI review requested due to automatic review settings April 17, 2026 15:13
@roboadhoc
Copy link
Copy Markdown
Contributor

Pull request status dashboard

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Este PR mejora la precisión en pagos multi-moneda evitando la pérdida de decimales causada por el redondeo del campo amount (Monetary), introduciendo un campo técnico amount_exact y ajustando las reconversiones/cómputos para usar el valor no redondeado.

Changes:

  • Añade amount_exact (Float) para conservar el monto con precisión completa y lo sincroniza en create()/write().
  • Añade previous_currency_id para “round-trip” de la moneda anterior entre llamadas consecutivas de onchange.
  • Actualiza conversiones/cómputos para usar amount_exact y setea amount_exact al pagar automáticamente desde account.move.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.

File Description
account_payment_pro/views/account_payment_view.xml Agrega campos técnicos invisibles (previous_currency_id, amount_exact) al formulario para soportar el round-trip del onchange.
account_payment_pro/models/account_payment.py Define amount_exact/previous_currency_id, agrega sync en create/write, implementa onchange(currency_id) y usa amount_exact en conversiones.
account_payment_pro/models/account_move.py Setea payment.amount_exact en el flujo de pay_now() para mantener consistencia con el nuevo campo.

Comment thread account_payment_pro/models/account_payment.py Outdated
Comment thread account_payment_pro/models/account_payment.py
Comment thread account_payment_pro/models/account_payment.py
Comment thread account_payment_pro/models/account_payment.py
@rov-adhoc rov-adhoc force-pushed the 18.0-h-112064-rov branch 5 times, most recently from f8428b5 to 956440c Compare April 24, 2026 13:35
- Modified `account_payment_pro/models/account_payment.py`: restore minimal write-off branch while making sign explicit; keep original behaviour of computing `amount_currency` by dividing `write_off_amount` by `exchange_rate` when payment and company currencies differ; preserve `currency_id` and compute `balance` in company currency.
- Extended `account_payment_pro/tests/test_account_paymet_pro_unit_test.py` with a new test `test_write_off_line_amounts_company_vs_payment_currency` that sets up a scenario with a company in ARS and a payment in USD, then creates and validates a payment with write-off, checking that the write-off line shows the correct amounts in both currencies.

Change note: Ahora, al crear y validar un pago con write-off en otra moneda, la línea de write-off muestra correctamente el importe en la moneda del pago (por ejemplo 1000/1300) y el saldo en la moneda de la compañía (por ejemplo 1000). Se añadió una prueba automática que valida este comportamiento para evitar regresiones.

closes ingadhoc#1017

Signed-off-by: rov-adhoc <rov@adhoc.com.ar>
@maq-adhoc
Copy link
Copy Markdown
Contributor

@roboadhoc r+ bump

roboadhoc pushed a commit that referenced this pull request Apr 24, 2026
- Modified `account_payment_pro/models/account_payment.py`: restore minimal write-off branch while making sign explicit; keep original behaviour of computing `amount_currency` by dividing `write_off_amount` by `exchange_rate` when payment and company currencies differ; preserve `currency_id` and compute `balance` in company currency.
- Extended `account_payment_pro/tests/test_account_paymet_pro_unit_test.py` with a new test `test_write_off_line_amounts_company_vs_payment_currency` that sets up a scenario with a company in ARS and a payment in USD, then creates and validates a payment with write-off, checking that the write-off line shows the correct amounts in both currencies.

Change note: Ahora, al crear y validar un pago con write-off en otra moneda, la línea de write-off muestra correctamente el importe en la moneda del pago (por ejemplo 1000/1300) y el saldo en la moneda de la compañía (por ejemplo 1000). Se añadió una prueba automática que valida este comportamiento para evitar regresiones.

closes #1017

closes #1016

Signed-off-by: rov-adhoc <rov@adhoc.com.ar>
Signed-off-by: Filoquin adhoc <maq@adhoc.com.ar>
roboadhoc added a commit that referenced this pull request Apr 24, 2026
@roboadhoc roboadhoc closed this Apr 24, 2026
@roboadhoc roboadhoc deleted the 18.0-h-112064-rov branch April 24, 2026 15:20
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