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
=== modified file 'sale/sale.py'
--- sale/sale.py 2011-09-22 10:28:12 +0000
+++ sale/sale.py 2012-01-05 10:39:37 +0000
@@ -887,8 +887,9 @@
887 'product_packaging': False,887 'product_packaging': False,
888 'price_unit': 0.0,888 'price_unit': 0.0,
889 }889 }
890890
891 def invoice_line_create(self, cr, uid, ids, context=None):891 def invoice_line_prepare(self, cr, uid, ids, context=None):
892 values = {}
892 if context is None:893 if context is None:
893 context = {}894 context = {}
894895
@@ -939,7 +940,7 @@
939 if not a:940 if not a:
940 raise osv.except_osv(_('Error !'),941 raise osv.except_osv(_('Error !'),
941 _('There is no income category account defined in default Properties for Product Category or Fiscal Position is not defined !'))942 _('There is no income category account defined in default Properties for Product Category or Fiscal Position is not defined !'))
942 inv_id = self.pool.get('account.invoice.line').create(cr, uid, {943 values[line.id] = {
943 'name': line.name,944 'name': line.name,
944 'origin': line.order_id.name,945 'origin': line.order_id.name,
945 'account_id': a,946 'account_id': a,
@@ -951,11 +952,23 @@
951 'invoice_line_tax_id': [(6, 0, [x.id for x in line.tax_id])],952 'invoice_line_tax_id': [(6, 0, [x.id for x in line.tax_id])],
952 'note': line.notes,953 'note': line.notes,
953 'account_analytic_id': line.order_id.project_id and line.order_id.project_id.id or False,954 'account_analytic_id': line.order_id.project_id and line.order_id.project_id.id or False,
954 })955 }
955 cr.execute('insert into sale_order_line_invoice_rel (order_line_id,invoice_id) values (%s,%s)', (line.id, inv_id))956 return values
956 self.write(cr, uid, [line.id], {'invoiced': True})957
957 sales[line.order_id.id] = True958 def invoice_line_create(self, cr, uid, ids, context=None):
958 create_ids.append(inv_id)959 if context is None:
960 context = {}
961 create_ids = []
962 sales = {}
963 values = self.invoice_line_prepare(cr, uid, ids, context)
964 for line_id in values.keys() :
965 line = self.browse(cr, uid, line_id)
966 inv_id = self.pool.get('account.invoice.line').create(cr, uid, values[line_id])
967 cr.execute('insert into sale_order_line_invoice_rel (order_line_id,invoice_id) values (%s,%s)', (line.id, inv_id))
968 self.write(cr, uid, [line.id], {'invoiced': True})
969 sales[line.order_id.id] = True
970 create_ids.append(inv_id)
971
959 # Trigger workflow events972 # Trigger workflow events
960 wf_service = netsvc.LocalService("workflow")973 wf_service = netsvc.LocalService("workflow")
961 for sid in sales.keys():974 for sid in sales.keys():