Merge lp:~akretion-team/openobject-addons/addons-stock-extensible-action-invoice-create into lp:openobject-addons

Proposed by Renato Lima - http://www.akretion.com
Status: Rejected
Rejected by: Fabien (Open ERP)
Proposed branch: lp:~akretion-team/openobject-addons/addons-stock-extensible-action-invoice-create
Merge into: lp:openobject-addons
Diff against target: 137 lines (+52/-55)
1 file modified
stock/stock.py (+52/-55)
To merge this branch: bzr merge lp:~akretion-team/openobject-addons/addons-stock-extensible-action-invoice-create
Reviewer Review Type Date Requested Status
Fabien (Open ERP) Disapprove
Review via email: mp+78181@code.launchpad.net

Description of the change

Hello,

I refactore the action_invoice_create method in stock module to make more extensible to overriding like this merge proposal https://code.launchpad.net/~akretion-team/openobject-addons/addons-sale-extensible-action-ship-create/+merge/76609.

Thanks,

Renato Lima

To post a comment you must log in.
Revision history for this message
Raphaël Valyi - http://www.akretion.com (rvalyi) wrote :

Remark: you might also add a flag to deprecate the _invoice_line_hook method: you can keep it for API compat, but the new _prepare_invoice_line may replace it totally, so in the future releases, _invoice_line_hook would better be removed.

Revision history for this message
Raphaël Valyi - http://www.akretion.com (rvalyi) wrote :

Hello,

we are working hard to also propose an equivalent refactoring of sale/stock.py along with this one. Eventually you can wait we propose it. Hopefully we do it even today.

Revision history for this message
Fabien (Open ERP) (fp-tinyerp) wrote :

i finally uncommited/rejected this merge proposal as it crashed the buildbot when installing stock_invoice_directly

review: Disapprove

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'stock/stock.py'
2--- stock/stock.py 2011-09-27 21:38:03 +0000
3+++ stock/stock.py 2011-10-04 23:23:19 +0000
4@@ -955,6 +955,51 @@
5 else:
6 inv_type = 'out_invoice'
7 return inv_type
8+
9+ def _prepare_invoice(self, cr, uid, picking, partner, payment_term_id, account_id, inv_type, journal_id, context=False):
10+
11+ address_contact_id, address_invoice_id = \
12+ self._get_address_invoice(cr, uid, picking).values()
13+
14+ return {
15+ 'name': picking.name,
16+ 'origin': (picking.name or '') + (picking.origin and (':' + picking.origin) or ''),
17+ 'type': inv_type,
18+ 'account_id': account_id,
19+ 'partner_id': partner.id,
20+ 'address_invoice_id': address_invoice_id,
21+ 'address_contact_id': address_contact_id,
22+ 'comment': self._get_comment_invoice(cr, uid, picking),
23+ 'payment_term': payment_term_id,
24+ 'fiscal_position': partner.property_account_position.id,
25+ 'date_invoice': context.get('date_inv',False),
26+ 'company_id': picking.company_id.id,
27+ 'user_id':uid,
28+ 'currency_id': self.get_currency_id(cr, uid, picking) or False,
29+ 'journal_id': journal_id,
30+ }
31+
32+ def _prepare_invoice_line(self, cr, uid, group, picking, move_line, invoice_id, account_id, inv_type, context=False):
33+
34+ #set UoS if it's a sale and the picking doesn't have one
35+ uos_id = move_line.product_uos and move_line.product_uos.id or False
36+ if not uos_id and inv_type in ('out_invoice', 'out_refund'):
37+ uos_id = move_line.product_uom.id
38+
39+ return {
40+ 'name': group and picking.name and picking.name + '-' + move_line.name or move_line.name,
41+ 'origin': move_line.picking_id.origin and move_line.picking_id.name and (move_line.picking_id.origin + ':' + move_line.picking_id.name) or (move_line.picking_id.name or ''),
42+ 'invoice_id': invoice_id,
43+ 'uos_id': uos_id,
44+ 'product_id': move_line.product_id.id,
45+ 'account_id': account_id,
46+ 'price_unit': self._get_price_unit_invoice(cr, uid,move_line, inv_type),
47+ 'discount': self._get_discount_invoice(cr, uid, move_line),
48+ 'quantity': move_line.product_uos_qty or move_line.product_qty,
49+ 'invoice_line_tax_id': [(6, 0, self._get_taxes_invoice(cr, uid, move_line, inv_type))],
50+ 'account_analytic_id': self._get_account_analytic_invoice(cr, uid, picking, move_line),
51+ }
52+
53
54 def action_invoice_create(self, cr, uid, ids, journal_id=False,
55 group=False, type='out_invoice', context=None):
56@@ -1008,41 +1053,14 @@
57 }
58 invoice_obj.write(cr, uid, [invoice_id], invoice_vals, context=context)
59 else:
60- invoice_vals = {
61- 'name': picking.name,
62- 'origin': (picking.name or '') + (picking.origin and (':' + picking.origin) or ''),
63- 'type': inv_type,
64- 'account_id': account_id,
65- 'partner_id': address.partner_id.id,
66- 'address_invoice_id': address_invoice_id,
67- 'address_contact_id': address_contact_id,
68- 'comment': comment,
69- 'payment_term': payment_term_id,
70- 'fiscal_position': partner.property_account_position.id,
71- 'date_invoice': context.get('date_inv',False),
72- 'company_id': picking.company_id.id,
73- 'user_id':uid
74- }
75- cur_id = self.get_currency_id(cr, uid, picking)
76- if cur_id:
77- invoice_vals['currency_id'] = cur_id
78- if journal_id:
79- invoice_vals['journal_id'] = journal_id
80- invoice_id = invoice_obj.create(cr, uid, invoice_vals,
81- context=context)
82+ invoice_id = invoice_obj.create(cr, uid, self._prepare_invoice(cr, uid, picking, partner, \
83+ payment_term_id, account_id, inv_type, journal_id, context), context=context)
84 invoices_group[partner.id] = invoice_id
85 res[picking.id] = invoice_id
86 for move_line in picking.move_lines:
87 if move_line.state == 'cancel':
88 continue
89- origin = move_line.picking_id.name or ''
90- if move_line.picking_id.origin:
91- origin += ':' + move_line.picking_id.origin
92- if group:
93- name = (picking.name or '') + '-' + move_line.name
94- else:
95- name = move_line.name
96-
97+
98 if inv_type in ('out_invoice', 'out_refund'):
99 account_id = move_line.product_id.product_tmpl_id.\
100 property_account_income.id
101@@ -1055,32 +1073,11 @@
102 if not account_id:
103 account_id = move_line.product_id.categ_id.\
104 property_account_expense_categ.id
105-
106- price_unit = self._get_price_unit_invoice(cr, uid,
107- move_line, inv_type)
108- discount = self._get_discount_invoice(cr, uid, move_line)
109- tax_ids = self._get_taxes_invoice(cr, uid, move_line, inv_type)
110- account_analytic_id = self._get_account_analytic_invoice(cr, uid, picking, move_line)
111-
112- #set UoS if it's a sale and the picking doesn't have one
113- uos_id = move_line.product_uos and move_line.product_uos.id or False
114- if not uos_id and inv_type in ('out_invoice', 'out_refund'):
115- uos_id = move_line.product_uom.id
116-
117+
118 account_id = self.pool.get('account.fiscal.position').map_account(cr, uid, partner.property_account_position, account_id)
119- invoice_line_id = invoice_line_obj.create(cr, uid, {
120- 'name': name,
121- 'origin': origin,
122- 'invoice_id': invoice_id,
123- 'uos_id': uos_id,
124- 'product_id': move_line.product_id.id,
125- 'account_id': account_id,
126- 'price_unit': price_unit,
127- 'discount': discount,
128- 'quantity': move_line.product_uos_qty or move_line.product_qty,
129- 'invoice_line_tax_id': [(6, 0, tax_ids)],
130- 'account_analytic_id': account_analytic_id,
131- }, context=context)
132+
133+ invoice_line_id = invoice_line_obj.create(cr, uid, self._prepare_invoice_line(cr, uid, group, picking, move_line, \
134+ invoice_id, account_id, inv_type, context=context), context=context)
135 self._invoice_line_hook(cr, uid, move_line, invoice_line_id)
136
137 invoice_obj.button_compute(cr, uid, [invoice_id], context=context,

Subscribers

People subscribed via source and target branches

to all changes: