← Back to team overview

openerp-community-reviewer team mailing list archive

[Merge] lp:~camptocamp/department-mgmt/add-account-department-fix-default-anyltic-jge into lp:department-mgmt

 

Joël Grand-Guillaume @ camptocamp has proposed merging lp:~camptocamp/department-mgmt/add-account-department-fix-default-anyltic-jge into lp:department-mgmt.

Requested reviews:
  Department Core Editors (department-core-editors)
Related bugs:
  Bug #1296109 in Department Management: "Not possible to add the department to an analytic account"
  https://bugs.launchpad.net/department-mgmt/+bug/1296109
  Bug #1296119 in Department Management: "Department is not being defaulted when the analytic lines are created"
  https://bugs.launchpad.net/department-mgmt/+bug/1296119

For more details, see:
https://code.launchpad.net/~camptocamp/department-mgmt/add-account-department-fix-default-anyltic-jge/+merge/218807

Hi,


Add a default value for department_uid and add a new field to manage account's related department.

As suggested in the MP related to task's department (https://code.launchpad.net/~camptocamp/department-mgmt/add-dep-on-project-task-jge/+merge/217068) I think we have 2 important informations in analytic line,.

 * The first one is the user's employee related department
 * The second is the analytic account's related department

Both information are valuable, depending on what you want to know. In my use case, the department_id of the line is fulfill by the employee's department through timesheet lines mostely.

I suggest here a way of dealing with this, basically:

 * department_id is the user's related department, given by a default value calling _get_department
 * A new field called account_department_id is a field.related on the analytic account department_id
 * Adapt all search, group and tree view

This is another suggestion/proposal against this one: 

https://code.launchpad.net/~jb.eficent/department-mgmt/department-mgmt-bugfixes_analytic/+merge/212299

Regards,

Joël
-- 
https://code.launchpad.net/~camptocamp/department-mgmt/add-account-department-fix-default-anyltic-jge/+merge/218807
Your team Department Core Editors is requested to review the proposed merge of lp:~camptocamp/department-mgmt/add-account-department-fix-default-anyltic-jge into lp:department-mgmt.
=== modified file 'analytic_department/analytic.py'
--- analytic_department/analytic.py	2013-03-04 16:36:08 +0000
+++ analytic_department/analytic.py	2014-05-08 13:26:35 +0000
@@ -5,12 +5,45 @@
 class AnalyticAccount(orm.Model):
     _inherit = "account.analytic.account"
     _columns = {
-        'department_id': fields.many2one('hr.department', 'Department'),
+        'department_id': fields.many2one(
+            'hr.department', 
+            'Department'),
     }
 
 
 class AnalyticLine(orm.Model):
     _inherit = "account.analytic.line"
+
+    def _get_department(self, cr, uid, ids, context=None):
+        employee_obj = self.pool['hr.employee']
+        department_id = False
+        employee_ids = employee_obj.search(cr, uid, [('user_id','=', uid)])
+        if employee_ids:
+            employee = employee_obj.browse(cr, uid, 
+                                                employee_ids[0], 
+                                                context=context)
+            if employee.department_id:
+                department_id = employee.department_id.id
+        return department_id
+
     _columns = {
-        'department_id': fields.many2one('hr.department', 'Department'),
-    }
+        'department_id': fields.many2one(
+            'hr.department', 
+            'Department',
+            help="User's related department"),
+        'account_department_id': fields.related(
+            'account_id',
+            'department_id',
+            type='many2one',
+            relation='hr.department',
+            string='Account Department',
+            store=True,
+            readonly=True,
+            help="Account's related department"),
+    }
+
+    _defaults = {
+        'department_id': _get_department,
+    }
+
+       
\ No newline at end of file

=== modified file 'analytic_department/analytic_view.xml'
--- analytic_department/analytic_view.xml	2013-03-04 16:36:08 +0000
+++ analytic_department/analytic_view.xml	2014-05-08 13:26:35 +0000
@@ -26,6 +26,17 @@
                 </field>
             </field>
         </record>
+
+        <record id="view_account_analytic_account_form" model="ir.ui.view">
+            <field name="name">account.analytic.account.form</field>
+            <field name="model">account.analytic.account</field>
+            <field name="inherit_id" ref="analytic.view_account_analytic_account_form"/>
+            <field name="arch" type="xml">
+                <field name="code" position="after">
+                    <field name="department_id"/>
+                </field>
+            </field>
+        </record>
         
         <record id="view_account_analytic_line_form" model="ir.ui.view">
             <field name="name">account.analytic.line.form</field>
@@ -34,6 +45,7 @@
             <field name="arch" type="xml">
                 <field name="company_id" position="after">
                     <field name="department_id"/>
+                    <field name="account_department_id"/>
                 </field>
             </field>
         </record>
@@ -45,6 +57,7 @@
             <field name="arch" type="xml">
                 <field name="company_id" position="after">
                     <field name="department_id"/>
+                    <field name="account_department_id"/>
                 </field>
             </field>
         </record>
@@ -56,9 +69,11 @@
             <field name="arch" type="xml">
                 <field name="user_id" position="before">
                     <field name="department_id" widget="selection"/>
+                    <field name="account_department_id" widget="selection"/>
                 </field>
                 <xpath expr="/search/group/filter[@string='User']" position="after">
                     <filter string="Department" icon="terp-folder-orange" domain="[]" context="{'group_by':'department_id'}"/>
+                    <filter string="Account Department" icon="terp-folder-orange" domain="[]" context="{'group_by':'account_department_id'}"/>
                 </xpath>
             </field>
         </record>


Follow ups