Merge lp:~akretion-team/openobject-addons/better-progressive-invoicing into lp:openobject-addons

Proposed by Raphaël Valyi - http://www.akretion.com
Status: Rejected
Rejected by: Fabien (Open ERP)
Proposed branch: lp:~akretion-team/openobject-addons/better-progressive-invoicing
Merge into: lp:openobject-addons
Diff against target: 31 lines (+11/-10)
1 file modified
sale/sale.py (+11/-10)
To merge this branch: bzr merge lp:~akretion-team/openobject-addons/better-progressive-invoicing
Reviewer Review Type Date Requested Status
OpenERP Core Team Pending
Review via email: mp+86618@code.launchpad.net

Description of the change

Hello
this merge proposal is the concrete result of 2 limitations we have seen in OpenERP:

1) In some countries, we may not mix everything on an invoice and use negative quantities. Take Brazil, service and product invoices need to be different records. If you sale both a service and a product, you will need to split the order in 2 invoices: one for service and an other one for products. A convenient way to generate 2 invoices is calling the sale.order#_make_invoice method twice with the proper filtered order lines.
This would almost work but the 2nd invoice would contain the lines of the 1st invoice with a negative value. We need a way to avoid this. Generating the invoice lines to delete them is really not a clean options as it would make OpenERP even more slower than it is already.

2) Take progressive invoicing of projects based on orders (you invoice ordered value by parts according to some progress estimation, it's common in civil engineering for instance), so you have the same need to partition order lines over several invoices. Again, the natural way to implement this is to call sale.order#_make_invoice several times with the appropriate lines and quantities. Again you want to implement the split logic BEFORE entering _make_invoice so you don't want _make_invoice to mess up the result by guesstimating itself some negative lines.

The simplest way I found to implement that is to have an option in the context, so that an overrider might skip that default advance invoice logic when calling super.

We used that in production for nearly a year now. Could you merge it in 6.1?

To post a comment you must log in.
Revision history for this message
Fabien (Open ERP) (fp-tinyerp) wrote :

I don't think it's logic to introduce a context that is used but not defined in the sale module.
Is there any other solution ?

Unmerged revisions

6099. By Raphaël Valyi - http://www.akretion.com

[IMP] sale: add a way through which an overrider (like localization) can easily partition a sale order over several invoices WITHOUT having to use the default negative quantities which may not be very readable nor legal in some countries.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'sale/sale.py'
2--- sale/sale.py 2011-12-21 13:10:28 +0000
3+++ sale/sale.py 2011-12-21 20:17:37 +0000
4@@ -414,16 +414,17 @@
5 a = order.partner_id.property_account_receivable.id
6 pay_term = order.payment_term and order.payment_term.id or False
7 invoiced_sale_line_ids = self.pool.get('sale.order.line').search(cr, uid, [('order_id', '=', order.id), ('invoiced', '=', True)], context=context)
8- from_line_invoice_ids = []
9- for invoiced_sale_line_id in self.pool.get('sale.order.line').browse(cr, uid, invoiced_sale_line_ids, context=context):
10- for invoice_line_id in invoiced_sale_line_id.invoice_lines:
11- if invoice_line_id.invoice_id.id not in from_line_invoice_ids:
12- from_line_invoice_ids.append(invoice_line_id.invoice_id.id)
13- for preinv in order.invoice_ids:
14- if preinv.state not in ('cancel',) and preinv.id not in from_line_invoice_ids:
15- for preline in preinv.invoice_line:
16- inv_line_id = obj_invoice_line.copy(cr, uid, preline.id, {'invoice_id': False, 'price_unit': -preline.price_unit})
17- lines.append(inv_line_id)
18+ if not context.get('skip_preinv', False):
19+ from_line_invoice_ids = []
20+ for invoiced_sale_line_id in self.pool.get('sale.order.line').browse(cr, uid, invoiced_sale_line_ids, context=context):
21+ for invoice_line_id in invoiced_sale_line_id.invoice_lines:
22+ if invoice_line_id.invoice_id.id not in from_line_invoice_ids:
23+ from_line_invoice_ids.append(invoice_line_id.invoice_id.id)
24+ for preinv in order.invoice_ids:
25+ if preinv.state not in ('cancel',) and preinv.id not in from_line_invoice_ids:
26+ for preline in preinv.invoice_line:
27+ inv_line_id = obj_invoice_line.copy(cr, uid, preline.id, {'invoice_id': False, 'price_unit': -preline.price_unit})
28+ lines.append(inv_line_id)
29 inv = {
30 'name': order.client_order_ref or '',
31 'origin': order.name,

Subscribers

People subscribed via source and target branches

to all changes: