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
=== modified file 'account_invoice_template/__init__.py'
--- account_invoice_template/__init__.py 2013-06-18 07:33:16 +0000
+++ account_invoice_template/__init__.py 2013-09-26 08:59:58 +0000
@@ -1,6 +1,6 @@
1# -*- coding: utf-8 -*-1# -*- coding: utf-8 -*-
2##############################################################################2##############################################################################
3# 3#
4# Copyright (C) 2011 Agile Business Group sagl (<http://www.agilebg.com>)4# Copyright (C) 2011 Agile Business Group sagl (<http://www.agilebg.com>)
5# Copyright (C) 2011 Domsense srl (<http://www.domsense.com>)5# Copyright (C) 2011 Domsense srl (<http://www.domsense.com>)
6#6#
77
=== modified file 'account_invoice_template/__openerp__.py'
--- account_invoice_template/__openerp__.py 2013-06-18 07:33:16 +0000
+++ account_invoice_template/__openerp__.py 2013-09-26 08:59:58 +0000
@@ -1,6 +1,6 @@
1# -*- coding: utf-8 -*-1# -*- coding: utf-8 -*-
2##############################################################################2##############################################################################
3# 3#
4# Copyright (C) 2011 Agile Business Group sagl (<http://www.agilebg.com>)4# Copyright (C) 2011 Agile Business Group sagl (<http://www.agilebg.com>)
5# Copyright (C) 2011 Domsense srl (<http://www.domsense.com>)5# Copyright (C) 2011 Domsense srl (<http://www.domsense.com>)
6#6#
@@ -26,14 +26,17 @@
26Templates for Invoices26Templates for Invoices
2727
28User can configure invoice templates, useful for recurring invoices.28User can configure invoice templates, useful for recurring invoices.
29The 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.29The amount of each template line can be computed (through python code)
30The invoice form allows lo load, through a wizard, the template to use and the amounts to fill.30or kept as user input. If user input, when using the template, user has to fill
31the amount of every input lines.
32The invoice form allows lo load, through a wizard, the template to use and the
33amounts to fill.
31""",34""",
32 'author': 'Agile Business Group',35 'author': 'Agile Business Group',
33 'website': 'http://www.agilebg.com',36 'website': 'http://www.agilebg.com',
34 'license': 'AGPL-3',37 'license': 'AGPL-3',
35 "depends" : ['account_move_template'],38 "depends": ['account_move_template'],
36 "data" : [39 "data": [
37 'invoice_template.xml',40 'invoice_template.xml',
38 'wizard/select_template.xml',41 'wizard/select_template.xml',
39 'security/ir.model.access.csv',42 'security/ir.model.access.csv',
4043
=== modified file 'account_invoice_template/account_invoice_template.py'
--- account_invoice_template/account_invoice_template.py 2013-06-18 07:33:16 +0000
+++ account_invoice_template/account_invoice_template.py 2013-09-26 08:59:58 +0000
@@ -20,7 +20,7 @@
20##############################################################################20##############################################################################
2121
22from openerp.osv import fields, orm22from openerp.osv import fields, orm
23from openerp.tools.translate import _23
2424
25class account_invoice_template(orm.Model):25class account_invoice_template(orm.Model):
2626
@@ -30,13 +30,14 @@
30 _columns = {30 _columns = {
31 'partner_id': fields.many2one('res.partner', 'Partner', required=True),31 'partner_id': fields.many2one('res.partner', 'Partner', required=True),
32 'account_id': fields.many2one('account.account', 'Account', required=True),32 'account_id': fields.many2one('account.account', 'Account', required=True),
33 'template_line_ids': fields.one2many('account.invoice.template.line', 'template_id', 'Template Lines'),33 'template_line_ids': fields.one2many('account.invoice.template.line',
34 'template_id', 'Template Lines'),
34 'type': fields.selection([35 'type': fields.selection([
35 ('out_invoice','Customer Invoice'),36 ('out_invoice', 'Customer Invoice'),
36 ('in_invoice','Supplier Invoice'),37 ('in_invoice', 'Supplier Invoice'),
37 ('out_refund','Customer Refund'),38 ('out_refund', 'Customer Refund'),
38 ('in_refund','Supplier Refund'),39 ('in_refund', 'Supplier Refund'),
39 ],'Type', required=True ),40 ], 'Type', required=True),
40 }41 }
4142
4243
@@ -46,15 +47,21 @@
46 _inherit = 'account.document.template.line'47 _inherit = 'account.document.template.line'
4748
48 _columns = {49 _columns = {
49 'account_id': fields.many2one('account.account', 'Account', required=True, domain=[('type','<>','view'), ('type', '<>', 'closed')]),50 'account_id': fields.many2one('account.account', 'Account',
50 'analytic_account_id': fields.many2one('account.analytic.account', 'Analytic Account', ondelete="cascade"),51 required=True, domain=[('type', '<>', 'view'), ('type', '<>', 'closed')]),
51 'invoice_line_tax_id': fields.many2many('account.tax', 'account_invoice_template_line_tax', 'invoice_line_id', 'tax_id', 'Taxes', domain=[('parent_id','=',False)]),52 'analytic_account_id': fields.many2one('account.analytic.account',
52 'template_id': fields.many2one('account.invoice.template', 'Template', ondelete='cascade'),53 'Analytic Account', ondelete="cascade"),
54 'invoice_line_tax_id': fields.many2many('account.tax',
55 'account_invoice_template_line_tax', 'invoice_line_id', 'tax_id',
56 'Taxes', domain=[('parent_id', '=', False)]),
57 'template_id': fields.many2one('account.invoice.template', 'Template',
58 ondelete='cascade'),
53 'product_id': fields.many2one('product.product', 'Product'),59 'product_id': fields.many2one('product.product', 'Product'),
54 }60 }
5561
56 _sql_constraints = [62 _sql_constraints = [
57 ('sequence_template_uniq', 'unique (template_id,sequence)', 'The sequence of the line must be unique per template !')63 ('sequence_template_uniq', 'unique (template_id,sequence)',
64 'The sequence of the line must be unique per template !')
58 ]65 ]
5966
60 def product_id_change(self, cr, uid, ids, product_id, type, context=None):67 def product_id_change(self, cr, uid, ids, product_id, type, context=None):
@@ -65,14 +72,15 @@
65 if not product_id:72 if not product_id:
66 return {}73 return {}
6774
68 product = self.pool.get('product.product').browse(cr, uid, product_id, context=context)75 product = self.pool.get('product.product').browse(cr, uid, product_id,
76 context=context)
6977
70 # name78 # name
71 result.update({'name': product.name})79 result.update({'name': product.name})
7280
73 # account81 # account
74 account_id = False82 account_id = False
75 if type in ('out_invoice','out_refund'):83 if type in ('out_invoice', 'out_refund'):
76 account_id = product.product_tmpl_id.property_account_income.id84 account_id = product.product_tmpl_id.property_account_income.id
77 if not account_id:85 if not account_id:
78 account_id = product.categ_id.property_account_income_categ.id86 account_id = product.categ_id.property_account_income_categ.id
@@ -96,4 +104,3 @@
96 result.update({'invoice_line_tax_id': tax_ids})104 result.update({'invoice_line_tax_id': tax_ids})
97105
98 return {'value': result}106 return {'value': result}
99
100107
=== modified file 'account_invoice_template/wizard/select_template.py'
--- account_invoice_template/wizard/select_template.py 2013-06-18 13:59:38 +0000
+++ account_invoice_template/wizard/select_template.py 2013-09-26 08:59:58 +0000
@@ -19,91 +19,97 @@
19#19#
20##############################################################################20##############################################################################
2121
22from openerp.osv import fields,orm22from openerp.osv import fields, orm
23import time
24from openerp.tools.translate import _23from openerp.tools.translate import _
2524
25
26class wizard_select_template(orm.TransientModel):26class wizard_select_template(orm.TransientModel):
2727
28 _name = "wizard.select.invoice.template"28 _name = "wizard.select.invoice.template"
29 _columns = {29 _columns = {
30 'template_id': fields.many2one('account.invoice.template', 'Invoice Template', required=True),30 'template_id': fields.many2one('account.invoice.template',
31 'line_ids': fields.one2many('wizard.select.invoice.template.line', 'template_id', 'Lines'),31 'Invoice Template', required=True),
32 'line_ids': fields.one2many('wizard.select.invoice.template.line',
33 'template_id', 'Lines'),
32 'state': fields.selection([34 'state': fields.selection([
33 ('template_selected','Template selected'),35 ('template_selected', 'Template selected'),
34 ], 'State'),36 ], 'State'),
35 }37 }
3638
37 def load_lines(self, cr, uid, ids, context=None):39 def load_lines(self, cr, uid, ids, context=None):
38 wizard = self.browse(cr, uid, ids, context=context)[0]40 wizard = self.browse(cr, uid, ids, context=context)[0]
39 template_pool = self.pool.get('account.invoice.template')41 template_pool = self.pool.get('account.invoice.template')
40 wizard_line_pool = self.pool.get('wizard.select.invoice.template.line')42 wizard_line_pool = self.pool.get('wizard.select.invoice.template.line')
41 model_data_obj = self.pool.get('ir.model.data')43 model_data_obj = self.pool.get('ir.model.data')
4244
43 template = template_pool.browse(cr, uid, wizard.template_id.id)45 template = template_pool.browse(cr, uid, wizard.template_id.id,
46 context=context)
44 for line in template.template_line_ids:47 for line in template.template_line_ids:
45 if line.type == 'input':48 if line.type == 'input':
46 wizard_line_pool.create(cr, uid,{49 wizard_line_pool.create(cr, uid, {
47 'template_id': wizard.id,50 'template_id': wizard.id,
48 'sequence': line.sequence,51 'sequence': line.sequence,
49 'name': line.name,52 'name': line.name,
50 'amount': line.product_id and line.product_id.list_price or 0.0,53 'amount': line.product_id and line.product_id.list_price or 0.0,
51 'account_id': line.account_id.id,54 'account_id': line.account_id.id,
52 'product_id': line.product_id.id,55 'product_id': line.product_id.id,
53 })56 }, context=context)
54 if not wizard.line_ids:57 if not wizard.line_ids:
55 return self.load_template(cr, uid, ids)58 return self.load_template(cr, uid, ids, context=context)
56 wizard.write({'state': 'template_selected'})59 wizard.write({'state': 'template_selected'}, context=context)
5760
58 view_rec = model_data_obj.get_object_reference(cr, uid, 'account_invoice_template', 'wizard_select_template')61 view_rec = model_data_obj.get_object_reference(cr, uid,
62 'account_invoice_template', 'wizard_select_template')
59 view_id = view_rec and view_rec[1] or False63 view_id = view_rec and view_rec[1] or False
6064
61 return {65 return {
62 'view_type': 'form',66 'view_type': 'form',
63 'view_id' : [view_id],67 'view_id': [view_id],
64 'view_mode': 'form',68 'view_mode': 'form',
65 'res_model': 'wizard.select.invoice.template',69 'res_model': 'wizard.select.invoice.template',
66 'res_id': wizard.id,70 'res_id': wizard.id,
67 'type': 'ir.actions.act_window',71 'type': 'ir.actions.act_window',
68 'target': 'new',72 'target': 'new',
69 'context': context,73 'context': context,
70 }74 }
7175
72 def load_template(self, cr, uid, ids, context=None):76 def load_template(self, cr, uid, ids, context=None):
77 if context is None:
78 context = {}
73 template_obj = self.pool.get('account.invoice.template')79 template_obj = self.pool.get('account.invoice.template')
74 template_line_obj = self.pool.get('account.invoice.template.line')
75 account_period_obj = self.pool.get('account.period')
76 account_invoice_obj = self.pool.get('account.invoice')80 account_invoice_obj = self.pool.get('account.invoice')
77 account_invoice_line_obj = self.pool.get('account.invoice.line')81 account_invoice_line_obj = self.pool.get('account.invoice.line')
78 mod_obj = self.pool.get('ir.model.data')82 mod_obj = self.pool.get('ir.model.data')
79 entry = {}
8083
81 wizard = self.browse(cr, uid, ids, context=context)[0]84 wizard = self.browse(cr, uid, ids, context=context)[0]
82 if not template_obj.check_zero_lines(cr, uid, wizard):85 if not template_obj.check_zero_lines(cr, uid, wizard):
83 raise orm.except_orm(_('Error !'), _('At least one amount has to be non-zero!'))86 raise orm.except_orm(_('Error !'),
87 _('At least one amount has to be non-zero!'))
84 input_lines = {}88 input_lines = {}
85 for template_line in wizard.line_ids:89 for template_line in wizard.line_ids:
86 input_lines[template_line.sequence] = template_line.amount90 input_lines[template_line.sequence] = template_line.amount
8791
88 computed_lines = template_obj.compute_lines(cr, uid, wizard.template_id.id, input_lines)92 computed_lines = template_obj.compute_lines(cr, uid,
93 wizard.template_id.id, input_lines)
8994
90 inv_values = account_invoice_obj.onchange_partner_id(95 inv_values = account_invoice_obj.onchange_partner_id(
91 cr, uid, ids, wizard.template_id.type, wizard.template_id.partner_id.id)['value']96 cr, uid, ids, wizard.template_id.type,
97 wizard.template_id.partner_id.id)['value']
92 inv_values['partner_id'] = wizard.template_id.partner_id.id98 inv_values['partner_id'] = wizard.template_id.partner_id.id
93 inv_values['account_id'] = wizard.template_id.account_id.id99 inv_values['account_id'] = wizard.template_id.account_id.id
94 inv_values['type'] = wizard.template_id.type100 inv_values['type'] = wizard.template_id.type
95101 context['type'] = wizard.template_id.type
96 inv_id = account_invoice_obj.create(cr, uid, inv_values, context={'type':wizard.template_id.type})102 inv_id = account_invoice_obj.create(cr, uid, inv_values, context=context)
97 for line in wizard.template_id.template_line_ids:103 for line in wizard.template_id.template_line_ids:
98 analytic_account_id = False104 analytic_account_id = False
99 if line.analytic_account_id:105 if line.analytic_account_id:
100 analytic_account_id = line.analytic_account_id.id106 analytic_account_id = line.analytic_account_id.id
101 invoice_line_tax_id = []107 invoice_line_tax_id = []
102 if line.invoice_line_tax_id:108 if line.invoice_line_tax_id:
103 tax_ids=[]109 tax_ids = []
104 for tax in line.invoice_line_tax_id:110 for tax in line.invoice_line_tax_id:
105 tax_ids.append(tax.id)111 tax_ids.append(tax.id)
106 invoice_line_tax_id.append((6,0, tax_ids))112 invoice_line_tax_id.append((6, 0, tax_ids))
107 val = {113 val = {
108 'name': line.name,114 'name': line.name,
109 'invoice_id': inv_id,115 'invoice_id': inv_id,
@@ -113,7 +119,7 @@
113 'price_unit': computed_lines[line.sequence],119 'price_unit': computed_lines[line.sequence],
114 'product_id': line.product_id.id,120 'product_id': line.product_id.id,
115 }121 }
116 id_line = account_invoice_line_obj.create(cr, uid, val)122 account_invoice_line_obj.create(cr, uid, val, context=context)
117123
118 if wizard.template_id.type in ('out_invoice', 'out_refund'):124 if wizard.template_id.type in ('out_invoice', 'out_refund'):
119 xml_id = 'invoice_form'125 xml_id = 'invoice_form'
@@ -122,12 +128,12 @@
122 resource_id = mod_obj.get_object_reference(cr, uid, 'account', xml_id)[1]128 resource_id = mod_obj.get_object_reference(cr, uid, 'account', xml_id)[1]
123129
124 return {130 return {
125 'domain': "[('id','in', ["+str(inv_id)+"])]",131 'domain': "[('id','in', [" + str(inv_id) + "])]",
126 'name': 'Invoice',132 'name': 'Invoice',
127 'view_type': 'form',133 'view_type': 'form',
128 'view_mode': 'form',134 'view_mode': 'form',
129 'res_model': 'account.invoice',135 'res_model': 'account.invoice',
130 'views': [(resource_id,'form')],136 'views': [(resource_id, 'form')],
131 'type': 'ir.actions.act_window',137 'type': 'ir.actions.act_window',
132 'target': 'current',138 'target': 'current',
133 'res_id': inv_id or False,139 'res_id': inv_id or False,
@@ -141,8 +147,8 @@
141 'template_id': fields.many2one('wizard.select.invoice.template', 'Template'),147 'template_id': fields.many2one('wizard.select.invoice.template', 'Template'),
142 'sequence': fields.integer('Number', required=True),148 'sequence': fields.integer('Number', required=True),
143 'name': fields.char('Name', size=64, required=True, readonly=True),149 'name': fields.char('Name', size=64, required=True, readonly=True),
144 'account_id': fields.many2one('account.account', 'Account', required=True, readonly=True),150 'account_id': fields.many2one('account.account', 'Account',
151 required=True, readonly=True),
145 'amount': fields.float('Amount', required=True),152 'amount': fields.float('Amount', required=True),
146 'product_id': fields.many2one('product.product', 'Product'),153 'product_id': fields.many2one('product.product', 'Product'),
147 }154 }
148

Subscribers

People subscribed via source and target branches