Enhanced Import Amount Type Selection (#506)

* Enhanced Import Amount Type Selection

updated version of https://github.com/we-promise/sure/pull/179

* copilot sugestions

* ai sugestions

* Update import.rb

* Update schema.rb

* Update schema.rb

* Update schema.rb

---------

Signed-off-by: Juan José Mata <juanjo.mata@gmail.com>
Co-authored-by: Juan José Mata <juanjo.mata@gmail.com>
This commit is contained in:
Mark Hendriksen
2026-01-23 22:12:02 +01:00
committed by GitHub
parent 696ff0966b
commit 9b84c5bdbc
9 changed files with 94 additions and 8 deletions

View File

@@ -47,12 +47,27 @@ class Import::Row < ApplicationRecord
if import.amount_type_strategy == "signed_amount"
value * (import.signage_convention == "inflows_positive" ? -1 : 1)
elsif import.amount_type_strategy == "custom_column"
inflow_value = import.amount_type_inflow_value
legacy_identifier = import.amount_type_inflow_value
selected_identifier =
if import.amount_type_identifier_value.present?
import.amount_type_identifier_value
else
legacy_identifier
end
if entity_type == inflow_value
value * -1
inflow_treatment =
if import.amount_type_inflow_value.in?(%w[inflows_positive inflows_negative])
import.amount_type_inflow_value
elsif import.signage_convention.in?(%w[inflows_positive inflows_negative])
import.signage_convention
else
"inflows_positive"
end
if entity_type == selected_identifier
value * (inflow_treatment == "inflows_positive" ? -1 : 1)
else
value
value * (inflow_treatment == "inflows_positive" ? 1 : -1)
end
else
raise "Unknown amount type strategy for import: #{import.amount_type_strategy}"