Merge lp:~camptocamp/department-mgmt/add-account-department-fix-default-anyltic-jge into lp:~department-core-editors/department-mgmt/7.0

Proposed by Joël Grand-Guillaume @ camptocamp
Status: Merged
Merged at revision: 19
Proposed branch: lp:~camptocamp/department-mgmt/add-account-department-fix-default-anyltic-jge
Merge into: lp:~department-core-editors/department-mgmt/7.0
Diff against target: 118 lines (+66/-3)
2 files modified
analytic_department/analytic.py (+51/-3)
analytic_department/analytic_view.xml (+15/-0)
To merge this branch: bzr merge lp:~camptocamp/department-mgmt/add-account-department-fix-default-anyltic-jge
Reviewer Review Type Date Requested Status
Daniel Reis Approve
Guewen Baconnier @ Camptocamp code review Approve
JB (eficent.com) Pending
Review via email: mp+218807@code.launchpad.net

Description of the change

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

To post a comment you must log in.
Revision history for this message
Guewen Baconnier @ Camptocamp (gbaconnier-c2c) wrote :

l.21: context propagation is missing
l.25-25: indentation could be aligned
l.37: if the department of the account changes, the analytic lines won't be changed. That's maybe what is wanted though. I propose either to add triggers, either to add a comment why the departement on the analytic lines should not be changed

review: Needs Fixing
21. By Joël Grand-Guillaume @ camptocamp

[IMP] Add triggers on needed field (as suggested by review)
[FIX] Context propagation
[IMP] Few PEP8

Revision history for this message
Joël Grand-Guillaume @ camptocamp (jgrandguillaume-c2c) wrote :

Hi,

Thanks for the review I missed the trigger :( I corrected all the points.

Regards,

Joël

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

Thanks!
LGTM

review: Approve (code review)
Revision history for this message
Daniel Reis (dreis-pt) wrote :

I believe this covers the distinct user cases better than Jordi's MP.
So I would prefer for this one to be merged.
Anyway, I invited him for this review.

On the syle side, it's just a personal preference, but for:

    employee_ids = employee_obj.search(cr, uid,
                                       [('user_id','=', uid)],
                                       context=context)

I usually prefer:

    employee_ids = employee_obj.search(
        cr, uid,[('user_id','=', uid)], context=context)

review: Approve
Revision history for this message
Pedro Manuel Baeza (pedro.baeza) wrote :

FYI, first form doesn't comply with PEP8 indentation rule that if you put arguments of first line, you have to put vertical alignment, but the second one lacks some spaces after commas ;)

That it's marked as E128 error on flake8.

Regards.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'analytic_department/analytic.py'
2--- analytic_department/analytic.py 2013-03-04 16:36:08 +0000
3+++ analytic_department/analytic.py 2014-05-12 08:05:04 +0000
4@@ -5,12 +5,60 @@
5 class AnalyticAccount(orm.Model):
6 _inherit = "account.analytic.account"
7 _columns = {
8- 'department_id': fields.many2one('hr.department', 'Department'),
9+ 'department_id': fields.many2one(
10+ 'hr.department',
11+ 'Department'),
12 }
13
14
15 class AnalyticLine(orm.Model):
16 _inherit = "account.analytic.line"
17+
18+ def _get_department(self, cr, uid, ids, context=None):
19+ employee_obj = self.pool['hr.employee']
20+ department_id = False
21+ employee_ids = employee_obj.search(cr, uid,
22+ [('user_id','=', uid)],
23+ context=context)
24+ if employee_ids:
25+ employee = employee_obj.browse(cr, uid,
26+ employee_ids[0],
27+ context=context)
28+ if employee.department_id:
29+ department_id = employee.department_id.id
30+ return department_id
31+
32+ def _get_account_line(self, cr, uid, ids, context=None):
33+ aa_line_obj = self.pool.get('account.analytic.line')
34+ return aa_line_obj.search(cr, uid,
35+ [('account_id', 'in', ids)],
36+ context=context)
37+
38 _columns = {
39- 'department_id': fields.many2one('hr.department', 'Department'),
40- }
41+ 'department_id': fields.many2one(
42+ 'hr.department',
43+ 'Department',
44+ help="User's related department"),
45+ 'account_department_id': fields.related(
46+ 'account_id',
47+ 'department_id',
48+ type='many2one',
49+ relation='hr.department',
50+ string='Account Department',
51+ store={
52+ 'account.analytic.account': (_get_account_line,
53+ ['department_id'],
54+ 50),
55+ 'account.analytic.line': (lambda self, cr, uid, ids, c=None: ids,
56+ ['account_id'],
57+ 10),
58+ },
59+ readonly=True,
60+ help="Account's related department"),
61+ }
62+
63+ _defaults = {
64+ 'department_id': _get_department,
65+ }
66+
67+
68\ No newline at end of file
69
70=== modified file 'analytic_department/analytic_view.xml'
71--- analytic_department/analytic_view.xml 2013-03-04 16:36:08 +0000
72+++ analytic_department/analytic_view.xml 2014-05-12 08:05:04 +0000
73@@ -26,6 +26,17 @@
74 </field>
75 </field>
76 </record>
77+
78+ <record id="view_account_analytic_account_form" model="ir.ui.view">
79+ <field name="name">account.analytic.account.form</field>
80+ <field name="model">account.analytic.account</field>
81+ <field name="inherit_id" ref="analytic.view_account_analytic_account_form"/>
82+ <field name="arch" type="xml">
83+ <field name="code" position="after">
84+ <field name="department_id"/>
85+ </field>
86+ </field>
87+ </record>
88
89 <record id="view_account_analytic_line_form" model="ir.ui.view">
90 <field name="name">account.analytic.line.form</field>
91@@ -34,6 +45,7 @@
92 <field name="arch" type="xml">
93 <field name="company_id" position="after">
94 <field name="department_id"/>
95+ <field name="account_department_id"/>
96 </field>
97 </field>
98 </record>
99@@ -45,6 +57,7 @@
100 <field name="arch" type="xml">
101 <field name="company_id" position="after">
102 <field name="department_id"/>
103+ <field name="account_department_id"/>
104 </field>
105 </field>
106 </record>
107@@ -56,9 +69,11 @@
108 <field name="arch" type="xml">
109 <field name="user_id" position="before">
110 <field name="department_id" widget="selection"/>
111+ <field name="account_department_id" widget="selection"/>
112 </field>
113 <xpath expr="/search/group/filter[@string='User']" position="after">
114 <filter string="Department" icon="terp-folder-orange" domain="[]" context="{'group_by':'department_id'}"/>
115+ <filter string="Account Department" icon="terp-folder-orange" domain="[]" context="{'group_by':'account_department_id'}"/>
116 </xpath>
117 </field>
118 </record>

Subscribers

People subscribed via source and target branches