Commit bfcbe492 authored by Ayush Tiwari's avatar Ayush Tiwari

bt5_config: Replace BM with one zexp file

parent 8d08790c
# This script indexes the preferred Transformation to produce
# a variation of a product.
# transformation_item_list is a list of:
# transformation, variation_list_list
# transformation is a transformation to index, while variation_list_list
# is a list of variation categories that are relevant for the produced resource
from Products.ERP5Type.Document import newTempMovement
# List of dictionaries:
# { id:resource_id,
# variation_text: resource_variation_text,
# row_dict_list: list of rows to insert; each row is represented as a dict.}
row_dict_dict_list = []
portal = context.getPortalObject()
for transformation_relative_url, variation_list_list in transformation_item_list:
transformation = portal.restrictedTraverse(transformation_relative_url)
resource = transformation.getResourceValue()
if resource is None:
continue
for variation_list in variation_list_list:
movement = newTempMovement(resource, 'temp',
specialise_value=transformation,
variation_category_list=variation_list,
resource_value=resource,
quantity=1.0)
base_row = dict(uid=resource.getUid(), variation_text=movement.getVariationText())
row_dict_list = []
for amount in movement.getAggregatedAmountList():
transformed_resource_uid = amount.getResourceUid()
quantity = amount.getQuantity()
if transformed_resource_uid is not None and quantity is not None:
row_dict = base_row.copy()
row_dict.update(transformed_uid=transformed_resource_uid,
transformed_variation_text=amount.getVariationText(),
quantity=quantity)
row_dict_list.append(row_dict)
base_row['row_dict_list'] = row_dict_list
row_dict_dict_list.append(base_row)
context.z_catalog_transformation_list(row_dict_dict_list=row_dict_dict_list)
# Indexing all transformation lines for all possible variations of a Resource can be very costly.
# Avoid doing this in a single transaction, and split the operation.
batch_size = 100
current_batch = []
current_size = 0
for i, transformation in enumerate(getDefaultConversionTransformationValue):
if transformation is None:
continue
transformation_relative_url = transformation.getRelativeUrl()
variation_list_list = getTransformationVariationCategoryCartesianProduct[i]
size = len(transformation)*len(variation_list_list)
if size + current_size < batch_size:
current_batch.append((transformation_relative_url, variation_list_list))
current_size += size
else:
if current_batch:
context.activate(activity='SQLQueue').SQLCatalog_catalogTransformation(current_batch)
current_batch = [(transformation_relative_url, variation_list_list)]
current_size = size
if current_batch:
context.activate(activity='SQLQueue').SQLCatalog_catalogTransformation(current_batch)
"""
Default full text searchable key implementation.
"""
from Products.ZSQLCatalog.SQLCatalog import ComplexQuery
from Products.ZSQLCatalog.SQLCatalog import Query
query = ComplexQuery(Query(title=value),
Query(reference=value),
operator="OR")
return query
from Products.ERP5Type.Log import log
from Products.ZSQLCatalog.SQLCatalog import Query
# warn by logging (not possible use python's warn module in restricted environment)
log("'quick_search_text' and 'advanced_search_text' scriptable keys are deprecated. Use 'search_text' instead.")
return Query(search_text=value)
"""
Search text query generator. Accepts a string and returns a ComplexQuery.
For example:
search_text = DMS reference:bt5-dms version:001 language:bg mine:yes (portal_type:Presentation OR portal_type:File) created:12m contributor_title:%tyagov%
will parse search_text and generate a complexQuery which will return all documents which:
- have full_text searchable text containing "DMS"
- have reference equal to bt5-dms
- have portal_type "Presentation" OR "File"
- are created within last 12 months
- are owned by current logged in user
- are contributed by given Person's title
- etc ..
"""
if 'full_text' in context.sql_search_tables:
column = 'SearchableText'
else:
column = 'title'
node = context.Base_getAdvancedSearchSyntaxTreeNode(value, column=column)
if node is None:
return context.buildSingleQuery(column, value)
else:
return context.buildQueryFromAbstractSyntaxTreeNode(node, column, ignore_unknown_columns=True)
from Products.ZSQLCatalog.SQLCatalog import Query, SimpleQuery, AndQuery
portal = context.getPortalObject()
# This scriptable key supports content_translation if the table is present
catalog = portal.portal_catalog.getSQLCatalog()
if 'content_translation' in catalog.getProperty('sql_search_tables'):
if [x for x in catalog.getProperty('sql_catalog_search_keys', []) if 'Mroonga' in x]:
return AndQuery(SimpleQuery(**{'content_translation.translated_text': value, 'comparison_operator': 'mroonga_boolean'}),
Query(**{'content_translation.property_name': 'title'}))
else:
return AndQuery(SimpleQuery(**{'content_translation.translated_text': value, 'comparison_operator': 'match_boolean'}),
Query(**{'content_translation.property_name': 'title'}))
# Otherwise it simply use title
return Query(title=value)
DELETE FROM category WHERE <dtml-sqltest uid op=eq type=int>
\ No newline at end of file
<dtml-comment>
JM: Since unindexing a measure triggers the reindexing of the related
resource (what will clean the measure table - cf z0_catalog_measure_list),
is it required to delete according to uid column?
The test against metric_type_uid is there in case we delete a metric_type_uid
category that is used as an implicit measure.
</dtml-comment>
DELETE FROM measure
WHERE <dtml-sqltest uid op=eq type=int>
OR <dtml-sqltest uid op=eq type=int column="metric_type_uid">
DELETE FROM quantity_unit_conversion
WHERE <dtml-sqltest uid op=eq type=int>
\ No newline at end of file
DELETE FROM stock WHERE <dtml-sqltest uid op=eq type=int multiple>
\ No newline at end of file
DELETE FROM transformation
WHERE <dtml-sqltest uid op=eq type=int>
\ No newline at end of file
DELETE FROM versioning WHERE <dtml-sqltest uid op=eq type=int>
\ No newline at end of file
REPLACE INTO
alarm (uid, alarm_date)
VALUES
<dtml-in prefix="loop" expr="_.range(_.len(uid))">
(
<dtml-sqlvar expr="uid[loop_item]" type="int">,
<dtml-sqlvar expr="getAlarmDate[loop_item]" type="datetime" optional>
)
<dtml-if sequence-end><dtml-else>,</dtml-if>
</dtml-in>
<dtml-let delivery_list="[]">
<dtml-in prefix="loop" expr="_.range(_.len(uid))">
<dtml-if "isDelivery[loop_item]">
<dtml-call expr="delivery_list.append(loop_item)">
</dtml-if>
</dtml-in>
<dtml-if expr="_.len(delivery_list) > 0">
REPLACE INTO
delivery
VALUES
<dtml-in prefix="loop" expr="delivery_list">
(
<dtml-sqlvar expr="uid[loop_item]" type="int">,
<dtml-sqlvar expr="getSourceUid[loop_item]" type="int" optional>,
<dtml-sqlvar expr="getDestinationUid[loop_item]" type="int" optional>,
<dtml-sqlvar expr="getSourceSectionUid[loop_item]" type="int" optional>,
<dtml-sqlvar expr="getDestinationSectionUid[loop_item]" type="int" optional>,
<dtml-sqlvar expr="getResourceUid[loop_item]" type="int" optional>,
<dtml-sqlvar expr="getStartDate[loop_item]" type="datetime" optional>,
<dtml-sqlvar expr="getStartDateRangeMin[loop_item]" type="datetime" optional>,
<dtml-sqlvar expr="getStartDateRangeMax[loop_item]" type="datetime" optional>,
<dtml-sqlvar expr="getStopDate[loop_item]" type="datetime" optional>,
<dtml-sqlvar expr="getStopDateRangeMin[loop_item]" type="datetime" optional>,
<dtml-sqlvar expr="getStopDateRangeMax[loop_item]" type="datetime" optional>
)
<dtml-if sequence-end><dtml-else>,</dtml-if>
</dtml-in>
</dtml-if>
</dtml-let>
DELETE FROM
item
WHERE
<dtml-in uid>
uid=<dtml-sqlvar sequence-item type="int"><dtml-if sequence-end><dtml-else> OR </dtml-if>
</dtml-in>
;
<dtml-var "'\0'">
<dtml-let movement_list="[]" uid_dict="{}">
<dtml-in prefix="loop" expr="_.range(_.len(uid))">
<dtml-if "isMovement[loop_item] and isAccountable[loop_item] and getMovedItemUidList[loop_item]">
<dtml-call expr="uid_dict.update({uid[loop_item]: uid_dict.get(uid[loop_item], -1) + 1})">
<dtml-call expr="movement_list.append(loop_item)">
</dtml-if>
</dtml-in>
<dtml-if expr="_.len(movement_list) > 0">
REPLACE INTO
item
VALUES
<dtml-in prefix="loop" expr="movement_list">
<dtml-in expr="getMovedItemUidList[loop_item]">
(
<dtml-call expr="uid_dict.update({uid[loop_item]: uid_dict.get(uid[loop_item], -1) + 1})">
<dtml-sqlvar expr="uid[loop_item]" type="int">,
<dtml-sqlvar expr="uid_dict[uid[loop_item]]" type="int">,
<dtml-sqlvar expr="getStopDate[loop_item]" type="datetime" optional>,
<dtml-sqlvar expr="getDestinationUid[loop_item]" type="int" optional>,
<dtml-sqlvar expr="getDestinationSectionUid[loop_item]" type="int" optional>,
<dtml-sqlvar expr="getResourceUid[loop_item]" type="int" optional>,
<dtml-sqlvar sequence-item type="int" optional>,
<dtml-sqlvar expr="getVariationText[loop_item]" type="string" optional>,
<dtml-sqlvar expr="getSimulationState[loop_item]" type="string" optional>
)
<dtml-if sequence-end><dtml-else>,</dtml-if>
</dtml-in>
<dtml-if sequence-end><dtml-else>,</dtml-if>
</dtml-in>
</dtml-if>
</dtml-let>
\ No newline at end of file
DELETE FROM `measure` WHERE
<dtml-sqltest uid column="resource_uid" type="int" multiple>;
<dtml-let measure_list="[]">
<dtml-in getMeasureRowList prefix="loop">
<dtml-call expr="loop_item and measure_list.extend(loop_item)">
</dtml-in>
<dtml-if measure_list>
<dtml-var sql_delimiter>
REPLACE INTO `measure`
VALUES
<dtml-in measure_list prefix="loop">
(
<dtml-sqlvar expr="loop_item['uid']" type="int">,
<dtml-sqlvar expr="loop_item['resource_uid']" type="int">,
<dtml-sqlvar expr="loop_item['variation']" type="string">,
<dtml-sqlvar expr="loop_item['metric_type_uid']" type="int">,
<dtml-sqlvar expr="loop_item['quantity']" type="float">
)
<dtml-unless sequence-end>,</dtml-unless>
</dtml-in>
</dtml-if>
</dtml-let>
DELETE FROM
category
WHERE
<dtml-in uid>
uid=<dtml-sqlvar sequence-item type="int"><dtml-if sequence-end><dtml-else> OR </dtml-if>
</dtml-in>
;
<dtml-var "'\0'">
<dtml-let category_list="[]" getCategoryParentUidList="portal_categories.getCategoryParentUidList">
<dtml-in prefix="loop" expr="_.range(_.len(uid))">
<dtml-if expr="getCategoryList[loop_item]">
<dtml-let uid_list="getCategoryParentUidList(getCategoryList[loop_item])">
<dtml-if uid_list>
<dtml-in prefix="uid" expr="uid_list">
<dtml-call expr="category_list.append((uid[loop_item], uid_item[0], uid_item[1], uid_item[2]))">
</dtml-in></dtml-if></dtml-let></dtml-if></dtml-in>
<dtml-if expr="category_list">
REPLACE INTO category VALUES
<dtml-in prefix="loop" expr="category_list">
(<dtml-sqlvar expr="loop_item[0]" type="int">, <dtml-sqlvar expr="loop_item[1]" type="int">, <dtml-sqlvar expr="loop_item[2]" type="int">, <dtml-sqlvar expr="loop_item[3]" type="int">)<dtml-if sequence-end><dtml-else>,</dtml-if>
</dtml-in>
</dtml-if>
</dtml-let>
\ No newline at end of file
DELETE FROM
category
WHERE
<dtml-in uid>
uid=<dtml-sqlvar sequence-item type="int"><dtml-if sequence-end><dtml-else> OR </dtml-if>
</dtml-in>
;
<dtml-var "'\0'">
<dtml-let category_list="[]" getCategoryParentUidList="portal_categories.getCategoryParentUidList">
<dtml-in prefix="loop" expr="_.range(_.len(uid))">
<dtml-if expr="getAcquiredCategoryList[loop_item]">
<dtml-let uid_list="getCategoryParentUidList(getAcquiredCategoryList[loop_item])">
<dtml-if uid_list>
<dtml-in prefix="uid" expr="uid_list">
<dtml-call expr="category_list.append((uid[loop_item], uid_item[0], uid_item[1], uid_item[2]))">
</dtml-in></dtml-if></dtml-let></dtml-if></dtml-in>
<dtml-if expr="category_list">
REPLACE INTO category VALUES
<dtml-in prefix="loop" expr="category_list">
(<dtml-sqlvar expr="loop_item[0]" type="int">, <dtml-sqlvar expr="loop_item[1]" type="int">, <dtml-sqlvar expr="loop_item[2]" type="int">, <dtml-sqlvar expr="loop_item[3]" type="int">)<dtml-if sequence-end><dtml-else>,</dtml-if>
</dtml-in>
</dtml-if>
</dtml-let>
\ No newline at end of file
REPLACE INTO
catalog
(`uid`, `security_uid`, `owner`, `viewable_owner`, `path`, `relative_url`, `parent_uid`, `id`, `description`, `title`, `meta_type`,
`portal_type`, `opportunity_state`, `corporate_registration_code`, `ean13_code`, `validation_state`, `simulation_state`,
`causality_state`, `invoice_state`, `payment_state`, `event_state`, `immobilisation_state`, `reference`, `grouping_reference`, `grouping_date`,
`source_reference`, `destination_reference`, `string_index`, `int_index`, `float_index`, `has_cell_content`, `creation_date`,
`modification_date`)
VALUES
<dtml-in prefix="loop" expr="_.range(_.len(uid))">
(
<dtml-sqlvar expr="uid[loop_item]" type="int">,
<dtml-sqlvar expr="security_uid[loop_item]" type="int">,
<dtml-sqlvar expr="getOwnerInfo[loop_item]['id']" type="string">,
<dtml-sqlvar expr="(getViewPermissionOwner[loop_item] is not None) and getViewPermissionOwner[loop_item] or ''" type="string" optional>,
<dtml-sqlvar expr="getPath[loop_item]" type="string">,
<dtml-sqlvar expr="getRelativeUrl[loop_item]" type="string">,
<dtml-sqlvar expr="getParentUid[loop_item]" type="int">,
<dtml-sqlvar expr="id[loop_item]" type="string" optional>,
<dtml-sqlvar expr="getDescription[loop_item]" type="string" optional>,
<dtml-sqlvar expr="getTitle[loop_item]" type="string" optional>,
<dtml-sqlvar expr="meta_type[loop_item]" type="string" optional>,
<dtml-sqlvar expr="getPortalType[loop_item]" type="string" optional>,
<dtml-sqlvar expr="getOpportunityState[loop_item]" type="string" optional>,
<dtml-sqlvar expr="getCorporateRegistrationCode[loop_item]" type="string" optional>,
<dtml-sqlvar expr="getEan13Code[loop_item]" type="string" optional>,
<dtml-sqlvar expr="getValidationState[loop_item]" type="string" optional>,
<dtml-sqlvar expr="getSimulationState[loop_item]" type="string" optional>,
<dtml-sqlvar expr="getCausalityState[loop_item]" type="string" optional>,
<dtml-sqlvar expr="getInvoiceState[loop_item]" type="string" optional>,
<dtml-sqlvar expr="getPaymentState[loop_item]" type="string" optional>,
<dtml-sqlvar expr="getEventState[loop_item]" type="string" optional>,
<dtml-sqlvar expr="getImmobilisationState[loop_item]" type="string" optional>,
<dtml-sqlvar expr="getReference[loop_item]" type="string" optional>,
<dtml-sqlvar expr="getGroupingReference[loop_item]" type="string" optional>,
<dtml-sqlvar expr="getGroupingDate[loop_item]" type="datetime" optional>,
<dtml-sqlvar expr="getSourceReference[loop_item]" type="string" optional>,
<dtml-sqlvar expr="getDestinationReference[loop_item]" type="string" optional>,
<dtml-sqlvar expr="getStringIndex[loop_item]" type="string" optional>,
<dtml-sqlvar expr="getIntIndex[loop_item]" type="int" optional>,
<dtml-sqlvar expr="getFloatIndex[loop_item]" type="float" optional>,
<dtml-sqlvar expr="hasCellContent[loop_item]" type="int" optional>,
<dtml-sqlvar expr="getCreationDate[loop_item]" type="datetime" optional>,
<dtml-sqlvar expr="getModificationDate[loop_item]" type="datetime" optional>
)
<dtml-if sequence-end><dtml-else>,</dtml-if>
</dtml-in>
DELETE FROM
predicate_category
WHERE
<dtml-in uid>
uid=<dtml-sqlvar sequence-item type="int"><dtml-if sequence-end><dtml-else> OR </dtml-if>
</dtml-in>
;
<dtml-var "'\0'">
<dtml-let predicate_list="[]">
<dtml-in prefix="loop" expr="_.range(_.len(uid))">
<dtml-if "isPredicate[loop_item]">
<dtml-if expr="_.len(predicate_property_dict[loop_item]) > 0">
<dtml-call expr="predicate_list.append(loop_item)">
</dtml-if>
</dtml-if>
</dtml-in>
<dtml-if expr="_.len(predicate_list) > 0">
REPLACE INTO predicate_category VALUES
<dtml-in prefix="loop" expr="predicate_list">
<dtml-if sequence-start><dtml-else>,</dtml-if>
<dtml-if "predicate_property_dict[loop_item].has_key('membership_criterion_category_list')">
<dtml-let uid_list="portal_categories.CategoryTool_getPreferredPredicateCategoryParentUidItemList(predicate_property_dict[loop_item]['membership_criterion_category_list'], getObject[loop_item])">
<dtml-if uid_list>
<dtml-in "uid_list">
(<dtml-sqlvar expr="uid[loop_item]" type="int">, <dtml-var "_['sequence-item'][0]" >, <dtml-var "_['sequence-item'][1]" >, <dtml-var "_['sequence-item'][2]" >)
<dtml-if sequence-end><dtml-else>,</dtml-if>
</dtml-in>
<dtml-else>
(<dtml-sqlvar expr="uid[loop_item]" type="int">, 0, 0,1)
</dtml-if>
</dtml-let>
<dtml-else>
(<dtml-sqlvar expr="uid[loop_item]" type="int">, 0, 0,1)
</dtml-if>
</dtml-in>
</dtml-if>
</dtml-let>
<dtml-let predicate_list="[]">
<dtml-in prefix="loop" expr="_.range(_.len(uid))">
<dtml-if "isPredicate[loop_item]">
<dtml-if expr="_.len(predicate_property_dict[loop_item]) > 0">
<dtml-call expr="predicate_list.append(loop_item)">
</dtml-if>
</dtml-if>
</dtml-in>
<dtml-if expr="_.len(predicate_list) > 0">
REPLACE INTO predicate VALUES
<dtml-in prefix="loop" expr="predicate_list">
<dtml-if sequence-start><dtml-else>,</dtml-if>
(
<dtml-sqlvar expr="uid[loop_item]" type="int">,
<dtml-sqlvar expr="predicate_property_dict[loop_item].get('quantity', None)" type="float" optional>,
<dtml-sqlvar expr="predicate_property_dict[loop_item].get('quantity_range_min', None)" type="float" optional>,
<dtml-sqlvar expr="predicate_property_dict[loop_item].get('quantity_range_max', None)" type="float" optional>,
<dtml-sqlvar expr="predicate_property_dict[loop_item].get('start_date', None)" type="datetime" optional>,
<dtml-sqlvar expr="predicate_property_dict[loop_item].get('start_date_range_min', None)" type="datetime" optional>,
<dtml-sqlvar expr="predicate_property_dict[loop_item].get('start_date_range_max', None)" type="datetime" optional>
)
</dtml-in>
</dtml-if>
</dtml-let>
<dtml-let quantity_unit_conversion_dict="{}" value_list="[]">
<dtml-in getQuantityUnitConversionDefinitionRowList
prefix="loop">
<dtml-if loop_item>
<dtml-comment>
Make sure that we get no duplicates, and also aggregate the uids of the modified resources for deletion
</dtml-comment>
<dtml-in loop_item prefix="inner">
<dtml-call expr="quantity_unit_conversion_dict.setdefault(inner_item['resource_uid'], {}).setdefault(inner_item['quantity_unit_uid'], inner_item)">
</dtml-in>
</dtml-if>
</dtml-in>
<dtml-if quantity_unit_conversion_dict>
DELETE FROM `quantity_unit_conversion` WHERE
<dtml-sqltest "quantity_unit_conversion_dict.keys()" column="resource_uid" type="int" multiple>;
<dtml-var sql_delimiter>
<dtml-in "quantity_unit_conversion_dict.values()" prefix="loop">
<dtml-call "value_list.extend(loop_item.values())">
</dtml-in>
REPLACE INTO `quantity_unit_conversion`
VALUES
<dtml-in "value_list" prefix="loop">
(
<dtml-sqlvar expr="loop_item['uid']" type="int" optional>,
<dtml-sqlvar expr="loop_item['resource_uid']" type="int">,
<dtml-sqlvar expr="loop_item['quantity_unit_uid']" type="int">,
<dtml-sqlvar expr="loop_item['quantity']" type="float">
)
<dtml-unless sequence-end>,</dtml-unless>
</dtml-in>
</dtml-if>
</dtml-let>
\ No newline at end of file
<dtml-let row_list="[]">
<dtml-in prefix="loop" expr="_.range(_.len(optimised_roles_and_users))">
<dtml-in prefix="role" expr="optimised_roles_and_users[loop_item]">
<dtml-call expr="row_list.append([role_item[0], role_item[2]])">
</dtml-in>
</dtml-in>
<dtml-if expr="row_list">
INSERT INTO
roles_and_users(uid, allowedRolesAndUsers)
VALUES
<dtml-in prefix="row" expr="row_list">
(<dtml-sqlvar expr="row_item[0]" type="string">, <dtml-sqlvar expr="row_item[1]" type="string">)
<dtml-if sequence-end><dtml-else>,</dtml-if>
</dtml-in>
</dtml-if>
</dtml-let>
DELETE FROM
stock
WHERE
<dtml-in uid>
uid=<dtml-sqlvar sequence-item type="int"><dtml-if sequence-end><dtml-else> OR </dtml-if>
</dtml-in>
;
<dtml-var "'\0'">
<dtml-let row_list="[]" uid_dict="{}">
<dtml-in prefix="loop" expr="_.range(_.len(uid))">
<dtml-if "not(isInventoryMovement[loop_item]) and isMovement[loop_item] and getResourceUid[loop_item]">
<dtml-in prefix="movement" expr="asMovementList[loop_item]" no_push_item>
<dtml-let movement_item_quantity="movement_item.getInventoriatedQuantity() or 0">
<dtml-if "getDestinationUid[loop_item]">
<dtml-call expr="uid_dict.update({uid[loop_item]: uid_dict.get(uid[loop_item], -1) + 1})">
<dtml-call expr="row_list.append([
uid[loop_item],
uid_dict[uid[loop_item]],
getExplanationUid[loop_item],
getDestinationUid[loop_item],
getDestinationSectionUid[loop_item],
getDestinationPaymentUid[loop_item],
getDestinationFunctionUid[loop_item],
getDestinationProjectUid[loop_item],
getDestinationFundingUid[loop_item],
getLedgerUid[loop_item],
getDestinationPaymentRequestUid[loop_item],
getSourceSectionUid[loop_item],
getSourceUid[loop_item],
getResourceUid[loop_item],
movement_item_quantity,
isCancellationAmount[loop_item],
isAccountable[loop_item],
movement_item.getStopDate(),
movement_item.getStartDate(),
getDestinationInventoriatedTotalAssetPrice[loop_item],
getPortalType[loop_item],
getSimulationState[loop_item],
getVariationText[loop_item],
getSubVariationText[loop_item]])">
</dtml-if>
<dtml-if "getSourceUid[loop_item]">
<dtml-call expr="uid_dict.update({uid[loop_item]: uid_dict.get(uid[loop_item], -1) + 1})">
<dtml-call expr="row_list.append([
uid[loop_item],
uid_dict[uid[loop_item]],
getExplanationUid[loop_item],
getSourceUid[loop_item],
getSourceSectionUid[loop_item],
getSourcePaymentUid[loop_item],
getSourceFunctionUid[loop_item],
getSourceProjectUid[loop_item],
getSourceFundingUid[loop_item],
getLedgerUid[loop_item],
getSourcePaymentRequestUid[loop_item],
getDestinationSectionUid[loop_item],
getDestinationUid[loop_item],
getResourceUid[loop_item],
-movement_item_quantity,
isCancellationAmount[loop_item],
isAccountable[loop_item],
movement_item.getStartDate(),
movement_item.getStopDate(),
getSourceInventoriatedTotalAssetPrice[loop_item],
getPortalType[loop_item],
getSimulationState[loop_item],
getVariationText[loop_item],
getSubVariationText[loop_item]])">
</dtml-if>
</dtml-let>
</dtml-in>
</dtml-if>
</dtml-in>
<dtml-if "row_list">
REPLACE INTO
stock
(
`uid`,
`order_id`,
`explanation_uid`,
`node_uid`,
`section_uid`,
`payment_uid`,
`function_uid`,
`project_uid`,
`funding_uid`,
`ledger_uid`,
`payment_request_uid`,
`mirror_section_uid`,
`mirror_node_uid`,
`resource_uid`,
`quantity`,
`is_cancellation`,
`is_accountable`,
`date`,
`mirror_date`,
`total_price`,
`portal_type`,
`simulation_state`,
`variation_text`,
`sub_variation_text`
)
VALUES
<dtml-in prefix="row" expr="row_list">
(
<dtml-sqlvar expr="row_item[0]" type="int">,
<dtml-sqlvar expr="row_item[1]" type="int">,
<dtml-sqlvar expr="row_item[2]" type="int" optional>,
<dtml-sqlvar expr="row_item[3]" type="int">,
<dtml-sqlvar expr="row_item[4]" type="int" optional>,
<dtml-sqlvar expr="row_item[5]" type="int" optional>,
<dtml-sqlvar expr="row_item[6]" type="int" optional>,
<dtml-sqlvar expr="row_item[7]" type="int" optional>,
<dtml-sqlvar expr="row_item[8]" type="int" optional>,
<dtml-sqlvar expr="row_item[9]" type="int" optional>,
<dtml-sqlvar expr="row_item[10]" type="int" optional>,
<dtml-sqlvar expr="row_item[11]" type="int" optional>,
<dtml-sqlvar expr="row_item[12]" type="int" optional>,
<dtml-sqlvar expr="row_item[13]" type="int">,
<dtml-sqlvar expr="row_item[14]" type="float" optional>,
<dtml-sqlvar expr="row_item[15]" type="int">,
<dtml-sqlvar expr="row_item[16]" type="int">,
<dtml-sqlvar expr="row_item[17]" type="datetime" optional>,
<dtml-sqlvar expr="row_item[18]" type="datetime" optional>,
<dtml-sqlvar expr="row_item[19]" type="float" optional>,
<dtml-sqlvar expr="row_item[20]" type="string" optional>,
<dtml-sqlvar expr="row_item[21]" type="string" optional>,
<dtml-sqlvar expr="row_item[22]" type="string" optional>,
<dtml-sqlvar expr="row_item[23]" type="string" optional>
)
<dtml-if sequence-end><dtml-else>,</dtml-if>
</dtml-in>
</dtml-if>
</dtml-let>
<dtml-let row_list="[]">
<dtml-in prefix="loop" expr="_.range(_.len(uid))">
<dtml-if "not(isInventoryMovement[loop_item]) and isMovement[loop_item] and getResourceUid[loop_item]">
<dtml-if "getDestinationUid[loop_item]">
<dtml-call expr="row_list.append([
uid[loop_item],
order_id[loop_item],
getExplanationUid[loop_item],
getDestinationUid[loop_item],
getDestinationSectionUid[loop_item],
getDestinationPaymentUid[loop_item],
getDestinationFunctionUid[loop_item],
getDestinationProjectUid[loop_item],
getDestinationFundingUid[loop_item],
getLedgerUid[loop_item],
getDestinationPaymentRequestUid[loop_item],
getSourceSectionUid[loop_item],
getSourceUid[loop_item],
getResourceUid[loop_item],
getInventoriatedQuantity[loop_item],
isCancellationAmount[loop_item],
isAccountable[loop_item],
getStopDate[loop_item],
getStartDate[loop_item],
getDestinationInventoriatedTotalAssetPrice[loop_item],
getPortalType[loop_item],
getSimulationState[loop_item],
getVariationText[loop_item],
getSubVariationText[loop_item]])">
</dtml-if>
<dtml-if "getSourceUid[loop_item]">
<dtml-call expr="row_list.append([
uid[loop_item],
mirror_order_id[loop_item],
getExplanationUid[loop_item],
getSourceUid[loop_item],
getSourceSectionUid[loop_item],
getSourcePaymentUid[loop_item],
getSourceFunctionUid[loop_item],
getSourceProjectUid[loop_item],
getSourceFundingUid[loop_item],
getLedgerUid[loop_item],
getSourcePaymentRequestUid[loop_item],
getDestinationSectionUid[loop_item],
getDestinationUid[loop_item],
getResourceUid[loop_item],
-(getInventoriatedQuantity[loop_item] or 0),
isCancellationAmount[loop_item],
isAccountable[loop_item],
getStartDate[loop_item],
getStopDate[loop_item],
getSourceInventoriatedTotalAssetPrice[loop_item],
getPortalType[loop_item],
getSimulationState[loop_item],
getVariationText[loop_item],
getSubVariationText[loop_item]])">
</dtml-if>
</dtml-if>
</dtml-in>
<dtml-if "row_list">
INSERT INTO
stock
VALUES
<dtml-in prefix="row" expr="row_list">
(
<dtml-sqlvar expr="row_item[0]" type="int">,
<dtml-sqlvar expr="row_item[1]" type="int">,
<dtml-sqlvar expr="row_item[2]" type="int" optional>,
<dtml-sqlvar expr="row_item[3]" type="int">,
<dtml-sqlvar expr="row_item[4]" type="int" optional>,
<dtml-sqlvar expr="row_item[5]" type="int" optional>,
<dtml-sqlvar expr="row_item[6]" type="int" optional>,
<dtml-sqlvar expr="row_item[7]" type="int" optional>,
<dtml-sqlvar expr="row_item[8]" type="int" optional>,
<dtml-sqlvar expr="row_item[9]" type="int" optional>,
<dtml-sqlvar expr="row_item[10]" type="int" optional>,
<dtml-sqlvar expr="row_item[11]" type="int" optional>,
<dtml-sqlvar expr="row_item[12]" type="int" optional>,
<dtml-sqlvar expr="row_item[13]" type="int">,
<dtml-sqlvar expr="row_item[14]" type="float" optional>,
<dtml-sqlvar expr="row_item[15]" type="int">,
<dtml-sqlvar expr="row_item[16]" type="int">,
<dtml-sqlvar expr="row_item[17]" type="datetime" optional>,
<dtml-sqlvar expr="row_item[18]" type="datetime" optional>,
<dtml-sqlvar expr="row_item[19]" type="float" optional>,
<dtml-sqlvar expr="row_item[20]" type="string" optional>,
<dtml-sqlvar expr="row_item[21]" type="string" optional>,
<dtml-sqlvar expr="row_item[22]" type="string" optional>,
<dtml-sqlvar expr="row_item[23]" type="string" optional>
)
<dtml-if sequence-end><dtml-else>,</dtml-if>
</dtml-in>
</dtml-if>
</dtml-let>
<dtml-let row_list="[]">
<dtml-in prefix="loop" expr="_.range(_.len(subject_set_uid))">
<dtml-if expr="optimised_subject_list[loop_item]">
<dtml-in prefix="role" expr="optimised_subject_list[loop_item]">
<dtml-call expr="row_list.append([subject_set_uid[loop_item], role_item])">
</dtml-in>
</dtml-if>
</dtml-in>
<dtml-if expr="row_list">
INSERT INTO
subject
(`subject_set_uid`, `subject`)
VALUES
<dtml-in prefix="row" expr="row_list">
(<dtml-sqlvar expr="row_item[0]" type="string">, <dtml-sqlvar expr="row_item[1]" type="string">)
<dtml-if sequence-end><dtml-else>,</dtml-if>
</dtml-in>
</dtml-if>
</dtml-let>
<dtml-let row_list="[]">
<dtml-in row_dict_dict_list prefix="outer">
DELETE FROM `transformation` WHERE
<dtml-sqltest expr="outer_item['uid']" column="uid" type="int">
AND
<dtml-sqltest expr="outer_item['variation_text']" column="variation_text" type="string">;
<dtml-var sql_delimiter>
<dtml-call "row_list.extend(outer_item['row_dict_list'])">
</dtml-in>
<dtml-if "len(row_list)>0">
<dtml-var sql_delimiter>
INSERT INTO `transformation`
VALUES
<dtml-in row_list prefix="loop">
(
<dtml-sqlvar expr="loop_item['uid']" type="int">,
<dtml-sqlvar expr="loop_item['variation_text']" type="string">,
<dtml-sqlvar expr="loop_item['transformed_uid']" type="int">,
<dtml-sqlvar expr="loop_item['transformed_variation_text']" type="string">,
<dtml-sqlvar expr="loop_item['quantity']" type="float">
)
<dtml-unless sequence-end>,</dtml-unless>
</dtml-in>
</dtml-if>
</dtml-let>
\ No newline at end of file
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