Merge lp:~akretion-team/account-analytic/account-analytic-required-pep8 into lp:~acsone-openerp/account-analytic/account_analytic_required-test_suite-sbi

Proposed by Alexis de Lattre on 2014-04-18
Status: Merged
Merged at revision: 19
Proposed branch: lp:~akretion-team/account-analytic/account-analytic-required-pep8
Merge into: lp:~acsone-openerp/account-analytic/account_analytic_required-test_suite-sbi
Diff against target: 212 lines (+80/-31)
5 files modified
account_analytic_required/__init__.py (+1/-1)
account_analytic_required/__openerp__.py (+10/-7)
account_analytic_required/account.py (+46/-15)
account_analytic_required/account_view.xml (+12/-1)
account_analytic_required/tests/test_account_analytic_required.py (+11/-7)
To merge this branch: bzr merge lp:~akretion-team/account-analytic/account-analytic-required-pep8
Reviewer Review Type Date Requested Status
Raphaël Valyi - http://www.akretion.com (community) Approve on 2014-04-18
Stéphane Bidoul (Acsone) 2014-04-18 Pending
Review via email: mp+216497@code.launchpad.net

Description of the change

Flake8 valid.
Small code cleanup.
Add account analytic policy in tree view (make it much easier to check the configuration of all the account types).

To post a comment you must log in.

straightforward LGTM

review: Approve
Stéphane Bidoul (Acsone) (sbi) wrote :

Ah, long lines...

Merged, thanks!

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'account_analytic_required/__init__.py'
2--- account_analytic_required/__init__.py 2012-11-21 08:56:48 +0000
3+++ account_analytic_required/__init__.py 2014-04-18 22:34:20 +0000
4@@ -21,4 +21,4 @@
5 ##############################################################################
6
7
8-import account
9+from . import account
10
11=== modified file 'account_analytic_required/__openerp__.py'
12--- account_analytic_required/__openerp__.py 2013-04-23 14:25:48 +0000
13+++ account_analytic_required/__openerp__.py 2014-04-18 22:34:20 +0000
14@@ -2,7 +2,7 @@
15 ##############################################################################
16 #
17 # Account analytic required module for OpenERP
18-# Copyright (C) 2011 Akretion (http://www.akretion.com). All Rights Reserved
19+# Copyright (C) 2011 Akretion (http://www.akretion.com)
20 # @author Alexis de Lattre <alexis.delattre@akretion.com>
21 #
22 # This program is free software: you can redistribute it and/or modify
23@@ -22,13 +22,17 @@
24
25
26 {
27- 'name': 'Account analytic required',
28+ 'name': 'Account Analytic Required',
29 'version': '0.2',
30- 'category': 'Generic Modules/Accounting',
31+ 'category': 'Analytic Accounting',
32 'license': 'AGPL-3',
33- 'description': """This module adds an option "analytic policy" on account types. You have the choice between 3 policies : always, never and optional.
34-
35-For example, if you want to have an analytic account on all your expenses, set the policy to "always" for the account type "expense" ; then, if you try to save an account move line with an account of type "expense" without analytic account, you will get an error message.
36+ 'description': """
37+Account Analytic Required
38+=========================
39+
40+This module adds an option *analytic policy* on account types. You have the choice between 3 policies : *always*, *never* and *optional*.
41+
42+For example, if you want to have an analytic account on all your expenses, set the policy to *always* for the account type *expense* ; then, if you try to save an account move line with an account of type *expense* without analytic account, you will get an error message.
43
44 Module developped by Alexis de Lattre <alexis.delattre@akretion.com> during the Akretion-Camptocamp code sprint of June 2011.
45 """,
46@@ -39,4 +43,3 @@
47 'installable': True,
48 'active': False,
49 }
50-
51
52=== modified file 'account_analytic_required/account.py'
53--- account_analytic_required/account.py 2014-04-18 13:45:56 +0000
54+++ account_analytic_required/account.py 2014-04-18 22:34:20 +0000
55@@ -2,7 +2,7 @@
56 ##############################################################################
57 #
58 # Account analytic required module for OpenERP
59-# Copyright (C) 2011 Akretion (http://www.akretion.com). All Rights Reserved
60+# Copyright (C) 2011 Akretion (http://www.akretion.com)
61 # @author Alexis de Lattre <alexis.delattre@akretion.com>
62 # Developped during the Akretion-Camptocamp code sprint of June 2011
63 #
64@@ -22,22 +22,29 @@
65 ##############################################################################
66
67 from openerp.osv import orm, fields
68-from tools.translate import _
69+from openerp.tools.translate import _
70
71
72 class account_account_type(orm.Model):
73 _inherit = "account.account.type"
74
75 _columns = {
76- 'analytic_policy' : fields.selection([
77+ 'analytic_policy': fields.selection([
78 ('optional', 'Optional'),
79 ('always', 'Always'),
80 ('never', 'Never')
81- ], 'Policy for analytic account', help="Set the policy for analytic accounts : if you select 'Optional', the accountant is free to put an analytic account on an account move line with this type of account ; if you select 'Always', the accountant will get an error message if there is no analytic account ; if you select 'Never', the accountant will get an error message if an analytic account is present."),
82+ ], 'Policy for analytic account',
83+ help="Set the policy for analytic accounts : if you select "
84+ "'Optional', the accountant is free to put an analytic account "
85+ "on an account move line with this type of account ; if you "
86+ "select 'Always', the accountant will get an error message if "
87+ "there is no analytic account ; if you select 'Never', the "
88+ "accountant will get an error message if an analytic account "
89+ "is present."),
90 }
91
92 _defaults = {
93- 'analytic_policy': lambda *a: 'optional',
94+ 'analytic_policy': 'optional',
95 }
96
97
98@@ -52,21 +59,45 @@
99 for move_line in self.browse(cr, uid, ids, context):
100 if move_line.debit == 0 and move_line.credit == 0:
101 continue
102- analytic_policy = move_line.account_id.user_type.analytic_policy
103- if analytic_policy == 'always' and not move_line.analytic_account_id:
104- raise orm.except_orm(_('Error :'), _("Analytic policy is set to 'Always' with account %s '%s' but the analytic account is missing in the account move line with label '%s'." % (move_line.account_id.code, move_line.account_id.name, move_line.name)))
105- elif analytic_policy == 'never' and move_line.analytic_account_id:
106- raise orm.except_orm(_('Error :'), _("Analytic policy is set to 'Never' with account %s '%s' but the account move line with label '%s' has an analytic account %s '%s'." % (move_line.account_id.code, move_line.account_id.name, move_line.name, move_line.analytic_account_id.code, move_line.analytic_account_id.name)))
107+ analytic_policy = \
108+ move_line.account_id.user_type.analytic_policy
109+ if analytic_policy == 'always' and \
110+ not move_line.analytic_account_id:
111+ raise orm.except_orm(
112+ _('Error :'),
113+ _("Analytic policy is set to 'Always' with account "
114+ "%s '%s' but the analytic account is missing in "
115+ "the account move line with label '%s'.")
116+ % (
117+ move_line.account_id.code,
118+ move_line.account_id.name,
119+ move_line.name))
120+ elif analytic_policy == 'never' and \
121+ move_line.analytic_account_id:
122+ raise orm.except_orm(
123+ _('Error :'),
124+ _("Analytic policy is set to 'Never' with account %s "
125+ "'%s' but the account move line with label '%s' "
126+ "has an analytic account %s '%s'.")
127+ % (
128+ move_line.account_id.code,
129+ move_line.account_id.name,
130+ move_line.name,
131+ move_line.analytic_account_id.code,
132+ move_line.analytic_account_id.name))
133 return True
134
135 def create(self, cr, uid, vals, context=None, check=True):
136- line_id = super(account_move_line, self).create(cr, uid, vals, context=context, check=check)
137+ line_id = super(account_move_line, self).create(
138+ cr, uid, vals, context=context, check=check)
139 self.check_analytic_required(cr, uid, line_id, vals, context=context)
140 return line_id
141
142- def write(self, cr, uid, ids, vals, context=None, check=True, update_check=True):
143- res = super(account_move_line, self).write(cr, uid, ids, vals, context=context, check=check, update_check=update_check)
144+ def write(
145+ self, cr, uid, ids, vals, context=None, check=True,
146+ update_check=True):
147+ res = super(account_move_line, self).write(
148+ cr, uid, ids, vals, context=context, check=check,
149+ update_check=update_check)
150 self.check_analytic_required(cr, uid, ids, vals, context=context)
151 return res
152-
153-
154
155=== modified file 'account_analytic_required/account_view.xml'
156--- account_analytic_required/account_view.xml 2012-11-21 08:56:48 +0000
157+++ account_analytic_required/account_view.xml 2014-04-18 22:34:20 +0000
158@@ -15,7 +15,18 @@
159 <field name="inherit_id" ref="account.view_account_type_form" />
160 <field name="arch" type="xml">
161 <field name="code" position="after">
162- <field name="analytic_policy" />
163+ <field name="analytic_policy" />
164+ </field>
165+ </field>
166+</record>
167+
168+<record id="view_account_type_tree" model="ir.ui.view">
169+ <field name="name">account_analytic_required.account_type_tree</field>
170+ <field name="model">account.account.type</field>
171+ <field name="inherit_id" ref="account.view_account_type_tree" />
172+ <field name="arch" type="xml">
173+ <field name="code" position="after">
174+ <field name="analytic_policy" />
175 </field>
176 </field>
177 </record>
178
179=== modified file 'account_analytic_required/tests/test_account_analytic_required.py'
180--- account_analytic_required/tests/test_account_analytic_required.py 2014-04-18 13:45:56 +0000
181+++ account_analytic_required/tests/test_account_analytic_required.py 2014-04-18 22:34:20 +0000
182@@ -56,7 +56,8 @@
183 'debit': 0,
184 'credit': amount,
185 'account_id': self.ref('account.a_sale'),
186- 'analytic_account_id': self.analytic_account_id if with_analytic else False})
187+ 'analytic_account_id':
188+ self.analytic_account_id if with_analytic else False})
189 self.move_line_obj.create(
190 self.cr, self.uid,
191 {'move_id': move_id,
192@@ -115,11 +116,14 @@
193 def test_change_account(self):
194 self._set_analytic_policy('always', aref='account.a_expense')
195 line_id = self._create_move(with_analytic=False)
196- # change account to a_pay with policy always but missing analytic_account
197+ # change account to a_pay with policy always but missing
198+ # analytic_account
199 with self.assertRaises(orm.except_orm):
200- self.move_line_obj.write(self.cr, self.uid, line_id,
201- {'account_id': self.ref('account.a_expense')})
202+ self.move_line_obj.write(
203+ self.cr, self.uid, line_id,
204+ {'account_id': self.ref('account.a_expense')})
205 # change account to a_pay with policy always with partner -> ok
206- self.move_line_obj.write(self.cr, self.uid, line_id,
207- {'account_id': self.ref('account.a_expense'),
208- 'analytic_account_id': self.analytic_account_id})
209+ self.move_line_obj.write(
210+ self.cr, self.uid, line_id, {
211+ 'account_id': self.ref('account.a_expense'),
212+ 'analytic_account_id': self.analytic_account_id})

Subscribers

People subscribed via source and target branches