Merge lp:~openerp-dev/openobject-addons/trunk-bug-717198-pso into lp:openobject-addons

Proposed by Priyesh (OpenERP)
Status: Merged
Merged at revision: 4757
Proposed branch: lp:~openerp-dev/openobject-addons/trunk-bug-717198-pso
Merge into: lp:openobject-addons
Diff against target: 60 lines (+33/-0)
2 files modified
account_analytic_plans/account_analytic_plans.py (+21/-0)
account_analytic_plans/account_analytic_plans_view.xml (+12/-0)
To merge this branch: bzr merge lp:~openerp-dev/openobject-addons/trunk-bug-717198-pso
Reviewer Review Type Date Requested Status
Priyesh (OpenERP) (community) Needs Resubmitting
qdp (OpenERP) Needs Fixing
Mustufa Rangwala (Open ERP) (community) Approve
Review via email: mp+57623@code.launchpad.net

Description of the change

Fixed bug: 717198 (https://bugs.launchpad.net/openobject-addons/+bug/717198)
Fixed wrong computation of amount currency in analytic lines.

To post a comment you must log in.
Revision history for this message
Priyesh (OpenERP) (pso-openerp) wrote :

Moved amount currency function from account to analytic plans.

review: Needs Resubmitting
Revision history for this message
Mustufa Rangwala (Open ERP) (mra-tinyerp) wrote :

account/account_analytic_line.py => remove unused changes.
self.pool.get('res.currency') => declare outside loop

review: Needs Fixing
Revision history for this message
Priyesh (OpenERP) (pso-openerp) wrote :

Removed Extra spaces and Declared "self.pool.get('res.currency')" outside loop.

review: Needs Resubmitting
Revision history for this message
Mustufa Rangwala (Open ERP) (mra-tinyerp) :
review: Approve
Revision history for this message
qdp (OpenERP) (qdp) wrote :

for this bug, i'm not sure this is the god way to solve the problem. I would have prefer to have a new fields.float to save the percentage used t compute the amount in company currency, then in the _get_amount function we can just call super() and apply this percentage to the result to get the final result.

It seems more interesting because:
1)it reuses the code of super and do not compute again by its own the amount in currency (which is error prone, btw there is an error in this method: you should have passed a date in the context in compute() in order to use the rate at the good date... so maybe there are other errors)
2)it stores a new information that seems very valuable for any future needs

Thanks

review: Needs Fixing
Revision history for this message
Mustufa Rangwala (Open ERP) (mra-tinyerp) wrote :

As per the discussion with qdp no need to call super() as it is related field on parent class and here we define it fields.function.

just add percentage field on analytic line and return total_in_currency * percentage ..

Thanks to qdp for suggestion.
mra

Revision history for this message
Priyesh (OpenERP) (pso-openerp) wrote :

Added new field for percentage, Improved create_analytic_lines and Improved function for amount currency

review: Needs Resubmitting

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'account_analytic_plans/account_analytic_plans.py'
2--- account_analytic_plans/account_analytic_plans.py 2011-01-14 00:11:01 +0000
3+++ account_analytic_plans/account_analytic_plans.py 2011-05-06 06:06:37 +0000
4@@ -47,6 +47,26 @@
5 res[r[self._fields_id]].append( r['id'] )
6 return res
7
8+class account_analytic_line(osv.osv):
9+ _inherit = 'account.analytic.line'
10+ _description = 'Analytic Line'
11+
12+ def _get_amount(self, cr, uid, ids, name, args, context=None):
13+ res = {}
14+ for id in ids:
15+ res.setdefault(id, 0.0)
16+ for line in self.browse(cr, uid, ids, context=context):
17+ amount = line.move_id and line.move_id.amount_currency * (line.percentage / 100) or 0.0
18+ res[line.id] = amount
19+ return res
20+
21+ _columns = {
22+ 'amount_currency': fields.function(_get_amount, string="Amount Currency", type="float", method=True, store=True, help="The amount expressed in the related account currency if not equal to the company one.", readonly=True),
23+ 'percentage': fields.float('Percentage')
24+ }
25+
26+account_analytic_line()
27+
28 class account_analytic_plan(osv.osv):
29 _name = "account.analytic.plan"
30 _description = "Analytic Plan"
31@@ -338,6 +358,7 @@
32 'move_id': line.id,
33 'journal_id': line.journal_id.analytic_journal_id.id,
34 'ref': line.ref,
35+ 'percentage': line2.rate
36 }
37 analytic_line_obj.create(cr, uid, al_vals, context=context)
38 return True
39
40=== modified file 'account_analytic_plans/account_analytic_plans_view.xml'
41--- account_analytic_plans/account_analytic_plans_view.xml 2011-01-27 09:49:39 +0000
42+++ account_analytic_plans/account_analytic_plans_view.xml 2011-05-06 06:06:37 +0000
43@@ -312,5 +312,17 @@
44 </field>
45 </record>
46
47+ <record id="view_account_analytic_line_percentage_form" model="ir.ui.view">
48+ <field name="name">account.analytic.line.percentage.form</field>
49+ <field name="model">account.analytic.line</field>
50+ <field name="type">form</field>
51+ <field name="inherit_id" ref="account.view_account_analytic_line_form"/>
52+ <field name="arch" type="xml">
53+ <field name="amount" colspan="4" position="after">
54+ <field name="percentage" colspan="4"/>
55+ </field>
56+ </field>
57+ </record>
58+
59 </data>
60 </openerp>

Subscribers

People subscribed via source and target branches

to all changes: