Payment terms: models, the split of a total and the invoice integration
Code: erp_addon_account::payterm (models and loading), payterm::compute (pure arithmetic, unit tests in
test_compute.rs), payterm::partner (defaults) and invoice::sync (use on invoices).
| Model | Notes |
|---|---|
account.payment.term | name, note, active, sequence, optional company_id (access by branch ancestry), display_on_invoice, line_ids |
account.payment.term.line | value (percent or fixed), value_amount, delay_type, nb_days, days_next_month, payment_id |
account.move | invoice_payment_term_id (restricts deletion of a used term) |
res.partner | company-dependent property_payment_term_id (customer) and property_supplier_payment_term_id (vendor); both are commercial fields |
Checks
Section titled “Checks”A constraint on the term (names name and line_ids) runs on every create and write: percent lines between 0 and
100 and adding up to 100 once rounded to the digits of the Payment Terms decimal precision (shipped as 6, setting:
Technical > Decimal Precision; without a row the code uses 6). A constraint on each line checks the day of the next
month (a number from 0 to 31). Editing one line directly, without writing its term, does not re-run the sum check:
the invoice sync checks the percent sum again before it uses the terms and refuses an invalid term.
The split
Section titled “The split”compute::instalments(lines, date_ref, total, total_currency, sign, company_increment, currency_increment):
a percent line takes its share of each total, quantized once to the currency increment; a fixed line takes its amount
with sign in the document currency and the company amount through the ratio of the two totals; the last line takes
the exact remainder in both currencies. A fixed line on a document whose company or document total is zero is
refused (no ratio exists). Dates: compute::due_date.
On invoices
Section titled “On invoices”sync_terms (invoice/sync.rs) writes one payment_term line per instalment, matched to existing lines in id order
(updated, added or deleted), and the header invoice_date_due is the latest instalment date. Without terms, or
without an invoice or accounting date, one line is written as before. A new invoice takes the partner’s terms of
its kind and company unless the values or the context (default_invoice_payment_term_id) give one; writing
partner_id on drafts of one kind and company does the same.
Not yet: early payment discount, cash rounding, the instalment preview.