;csv: amount-setting doc tweaks

This commit is contained in:
Simon Michael 2021-06-11 16:47:58 -10:00
parent b81f8f768d
commit b114571d26

View File

@ -4051,37 +4051,37 @@ Here are the ways to set a posting's amount:
Since hledger always negates amountN-out, if it was already negative, Since hledger always negates amountN-out, if it was already negative,
we must undo that by negating once more (but only if the field is non-empty): we must undo that by negating once more (but only if the field is non-empty):
```rules ```rules
fields date, description, amount1-in, amount1-out fields date, description, amount1-in, amount1-out
if %amount1-out [1-9] if %amount1-out [1-9]
amount1-out -%amount1-out amount1-out -%amount1-out
``` ```
c. **If both fields, or neither field, can contain a non-zero value:**\ c. **If both fields, or neither field, can contain a non-zero value:**\
hledger normally expects exactly one of the fields to have a non-zero value. hledger normally expects exactly one of the fields to have a non-zero value.
Eg, the `amountN-in`/`amountN-out` rules would reject values like these: Eg, the `amountN-in`/`amountN-out` rules would reject value pairs like these:
```csv ```csv
"" , "" "", ""
"0" , "0" "0", "0"
"1" , "none" "1", "none"
``` ```
So, use [conditional rules](#if-block) to set the amount from the appropriate field. So, use smarter [conditional rules](#if-block) to set the amount from the appropriate field.
Eg, these rules would make it use only the value containing non-zero digits, Eg, these rules would make it use only the value containing non-zero digits,
handling the above: handling the above:
```rules ```rules
fields date, description, in, out fields date, description, in, out
if %in [1-9] if %in [1-9]
amount1 %in amount1 %in
if %out [1-9] if %out [1-9]
amount1 %out amount1 %out
``` ```
3. **If you are stuck with hledger <1.17, or you want posting 2's amount converted to cost:**\ 3. **If you are stuck with hledger <1.17, or you want posting 2's amount converted to cost:**\
Use the old numberless syntax, which sets amount1 and amount2: Assign to `amount` (or to `amount-in` and `amount-out`).
assign to `amount` (or to `amount-in` and `amount-out`). (The old numberless syntax, which sets amount1 and amount2.)
4. **If the CSV has the balance instead of the transaction amount:**\ 4. **If the CSV has the balance instead of the transaction amount:**\
Assign to `balanceN`, which sets posting N's amount indirectly via a Assign to `balanceN`, which sets posting N's amount indirectly via a