← Back to team overview

openerp-community-reviewer team mailing list archive

[Merge] lp:~camptocamp/project-reporting/7.0-fix-dissociate-lep into lp:project-reporting

 

Leonardo Pistone @ camptocamp has proposed merging lp:~camptocamp/project-reporting/7.0-fix-dissociate-lep into lp:project-reporting.

Requested reviews:
  Project Core Editors (project-core-editors)
Related bugs:
  Bug #1266850 in Project Management - Invoicing and Reporting: "project_billing_utils: dissociate invoice wizard uses SQL and that breaks triggers in module analytic_hours_block"
  https://bugs.launchpad.net/project-reporting/+bug/1266850

For more details, see:
https://code.launchpad.net/~camptocamp/project-reporting/7.0-fix-dissociate-lep/+merge/200695
-- 
https://code.launchpad.net/~camptocamp/project-reporting/7.0-fix-dissociate-lep/+merge/200695
Your team Project Core Editors is requested to review the proposed merge of lp:~camptocamp/project-reporting/7.0-fix-dissociate-lep into lp:project-reporting.
=== modified file 'project_billing_utils/__init__.py'
--- project_billing_utils/__init__.py	2013-06-20 15:17:21 +0000
+++ project_billing_utils/__init__.py	2014-01-07 17:14:34 +0000
@@ -1,8 +1,8 @@
 # -*- coding: utf-8 -*-
 ##############################################################################
 #
-#    Author: Joël Grand-Guillaume
-#    Copyright 2010 Camptocamp SA
+#    Author: Joël Grand-Guillaume, Leonardo Pistone
+#    Copyright 2010-2014 Camptocamp SA
 #
 #    This program is free software: you can redistribute it and/or modify
 #    it under the terms of the GNU Affero General Public License as
@@ -22,4 +22,5 @@
 import project
 import wizard
 import invoice
+import analytic  # noqa
 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

=== added file 'project_billing_utils/analytic.py'
--- project_billing_utils/analytic.py	1970-01-01 00:00:00 +0000
+++ project_billing_utils/analytic.py	2014-01-07 17:14:34 +0000
@@ -0,0 +1,46 @@
+# -*- coding: utf-8 -*-
+##############################################################################
+#
+#    Author: Leonardo Pistone
+#    Copyright 2014 Camptocamp SA
+#
+#    This program is free software: you can redistribute it and/or modify
+#    it under the terms of the GNU Affero General Public License as
+#    published by the Free Software Foundation, either version 3 of the
+#    License, or (at your option) any later version.
+#
+#    This program is distributed in the hope that it will be useful,
+#    but WITHOUT ANY WARRANTY; without even the implied warranty of
+#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#    GNU Affero General Public License for more details.
+#
+#    You should have received a copy of the GNU Affero General Public License
+#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
+#
+##############################################################################
+"""Changes to allow the dissociate analytic lines wizard to work."""
+
+from openerp.osv import orm
+
+
+class account_analytic_line(orm.Model):
+
+    """Hack the analytic line to optionally skip the invoice check."""
+
+    _inherit = 'account.analytic.line'
+
+    def write(self, cr, uid, ids, vals, context=None):
+        """Put a key in the vals, since we have no context. Return super."""
+        if context.get('skip_invoice_check'):
+            vals['_x_vals_skip_invoice_check'] = True
+
+        return super(account_analytic_line, self).write(
+            cr, uid, ids, vals, context=context)
+
+    def _check_inv(self, cr, uid, ids, vals):
+        """Optionally skip invoice check. Return boolean."""
+        if '_x_vals_skip_invoice_check' in vals:
+            del vals['_x_vals_skip_invoice_check']
+            return True
+        return super(account_analytic_line, self)._check_inv(
+            cr, uid, ids, vals)

=== modified file 'project_billing_utils/wizard/dissociate_aal.py'
--- project_billing_utils/wizard/dissociate_aal.py	2013-10-31 15:31:39 +0000
+++ project_billing_utils/wizard/dissociate_aal.py	2014-01-07 17:14:34 +0000
@@ -1,8 +1,8 @@
 # -*- coding: utf-8 -*-
 ##############################################################################
 #
-#    Author: Joël Grand-Guillaume
-#    Copyright 2010 Camptocamp SA
+#    Author: Joël Grand-Guillaume, Leonardo Pistone
+#    Copyright 2010-2014 Camptocamp SA
 #
 #    This program is free software: you can redistribute it and/or modify
 #    it under the terms of the GNU Affero General Public License as
@@ -18,30 +18,33 @@
 #    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 #
 ##############################################################################
+"""Introduce a wizard to dissociate an Analytic Line from an Invoice."""
 from openerp.osv import orm
 
 
 class DissociateInvoice(orm.TransientModel):
+
+    """Wizard to dissociate an Analytic Line from an Invoice."""
+
     _name = 'dissociate.aal.to.invoice'
     _description = 'Dissociate Analytic Lines'
 
     def dissociate_aal(self, cr, uid, ids, context=None):
+        """Dissociate invoice from the line and return {}.
+
+        This is necessary because the module hr_timesheet_invoice introduces
+        a check that we want to avoid.
+
+        """
         if context is None:
             context = {}
+
         aal_obj = self.pool.get(context['active_model'])
-        aal_ids = context.get('active_ids', False)
-        if isinstance(ids, list):
-            req_id = ids[0]
-        else:
-            req_id = ids
-        ids2 = []
-        for id in aal_ids:
-            ids2.append(id)
-        # Use of SQL here cause otherwise the ORM won't allow to modify the invoiced AAL
-        # which is exactly what we want !
-        query = "UPDATE account_analytic_line SET invoice_id = NULL WHERE id IN %s"
-        cr.execute(query, (tuple(ids2),))
-
+        ctx = context.copy()
+        ctx['skip_invoice_check'] = True
+        aal_obj.write(cr, uid, context['active_ids'], {
+            'invoice_id': False
+        }, ctx)
         return {}
 
 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:


Follow ups