Merge lp:~camptocamp/project-reporting/7.0-fix-dissociate-lep into lp:~project-core-editors/project-reporting/7.0

Proposed by Leonardo Pistone
Status: Merged
Approved by: Alexandre Fayolle - camptocamp
Approved revision: 17
Merged at revision: 17
Proposed branch: lp:~camptocamp/project-reporting/7.0-fix-dissociate-lep
Merge into: lp:~project-core-editors/project-reporting/7.0
Diff against target: 133 lines (+67/-17)
3 files modified
project_billing_utils/__init__.py (+3/-2)
project_billing_utils/analytic.py (+46/-0)
project_billing_utils/wizard/dissociate_aal.py (+18/-15)
To merge this branch: bzr merge lp:~camptocamp/project-reporting/7.0-fix-dissociate-lep
Reviewer Review Type Date Requested Status
Alexandre Fayolle - camptocamp code review, no test Approve
Matthieu Dietrich @ camptocamp (community) code review, test Approve
Guewen Baconnier @ Camptocamp code review Approve
Review via email: mp+200695@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Alexandre Fayolle - camptocamp (alexandre-fayolle-c2c) wrote :

You've changed the name of the key in project_billing_utils/analytic.py as I suggested yesterday evening, but forgot to change it in project_billing_utils/wizard/dissociate_aal.py (line 127 of the diff below), which means the branch in the current state no longer fixes lp:1266850

Stylistically I'm not fond of the blank line between class definition line and docstring, or the blank line at the end of the docstring (but I won't fight over this).

review: Needs Fixing (code review, no test)
Revision history for this message
Leonardo Pistone (lepistone) wrote :

Thanks for your review Alexandre.

1. We changed the key passed in "vals", but the key in the context is still the same. So that LGTM.

2. I followed http://www.python.org/dev/peps/pep-0257/#multi-line-docstrings "Insert a blank line before and after all docstrings (one-line or multi-line) that document a class"

Revision history for this message
Guewen Baconnier @ Camptocamp (gbaconnier-c2c) wrote :

LGTM

review: Approve (code review)
Revision history for this message
Matthieu Dietrich @ camptocamp (mdietrich-c2c) wrote :

LGTM, tested locally.

review: Approve (code review, test)
Revision history for this message
Alexandre Fayolle - camptocamp (alexandre-fayolle-c2c) :
review: Approve (code review, no test)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'project_billing_utils/__init__.py'
2--- project_billing_utils/__init__.py 2013-06-20 15:17:21 +0000
3+++ project_billing_utils/__init__.py 2014-01-07 17:14:34 +0000
4@@ -1,8 +1,8 @@
5 # -*- coding: utf-8 -*-
6 ##############################################################################
7 #
8-# Author: Joël Grand-Guillaume
9-# Copyright 2010 Camptocamp SA
10+# Author: Joël Grand-Guillaume, Leonardo Pistone
11+# Copyright 2010-2014 Camptocamp SA
12 #
13 # This program is free software: you can redistribute it and/or modify
14 # it under the terms of the GNU Affero General Public License as
15@@ -22,4 +22,5 @@
16 import project
17 import wizard
18 import invoice
19+import analytic # noqa
20 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
21
22=== added file 'project_billing_utils/analytic.py'
23--- project_billing_utils/analytic.py 1970-01-01 00:00:00 +0000
24+++ project_billing_utils/analytic.py 2014-01-07 17:14:34 +0000
25@@ -0,0 +1,46 @@
26+# -*- coding: utf-8 -*-
27+##############################################################################
28+#
29+# Author: Leonardo Pistone
30+# Copyright 2014 Camptocamp SA
31+#
32+# This program is free software: you can redistribute it and/or modify
33+# it under the terms of the GNU Affero General Public License as
34+# published by the Free Software Foundation, either version 3 of the
35+# License, or (at your option) any later version.
36+#
37+# This program is distributed in the hope that it will be useful,
38+# but WITHOUT ANY WARRANTY; without even the implied warranty of
39+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
40+# GNU Affero General Public License for more details.
41+#
42+# You should have received a copy of the GNU Affero General Public License
43+# along with this program. If not, see <http://www.gnu.org/licenses/>.
44+#
45+##############################################################################
46+"""Changes to allow the dissociate analytic lines wizard to work."""
47+
48+from openerp.osv import orm
49+
50+
51+class account_analytic_line(orm.Model):
52+
53+ """Hack the analytic line to optionally skip the invoice check."""
54+
55+ _inherit = 'account.analytic.line'
56+
57+ def write(self, cr, uid, ids, vals, context=None):
58+ """Put a key in the vals, since we have no context. Return super."""
59+ if context.get('skip_invoice_check'):
60+ vals['_x_vals_skip_invoice_check'] = True
61+
62+ return super(account_analytic_line, self).write(
63+ cr, uid, ids, vals, context=context)
64+
65+ def _check_inv(self, cr, uid, ids, vals):
66+ """Optionally skip invoice check. Return boolean."""
67+ if '_x_vals_skip_invoice_check' in vals:
68+ del vals['_x_vals_skip_invoice_check']
69+ return True
70+ return super(account_analytic_line, self)._check_inv(
71+ cr, uid, ids, vals)
72
73=== modified file 'project_billing_utils/wizard/dissociate_aal.py'
74--- project_billing_utils/wizard/dissociate_aal.py 2013-10-31 15:31:39 +0000
75+++ project_billing_utils/wizard/dissociate_aal.py 2014-01-07 17:14:34 +0000
76@@ -1,8 +1,8 @@
77 # -*- coding: utf-8 -*-
78 ##############################################################################
79 #
80-# Author: Joël Grand-Guillaume
81-# Copyright 2010 Camptocamp SA
82+# Author: Joël Grand-Guillaume, Leonardo Pistone
83+# Copyright 2010-2014 Camptocamp SA
84 #
85 # This program is free software: you can redistribute it and/or modify
86 # it under the terms of the GNU Affero General Public License as
87@@ -18,30 +18,33 @@
88 # along with this program. If not, see <http://www.gnu.org/licenses/>.
89 #
90 ##############################################################################
91+"""Introduce a wizard to dissociate an Analytic Line from an Invoice."""
92 from openerp.osv import orm
93
94
95 class DissociateInvoice(orm.TransientModel):
96+
97+ """Wizard to dissociate an Analytic Line from an Invoice."""
98+
99 _name = 'dissociate.aal.to.invoice'
100 _description = 'Dissociate Analytic Lines'
101
102 def dissociate_aal(self, cr, uid, ids, context=None):
103+ """Dissociate invoice from the line and return {}.
104+
105+ This is necessary because the module hr_timesheet_invoice introduces
106+ a check that we want to avoid.
107+
108+ """
109 if context is None:
110 context = {}
111+
112 aal_obj = self.pool.get(context['active_model'])
113- aal_ids = context.get('active_ids', False)
114- if isinstance(ids, list):
115- req_id = ids[0]
116- else:
117- req_id = ids
118- ids2 = []
119- for id in aal_ids:
120- ids2.append(id)
121- # Use of SQL here cause otherwise the ORM won't allow to modify the invoiced AAL
122- # which is exactly what we want !
123- query = "UPDATE account_analytic_line SET invoice_id = NULL WHERE id IN %s"
124- cr.execute(query, (tuple(ids2),))
125-
126+ ctx = context.copy()
127+ ctx['skip_invoice_check'] = True
128+ aal_obj.write(cr, uid, context['active_ids'], {
129+ 'invoice_id': False
130+ }, ctx)
131 return {}
132
133 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

Subscribers

People subscribed via source and target branches