Merge lp:~agilebg/account-financial-tools/7.0-add_account_invoice_template_fixes into lp:~bruno-bottacini/account-financial-tools/7.0-add_account_invoice_template

Proposed by Lorenzo Battistini
Status: Merged
Approved by: bruno bottacini
Approved revision: 117
Merge reported by: bruno bottacini
Merged at revision: not available
Proposed branch: lp:~agilebg/account-financial-tools/7.0-add_account_invoice_template_fixes
Merge into: lp:~bruno-bottacini/account-financial-tools/7.0-add_account_invoice_template
Diff against target: 297 lines (+73/-57)
4 files modified
account_invoice_template/__init__.py (+1/-1)
account_invoice_template/__openerp__.py (+8/-5)
account_invoice_template/account_invoice_template.py (+22/-15)
account_invoice_template/wizard/select_template.py (+42/-36)
To merge this branch: bzr merge lp:~agilebg/account-financial-tools/7.0-add_account_invoice_template_fixes
Reviewer Review Type Date Requested Status
bruno bottacini Approve
Nicolas Bessi - Camptocamp (community) no test, code review Approve
Review via email: mp+183205@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Nicolas Bessi - Camptocamp (nbessi-c2c-deactivatedaccount) wrote :

Hello,

Thanks for the patch.

The diff looks good to me.

That said the module needs a general cleanup and review.

There is some oddities here and there and
a simple pass of the wizard file on flake 8 gave the following output:

select_template.py:3:2:warning: W291 trailing whitespace (python-flake8)
select_template.py:22:31:error: E231 missing whitespace after ',' (python-flake8)
select_template.py:23:1:warning: F401 'time' imported but unused (python-flake8)
select_template.py:26:1:error: E302 expected 2 blank lines, found 1 (python-flake8)
select_template.py:30:101:error: E501 line too long (102 > 100 characters) (python-flake8)
select_template.py:33:33:error: E231 missing whitespace after ',' (python-flake8)
select_template.py:38:17:error: E222 multiple spaces after operator (python-flake8)
select_template.py:46:48:error: E231 missing whitespace after ',' (python-flake8)
select_template.py:58:101:error: E501 line too long (117 > 100 characters) (python-flake8)
select_template.py:62:12:error: E121 continuation line indentation is not a multiple of four (python-flake8)
select_template.py:63:21:error: E203 whitespace before ':' (python-flake8)
select_template.py:76:1:warning: F841 local variable 'template_line_obj' is assigned to but never used (python-flake8)
select_template.py:77:1:warning: F841 local variable 'account_period_obj' is assigned to but never used (python-flake8)
select_template.py:81:1:warning: F841 local variable 'entry' is assigned to but never used (python-flake8)
select_template.py:83:17:error: E222 multiple spaces after operator (python-flake8)
select_template.py:105:24:error: E225 missing whitespace around operator (python-flake8)
select_template.py:108:46:error: E231 missing whitespace after ',' (python-flake8)
select_template.py:118:1:warning: F841 local variable 'id_line' is assigned to but never used (python-flake8)
select_template.py:132:35:error: E231 missing whitespace after ',' (python-flake8)
select_template.py:150:1:warning: W391 blank line at end of file (python-flake8)

Keep up the good work.

Regards

Nicolas

review: Approve (no test, code review)
117. By Lorenzo Battistini

[IMP] PEP8

Revision history for this message
Lorenzo Battistini (elbati) wrote :

Hello Nicolas,
just made the changes, thanks.

Revision history for this message
bruno bottacini (bruno-bottacini) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'account_invoice_template/__init__.py'
2--- account_invoice_template/__init__.py 2013-06-18 07:33:16 +0000
3+++ account_invoice_template/__init__.py 2013-09-26 08:59:58 +0000
4@@ -1,6 +1,6 @@
5 # -*- coding: utf-8 -*-
6 ##############################################################################
7-#
8+#
9 # Copyright (C) 2011 Agile Business Group sagl (<http://www.agilebg.com>)
10 # Copyright (C) 2011 Domsense srl (<http://www.domsense.com>)
11 #
12
13=== modified file 'account_invoice_template/__openerp__.py'
14--- account_invoice_template/__openerp__.py 2013-06-18 07:33:16 +0000
15+++ account_invoice_template/__openerp__.py 2013-09-26 08:59:58 +0000
16@@ -1,6 +1,6 @@
17 # -*- coding: utf-8 -*-
18 ##############################################################################
19-#
20+#
21 # Copyright (C) 2011 Agile Business Group sagl (<http://www.agilebg.com>)
22 # Copyright (C) 2011 Domsense srl (<http://www.domsense.com>)
23 #
24@@ -26,14 +26,17 @@
25 Templates for Invoices
26
27 User can configure invoice templates, useful for recurring invoices.
28-The amount of each template line can be computed (through python code) or kept as user input. If user input, when using the template, user has to fill the amount of every input lines.
29-The invoice form allows lo load, through a wizard, the template to use and the amounts to fill.
30+The amount of each template line can be computed (through python code)
31+or kept as user input. If user input, when using the template, user has to fill
32+the amount of every input lines.
33+The invoice form allows lo load, through a wizard, the template to use and the
34+amounts to fill.
35 """,
36 'author': 'Agile Business Group',
37 'website': 'http://www.agilebg.com',
38 'license': 'AGPL-3',
39- "depends" : ['account_move_template'],
40- "data" : [
41+ "depends": ['account_move_template'],
42+ "data": [
43 'invoice_template.xml',
44 'wizard/select_template.xml',
45 'security/ir.model.access.csv',
46
47=== modified file 'account_invoice_template/account_invoice_template.py'
48--- account_invoice_template/account_invoice_template.py 2013-06-18 07:33:16 +0000
49+++ account_invoice_template/account_invoice_template.py 2013-09-26 08:59:58 +0000
50@@ -20,7 +20,7 @@
51 ##############################################################################
52
53 from openerp.osv import fields, orm
54-from openerp.tools.translate import _
55+
56
57 class account_invoice_template(orm.Model):
58
59@@ -30,13 +30,14 @@
60 _columns = {
61 'partner_id': fields.many2one('res.partner', 'Partner', required=True),
62 'account_id': fields.many2one('account.account', 'Account', required=True),
63- 'template_line_ids': fields.one2many('account.invoice.template.line', 'template_id', 'Template Lines'),
64+ 'template_line_ids': fields.one2many('account.invoice.template.line',
65+ 'template_id', 'Template Lines'),
66 'type': fields.selection([
67- ('out_invoice','Customer Invoice'),
68- ('in_invoice','Supplier Invoice'),
69- ('out_refund','Customer Refund'),
70- ('in_refund','Supplier Refund'),
71- ],'Type', required=True ),
72+ ('out_invoice', 'Customer Invoice'),
73+ ('in_invoice', 'Supplier Invoice'),
74+ ('out_refund', 'Customer Refund'),
75+ ('in_refund', 'Supplier Refund'),
76+ ], 'Type', required=True),
77 }
78
79
80@@ -46,15 +47,21 @@
81 _inherit = 'account.document.template.line'
82
83 _columns = {
84- 'account_id': fields.many2one('account.account', 'Account', required=True, domain=[('type','<>','view'), ('type', '<>', 'closed')]),
85- 'analytic_account_id': fields.many2one('account.analytic.account', 'Analytic Account', ondelete="cascade"),
86- 'invoice_line_tax_id': fields.many2many('account.tax', 'account_invoice_template_line_tax', 'invoice_line_id', 'tax_id', 'Taxes', domain=[('parent_id','=',False)]),
87- 'template_id': fields.many2one('account.invoice.template', 'Template', ondelete='cascade'),
88+ 'account_id': fields.many2one('account.account', 'Account',
89+ required=True, domain=[('type', '<>', 'view'), ('type', '<>', 'closed')]),
90+ 'analytic_account_id': fields.many2one('account.analytic.account',
91+ 'Analytic Account', ondelete="cascade"),
92+ 'invoice_line_tax_id': fields.many2many('account.tax',
93+ 'account_invoice_template_line_tax', 'invoice_line_id', 'tax_id',
94+ 'Taxes', domain=[('parent_id', '=', False)]),
95+ 'template_id': fields.many2one('account.invoice.template', 'Template',
96+ ondelete='cascade'),
97 'product_id': fields.many2one('product.product', 'Product'),
98 }
99
100 _sql_constraints = [
101- ('sequence_template_uniq', 'unique (template_id,sequence)', 'The sequence of the line must be unique per template !')
102+ ('sequence_template_uniq', 'unique (template_id,sequence)',
103+ 'The sequence of the line must be unique per template !')
104 ]
105
106 def product_id_change(self, cr, uid, ids, product_id, type, context=None):
107@@ -65,14 +72,15 @@
108 if not product_id:
109 return {}
110
111- product = self.pool.get('product.product').browse(cr, uid, product_id, context=context)
112+ product = self.pool.get('product.product').browse(cr, uid, product_id,
113+ context=context)
114
115 # name
116 result.update({'name': product.name})
117
118 # account
119 account_id = False
120- if type in ('out_invoice','out_refund'):
121+ if type in ('out_invoice', 'out_refund'):
122 account_id = product.product_tmpl_id.property_account_income.id
123 if not account_id:
124 account_id = product.categ_id.property_account_income_categ.id
125@@ -96,4 +104,3 @@
126 result.update({'invoice_line_tax_id': tax_ids})
127
128 return {'value': result}
129-
130
131=== modified file 'account_invoice_template/wizard/select_template.py'
132--- account_invoice_template/wizard/select_template.py 2013-06-18 13:59:38 +0000
133+++ account_invoice_template/wizard/select_template.py 2013-09-26 08:59:58 +0000
134@@ -19,91 +19,97 @@
135 #
136 ##############################################################################
137
138-from openerp.osv import fields,orm
139-import time
140+from openerp.osv import fields, orm
141 from openerp.tools.translate import _
142
143+
144 class wizard_select_template(orm.TransientModel):
145
146 _name = "wizard.select.invoice.template"
147 _columns = {
148- 'template_id': fields.many2one('account.invoice.template', 'Invoice Template', required=True),
149- 'line_ids': fields.one2many('wizard.select.invoice.template.line', 'template_id', 'Lines'),
150+ 'template_id': fields.many2one('account.invoice.template',
151+ 'Invoice Template', required=True),
152+ 'line_ids': fields.one2many('wizard.select.invoice.template.line',
153+ 'template_id', 'Lines'),
154 'state': fields.selection([
155- ('template_selected','Template selected'),
156+ ('template_selected', 'Template selected'),
157 ], 'State'),
158 }
159
160 def load_lines(self, cr, uid, ids, context=None):
161- wizard = self.browse(cr, uid, ids, context=context)[0]
162+ wizard = self.browse(cr, uid, ids, context=context)[0]
163 template_pool = self.pool.get('account.invoice.template')
164 wizard_line_pool = self.pool.get('wizard.select.invoice.template.line')
165 model_data_obj = self.pool.get('ir.model.data')
166
167- template = template_pool.browse(cr, uid, wizard.template_id.id)
168+ template = template_pool.browse(cr, uid, wizard.template_id.id,
169+ context=context)
170 for line in template.template_line_ids:
171 if line.type == 'input':
172- wizard_line_pool.create(cr, uid,{
173+ wizard_line_pool.create(cr, uid, {
174 'template_id': wizard.id,
175 'sequence': line.sequence,
176 'name': line.name,
177 'amount': line.product_id and line.product_id.list_price or 0.0,
178 'account_id': line.account_id.id,
179 'product_id': line.product_id.id,
180- })
181+ }, context=context)
182 if not wizard.line_ids:
183- return self.load_template(cr, uid, ids)
184- wizard.write({'state': 'template_selected'})
185+ return self.load_template(cr, uid, ids, context=context)
186+ wizard.write({'state': 'template_selected'}, context=context)
187
188- view_rec = model_data_obj.get_object_reference(cr, uid, 'account_invoice_template', 'wizard_select_template')
189+ view_rec = model_data_obj.get_object_reference(cr, uid,
190+ 'account_invoice_template', 'wizard_select_template')
191 view_id = view_rec and view_rec[1] or False
192
193 return {
194- 'view_type': 'form',
195- 'view_id' : [view_id],
196- 'view_mode': 'form',
197- 'res_model': 'wizard.select.invoice.template',
198- 'res_id': wizard.id,
199- 'type': 'ir.actions.act_window',
200- 'target': 'new',
201- 'context': context,
202+ 'view_type': 'form',
203+ 'view_id': [view_id],
204+ 'view_mode': 'form',
205+ 'res_model': 'wizard.select.invoice.template',
206+ 'res_id': wizard.id,
207+ 'type': 'ir.actions.act_window',
208+ 'target': 'new',
209+ 'context': context,
210 }
211
212 def load_template(self, cr, uid, ids, context=None):
213+ if context is None:
214+ context = {}
215 template_obj = self.pool.get('account.invoice.template')
216- template_line_obj = self.pool.get('account.invoice.template.line')
217- account_period_obj = self.pool.get('account.period')
218 account_invoice_obj = self.pool.get('account.invoice')
219 account_invoice_line_obj = self.pool.get('account.invoice.line')
220 mod_obj = self.pool.get('ir.model.data')
221- entry = {}
222
223- wizard = self.browse(cr, uid, ids, context=context)[0]
224+ wizard = self.browse(cr, uid, ids, context=context)[0]
225 if not template_obj.check_zero_lines(cr, uid, wizard):
226- raise orm.except_orm(_('Error !'), _('At least one amount has to be non-zero!'))
227+ raise orm.except_orm(_('Error !'),
228+ _('At least one amount has to be non-zero!'))
229 input_lines = {}
230 for template_line in wizard.line_ids:
231 input_lines[template_line.sequence] = template_line.amount
232
233- computed_lines = template_obj.compute_lines(cr, uid, wizard.template_id.id, input_lines)
234+ computed_lines = template_obj.compute_lines(cr, uid,
235+ wizard.template_id.id, input_lines)
236
237 inv_values = account_invoice_obj.onchange_partner_id(
238- cr, uid, ids, wizard.template_id.type, wizard.template_id.partner_id.id)['value']
239+ cr, uid, ids, wizard.template_id.type,
240+ wizard.template_id.partner_id.id)['value']
241 inv_values['partner_id'] = wizard.template_id.partner_id.id
242 inv_values['account_id'] = wizard.template_id.account_id.id
243 inv_values['type'] = wizard.template_id.type
244-
245- inv_id = account_invoice_obj.create(cr, uid, inv_values, context={'type':wizard.template_id.type})
246+ context['type'] = wizard.template_id.type
247+ inv_id = account_invoice_obj.create(cr, uid, inv_values, context=context)
248 for line in wizard.template_id.template_line_ids:
249 analytic_account_id = False
250 if line.analytic_account_id:
251 analytic_account_id = line.analytic_account_id.id
252 invoice_line_tax_id = []
253 if line.invoice_line_tax_id:
254- tax_ids=[]
255+ tax_ids = []
256 for tax in line.invoice_line_tax_id:
257 tax_ids.append(tax.id)
258- invoice_line_tax_id.append((6,0, tax_ids))
259+ invoice_line_tax_id.append((6, 0, tax_ids))
260 val = {
261 'name': line.name,
262 'invoice_id': inv_id,
263@@ -113,7 +119,7 @@
264 'price_unit': computed_lines[line.sequence],
265 'product_id': line.product_id.id,
266 }
267- id_line = account_invoice_line_obj.create(cr, uid, val)
268+ account_invoice_line_obj.create(cr, uid, val, context=context)
269
270 if wizard.template_id.type in ('out_invoice', 'out_refund'):
271 xml_id = 'invoice_form'
272@@ -122,12 +128,12 @@
273 resource_id = mod_obj.get_object_reference(cr, uid, 'account', xml_id)[1]
274
275 return {
276- 'domain': "[('id','in', ["+str(inv_id)+"])]",
277+ 'domain': "[('id','in', [" + str(inv_id) + "])]",
278 'name': 'Invoice',
279 'view_type': 'form',
280 'view_mode': 'form',
281 'res_model': 'account.invoice',
282- 'views': [(resource_id,'form')],
283+ 'views': [(resource_id, 'form')],
284 'type': 'ir.actions.act_window',
285 'target': 'current',
286 'res_id': inv_id or False,
287@@ -141,8 +147,8 @@
288 'template_id': fields.many2one('wizard.select.invoice.template', 'Template'),
289 'sequence': fields.integer('Number', required=True),
290 'name': fields.char('Name', size=64, required=True, readonly=True),
291- 'account_id': fields.many2one('account.account', 'Account', required=True, readonly=True),
292+ 'account_id': fields.many2one('account.account', 'Account',
293+ required=True, readonly=True),
294 'amount': fields.float('Amount', required=True),
295 'product_id': fields.many2one('product.product', 'Product'),
296 }
297-

Subscribers

People subscribed via source and target branches