Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
erp5
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Klaus Wölfel
erp5
Commits
b036965a
Commit
b036965a
authored
Nov 20, 2024
by
Klaus Wölfel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
WIP: Add lowest_value_test to WeightedAverage
parent
285343a1
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
5 deletions
+18
-5
product/ERP5/bootstrap/erp5_core/SkinTemplateItem/portal_skins/erp5_core/Resource_zGetAssetPrice.sql
...teItem/portal_skins/erp5_core/Resource_zGetAssetPrice.sql
+18
-5
No files found.
product/ERP5/bootstrap/erp5_core/SkinTemplateItem/portal_skins/erp5_core/Resource_zGetAssetPrice.sql
View file @
b036965a
...
...
@@ -7,13 +7,16 @@ since they rely on the same kind of "split by period" model.
First split timeframe into Year (or Month) periods, and fold all movements
during each period.
Then perform a weighted average over all periods.
Parameter lowest_value_test compares latest price and WeightedAverage average price and takes the
smallest one.
*/
set
@
total_asset_price
=
0
.
0
,
@
total_quantity
=
0
.
0
<
dtml
-
var
sql_delimiter
>
select
byperiod
.
*
,
(
@
unit_price
:
=
(
@
total_asset_price
+
incoming_total_price
)
/
(
@
total_quantity
+
incoming_total_quantity
)
)
as
unit_price
,
(
@
unit_price
:
=
MIN
((
@
total_asset_price
+
incoming_total_price
)
/
(
@
total_quantity
+
incoming_total_quantity
)),
last_price
)
as
unit_price
,
(
@
total_asset_price
:
=
@
total_asset_price
+
incoming_total_price
+
...
...
@@ -27,11 +30,21 @@ from
SUM
(
IF
(
quantity
>
0
,
total_price
,
0
))
as
incoming_total_price
,
SUM
(
IF
(
quantity
>
0
,
quantity
,
0
))
as
incoming_total_quantity
,
SUM
(
IF
(
quantity
>
0
,
0
,
quantity
))
as
outgoing_total_quantity
,
SUM
(
quantity
)
as
quantity_diff
SUM
(
quantity
)
as
quantity_diff
,
MAX
(
last_price
)
as
last_price
from
stock
,
catalog
where
<
dtml
-
var
where_expression
>
(
select
date
,
total_price
,
quantity
,
IF
(
date
=
MAX
(
IF
(
quantity
>
0
,
date
,
0
))
OVER
(
PARTITION
BY
year
(
date
)),
total_price
,
0
)
as
last_price
<
dtml
-
if
"'Monthly' in valuation_method"
>
,
IF
(
date
=
MAX
(
IF
(
quantity
>
0
,
date
,
0
))
OVER
(
PARTITION
BY
month
(
date
)),
total_price
,
0
)
as
last_price
</
dtml
-
if
>
from
stock
,
catalog
where
<
dtml
-
var
where_expression
>
)
as
last_price_per_period
group
by
d_year
<
dtml
-
if
"'Monthly' in valuation_method"
>
,
d_month
</
dtml
-
if
>
order
by
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment