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
=== modified file 'account_analytic_plans/account_analytic_plans.py'
--- account_analytic_plans/account_analytic_plans.py 2011-01-14 00:11:01 +0000
+++ account_analytic_plans/account_analytic_plans.py 2011-05-06 06:06:37 +0000
@@ -47,6 +47,26 @@
47 res[r[self._fields_id]].append( r['id'] )47 res[r[self._fields_id]].append( r['id'] )
48 return res48 return res
4949
50class account_analytic_line(osv.osv):
51 _inherit = 'account.analytic.line'
52 _description = 'Analytic Line'
53
54 def _get_amount(self, cr, uid, ids, name, args, context=None):
55 res = {}
56 for id in ids:
57 res.setdefault(id, 0.0)
58 for line in self.browse(cr, uid, ids, context=context):
59 amount = line.move_id and line.move_id.amount_currency * (line.percentage / 100) or 0.0
60 res[line.id] = amount
61 return res
62
63 _columns = {
64 '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),
65 'percentage': fields.float('Percentage')
66 }
67
68account_analytic_line()
69
50class account_analytic_plan(osv.osv):70class account_analytic_plan(osv.osv):
51 _name = "account.analytic.plan"71 _name = "account.analytic.plan"
52 _description = "Analytic Plan"72 _description = "Analytic Plan"
@@ -338,6 +358,7 @@
338 'move_id': line.id,358 'move_id': line.id,
339 'journal_id': line.journal_id.analytic_journal_id.id,359 'journal_id': line.journal_id.analytic_journal_id.id,
340 'ref': line.ref,360 'ref': line.ref,
361 'percentage': line2.rate
341 }362 }
342 analytic_line_obj.create(cr, uid, al_vals, context=context)363 analytic_line_obj.create(cr, uid, al_vals, context=context)
343 return True364 return True
344365
=== modified file 'account_analytic_plans/account_analytic_plans_view.xml'
--- account_analytic_plans/account_analytic_plans_view.xml 2011-01-27 09:49:39 +0000
+++ account_analytic_plans/account_analytic_plans_view.xml 2011-05-06 06:06:37 +0000
@@ -312,5 +312,17 @@
312 </field>312 </field>
313 </record>313 </record>
314314
315 <record id="view_account_analytic_line_percentage_form" model="ir.ui.view">
316 <field name="name">account.analytic.line.percentage.form</field>
317 <field name="model">account.analytic.line</field>
318 <field name="type">form</field>
319 <field name="inherit_id" ref="account.view_account_analytic_line_form"/>
320 <field name="arch" type="xml">
321 <field name="amount" colspan="4" position="after">
322 <field name="percentage" colspan="4"/>
323 </field>
324 </field>
325 </record>
326
315</data>327</data>
316</openerp>328</openerp>

Subscribers

People subscribed via source and target branches

to all changes: