Commit b9911437 authored by Klaus Wölfel's avatar Klaus Wölfel

erp5_core: lowest_value_test and previous_period for WeightedAverage and...

erp5_core: lowest_value_test and previous_period for WeightedAverage and omit_internal for getMovementHistoryList
parent 004d5200
<dtml-if "'WeightedAverage' in valuation_method">
<dtml-if "'WeightedAverage'==valuation_method and previous_period_total_asset_price">
select
(@total_quantity:=<dtml-var "previous_period_total_quantity">+quantity_diff) as total_quantity,
<dtml-if "lowest_value_test">
(@unit_price:=LEAST((<dtml-var "previous_period_total_asset_price">+incoming_total_price)/(<dtml-var "previous_period_total_quantity">+incoming_total_quantity), last_incoming_unit_price)) as unit_price,
(@total_quantity * @unit_price) as total_asset_price
<dtml-else>
(@unit_price:=(<dtml-var "previous_period_total_asset_price">+incoming_total_price)/(<dtml-var "previous_period_total_quantity">+incoming_total_quantity), last_incoming_unit_price) as unit_price,
(<dtml-var "previous_period_total_asset_price"> + incoming_total_price + outgoing_total_quantity * @unit_price) as total_asset_price
</dtml-if>
from
(
select
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
<dtml-if "lowest_value_test">,
(
select
total_price / quantity
from
stock, catalog
where
quantity > 0
and
<dtml-var where_expression>
order by
date desc
limit 1
) as last_incoming_unit_price
</dtml-if>
from
stock, catalog
where
<dtml-var where_expression>
) as period
<dtml-elif "'WeightedAverage' in valuation_method">
/*
Almost the same SQL for WeightedAverage/MonthlyWeightedAverage
......
......@@ -11,7 +11,8 @@
<value> <string>where_expression\n
valuation_method\n
lowest_value_test\n
</string> </value>
previous_period_total_asset_price\n
previous_period_total_quantity</string> </value>
</item>
<item>
<key> <string>connection_id</string> </key>
......
......@@ -1817,6 +1817,8 @@ class SimulationTool(BaseTool):
simulation_period='',
valuation_method=None,
lowest_value_test=False,
previous_period_total_asset_price=None,
previous_period_total_quantity=None,
**kw):
"""
Same thing as getInventory but returns an asset
......@@ -1858,8 +1860,14 @@ class SimulationTool(BaseTool):
'MonthlyWeightedAverage', 'MovingAverage'):
raise ValueError("Invalid valuation method: %s" % valuation_method)
if lowest_value_test and valuation_method not in ('Fifo', 'Filo',
'MovingAverage'):
'MovingAverage', 'WeightedAverage'):
raise NotImplementedError('lowest_value_test not implemented')
if (previous_period_total_asset_price is not None or
previous_period_total_quantity is not None
) and valuation_method != 'WeightedAverage':
raise NotImplementedError(
'previous_period_total_asset_price and previous_period_quantity not implemented'
)
assert 'node_uid' in kw or 'section_uid' in kw
sql_kw = self._generateSQLKeywordDict(**kw)
......@@ -1872,6 +1880,8 @@ class SimulationTool(BaseTool):
result = self.Resource_zGetAssetPrice(
valuation_method=valuation_method,
lowest_value_test=lowest_value_test,
previous_period_total_asset_price=previous_period_total_asset_price,
previous_period_total_quantity=previous_period_total_quantity,
src__=src__,
**sql_kw)
......@@ -1974,6 +1984,7 @@ class SimulationTool(BaseTool):
omit_asset_increase=0, omit_asset_decrease=0,
initial_running_total_quantity=0,
initial_running_total_price=0, precision=None,
omit_internal=0,
**kw):
"""Returns a list of movements which modify the inventory
for a single or a group of resource, node, section, etc.
......@@ -1991,6 +2002,11 @@ class SimulationTool(BaseTool):
sql_kw = self._generateSQLKeywordDict(**kw)
if omit_internal:
# ignore internal movements
sql_kw['where_expression'] += ' AND ' \
'NOT(stock.section_uid<=>stock.mirror_section_uid)'
return self.Resource_zGetMovementHistoryList(
src__=src__, ignore_variation=ignore_variation,
standardise=standardise,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment