[FIX] account_budget: To print the summary of a budget

The theoritical amount is computed as:

theo amt = ellapsed time / total time period  * planned amount

where:

total time period is the difference between date_to and date_from defined
on the crossevered budget line.

ellapsed time is the difference between today and date_from.

The achievment(percentage) on a crossevered budget line is computed as:

percentage = practical amt / theo amt

where:

practical amt is the sum of all account analytic lines valid in the
crossevered budget line period.

When computing the report of a summary, the ellapsed time is equal
to the difference between date_to and date_from defined for the summary and
the practical amount only takes the account analytic lines in the summary
period.

opw:669545
This commit is contained in:
Goffin Simon
2016-02-24 09:58:02 +01:00
parent 53742a4a70
commit 56241b3368
+39 -17
View File
@@ -102,8 +102,8 @@ class crossovered_budget_lines(osv.osv):
acc_ids = [x.id for x in line.general_budget_id.account_ids]
if not acc_ids:
raise UserError(_("The Budget '%s' has no accounts!") % ustr(line.general_budget_id.name))
date_to = line.date_to
date_from = line.date_from
date_to = context.get('wizard_date_to') or line.date_to
date_from = context.get('wizard_date_from') or line.date_from
if line.analytic_account_id.id:
cr.execute("SELECT SUM(amount) FROM account_analytic_line WHERE account_id=%s AND (date "
"between to_date(%s,'yyyy-mm-dd') AND to_date(%s,'yyyy-mm-dd')) AND "
@@ -127,24 +127,46 @@ class crossovered_budget_lines(osv.osv):
res = {}
for line in self.browse(cr, uid, ids, context=context):
today = datetime.now()
# Used for the report
if context.get('wizard_date_from') and context.get('wizard_date_to'):
date_from = strToDatetime(context.get('wizard_date_from'))
date_to = strToDatetime(context.get('wizard_date_to'))
if date_from < strToDatetime(line.date_from):
date_from = strToDatetime(line.date_from)
elif date_from > strToDatetime(line.date_to):
date_from = False
if line.paid_date:
if strToDate(line.date_to) <= strToDate(line.paid_date):
theo_amt = 0.00
else:
theo_amt = line.planned_amount
if date_to > strToDatetime(line.date_to):
date_to = strToDatetime(line.date_to)
elif date_to < strToDatetime(line.date_from):
date_to = False
theo_amt = 0.00
if date_from and date_to:
line_timedelta = strToDatetime(line.date_to) - strToDatetime(line.date_from)
elapsed_timedelta = date_to - date_from
if elapsed_timedelta.days > 0:
theo_amt = (elapsed_timedelta.total_seconds() / line_timedelta.total_seconds()) * line.planned_amount
else:
line_timedelta = strToDatetime(line.date_to) - strToDatetime(line.date_from)
elapsed_timedelta = today - (strToDatetime(line.date_from))
if elapsed_timedelta.days < 0:
# If the budget line has not started yet, theoretical amount should be zero
theo_amt = 0.00
elif line_timedelta.days > 0 and today < strToDatetime(line.date_to):
# If today is between the budget line date_from and date_to
theo_amt = (elapsed_timedelta.total_seconds() / line_timedelta.total_seconds()) * line.planned_amount
if line.paid_date:
if strToDate(line.date_to) <= strToDate(line.paid_date):
theo_amt = 0.00
else:
theo_amt = line.planned_amount
else:
theo_amt = line.planned_amount
line_timedelta = strToDatetime(line.date_to) - strToDatetime(line.date_from)
elapsed_timedelta = today - (strToDatetime(line.date_from))
if elapsed_timedelta.days < 0:
# If the budget line has not started yet, theoretical amount should be zero
theo_amt = 0.00
elif line_timedelta.days > 0 and today < strToDatetime(line.date_to):
# If today is between the budget line date_from and date_to
# from pudb import set_trace; set_trace()
theo_amt = (elapsed_timedelta.total_seconds() / line_timedelta.total_seconds()) * line.planned_amount
else:
theo_amt = line.planned_amount
res[line.id] = theo_amt
return res