Commit 785ac757 authored by Xiaowu Zhang's avatar Xiaowu Zhang

erp5_trade: implement directly in getSource/DestionAssetPrice methods

parent dd7bfcad
from Products.ERP5Type.Document import newTempAccountingTransactionLine
if source_currency:
temp_transaction = newTempAccountingTransactionLine(
context.getPortalObject(),
"accounting_line",
source_section=section.getRelativeUrl(),
resource=source_currency.getRelativeUrl(),
start_date=delivery.getStartDate(),
)
exchange_rate = source_currency.getPrice(
context=temp_transaction.asContext(
categories=[temp_transaction.getResource(base=True),
section.getPriceCurrency(base=True)],
)
)
if exchange_rate:
return exchange_rate * context.getPrice()
return context.getPrice()
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>Script_magic</string> </key>
<value> <int>3</int> </value>
</item>
<item>
<key> <string>_bind_names</string> </key>
<value>
<object>
<klass>
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
</klass>
<tuple/>
<state>
<dictionary>
<item>
<key> <string>_asgns</string> </key>
<value>
<dictionary>
<item>
<key> <string>name_container</string> </key>
<value> <string>container</string> </value>
</item>
<item>
<key> <string>name_context</string> </key>
<value> <string>context</string> </value>
</item>
<item>
<key> <string>name_m_self</string> </key>
<value> <string>script</string> </value>
</item>
<item>
<key> <string>name_subpath</string> </key>
<value> <string>traverse_subpath</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>section, source_currency, delivery</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>Base_getAssetPrice</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
line = context
delivery = line.getParentValue().getParentValue()
if delivery.getPortalType() != "Purchase Packing List":
return None
section = delivery.getDestinationSectionValue()
source_currency = delivery.getPriceCurrencyValue()
return line.Base_getAssetPrice(
section = section,
source_currency = source_currency,
delivery = delivery)
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>Script_magic</string> </key>
<value> <int>3</int> </value>
</item>
<item>
<key> <string>_bind_names</string> </key>
<value>
<object>
<klass>
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
</klass>
<tuple/>
<state>
<dictionary>
<item>
<key> <string>_asgns</string> </key>
<value>
<dictionary>
<item>
<key> <string>name_container</string> </key>
<value> <string>container</string> </value>
</item>
<item>
<key> <string>name_context</string> </key>
<value> <string>context</string> </value>
</item>
<item>
<key> <string>name_m_self</string> </key>
<value> <string>script</string> </value>
</item>
<item>
<key> <string>name_subpath</string> </key>
<value> <string>traverse_subpath</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>PurchasePackingListCell_getDestinationAssetPrice</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
line = context
delivery = line.getParentValue().getParentValue()
if delivery.getPortalType() != "Purchase Packing List":
return None
section = delivery.getSourceSectionValue()
source_currency = delivery.getPriceCurrencyValue()
return line.Base_getAssetPrice(
section = section,
source_currency = source_currency,
delivery = delivery)
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>Script_magic</string> </key>
<value> <int>3</int> </value>
</item>
<item>
<key> <string>_bind_names</string> </key>
<value>
<object>
<klass>
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
</klass>
<tuple/>
<state>
<dictionary>
<item>
<key> <string>_asgns</string> </key>
<value>
<dictionary>
<item>
<key> <string>name_container</string> </key>
<value> <string>container</string> </value>
</item>
<item>
<key> <string>name_context</string> </key>
<value> <string>context</string> </value>
</item>
<item>
<key> <string>name_m_self</string> </key>
<value> <string>script</string> </value>
</item>
<item>
<key> <string>name_subpath</string> </key>
<value> <string>traverse_subpath</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>PurchasePackingListCell_getSourceAssetPrice</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
line = context
delivery = line.getParentValue()
if delivery.getPortalType() != "Purchase Packing List":
return None
section = delivery.getDestinationSectionValue()
source_currency = delivery.getPriceCurrencyValue()
return line.Base_getAssetPrice(
section = section,
source_currency = source_currency,
delivery = delivery)
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>Script_magic</string> </key>
<value> <int>3</int> </value>
</item>
<item>
<key> <string>_bind_names</string> </key>
<value>
<object>
<klass>
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
</klass>
<tuple/>
<state>
<dictionary>
<item>
<key> <string>_asgns</string> </key>
<value>
<dictionary>
<item>
<key> <string>name_container</string> </key>
<value> <string>container</string> </value>
</item>
<item>
<key> <string>name_context</string> </key>
<value> <string>context</string> </value>
</item>
<item>
<key> <string>name_m_self</string> </key>
<value> <string>script</string> </value>
</item>
<item>
<key> <string>name_subpath</string> </key>
<value> <string>traverse_subpath</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>PurchasePackingListLine_getDestinationAssetPrice</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
line = context
delivery = line.getParentValue()
if delivery.getPortalType() != "Purchase Packing List":
return None
section = delivery.getSourceSectionValue()
source_currency = delivery.getPriceCurrencyValue()
return line.Base_getAssetPrice(
section = section,
source_currency = source_currency,
delivery = delivery)
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>Script_magic</string> </key>
<value> <int>3</int> </value>
</item>
<item>
<key> <string>_bind_names</string> </key>
<value>
<object>
<klass>
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
</klass>
<tuple/>
<state>
<dictionary>
<item>
<key> <string>_asgns</string> </key>
<value>
<dictionary>
<item>
<key> <string>name_container</string> </key>
<value> <string>container</string> </value>
</item>
<item>
<key> <string>name_context</string> </key>
<value> <string>context</string> </value>
</item>
<item>
<key> <string>name_m_self</string> </key>
<value> <string>script</string> </value>
</item>
<item>
<key> <string>name_subpath</string> </key>
<value> <string>traverse_subpath</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>PurchasePackingListLine_getSourceAssetPrice</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
line = context
delivery = line.getParentValue().getParentValue()
if delivery.getPortalType() != "Sale Packing List":
return None
section = delivery.getDestinationSectionValue()
source_currency = delivery.getPriceCurrencyValue()
return line.Base_getAssetPrice(
section = section,
source_currency = source_currency,
delivery = delivery)
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>Script_magic</string> </key>
<value> <int>3</int> </value>
</item>
<item>
<key> <string>_bind_names</string> </key>
<value>
<object>
<klass>
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
</klass>
<tuple/>
<state>
<dictionary>
<item>
<key> <string>_asgns</string> </key>
<value>
<dictionary>
<item>
<key> <string>name_container</string> </key>
<value> <string>container</string> </value>
</item>
<item>
<key> <string>name_context</string> </key>
<value> <string>context</string> </value>
</item>
<item>
<key> <string>name_m_self</string> </key>
<value> <string>script</string> </value>
</item>
<item>
<key> <string>name_subpath</string> </key>
<value> <string>traverse_subpath</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>SalePackingListCell_getDestinationAssetPrice</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
line = context
delivery = line.getParentValue().getParentValue()
if delivery.getPortalType() != "Sale Packing List":
return None
section = delivery.getSourceSectionValue()
source_currency = delivery.getPriceCurrencyValue()
return line.Base_getAssetPrice(
section = section,
source_currency = source_currency,
delivery = delivery)
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>Script_magic</string> </key>
<value> <int>3</int> </value>
</item>
<item>
<key> <string>_bind_names</string> </key>
<value>
<object>
<klass>
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
</klass>
<tuple/>
<state>
<dictionary>
<item>
<key> <string>_asgns</string> </key>
<value>
<dictionary>
<item>
<key> <string>name_container</string> </key>
<value> <string>container</string> </value>
</item>
<item>
<key> <string>name_context</string> </key>
<value> <string>context</string> </value>
</item>
<item>
<key> <string>name_m_self</string> </key>
<value> <string>script</string> </value>
</item>
<item>
<key> <string>name_subpath</string> </key>
<value> <string>traverse_subpath</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>SalePackingListCell_getSourceAssetPrice</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
line = context
delivery = line.getParentValue()
if delivery.getPortalType() != "Sale Packing List":
return None
section = delivery.getDestinationSectionValue()
source_currency = delivery.getPriceCurrencyValue()
return line.Base_getAssetPrice(
section = section,
source_currency = source_currency,
delivery = delivery)
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>Script_magic</string> </key>
<value> <int>3</int> </value>
</item>
<item>
<key> <string>_bind_names</string> </key>
<value>
<object>
<klass>
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
</klass>
<tuple/>
<state>
<dictionary>
<item>
<key> <string>_asgns</string> </key>
<value>
<dictionary>
<item>
<key> <string>name_container</string> </key>
<value> <string>container</string> </value>
</item>
<item>
<key> <string>name_context</string> </key>
<value> <string>context</string> </value>
</item>
<item>
<key> <string>name_m_self</string> </key>
<value> <string>script</string> </value>
</item>
<item>
<key> <string>name_subpath</string> </key>
<value> <string>traverse_subpath</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>SalePackingListLine_getDestinationAssetPrice</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
line = context
delivery = line.getParentValue()
if delivery.getPortalType() != "Sale Packing List":
return None
section = delivery.getSourceSectionValue()
source_currency = delivery.getPriceCurrencyValue()
return line.Base_getAssetPrice(
section = section,
source_currency = source_currency,
delivery = delivery)
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>Script_magic</string> </key>
<value> <int>3</int> </value>
</item>
<item>
<key> <string>_bind_names</string> </key>
<value>
<object>
<klass>
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
</klass>
<tuple/>
<state>
<dictionary>
<item>
<key> <string>_asgns</string> </key>
<value>
<dictionary>
<item>
<key> <string>name_container</string> </key>
<value> <string>container</string> </value>
</item>
<item>
<key> <string>name_context</string> </key>
<value> <string>context</string> </value>
</item>
<item>
<key> <string>name_m_self</string> </key>
<value> <string>script</string> </value>
</item>
<item>
<key> <string>name_subpath</string> </key>
<value> <string>traverse_subpath</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>SalePackingListLine_getSourceAssetPrice</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
......@@ -487,7 +487,7 @@ class Movement(XMLObject, Amount, CompositionMixin, AmountGeneratorMixin):
type_based_script = self._getTypeBasedMethod('getSourceAssetPrice')
if type_based_script:
return type_based_script()
return self.getPrice()
return self._getAssetPrice(section = self.getSourceSectionValue())
security.declareProtected( Permissions.AccessContentsInformation,
'getDestinationAssetPrice')
......@@ -498,7 +498,30 @@ class Movement(XMLObject, Amount, CompositionMixin, AmountGeneratorMixin):
type_based_script = self._getTypeBasedMethod('getDestinationAssetPrice')
if type_based_script:
return type_based_script()
return self.getPrice()
return self._getAssetPrice(section = self.getDestinationSectionValue())
def _getAssetPrice(self,section):
from Products.ERP5Type.Document import newTempAccountingTransactionLine
price = self.getPrice()
source_currency = self.getPriceCurrencyValue()
section_source_currency = section.getPriceCurrency(base=True)
if source_currency and section_source_currency:
temp_transaction = newTempAccountingTransactionLine(
self.getPortalObject(),
"accounting_line",
source_section=section.getRelativeUrl(),
resource=source_currency.getRelativeUrl(),
start_date=self.getStartDate(),
)
exchange_rate = source_currency.getPrice(
context=temp_transaction.asContext(
categories=[temp_transaction.getResource(base=True),
section_source_currency],
)
)
if exchange_rate and price:
return exchange_rate * price
return price
security.declareProtected( Permissions.AccessContentsInformation,
'getSourceAssetPriceCurrency')
......
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