Merge lp:~taktik/openobject-addons/6.0-sale-cleaned into lp:openobject-addons/6.0

Proposed by David Lefever @ Taktik
Status: Needs review
Proposed branch: lp:~taktik/openobject-addons/6.0-sale-cleaned
Merge into: lp:openobject-addons/6.0
Diff against target: 53 lines (+21/-8)
1 file modified
sale/sale.py (+21/-8)
To merge this branch: bzr merge lp:~taktik/openobject-addons/6.0-sale-cleaned
Reviewer Review Type Date Requested Status
OpenERP Core Team Pending
Review via email: mp+87589@code.launchpad.net

Commit message

Refactored invoice_line_create.

Description of the change

Refactored invoice_line_create to add a new step, invoice_line_prepare, which only purpose is to prepare a set of values and return it.
This way we can inherit invoice_line_prepare to modify or add values before the actual creation.

To post a comment you must log in.

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-09-22 10:28:12 +0000
3+++ sale/sale.py 2012-01-05 10:39:37 +0000
4@@ -887,8 +887,9 @@
5 'product_packaging': False,
6 'price_unit': 0.0,
7 }
8-
9- def invoice_line_create(self, cr, uid, ids, context=None):
10+
11+ def invoice_line_prepare(self, cr, uid, ids, context=None):
12+ values = {}
13 if context is None:
14 context = {}
15
16@@ -939,7 +940,7 @@
17 if not a:
18 raise osv.except_osv(_('Error !'),
19 _('There is no income category account defined in default Properties for Product Category or Fiscal Position is not defined !'))
20- inv_id = self.pool.get('account.invoice.line').create(cr, uid, {
21+ values[line.id] = {
22 'name': line.name,
23 'origin': line.order_id.name,
24 'account_id': a,
25@@ -951,11 +952,23 @@
26 'invoice_line_tax_id': [(6, 0, [x.id for x in line.tax_id])],
27 'note': line.notes,
28 'account_analytic_id': line.order_id.project_id and line.order_id.project_id.id or False,
29- })
30- cr.execute('insert into sale_order_line_invoice_rel (order_line_id,invoice_id) values (%s,%s)', (line.id, inv_id))
31- self.write(cr, uid, [line.id], {'invoiced': True})
32- sales[line.order_id.id] = True
33- create_ids.append(inv_id)
34+ }
35+ return values
36+
37+ def invoice_line_create(self, cr, uid, ids, context=None):
38+ if context is None:
39+ context = {}
40+ create_ids = []
41+ sales = {}
42+ values = self.invoice_line_prepare(cr, uid, ids, context)
43+ for line_id in values.keys() :
44+ line = self.browse(cr, uid, line_id)
45+ inv_id = self.pool.get('account.invoice.line').create(cr, uid, values[line_id])
46+ cr.execute('insert into sale_order_line_invoice_rel (order_line_id,invoice_id) values (%s,%s)', (line.id, inv_id))
47+ self.write(cr, uid, [line.id], {'invoiced': True})
48+ sales[line.order_id.id] = True
49+ create_ids.append(inv_id)
50+
51 # Trigger workflow events
52 wf_service = netsvc.LocalService("workflow")
53 for sid in sales.keys():