Modify invoice template entries

I read some posts about modifying invoices, but could not find my issue.

I’d like to modify my invoice table to look like this:

amount | item code | item name | item description | price per item | total price per line

Which are the code blocks to be pasted into the table fields - or where would I find them? - Or do we have a collection of templates I haven’t come across till now? (If not, would be a nice-to-have…)

Cheers,
Wolf

I’m guessing you mean in the Invoice.odt template file?
Note: each line below needs to be in a separate placeholder text field in the template document.

amount

(Called Quantity in the standard invoice template)

 (format_number(line.quantity, invoice.party.lang, digits=line.unit_digits) + (line.unit and (' ' + line.unit.symbol) or '')) or ''

item code

if test="line.product"
line.product.code
/if

item name

if test="line.product"
line.product.rec_name
/if

item description

(Add the rest from the standard template Description if you also want any description from the invoice line to appear below the item’s description.)

if test="line.product"
line.product.description
/if

price per item

(Called Unit Price in the standard invoice template)

format_currency(line.unit_price, invoice.party.lang, invoice.currency, digits=line.__class__.unit_price.digits[1])

total price per line

(Called Amount in the standard invoice template)

format_currency(line.amount, invoice.party.lang, invoice.currency)

@dave - just perfect as ever!

One question in addition: Can I place

  • price included VAT per line
  • VAT rate
  • time period for payment

as a variable, taken from tryton, into my invoice?

Cheers,
Wolf

The default template has these shown at the bottom, for a number of reasons including:

  • Each line may have multiple taxes applied to it.
  • The tax may be rounded per line or per document. So if rounding per document it is possible to end up in a situation where adding up the taxes for each line does not exactly equal the tax for the document.
  • Taxes can be manually added to an invoice, and these won’t relate to a specific invoice line.

So, for safety it is best to stick with the tax grouped together at the bottom of the invoice as is done on the standard template.

However, if you know what you are doing and still really want to add the tax amounts to each line:

price included vat per line

(I think this will work as long as each line has at most one tax applied to it and the tax is not a fixed amount)

format_currency(line.amount + ((line.amount * (line.taxes[0].rate / 100)) if line.taxes[0] and line.taxes[0].type == 'percentage' else 0), invoice.party.lang, invoice.currency)

VAT rate

(I think this will work as long as each line has at most one tax applied to it and the tax is not a fixed amount)

(format_number(line.taxes[0].rate, invoice.party.lang, digits=2) + '%') if line.taxes and line.taxes[0].type == 'percentage' else ''

Do you mean based on the payment term?
Again this is not always simple, as each payment term may result in payments on different dates (for example: 50% in one week, 25% the following week, then 25% in a month).

time period for payment

(this is the maturity date from the first line to pay, which may not be what you were asking for)

format_date(invoice.lines_to_pay[0].maturity_date, invoice.party.lang) if invoice.lines_to_pay else ‘’

Note: I haven’t tried these out myself, so they may need to be adjusted slightly.