Merge lp:~jb.eficent/department-mgmt/department-mgmt-bugfixes_analytic into lp:~department-core-editors/department-mgmt/7.0

Proposed by JB (eficent.com)
Status: Rejected
Rejected by: Joël Grand-Guillaume @ camptocamp
Proposed branch: lp:~jb.eficent/department-mgmt/department-mgmt-bugfixes_analytic
Merge into: lp:~department-core-editors/department-mgmt/7.0
Diff against target: 65 lines (+32/-1)
3 files modified
analytic_department/__openerp__.py (+1/-1)
analytic_department/analytic.py (+20/-0)
analytic_department/analytic_view.xml (+11/-0)
To merge this branch: bzr merge lp:~jb.eficent/department-mgmt/department-mgmt-bugfixes_analytic
Reviewer Review Type Date Requested Status
Joël Grand-Guillaume @ camptocamp code review + test Disapprove
Daniel Reis Needs Fixing
Pedro Manuel Baeza code review Needs Information
Review via email: mp+212299@code.launchpad.net

Description of the change

Fixes bugs 1296119, 1296109

To post a comment you must log in.
Revision history for this message
Pedro Manuel Baeza (pedro.baeza) wrote :

Hi, Jordi,

Thanks for the contribution. Some questions about your MP:

- Why do you need _get_department method? If you put a related field, this method is not needed.
- Is it possible that you link a different department for the same account_id? If it's so, related field is not the best approach.

Regards.

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

I agree with Pedro. It would be best to keep department_id as a plain many2one, and instead have a default value for it.

Revision history for this message
Daniel Reis (dreis-pt) :
review: Needs Fixing
Revision history for this message
JB (eficent.com) (jb.eficent) wrote :

I first tried to use a default and call the _get_department (and left it there inconsciously), but found that I was not able to retrieve the analytic account's department from there. Not passed in the context. Any idea how can it be fetched?
I think it's not good idea to fetch it again from the employee.
I I would not like to change the logic of the programs that create the analytic line either.

Thanks for your feedback! Very valuable...

Jordi

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

Maybe extending the create() method - if department_id is empty, it could be found and filled after the super() call.

19. By JB (eficent.com)

Defaults department in analytic line during create, based on the department of the analytic account.

Revision history for this message
JB (eficent.com) (jb.eficent) wrote :

Now corrected as per your suggestions. Thanks!

Regards,
Jordi.

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

Hi,

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

Here is my proposal:

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

So, I mark "needs infos".

Regards,

Joël

review: Needs Information (code review + test)
Revision history for this message
Joël Grand-Guillaume @ camptocamp (jgrandguillaume-c2c) wrote :

Hi,

As this MP :https://code.launchpad.net/~camptocamp/department-mgmt/add-account-department-fix-default-anyltic-jge/+merge/218807

Has been merged, I mark this one as disapproved. Reply in there if anything wrong with that.

Regards,

Joël

review: Disapprove (code review + test)

Unmerged revisions

19. By JB (eficent.com)

Defaults department in analytic line during create, based on the department of the analytic account.

18. By JB (eficent.com)

Fixes bugs #1296119, #1296109 on analytic_department

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'analytic_department/__openerp__.py'
2--- analytic_department/__openerp__.py 2013-03-04 16:36:08 +0000
3+++ analytic_department/__openerp__.py 2014-03-26 10:06:58 +0000
4@@ -10,6 +10,6 @@
5 corresponding tree, search and form views.
6 """,
7 "website": "http://camptocamp.com",
8- "depends": ["account", "hr"],
9+ "depends": ["account", "hr", "analytic"],
10 "data": ["analytic_view.xml"],
11 }
12
13=== modified file 'analytic_department/analytic.py'
14--- analytic_department/analytic.py 2013-03-04 16:36:08 +0000
15+++ analytic_department/analytic.py 2014-03-26 10:06:58 +0000
16@@ -11,6 +11,26 @@
17
18 class AnalyticLine(orm.Model):
19 _inherit = "account.analytic.line"
20+
21 _columns = {
22 'department_id': fields.many2one('hr.department', 'Department'),
23 }
24+
25+ def create(self, cr, uid, vals, context=None):
26+ """ Updates the analytic line with the account's department
27+ by default """
28+ if context is None:
29+ context = {}
30+
31+ analytic_obj = self.pool.get('account.analytic.account')
32+ analytic_line_obj = self.pool.get('account.analytic.line')
33+
34+ if vals['account_id']:
35+ account = analytic_obj.browse(cr, uid, vals['account_id'],
36+ context=context)
37+ department_id = None
38+ if account.department_id:
39+ vals['department_id'] = account.department_id.id
40+
41+ return super(AnalyticLine, self).create(cr, uid, vals, context)
42+
43\ No newline at end of file
44
45=== modified file 'analytic_department/analytic_view.xml'
46--- analytic_department/analytic_view.xml 2013-03-04 16:36:08 +0000
47+++ analytic_department/analytic_view.xml 2014-03-26 10:06:58 +0000
48@@ -27,6 +27,17 @@
49 </field>
50 </record>
51
52+ <record id="view_account_analytic_account_form" model="ir.ui.view">
53+ <field name="name">account.analytic.account.form</field>
54+ <field name="model">account.analytic.account</field>
55+ <field name="inherit_id" ref="analytic.view_account_analytic_account_form"/>
56+ <field name="arch" type="xml">
57+ <field name="code" position="after">
58+ <field name="department_id"/>
59+ </field>
60+ </field>
61+ </record>
62+
63 <record id="view_account_analytic_line_form" model="ir.ui.view">
64 <field name="name">account.analytic.line.form</field>
65 <field name="model">account.analytic.line</field>

Subscribers

People subscribed via source and target branches