Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
Coopdevs OCB mirror
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
External wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Coopdevs
Odoo
Coopdevs OCB mirror
Commits
4bdf0457
Commit
4bdf0457
authored
10 years ago
by
Simon Lejeune
Browse files
Options
Downloads
Patches
Plain Diff
[FIX] account_budget: theoretical amount: ignore future and use datetime
parent
1561a528
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
addons/account_budget/account_budget.py
+21
-18
21 additions, 18 deletions
addons/account_budget/account_budget.py
with
21 additions
and
18 deletions
addons/account_budget/account_budget.py
+
21
−
18
View file @
4bdf0457
...
...
@@ -22,14 +22,20 @@
import
datetime
from
openerp.osv
import
fields
,
osv
from
openerp.tools
import
ustr
from
openerp.tools
import
ustr
,
DEFAULT_SERVER_DATE_FORMAT
from
openerp.tools.translate
import
_
import
openerp.addons.decimal_precision
as
dp
# ---------------------------------------------------------
# Utils
# ---------------------------------------------------------
def
strToDate
(
dt
):
dt_date
=
datetime
.
date
(
int
(
dt
[
0
:
4
]),
int
(
dt
[
5
:
7
]),
int
(
dt
[
8
:
10
]))
return
dt_date
return
datetime
.
date
(
int
(
dt
[
0
:
4
]),
int
(
dt
[
5
:
7
]),
int
(
dt
[
8
:
10
]))
def
strToDatetime
(
strdate
):
return
datetime
.
datetime
.
strptime
(
strdate
,
DEFAULT_SERVER_DATE_FORMAT
)
# ---------------------------------------------------------
# Budgets
...
...
@@ -135,17 +141,12 @@ class crossovered_budget_lines(osv.osv):
return
res
def
_theo_amt
(
self
,
cr
,
uid
,
ids
,
context
=
None
):
res
=
{}
if
context
is
None
:
if
context
is
None
:
context
=
{}
res
=
{}
for
line
in
self
.
browse
(
cr
,
uid
,
ids
,
context
=
context
):
today
=
datetime
.
datetime
.
today
()
date_to
=
today
.
strftime
(
"
%Y-%m-%d
"
)
date_from
=
line
.
date_from
if
context
.
has_key
(
'
wizard_date_from
'
):
date_from
=
context
[
'
wizard_date_from
'
]
if
context
.
has_key
(
'
wizard_date_to
'
):
date_to
=
context
[
'
wizard_date_to
'
]
today
=
datetime
.
datetime
.
now
()
if
line
.
paid_date
:
if
strToDate
(
line
.
date_to
)
<=
strToDate
(
line
.
paid_date
):
...
...
@@ -153,13 +154,15 @@ class crossovered_budget_lines(osv.osv):
else
:
theo_amt
=
line
.
planned_amount
else
:
total
=
strToDate
(
line
.
date_to
)
-
strToDate
(
line
.
date_from
)
elapsed
=
min
(
strToDate
(
line
.
date_to
),
strToDate
(
date_to
))
-
max
(
strToDate
(
line
.
date_from
),
strToDate
(
date_from
))
if
strToDate
(
date_to
)
<
strToDate
(
line
.
date_from
):
elapsed
=
strToDate
(
date_to
)
-
strToDate
(
date_to
)
line_timedelta
=
strToDatetime
(
line
.
date_to
)
-
strToDatetime
(
line
.
date_from
)
elapsed_timedelta
=
today
-
(
strToDatetime
(
line
.
date_from
))
if
total
.
days
:
theo_amt
=
float
((
elapsed
.
days
+
1
)
/
float
(
total
.
days
+
1
))
*
line
.
planned_amount
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
else
:
theo_amt
=
line
.
planned_amount
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment