This question has been flagged
2 Replies
7195 Views

When you create an invoice from the Invoice Tasks menu and you select multiple tasks they all get stuffed in one position in the invoice. This leads to very long descriptions of on position and is very obscure for customers in a bigger project with a lot of tasks.

Separate positions are only created if the tasks are invoiceable in different ways (i.e. when there are 5 Tasks with a 10% discount and 15 with 0% OpenERP would generate two positions).

How can I tell OpenERP to generate one position in the invoice for each task?

Avatar
Discard
Best Answer

This is actually quite easy to do.

If you want for example to aggregate the positions by date you can do it like this (really only one line per task should work the same way but instead of date you should pick the line id):

In your OpenERP addons folder search for the hr_timesheet_invoice addon. Open its hr_timesheet_invoice.py.

Search for:

cr.execute("""SELECT product_id, user_id, to_invoice, sum(amount), sum(unit_amount), product_uom_id

Replace it with:

cr.execute("""SELECT product_id, user_id, to_invoice, sum(amount), sum(unit_amount), product_uom_id, date

Search for:

GROUP BY product_id, user_id, to_invoice, product_uom_id""", (account.id, tuple(ids), journal_type))

Replace it with:

GROUP BY product_id, user_id, to_invoice, product_uom_id, date""", (account.id, tuple(ids), journal_type))

Search for:

for product_id, user_id, factor_id, total_price, qty, uom in cr.fetchall():

Replace it with:

for product_id, user_id, factor_id, total_price, qty, uom, date in cr.fetchall():

Search for:

cr.execute("SELECT * FROM account_analytic_line WHERE account_id = %s and id IN %s AND product_id=%s and to_invoice=%s ORDER BY account_analytic_line.date", (account.id, tuple(ids), product_id, factor_id))

Replace it with:

cr.execute("SELECT * FROM account_analytic_line WHERE account_id = %s and id IN %s AND product_id=%s and to_invoice=%s and date=%s ORDER BY account_analytic_line.date", (account.id, tuple(ids), product_id, factor_id, date))

That should work also I haven't it tested it very long.

To do it properly I guess you should create a custom module with the modified hr_timesheet_invoice.py which overwrites the original rather than directly modifing the original itself (as it will get overwritten at the next update) but I'm very new to OpenERP and haven't looked into the module structure yet... I guess I'll delay it until I have to update my version.

Avatar
Discard
Best Answer

Not supported by default, you will need a custom module.

You can eventually work in another way:

  • create sales order with several lines
  • use Project_mrp module so that SO creates tasks
  • invoice based on sales order, not on tasks

Other approach based on tasks:

  • invoice with one line but with putting the details
  • attach timesheets in another document that you send with the invoice
Avatar
Discard