Commit 449214a5 authored by Jean-Paul Smets's avatar Jean-Paul Smets
Browse files

Massive update to remove target values in simulation

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@2539 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent bcbcff30
......@@ -45,6 +45,6 @@ class Copy(DeliverySolver):
"""
Solve a delivery
"""
movement.setQuantity(movement.getTargetQuantity())
movement.setQuantity(movement.getSimulationQuantity())
registerDeliverySolver(Copy)
......@@ -40,12 +40,12 @@ class Distribute(DeliverySolver):
Solve a delivery by reducing / increasing each simulation movement
it relates to
"""
delivery_line_simulation_quantity = float(movement.getSimulationQuantity())
delivery_line_quantity = float(movement.getQuantity())
delivery_line_target_quantity = float(movement.getTargetQuantity())
if delivery_line_quantity != delivery_line_target_quantity:
if delivery_line_quantity != 0 :
# XXXXXXXXXXXXXXXXXXXXXXXXX something special should be done if delivery_line_quantity == 0 !
distribute_ratio = delivery_line_target_quantity / delivery_line_quantity
if delivery_line_simulation_quantity != delivery_line_quantity:
if delivery_line_simulation_quantity != 0 :
# XXXXXXXXXXXXXXXXXXXXXXXXX something special should be done if delivery_line_simulation_quantity == 0 !
distribute_ratio = delivery_line_quantity / delivery_line_simulation_quantity
for s in movement.getDeliveryRelatedValueList():
# Reduce quantity
s.setQuantity(s.getQuantity() * distribute_ratio)
......@@ -64,7 +64,6 @@ class Distribute(DeliverySolver):
s.setStartDate(movement.getStartDate())
s.setStopDate(movement.getStopDate())
s.diverge() # Make sure everyone knows this simulation movement is inconsistent
movement.setQuantity(movement.getTargetQuantity())
# No need to touch date since it should be defined at the upper level.
registerDeliverySolver(Distribute)
......@@ -28,6 +28,7 @@
from Globals import InitializeClass, PersistentMapping
from AccessControl import ClassSecurityInfo
from Acquisition import aq_base, aq_inner, aq_acquire, aq_chain
from Products.CMFCore.WorkflowCore import WorkflowAction
from Products.ERP5Type import Permissions, PropertySheet, Constraint, Interface
......@@ -201,10 +202,13 @@ Une ligne tarifaire."""
security.declarePrivate('_setSource')
def _setSource(self, value):
self._setCategoryMembership('source', value, base=0)
if self.getPortalType() not in self.getPortalBalanceTransactionLineTypeList():
source = self.restrictedTraverse(value)
if self.getPortalType() not in self.getPortalBalanceTransactionLineTypeList() and value not in (None, ''):
source = self.getPortalObject().portal_categories.resolveCategory(value)
destination = self.getDestination()
mirror_list = source.getDestinationList()
if source is not None:
mirror_list = source.getDestinationList()
else:
mirror_list = []
#LOG('_setSource', 0, 'value = %s, mirror_list = %s, destination = %s' % (str(value), str(mirror_list), str(destination)))
if len(mirror_list) > 0 and destination not in mirror_list:
self._setCategoryMembership('destination', mirror_list[0], base=0)
......@@ -219,11 +223,15 @@ Une ligne tarifaire."""
security.declarePrivate('_setDestination')
def _setDestination(self, value):
if self.getPortalType() not in self.getPortalBalanceTransactionLineTypeList():
if self.getPortalType() not in self.getPortalBalanceTransactionLineTypeList() and value not in (None, ''):
self._setCategoryMembership('destination', value, base=0)
destination = self.restrictedTraverse(value)
destination = self.getPortalObject().portal_categories.resolveCategory(value)
source = self.getSource()
mirror_list = destination.getDestinationList()
if destination is not None:
#LOG('_setSource', 0, 'destination %s' % destination)
mirror_list = destination.getDestinationList()
else:
mirror_list = []
#LOG('_setDestination', 0, 'value = %s, mirror_list = %s, source = %s' % (str(value), str(mirror_list), str(source)))
if len(mirror_list) > 0 and source not in mirror_list:
self._setCategoryMembership('source', mirror_list[0], base=0)
......
......@@ -206,38 +206,6 @@ class Amount(Base, Variated):
except:
LOG("ERP5 WARNING:", 100, 'could not set converted quantity for %s' % self.getRelativeUrl())
security.declareProtected(Permissions.AccessContentsInformation, 'getConvertedTargetQuantity')
def getConvertedTargetQuantity(self):
"""
Converts target_quantity to default unit
"""
#if 1:
try:
#if 1:
resource = self.getResourceValue()
resource_quantity_unit = resource.getDefaultQuantityUnit()
quantity_unit = self.getQuantityUnit()
quantity = self.getTargetQuantity()
converted_quantity = resource.convertQuantity(quantity, quantity_unit, resource_quantity_unit)
#else:
except:
#else:
LOG("ERP5 WARNING:", 100, 'could not convert target_quantity for %s' % self.getRelativeUrl())
converted_quantity = None
return converted_quantity
security.declareProtected(Permissions.ModifyPortalContent, 'setConvertedTargetQuantity')
def setConvertedTargetQuantity(self, value):
try:
#if 1:
resource = self.getResourceValue()
resource_quantity_unit = resource.getDefaultQuantityUnit()
quantity_unit = self.getQuantityUnit()
quantity = resource.convertQuantity(value, resource_quantity_unit, quantity_unit)
self.setTargetQuantity(quantity)
except:
LOG("ERP5 WARNING:", 100, 'could not set converted quantity for %s' % self.getRelativeUrl())
security.declareProtected(Permissions.AccessContentsInformation, 'getNetQuantity')
def getNetQuantity(self):
"""
......
......@@ -164,8 +164,8 @@ Une ligne tarifaire."""
# Never divergent
return 0
security.declareProtected(Permissions.AccessContentsInformation, 'getTargetTotalQuantity')
def getTargetTotalQuantity(self):
security.declareProtected(Permissions.AccessContentsInformation, 'getTotalQuantity')
def getTotalQuantity(self):
"""
Returns the quantity if no cell or the total quantity if cells
"""
......@@ -174,4 +174,4 @@ Une ligne tarifaire."""
else:
# Use MySQL
aggregate = self.ContainerLine_zGetTotal()[0]
return aggregate.target_total_quantity
return aggregate.total_quantity
......@@ -373,18 +373,12 @@ class Delivery(XMLObject):
for date_group in path_group.group_list :
invoice = invoice_module.newContent(portal_type = invoice_type,
target_start_date = date_group.start_date,
target_stop_date = date_group.stop_date,
start_date = date_group.start_date,
stop_date = date_group.stop_date,
source = path_group.source,
destination = path_group.destination,
source_section = path_group.source_section,
destination_section = path_group.destination_section,
target_source = path_group.source,
target_destination = path_group.destination,
target_source_section = path_group.source_section,
target_destination_section = path_group.destination_section,
causality_value = self,
title = self.getTitle(),
description = 'Invoice related to the Delivery %s' % self.getTitle())
......@@ -396,7 +390,8 @@ class Delivery(XMLObject):
LOG('buildInvoiceList resource_group.group_list',0,resource_group.group_list)
# Create a new Sale Invoice Transaction Line for each resource
invoice_line = invoice.newContent(portal_type=invoice_line_type
invoice_line = invoice.newContent(
portal_type=invoice_line_type
, resource=resource_group.resource)
# line_variation_category_list = []
......@@ -421,15 +416,15 @@ class Delivery(XMLObject):
#XXX for now, we quickly need this working, without the need of variant_group
object_to_update = invoice_line
# compute target_quantity, quantity and price for invoice_cell or invoice_line and
# compute quantity and price for invoice_cell or invoice_line and
# build relation between simulation_movement and invoice_cell or invoice_line
if object_to_update is not None :
target_quantity = 0
quantity = 0
total_price = 0
for movement in resource_group.movement_list :
target_quantity += movement.getConvertedTargetQuantity()
quantity += movement.getConvertedQuantity()
try :
total_price += movement.getNetConvertedTargetQuantity() * movement.getPrice() # XXX WARNING - ADD PRICED QUANTITY
total_price += movement.getNetConvertedQuantity() * movement.getPrice() # XXX WARNING - ADD PRICED QUANTITY
except :
total_price = None
# What do we really need to update in the simulation movement ?
......@@ -437,17 +432,16 @@ class Delivery(XMLObject):
movement._setDeliveryValue(object_to_update)
reindexable_movement_list.append(movement)
if target_quantity <> 0 and total_price is not None:
average_price = total_price/target_quantity
if quantity <> 0 and total_price is not None:
average_price = total_price/quantity
else :
average_price = 0
LOG('buildInvoiceList edit', 0, repr(( object_to_update, target_quantity, average_price, )))
object_to_update.edit(target_quantity = target_quantity,
quantity = target_quantity,
LOG('buildInvoiceList edit', 0, repr(( object_to_update, quantity, average_price, )))
object_to_update.edit(quantity = quantity,
price = average_price)
# update target_quantity, quantity and price for each invoice_cell
# update quantity and price for each invoice_cell
#XXX for variant_group in resource_group.group_list :
if 0 :
LOG('Variant_group examin',0,str(variant_group.category_list))
......@@ -476,15 +470,15 @@ class Delivery(XMLObject):
object_to_update = invoice_cell
break
# compute target_quantity, quantity and price for invoice_cell or invoice_line and
# compute quantity and price for invoice_cell or invoice_line and
# build relation between simulation_movement and invoice_cell or invoice_line
if object_to_update is not None :
cell_target_quantity = 0
cell_quantity = 0
cell_total_price = 0
for movement in variant_group.movement_list :
cell_target_quantity += movement.getConvertedTargetQuantity()
cell_quantity += movement.getConvertedQuantity()
try :
cell_total_price += movement.getNetConvertedTargetQuantity() * movement.getPrice() # XXX WARNING - ADD PRICED QUANTITY
cell_total_price += movement.getNetConvertedQuantity() * movement.getPrice() # XXX WARNING - ADD PRICED QUANTITY
except :
cell_total_price = None
# What do we really need to update in the simulation movement ?
......@@ -492,15 +486,15 @@ class Delivery(XMLObject):
movement._setDeliveryValue(object_to_update)
reindexable_movement_list.append(movement)
if cell_target_quantity <> 0 and cell_total_price is not None:
average_price = cell_total_price/cell_target_quantity
if cell_quantity <> 0 and cell_total_price is not None:
average_price = cell_total_price/cell_quantity
else :
average_price = 0
LOG('buildInvoiceList edit', 0, repr(( object_to_update, cell_target_quantity, average_price, )))
object_to_update.edit(target_quantity = cell_target_quantity,
quantity = cell_target_quantity,
LOG('buildInvoiceList edit', 0, repr(( object_to_update, cell_quantity, average_price, )))
object_to_update.edit(quantity = cell_quantity,
price = average_price)
# we now reindex the movements we modified
for movement in reindexable_movement_list :
movement.immediateReindexObject()
......@@ -527,13 +521,6 @@ class Delivery(XMLObject):
result = self.z_total_price(delivery_uid = self.getUid())
return result[0][0]
security.declareProtected(Permissions.AccessContentsInformation, 'getTargetTotalPrice')
def getTargetTotalPrice(self):
"""
"""
result = self.z_total_price(delivery_uid = self.getUid())
return result[0][1]
# security.declareProtected(Permissions.AccessContentsInformation, 'getTotalPrice')
# def getTotalPrice(self, context=None, REQUEST=None, **kw):
# """
......@@ -581,14 +568,6 @@ class Delivery(XMLObject):
aggregate = self.Delivery_zGetTotal(uid=self.getUid())[0]
return aggregate.total_quantity
security.declareProtected(Permissions.AccessContentsInformation, 'getTargetTotalQuantity')
def getTargetTotalQuantity(self):
"""
Returns the quantity if no cell or the total quantity if cells
"""
aggregate = self.Delivery_zGetTotal()[0]
return aggregate.target_total_quantity
security.declareProtected(Permissions.AccessContentsInformation, 'getDeliveryUid')
def getDeliveryUid(self):
return self.getUid()
......@@ -694,8 +673,8 @@ class Delivery(XMLObject):
LOG('Delivery.isSimulated m.isSimulated',0,m.isSimulated())
if not m.isSimulated():
LOG('Delivery.isSimulated m.getQuantity',0,m.getQuantity())
LOG('Delivery.isSimulated m.getTargetQuantity',0,m.getTargetQuantity())
if m.getQuantity() != 0.0 or m.getTargetQuantity() != 0:
LOG('Delivery.isSimulated m.getSimulationQuantity',0,m.getSimulationQuantity())
if m.getQuantity() != 0.0 or m.getSimulationQuantity() != 0:
return 0
# else Do we need to create a simulation movement ? XXX probably not
return 1
......@@ -718,9 +697,9 @@ class Delivery(XMLObject):
Source is divergent if simulated and target values differ
or if multiple sources are defined
"""
if self.getSource() != self.getTargetSource() \
if self.getSource() != self.getSimulationSource() \
or len(self.getSourceList()) > 1 \
or len(self.getTargetSourceList()) > 1:
or len(self.getSimulationSourceList()) > 1:
return 1
return 0
......@@ -732,12 +711,12 @@ class Delivery(XMLObject):
"""
LOG('Delivery.isDestinationDivergent, self.getPath()',0,self.getPath())
LOG('Delivery.isDestinationDivergent, self.getDestination()',0,self.getDestination())
LOG('Delivery.isDestinationDivergent, self.getTargetDestination()',0,self.getTargetDestination())
LOG('Delivery.isDestinationDivergent, self.getSimulationDestination()',0,self.getSimulationDestination())
LOG('Delivery.isDestinationDivergent, self.getDestinationList()',0,self.getDestinationList())
LOG('Delivery.isDestinationDivergent, self.getTargetDestinationList()',0,self.getTargetDestinationList())
if self.getDestination() != self.getTargetDestination() \
LOG('Delivery.isDestinationDivergent, self.getSimulationDestinationList()',0,self.getSimulationDestinationList())
if self.getDestination() != self.getSimulationDestination() \
or len(self.getDestinationList()) > 1 \
or len(self.getTargetDestinationList()) > 1:
or len(self.getSimulationDestinationList()) > 1:
return 1
return 0
......@@ -746,9 +725,9 @@ class Delivery(XMLObject):
"""
Same as isSourceDivergent for source_section
"""
if self.getSourceSection() != self.getTargetSourceSection() \
if self.getSourceSection() != self.getSimulationSourceSection() \
or len(self.getSourceSectionList()) > 1 \
or len(self.getTargetSourceSectionList()) > 1:
or len(self.getSimulationSourceSectionList()) > 1:
return 1
return 0
......@@ -757,9 +736,9 @@ class Delivery(XMLObject):
"""
Same as isDestinationDivergent for source_section
"""
if self.getDestinationSection() != self.getTargetDestinationSection() \
if self.getDestinationSection() != self.getSimulationDestinationSection() \
or len(self.getDestinationSectionList()) > 1 \
or len(self.getTargetDestinationSectionList()) > 1:
or len(self.getSimulationDestinationSectionList()) > 1:
return 1
return 0
......@@ -768,16 +747,16 @@ class Delivery(XMLObject):
"""
"""
LOG("isDivergent getStartDate", 0, repr(self.getStartDate()))
LOG("isDivergent getTargetStartDate", 0, repr(self.getTargetStartDate()))
LOG("isDivergent getSimulationStartDate", 0, repr(self.getSimulationStartDate()))
LOG("isDivergent getStopDate", 0, repr(self.getStopDate()))
LOG("isDivergent getTargetStopDate", 0, repr(self.getTargetStopDate()))
LOG("isDivergent getSimulationStopDate", 0, repr(self.getSimulationStopDate()))
from DateTime import DateTime
if self.getStartDate() is None or self.getTargetStartDate() is None \
or self.getStopDate() is None or self.getTargetStopDate() is None:
if self.getStartDate() is None or self.getSimulationStartDate() is None \
or self.getStopDate() is None or self.getSimulationStopDate() is None:
return 1
# This is uggly but required due to python2.2/2.3 Zope 2.6/2.7 inconsistency in _millis calculation
if self.getStartDate().Date() != self.getTargetStartDate().Date() or \
self.getStopDate().Date() != self.getTargetStopDate().Date():
if self.getStartDate().Date() != self.getSimulationStartDate().Date() or \
self.getStopDate().Date() != self.getSimulationStopDate().Date():
# LOG("isDivergent getStartDate", 0, repr(self.getStartDate()))
# LOG("isDivergent getTargetStartDate", 0, repr(self.getTargetStartDate()))
# LOG("isDivergent getStopDate", 0, repr(self.getStopDate()))
......
......@@ -240,21 +240,6 @@ Une ligne tarifaire."""
return self.getTargetQuantity() # We have acquisition here which me should mimic
# return None
security.declareProtected( Permissions.AccessContentsInformation, 'getTargetQuantity' )
def getTargetQuantity(self):
"""
Returns the target quantity if defined on the cell
or acquire it
"""
# Call a script on the context
if 'target_quantity' in self.getMappedValuePropertyList([]):
if getattr(aq_base(self), 'target_quantity', None) is not None:
return getattr(self, 'target_quantity')
else:
return self.aq_parent.getProperty('target_quantity')
else:
return None
def _setItemIdList(self, value):
"""
Computes total_quantity of all given items and stores this total_quantity
......@@ -353,34 +338,19 @@ Une ligne tarifaire."""
return self.getParent().getRootDeliveryValue()
# Simulation Consistency Check
def getRelatedQuantity(self):
def getSimulationQuantity(self):
"""
Computes the quantities in the simulation
"""
if isinstance(self, OrderLine):
result = self.OrderLine_zGetRelatedQuantity(uid=self.getUid())
if len(result) > 0:
return result[0].target_quantity
return None
else:
result = self.DeliveryLine_zGetRelatedQuantity(uid=self.getUid())
if len(result) > 0:
return result[0].quantity
return None
def getRelatedTargetQuantity(self):
"""
Computes the target quantities in the simulation
"""
if isinstance(self, OrderLine):
result = self.OrderLine_zGetRelatedQuantity(uid=self.getUid())
if len(result) > 0:
return result[0].target_quantity
return None
else:
result = self.DeliveryLine_zGetRelatedQuantity(uid=self.getUid())
if len(result) > 0:
return result[0].target_quantity
return result[0].quantity
return None
security.declareProtected( Permissions.ModifyPortalContent, 'notifyAfterUpdateRelatedContent' )
......
......@@ -209,23 +209,13 @@ Une ligne tarifaire."""
def _getTotalPrice(self, context):
if not self.hasCellContent():
price = self.getPrice(context=context)
if price is None: price = 0.0 # Quick and dirty fix XXX
return self.getQuantity() * price
else:
# Use MySQL
aggregate = self.DeliveryLine_zGetTotal()[0]
return aggregate.total_price
def _getTargetTotalPrice(self, context):
if not self.hasCellContent():
target_quantity = self.getTargetQuantity() or 0.0
quantity = self.getQuantity() or 0.0
price = self.getPrice(context=context) or 0.0
return target_quantity * price
return quantity * price
else:
# Use MySQL
aggregate = self.DeliveryLine_zGetTotal()[0]
return aggregate.target_total_price
return aggregate.total_price
security.declareProtected(Permissions.AccessContentsInformation, 'getTotalQuantity')
def getTotalQuantity(self):
......@@ -239,18 +229,6 @@ Une ligne tarifaire."""
aggregate = self.DeliveryLine_zGetTotal()[0]
return aggregate.total_quantity
security.declareProtected(Permissions.AccessContentsInformation, 'getTargetTotalQuantity')
def getTargetTotalQuantity(self):
"""
Returns the quantity if no cell or the total quantity if cells
"""
if not self.hasCellContent():
return self.getTargetQuantity()
else:
# Use MySQL
aggregate = self.DeliveryLine_zGetTotal()[0]
return aggregate.target_total_quantity
# Cell Related
security.declareProtected( Permissions.ModifyPortalContent, 'newCellContent' )
def newCellContent(self, id, **kw):
......@@ -320,7 +298,7 @@ Une ligne tarifaire."""
#LOG('new cell',0,str(k))
c = self.newCell(*k, **kwd)
c.edit( domain_base_category_list = self.getVariationBaseCategoryList(),
mapped_value_property_list = ('target_quantity', 'quantity', 'price',),
mapped_value_property_list = ('quantity', 'price',),
#predicate_operator = 'SUPERSET_OF',
membership_criterion_category = filter(lambda k_item: k_item is not None, k),
variation_category_list = filter(lambda k_item: k_item is not None, k),
......@@ -468,7 +446,7 @@ Une ligne tarifaire."""
security.declarePrivate('_checkConsistency')
def _checkConsistency(self, fixit=0, mapped_value_property_list = ('target_quantity', 'quantity', 'price')):
def _checkConsistency(self, fixit=0, mapped_value_property_list = ('quantity', 'price')):
"""
Check the constitency of transformation elements
"""
......@@ -507,18 +485,10 @@ Une ligne tarifaire."""
"""
Computes the quantities in the simulation
"""
result = self.DeliveryLine_zGetRelatedQuantity(uid=self.getUid())
if len(result) > 0:
return result[0].quantity
return None
def getSimulationTargetQuantity(self):
"""
Computes the target quantities in the simulation
"""
result = self.DeliveryLine_zGetRelatedQuantity(uid=self.getUid())
if len(result) > 0:
return result[0].target_quantity
if not self.hasCellContent():
result = self.DeliveryLine_zGetRelatedQuantity(uid=self.getUid())
if len(result) > 0:
return result[0].quantity
return None
def getSimulationSourceList(self):
......@@ -556,26 +526,3 @@ Une ligne tarifaire."""
"""
return self.getParent().getRootDeliveryValue()
# Simulation Consistency Check
def getRelatedQuantity(self):
"""
Computes the quantities in the simulation
"""
if not self.hasCellContent():
result = self.DeliveryLine_zGetRelatedQuantity(uid=self.getUid())
if len(result) > 0:
return result[0].quantity
return None
def getRelatedTargetQuantity(self):
"""
Computes the target quantities in the simulation
"""
if not self.hasCellContent():
result = self.DeliveryLine_zGetRelatedQuantity(uid=self.getUid())
if len(result) > 0:
return result[0].target_quantity
return None
......@@ -183,11 +183,8 @@ An ERP5 Rule..."""
delivery_value = c,
order_value = c,
quantity = c.getQuantity(),
target_quantity = c.getTargetQuantity(),
start_date = c.getStartDate(),
stop_date = c.getStopDate(),
target_start_date = c.getTargetStartDate(),
target_stop_date = c.getTargetStopDate(),
deliverable = 1
)
# We must create both order and delivery link in this case
......@@ -203,11 +200,8 @@ An ERP5 Rule..."""
delivery_value = delivery_line_object,
order_value = delivery_line_object,
quantity = delivery_line_object.getQuantity(),
target_quantity = delivery_line_object.getTargetQuantity(),
start_date = delivery_line_object.getStartDate(),
stop_date = delivery_line_object.getStopDate(),
target_start_date = delivery_line_object.getTargetStartDate(),
target_stop_date = delivery_line_object.getTargetStopDate(),
deliverable = 1
)
# Source, Destination, Quantity, Date, etc. are
......
......@@ -37,7 +37,28 @@ class Domain(PredicateGroup):
"""
An abstract class subclassed by reports and mapped values
Implements subdomain traversal methods
Structure is:
- base domain (like base category)
- sub domain (like category)
Allows to define ranges:
- price between X and Y
- portal_type in (a, b, c)
- price between X and Y and region in (a, b, c)
Reports:
- listbox allows to produce reports
- output to html, pdf or ooffice
- definition through the web (ie. which field in which column, which statistics)
- definition of selection (to list)
- ability for use to "save" favourite report (user reports)
- library of favourite reports (global reports)
- matrixbox allows to produce reports
- output to html, pdf or ooffice
- definition through the web (ie. which base_category or base_domain in which axis)
- definition of selection (to map to matrix)
- ability for use to "save" favourite report (user reports)
- library of favourite reports (global reports)
"""
meta_type = 'ERP5 Domain'
portal_type = 'Domain'
......
......@@ -106,7 +106,7 @@ class Invoice(AccountingTransaction):
for rule in o.objectValues():
invoice_transaction_rule_list.append(rule)
simulation_line_list += rule.objectValues()
LOG('buildInvoiceTransactionList simulation_line_list',0,simulation_line_list)
#LOG('buildInvoiceTransactionList simulation_line_list',0,simulation_line_list)
from Products.ERP5.MovementGroup import CategoryMovementGroup
class_list = [CategoryMovementGroup, ]
root_group = self.portal_simulation.collectMovement(simulation_line_list,class_list=class_list)
......@@ -144,9 +144,14 @@ class Invoice(AccountingTransaction):
# add sum of movements to invoice
#LOG('buildInvoiceTransactionList group_id',0,group_id)
#LOG('buildInvoiceTransactionList reference_movement',0,str(reference_movement.getRelativeUrl()))
#LOG('buildInvoiceTransactionList reference_movement',0,str(reference_movement.showDict()))
#LOG('buildInvoiceTransactionList reference_movement',0,str(reference_movement.getSource()))
#LOG('buildInvoiceTransactionList reference_movement',0,str(reference_movement.getDestination()))
sale_invoice_transaction_line_item = getattr(self, group_id, None)
if sale_invoice_transaction_line_item is None :
sale_invoice_transaction_line_item = self.newContent(portal_type = self._transaction_line_portal_type
sale_invoice_transaction_line_item = self.newContent(
portal_type = self._transaction_line_portal_type
, id = group_id
, source = reference_movement.getSource()
, destination = reference_movement.getDestination()
......@@ -156,11 +161,13 @@ class Invoice(AccountingTransaction):
sale_invoice_transaction_line_item._setDestinationSection(reference_movement.getDestinationSection())
if self.getSourceSection() != reference_movement.getSourceSection():
sale_invoice_transaction_line_item._setSourceSection(reference_movement.getSourceSection())
#LOG('buildInvoiceTransactionList sale_invoice_transaction_line',0,str(sale_invoice_transaction_line_item.showDict()))
else :
sale_invoice_transaction_line_item.edit(
source = reference_movement.getSource()
, destination = reference_movement.getDestination()
, quantity = quantity
, force_update = 1
)
if self.getDestinationSection() != reference_movement.getDestinationSection():
sale_invoice_transaction_line_item._setDestinationSection(reference_movement.getDestinationSection())
......@@ -200,7 +207,7 @@ class Invoice(AccountingTransaction):
for rule in o.objectValues():
payment_transaction_rule_list.append(rule)
simulation_line_list += rule.objectValues()
LOG('buildPaymentTransactionList simulation_line_list',0,simulation_line_list)
#LOG('buildPaymentTransactionList simulation_line_list',0,simulation_line_list)
# create payment transaction
accounting_module = self.accounting
......@@ -208,17 +215,15 @@ class Invoice(AccountingTransaction):
payment_id = str(accounting_module.generateNewId())
payment_transaction = accounting_module.newContent(portal_type = payment_type
, id = payment_id
, source = self.getSource()
, reference = self.getReference()
, resource = self.getResource()
, start_date = self.getStartDate()
, source_payment = self.getSourcePayment()
, source_section = self.getSourceSection()
, destination = self.getDestination()
, destination_payment = self.getDestinationPayment()
, destination_section = self.getDestinationSection()
)
LOG('buildPaymentTransactionList payment_transaction', 0, repr(( payment_transaction )))
#LOG('buildPaymentTransactionList payment_transaction', 0, repr(( payment_transaction.showDict() )))
# fill quantity in lines
for movement in simulation_line_list :
......@@ -228,16 +233,25 @@ class Invoice(AccountingTransaction):
payment_transaction_line = getattr(payment_transaction, movement_id, None)
if payment_transaction_line is None :
payment_transaction.newContent(portal_type = 'Accounting Transaction Line'
payment_transaction.newContent(
portal_type = 'Accounting Transaction Line'
, id = movement_id
, quantity = quantity
)
previous_quantity = 0.0
else :
previous_quantity = payment_transaction_line.getQuantity()
if previous_quantity is not None:
quantity = quantity + previous_quantity
payment_transaction_line.setQuantity(quantity)
if previous_quantity is not None:
quantity = quantity + previous_quantity
payment_transaction_line.edit(
quantity = quantity
, source = movement.getSource()
, destination = movement.getDestination()
, force_update = 1
)
#LOG('buildPaymentTransactionList movement', 0, repr(( movement.showDict() )))
#LOG('buildPaymentTransactionList payment_transaction_line', 0, repr(( payment_transaction_line.showDict() )))
# What do we really need to update in the simulation movement ?
if movement.getPortalType() == 'Simulation Movement' :
movement._setDeliveryValue(payment_transaction_line)
......
......@@ -85,9 +85,7 @@ class InvoicingRule(Rule):
my_context_movement = applied_rule.getParent()
LOG('InvoicingRule.expand, my_context_movement.getPhysicalPath()',0,my_context_movement.getPhysicalPath())
LOG('InvoicingRule.expand, my_context_movement.getSource()',0,my_context_movement.getSource())
LOG('InvoicingRule.expand, my_context_movement.getTargetSource()',0,my_context_movement.getTargetSource())
LOG('InvoicingRule.expand, my_context_movement.showDict()',0,my_context_movement.showDict())
LOG('InvoicingRule.expand, my_context_movement.getSource',0,my_context_movement.getSource())
if my_context_movement.getSource() is not None:
# We should only expand movements if they have a source
# otherwise, it creates infinite recursion
......@@ -106,16 +104,16 @@ class InvoicingRule(Rule):
resource = my_context_movement.getResource()
invoice_line._edit(
price = my_context_movement.getPrice(),
target_quantity = my_context_movement.getTargetQuantity(),
target_efficiency = my_context_movement.getTargetEfficiency(),
quantity = my_context_movement.getQuantity(),
efficiency = my_context_movement.getEfficiency(),
resource = resource,
target_start_date = my_context_movement.getTargetStartDate(),
target_stop_date = my_context_movement.getTargetStartDate(),
target_source = my_context_movement.getTargetDestination(),
target_source_section = my_context_movement.getTargetSourceSection(),
start_date = my_context_movement.getStartDate(),
stop_date = my_context_movement.getStartDate(),
source = my_context_movement.getDestination(),
source_section = my_context_movement.getSourceSection(),
quantity_unit = my_context_movement.getQuantityUnit(),
target_destination = my_context_movement.getTargetDestination(),
target_destination_section = my_context_movement.getTargetDestinationSection(),
destination = my_context_movement.getDestination(),
destination_section = my_context_movement.getDestinationSection(),
deliverable = 1 # We do need to collect invoice lines to build invoices
)
# transformation_source.setVariationCategoryList(
......
......@@ -269,14 +269,6 @@ a service in a public administration)."""
else:
return None
def _getTargetTotalPrice(self, context):
price = self.getPrice(context=context)
quantity = self.getTargetQuantity()
if type(price) in (type(1.0), type(1)) and type(quantity) in (type(1.0), type(1)):
return quantity * price
else:
return None
security.declareProtected(Permissions.AccessContentsInformation, 'getPrice')
def getPrice(self, context=None, REQUEST=None, **kw):
"""
......@@ -295,12 +287,6 @@ a service in a public administration)."""
"""
return self._getTotalPrice(self.asContext(context=context, REQUEST=REQUEST, **kw))
security.declareProtected(Permissions.AccessContentsInformation, 'getTargetTotalPrice')
def getTargetTotalPrice(self, context=None, REQUEST=None, **kw):
"""
"""
return self._getTargetTotalPrice(self.asContext(context=context, REQUEST=REQUEST, **kw))
security.declareProtected(Permissions.AccessContentsInformation, 'getTotalQuantity')
def getTotalQuantity(self):
"""
......@@ -308,13 +294,6 @@ a service in a public administration)."""
"""
return self.getQuantity()
security.declareProtected(Permissions.AccessContentsInformation, 'getTargetTotalQuantity')
def getTargetTotalQuantity(self):
"""
Returns the quantity if no cell or the total quantity if cells
"""
return self.getTargetQuantity()
# Industrial price API
security.declareProtected(Permissions.AccessContentsInformation, 'getIndustrialPrice')
def getIndustrialPrice(self):
......@@ -418,3 +397,155 @@ a service in a public administration)."""
security.declareProtected(Permissions.View, 'isSimulated')
def isSimulated(self):
return len(self.getDeliveryRelatedValueList()) > 0 or len(self.getOrderRelatedValueList()) > 0
# New Causality API
security.declareProtected(Permissions.AccessContentsInformation, 'getOrderQuantity')
def getOrderQuantity(self):
"""
Returns the quantity of related order(s)
"""
return self.getQuantity()
security.declareProtected(Permissions.AccessContentsInformation, 'getDeliveryQuantity')
def getDeliveryQuantity(self):
"""
Returns the quantity of related delivery(s)
"""
return self.getQuantity()
security.declareProtected(Permissions.AccessContentsInformation, 'getSimulationQuantity')
def getSimulationQuantity(self):
"""
Returns the sum of quantities in related simulation movements
"""
return self.getQuantity()
security.declareProtected(Permissions.AccessContentsInformation, 'getOrderStartDateList')
def getOrderStartDateList(self):
"""
Returns the start date of related order(s)
"""
return [self.getStartDate()]
security.declareProtected(Permissions.AccessContentsInformation, 'getDeliveryStartDateList')
def getDeliveryStartDateList(self):
"""
Returns the start date of related delivery(s)
"""
return [self.getStartDate()]
security.declareProtected(Permissions.AccessContentsInformation, 'getSimulationStartDateList')
def getSimulationStartDateList(self):
"""
Returns the of start date related simulation movements
"""
return [self.getStartDate()]
security.declareProtected(Permissions.AccessContentsInformation, 'getOrderStopDateList')
def getOrderStopDateList(self):
"""
Returns the stop date of related order(s)
"""
return [self.getStopDate()]
security.declareProtected(Permissions.AccessContentsInformation, 'getDeliveryStopDateList')
def getDeliveryStopDateList(self):
"""
Returns the stop date of related delivery(s)
"""
return [self.getStopDate()]
security.declareProtected(Permissions.AccessContentsInformation, 'getSimulationStopDateList')
def getSimulationStopDateList(self):
"""
Returns the of stop date related simulation movements
"""
return [self.getStopDate()]
security.declareProtected(Permissions.AccessContentsInformation, 'getOrderSourceList')
def getOrderSourceList(self):
"""
Returns the source of related orders
"""
return self.getSourceList()
security.declareProtected(Permissions.AccessContentsInformation, 'getDeliverySourceList')
def getDeliverySourceList(self):
"""
Returns the source of related deliveries
"""
return self.getSourceList()
security.declareProtected(Permissions.AccessContentsInformation, 'getSimulationSourceList')
def getSimulationSourceList(self):
"""
Returns the source of related simulation movements
"""
return self.getSourceList()
security.declareProtected(Permissions.AccessContentsInformation, 'getOrderDestinationList')
def getOrderDestinationList(self):
"""
Returns the destination of related orders
"""
return self.getDestinationList()
security.declareProtected(Permissions.AccessContentsInformation, 'getDeliveryDestinationList')
def getDeliveryDestinationList(self):
"""
Returns the destination of related deliveries
"""
return self.getDestinationList()
security.declareProtected(Permissions.AccessContentsInformation, 'getSimulationDestinationList')
def getSimulationDestinationList(self):
"""
Returns the destination of related simulation movements
"""
return self.getDestinationList()
security.declareProtected(Permissions.AccessContentsInformation, 'getOrderSourceSectionList')
def getOrderSourceSectionList(self):
"""
Returns the source_section of related orders
"""
return self.getSourceSectionList()
security.declareProtected(Permissions.AccessContentsInformation, 'getDeliverySourceSectionList')
def getDeliverySourceSectionList(self):
"""
Returns the source_section of related deliveries
"""
return self.getSourceSectionList()
security.declareProtected(Permissions.AccessContentsInformation, 'getSimulationSourceSectionList')
def getSimulationSourceSectionList(self):
"""
Returns the source_section of related simulation movements
"""
return self.getSourceSectionList()
security.declareProtected(Permissions.AccessContentsInformation, 'getOrderDestinationSectionList')
def getOrderDestinationSectionList(self):
"""
Returns the destination_section of related orders
"""
return self.getDestinationSectionList()
security.declareProtected(Permissions.AccessContentsInformation, 'getDeliveryDestinationSectionList')
def getDeliveryDestinationSectionList(self):
"""
Returns the destination_section of related deliveries
"""
return self.getDestinationSectionList()
security.declareProtected(Permissions.AccessContentsInformation, 'getSimulationDestinationSectionList')
def getSimulationDestinationSectionList(self):
"""
Returns the destination_section of related simulation movements
"""
return self.getDestinationSectionList()
\ No newline at end of file
......@@ -151,7 +151,7 @@ Une ligne tarifaire."""
c = self.newCell(*k, **kwd)
#LOG('OrderLine _setVariationCategoryList', 0, 'k = %s, c = %s, self.getVariationBaseCategoryList() = %s' % (repr(k), repr(c), repr(self.getVariationBaseCategoryList())))
c.edit( domain_base_category_list = self.getVariationBaseCategoryList(),
mapped_value_property_list = ('target_quantity', 'price',),
mapped_value_property_list = ('quantity', 'price',),
predicate_operator = 'SUPERSET_OF',
predicate_value = filter(lambda k_item: k_item is not None, k),
variation_category_list = filter(lambda k_item: k_item is not None, k),
......@@ -168,7 +168,7 @@ Une ligne tarifaire."""
self._delObject(k)
security.declarePrivate('_checkConsistency')
def _checkConsistency(self, fixit=0, mapped_value_property_list = ('target_quantity', 'price')):
def _checkConsistency(self, fixit=0, mapped_value_property_list = ('quantity', 'price')):
"""
Check the constitency of transformation elements
"""
......@@ -211,20 +211,11 @@ Une ligne tarifaire."""
self.aq_parent.activate()._createOrderRule()
# Simulation Consistency Check
def getRelatedQuantity(self):
"""
Computes the quantities in the simulation
"""
result = self.OrderLine_zGetRelatedQuantity(uid=self.getUid())
if len(result) > 0:
return result[0].quantity
return None
def getRelatedTargetQuantity(self):
def getSimulationQuantity(self):
"""
Computes the target quantities in the simulation
"""
result = self.OrderLine_zGetRelatedQuantity(uid=self.getUid())
if len(result) > 0:
return result[0].target_quantity
return result[0].quantity
return None
......@@ -146,7 +146,7 @@ An ERP5 Rule..."""
# eventually delete movement which do not exist anylonger
existing_uid_list = []
for movement in applied_rule.contentValues(filter={'portal_type':applied_rule.getPortalMovementTypeList()}):
#LOG('Movement', 0, str(movement))
LOG('Movement', 0, str(movement))
order_value = movement.getOrderValue(portal_type=applied_rule.getPortalOrderMovementTypeList())
if order_value is None:
movement.flushActivity(invoke=0)
......@@ -156,7 +156,7 @@ An ERP5 Rule..."""
existing_uid_list += [order_value.getUid()]
elif order_value.hasCellContent():
# Do not keep head of cells
#LOG('INFO', 0, 'Order Rule Deleting Simulatino Movement %s' % movement.getRelativeUrl())
LOG('INFO', 0, 'Order Rule Deleting Simulatino Movement %s' % movement.getRelativeUrl())
order_value.flushActivity(invoke=0)
applied_rule._delObject(movement.getId()) # XXXX Make sur this is not deleted if already in delivery
else:
......@@ -164,16 +164,22 @@ An ERP5 Rule..."""
# Copy each movement (line or cell) from the order
for order_line_object in my_order.contentValues(filter={'portal_type':applied_rule.getPortalMovementTypeList()}):
LOG('OrderRule.expand, examining:',0,order_line_object.getPhysicalPath())
try:
if order_line_object.hasCellContent():
for c in order_line_object.getCellValueList():
#LOG('Cell in', 0, '%s %s' % (c.getUid(), existing_uid_list))
LOG('Cell in', 0, '%s %s' % (c.getUid(), existing_uid_list))
if c.getUid() not in existing_uid_list:
new_id = order_line_object.getId() + '_' + c.getId()
#LOG('Create Cell', 0, str(new_id))
LOG('Create Cell', 0, str(new_id))
new_line = applied_rule.newContent(type_name=delivery_line_type,
id=new_id,
order_value = c,
quantity = c.getQuantity(),
source = c.getSource(),
destination = c.getDestination(),
source_section = c.getSourceSection(),
destination_section = c.getDestinationSection(),
deliverable = 1
)
LOG('OrderRule.expand, object created:',0,new_line.getPhysicalPath())
......@@ -182,16 +188,21 @@ An ERP5 Rule..."""
else:
if order_line_object.getUid() not in existing_uid_list:
new_id = order_line_object.getId()
#LOG('Line', 0, str(new_id))
LOG('Line', 0, str(new_id))
new_line = applied_rule.newContent(type_name=delivery_line_type,
container=applied_rule,
id=new_id,
order_value = order_line_object,
quantity = order_line_object.getQuantity(),
source = order_line_object.getSource(),
destination = order_line_object.getDestination(),
source_section = order_line_object.getSourceSection(),
destination_section = order_line_object.getDestinationSection(),
deliverable = 1
)
LOG('OrderRule.expand, object created:',0,new_line.getPhysicalPath())
new_line.immediateReindexObject()
#LOG('After Create Cell', 0, str(new_id))
LOG('After Create Cell', 0, str(new_id))
# Source, Destination, Quantity, Date, etc. are
# acquired from the order and need not to be copied.
except AttributeError:
......
......@@ -69,7 +69,7 @@ class PaymentRule(Rule):
if 'receivable' in movement.getId() :
parent = movement.getParent()
if parent.getPortalType()=='Applied Rule' and parent.getSpecialiseId()=='default_invoice_transaction_rule':
LOG('PaymentRule.test :', 0, repr(( 'applies with', movement, parent )))
#LOG('PaymentRule.test :', 0, repr(( 'applies with', movement, parent )))
return 1
return 0
......@@ -103,9 +103,21 @@ class PaymentRule(Rule):
type_name = payment_line_type,
id = receivable_id)
bank_movement.setQuantity(my_parent_movement.getQuantity())
receivable_movement.setQuantity(0 - my_parent_movement.getQuantity())
bank_movement.edit(
quantity = my_parent_movement.getQuantity(),
source = 'account/banques_etablissements_financiers', # XXX Not Generic
destination = 'account/banques_etablissements_financiers', # XXX Not Generic
source_section = my_parent_movement.getSourceSection(),
destination_section = my_parent_movement.getDestinationSection(),
)
receivable_movement.edit(
quantity = - my_parent_movement.getQuantity(),
source = 'account/creance_client', # XXX Not Generic
destination = 'account/dette_fournisseur', # XXX Not Generic
source_section = my_parent_movement.getSourceSection(),
destination_section = my_parent_movement.getDestinationSection(),
)
Rule.expand(self, applied_rule, **kw)
......
......@@ -226,6 +226,7 @@ identify a bank account."""
membership_criterion_category_list = []
membership_criterion_base_category_list = []
multimembership_criterion_base_category_list = []
test_method_id_list = []
criterion_property_list = []
for c in category_list:
bc = c.split('/')[0]
......@@ -243,12 +244,14 @@ identify a bank account."""
predicate_value.getMembershipCriterionBaseCategoryList())
multimembership_criterion_base_category_list.extend(
predicate_value.getMultimembershipCriterionBaseCategoryList())
test_method_id_list += list(predicate_value.getTestMethodIdList() or [])
for p in predicate_value.getCriterionList():
self.setCriterion(p.property, identity=p.identity, min=p.min, max=p.max)
self.setCriterionPropertyList(criterion_property_list)
self.setMembershipCriterionCategoryList(membership_criterion_category_list)
self.setMembershipCriterionBaseCategoryList(membership_criterion_base_category_list)
self.setMultimembershipCriterionBaseCategoryList(multimembership_criterion_base_category_list)
self._setMembershipCriterionCategoryList(membership_criterion_category_list)
self._setMembershipCriterionBaseCategoryList(membership_criterion_base_category_list)
self._setMultimembershipCriterionBaseCategoryList(multimembership_criterion_base_category_list)
self._setTestMethodIdList(test_method_id_list)
self.reindexObject()
# Predicate handling
......
......@@ -435,3 +435,18 @@ a service in a public administration)."""
return 0
getDeliverable = isDeliverable
# Simulation Dates - acquire target dates
security.declareProtected(Permissions.AccessContentsInformation, 'getOrderStartDate')
def getOrderStartDate(self):
order_value = self.getOrderValue()
if order_value is not None:
return order_value.getStartDate()
security.declareProtected(Permissions.AccessContentsInformation, 'getOrderStopDate')
def getOrderStopDate(self):
order_value = self.getOrderValue()
if order_value is not None:
return order_value.getStopDate()
\ No newline at end of file
......@@ -232,15 +232,15 @@ An ERP5 Rule..."""
produced_resource = applied_rule[new_id]
produced_resource._edit(
target_start_date = my_context_movement.getTargetStartDate(),
target_stop_date = my_context_movement.getTargetStartDate(),
start_date = my_context_movement.getStartDate(),
stop_date = my_context_movement.getStartDate(),
resource = my_context_movement.getResource(),
target_quantity = my_context_movement.getTargetQuantity() + lost_quantity,
target_source_list = (),
target_source_section_list = (),
quantity = my_context_movement.getQuantity() + lost_quantity,
source_list = (),
source_section_list = (),
quantity_unit = my_context_movement.getQuantityUnit(),
target_destination_section = production_section,
target_destination = production_node,
destination_section = production_section,
destination = production_node,
deliverable = 1
)
# Mising quantity unit conversion for my_quantity !!!! XXXX
......@@ -270,15 +270,15 @@ An ERP5 Rule..."""
if amount_line['quantity'] != 0.0:
# Only create line if it is not 0.0
transformed_resource._edit(
target_start_date = my_context_movement.getTargetStartDate(),
target_stop_date = my_context_movement.getTargetStartDate(),
target_quantity = amount_line['quantity'] * my_quantity,
target_efficiency = amount_line['efficiency'],
start_date = my_context_movement.getStartDate(),
stop_date = my_context_movement.getStartDate(),
quantity = amount_line['quantity'] * my_quantity,
efficiency = amount_line['efficiency'],
resource_value = amount_line['resource'],
quantity_unit = amount_line['quantity_unit'],
target_source = production_node,
target_source_section = production_section,
target_destination_list = (),
source = production_node,
source_section = production_section,
destination_list = (),
deliverable = 1
)
LOG('TransformationRule.expand transformed_resource.getPhysicalPath()',0,transformed_resource.getPhysicalPath())
......
......@@ -140,7 +140,7 @@ portal_balance_transaction_line_type_list = ('Balance Transaction Line',)
## Inventory States
portal_current_inventory_state_list = ('delivered', 'started', 'stopped', 'invoiced') # invoiced is Coramy specific and should be removed
portal_target_inventory_state_list = ('ready', 'delivered', 'started', 'stopped', 'invoiced') # if simulation_state in target_list, target_quantity should be considered instead of quantity for stock indexing
portal_target_inventory_state_list = ('ready', 'delivered', 'started', 'stopped', 'invoiced') # if simulation_state in target_list, target_quantity should be considered instead of quantity for stock indexing XXX why do we need two inventory_state_list ?
portal_draft_order_state_list = ('cancelled', 'draft', 'auto_planned' )
portal_planned_order_state_list = ('planned', 'ordered', )
portal_reserved_inventory_state_list = ('confirmed', 'getting_ready', 'ready')
......
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