Commit b36c16c1 authored by Jérome Perrin's avatar Jérome Perrin

more support for isCancellationAmount:

 - setSourceDebit(-1) will set cancellation amount
 - inventory API treat a movement of quantity -1 as an input movement if
   cancellation amount is set
 - s/getSource/DestinationTotalAssetDebit/Credit also support cancellation amount like
   s/getSource/DestinationDebit/Credit



git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@27694 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 9a7975a8
...@@ -372,7 +372,9 @@ class Movement(XMLObject, Amount): ...@@ -372,7 +372,9 @@ class Movement(XMLObject, Amount):
""" """
result = self.getSourceInventoriatedTotalAssetPrice() result = self.getSourceInventoriatedTotalAssetPrice()
if result is not None : if result is not None :
if result > 0: if result > 0 and not self.isCancellationAmount():
return result
if result < 0 and self.isCancellationAmount():
return result return result
return 0.0 return 0.0
...@@ -384,7 +386,9 @@ class Movement(XMLObject, Amount): ...@@ -384,7 +386,9 @@ class Movement(XMLObject, Amount):
""" """
result = self.getSourceInventoriatedTotalAssetPrice() result = self.getSourceInventoriatedTotalAssetPrice()
if result is not None : if result is not None :
if result < 0: if result < 0 and not self.isCancellationAmount():
return -result
if result > 0 and self.isCancellationAmount():
return -result return -result
return 0.0 return 0.0
...@@ -416,7 +420,9 @@ class Movement(XMLObject, Amount): ...@@ -416,7 +420,9 @@ class Movement(XMLObject, Amount):
""" """
result = self.getDestinationInventoriatedTotalAssetPrice() result = self.getDestinationInventoriatedTotalAssetPrice()
if result is not None : if result is not None :
if result > 0: if result > 0 and not self.isCancellationAmount():
return result
if result < 0 and self.isCancellationAmount():
return result return result
return 0.0 return 0.0
...@@ -428,7 +434,9 @@ class Movement(XMLObject, Amount): ...@@ -428,7 +434,9 @@ class Movement(XMLObject, Amount):
""" """
result = self.getDestinationInventoriatedTotalAssetPrice() result = self.getDestinationInventoriatedTotalAssetPrice()
if result is not None : if result is not None :
if result < 0: if result < 0 and not self.isCancellationAmount():
return -result
if result > 0 and self.isCancellationAmount():
return -result return -result
return 0.0 return 0.0
...@@ -762,7 +770,6 @@ class Movement(XMLObject, Amount): ...@@ -762,7 +770,6 @@ class Movement(XMLObject, Amount):
return - quantity return - quantity
elif quantity > 0 and self.isCancellationAmount(): elif quantity > 0 and self.isCancellationAmount():
return - quantity return - quantity
else:
return 0.0 return 0.0
security.declareProtected( Permissions.AccessContentsInformation, security.declareProtected( Permissions.AccessContentsInformation,
...@@ -779,7 +786,6 @@ class Movement(XMLObject, Amount): ...@@ -779,7 +786,6 @@ class Movement(XMLObject, Amount):
if quantity < 0 and not self.isCancellationAmount() \ if quantity < 0 and not self.isCancellationAmount() \
or quantity > 0 and self.isCancellationAmount(): or quantity > 0 and self.isCancellationAmount():
return 0.0 return 0.0
else:
return quantity return quantity
security.declareProtected( Permissions.AccessContentsInformation, security.declareProtected( Permissions.AccessContentsInformation,
...@@ -798,6 +804,7 @@ class Movement(XMLObject, Amount): ...@@ -798,6 +804,7 @@ class Movement(XMLObject, Amount):
source_debit = float(source_debit) source_debit = float(source_debit)
except TypeError: except TypeError:
source_debit = 0.0 source_debit = 0.0
self.setCancellationAmount(source_debit < 0)
self.setQuantity(- source_debit) self.setQuantity(- source_debit)
security.declareProtected(Permissions.ModifyPortalContent, 'setSourceCredit') security.declareProtected(Permissions.ModifyPortalContent, 'setSourceCredit')
...@@ -811,6 +818,7 @@ class Movement(XMLObject, Amount): ...@@ -811,6 +818,7 @@ class Movement(XMLObject, Amount):
source_credit = float(source_credit) source_credit = float(source_credit)
except TypeError: except TypeError:
source_credit = 0.0 source_credit = 0.0
self.setCancellationAmount(source_credit < 0)
self.setQuantity(source_credit) self.setQuantity(source_credit)
security.declareProtected( Permissions.ModifyPortalContent, security.declareProtected( Permissions.ModifyPortalContent,
...@@ -827,13 +835,17 @@ class Movement(XMLObject, Amount): ...@@ -827,13 +835,17 @@ class Movement(XMLObject, Amount):
""" """
quantity = 0 quantity = 0
if kw.has_key('source_debit') and kw.has_key('source_credit'): if kw.has_key('source_debit') and kw.has_key('source_credit'):
quantity += ((kw.pop('source_credit') or 0) - source_credit = kw.pop('source_credit') or 0
(kw.pop('source_debit') or 0)) source_debit = kw.pop('source_debit') or 0
quantity += (source_credit - source_debit)
kw['quantity'] = quantity kw['quantity'] = quantity
kw['cancellation_amount'] = (source_credit < 0 or source_debit < 0)
if kw.has_key('destination_debit') and kw.has_key('destination_credit'): if kw.has_key('destination_debit') and kw.has_key('destination_credit'):
quantity += (kw.pop('destination_debit') or 0 - destination_credit = kw.pop('destination_credit') or 0
kw.pop('destination_credit') or 0) destination_debit = kw.pop('destination_debit') or 0
quantity += (destination_debit - destination_credit)
kw['quantity'] = quantity kw['quantity'] = quantity
kw['cancellation_amount'] = (destination_credit < 0 or destination_debit < 0)
if not edit_order: if not edit_order:
edit_order = ('variation_category_list', ) edit_order = ('variation_category_list', )
return XMLObject._edit(self, edit_order=edit_order, **kw) return XMLObject._edit(self, edit_order=edit_order, **kw)
...@@ -854,9 +866,9 @@ class Movement(XMLObject, Amount): ...@@ -854,9 +866,9 @@ class Movement(XMLObject, Amount):
quantity = float(quantity) quantity = float(quantity)
except TypeError: except TypeError:
quantity = 0.0 quantity = 0.0
if quantity < 0: if quantity < 0 and not self.isCancellationAmount() \
or quantity > 0 and self.isCancellationAmount():
return 0.0 return 0.0
else:
return quantity return quantity
security.declareProtected( Permissions.AccessContentsInformation, security.declareProtected( Permissions.AccessContentsInformation,
...@@ -874,9 +886,10 @@ class Movement(XMLObject, Amount): ...@@ -874,9 +886,10 @@ class Movement(XMLObject, Amount):
quantity = float(quantity) quantity = float(quantity)
except TypeError: except TypeError:
quantity = 0.0 quantity = 0.0
if quantity < 0: if (quantity < 0 and not self.isCancellationAmount()):
return - quantity
elif quantity > 0 and self.isCancellationAmount():
return - quantity return - quantity
else:
return 0.0 return 0.0
security.declareProtected( Permissions.AccessContentsInformation, security.declareProtected( Permissions.AccessContentsInformation,
...@@ -894,9 +907,9 @@ class Movement(XMLObject, Amount): ...@@ -894,9 +907,9 @@ class Movement(XMLObject, Amount):
quantity = float(quantity) quantity = float(quantity)
except TypeError: except TypeError:
quantity = 0.0 quantity = 0.0
if quantity < 0: if quantity < 0 and not self.isCancellationAmount() \
or quantity > 0 and self.isCancellationAmount():
return 0.0 return 0.0
else:
return quantity return quantity
security.declareProtected( Permissions.AccessContentsInformation, security.declareProtected( Permissions.AccessContentsInformation,
...@@ -914,9 +927,10 @@ class Movement(XMLObject, Amount): ...@@ -914,9 +927,10 @@ class Movement(XMLObject, Amount):
quantity = float(quantity) quantity = float(quantity)
except TypeError: except TypeError:
quantity = 0.0 quantity = 0.0
if quantity < 0: if (quantity < 0 and not self.isCancellationAmount()):
return -quantity return - quantity
else: elif quantity > 0 and self.isCancellationAmount():
return - quantity
return 0.0 return 0.0
security.declareProtected( Permissions.ModifyPortalContent, security.declareProtected( Permissions.ModifyPortalContent,
...@@ -932,6 +946,7 @@ class Movement(XMLObject, Amount): ...@@ -932,6 +946,7 @@ class Movement(XMLObject, Amount):
source_debit = float(source_debit) source_debit = float(source_debit)
except TypeError: except TypeError:
source_debit = 0.0 source_debit = 0.0
self.setCancellationAmount(source_debit < 0)
self.setSourceTotalAssetPrice(source_debit) self.setSourceTotalAssetPrice(source_debit)
security.declareProtected( Permissions.ModifyPortalContent, security.declareProtected( Permissions.ModifyPortalContent,
...@@ -947,6 +962,7 @@ class Movement(XMLObject, Amount): ...@@ -947,6 +962,7 @@ class Movement(XMLObject, Amount):
source_credit = float(source_credit) source_credit = float(source_credit)
except TypeError: except TypeError:
source_credit = 0.0 source_credit = 0.0
self.setCancellationAmount(source_credit < 0)
self.setSourceTotalAssetPrice( - source_credit) self.setSourceTotalAssetPrice( - source_credit)
security.declareProtected( Permissions.ModifyPortalContent, security.declareProtected( Permissions.ModifyPortalContent,
...@@ -962,6 +978,7 @@ class Movement(XMLObject, Amount): ...@@ -962,6 +978,7 @@ class Movement(XMLObject, Amount):
destination_debit = float(destination_debit) destination_debit = float(destination_debit)
except TypeError: except TypeError:
destination_debit = 0.0 destination_debit = 0.0
self.setCancellationAmount(destination_debit < 0)
self.setDestinationTotalAssetPrice(destination_debit) self.setDestinationTotalAssetPrice(destination_debit)
security.declareProtected( Permissions.ModifyPortalContent, security.declareProtected( Permissions.ModifyPortalContent,
...@@ -977,6 +994,7 @@ class Movement(XMLObject, Amount): ...@@ -977,6 +994,7 @@ class Movement(XMLObject, Amount):
destination_credit = float(destination_credit) destination_credit = float(destination_credit)
except TypeError: except TypeError:
destination_credit = 0.0 destination_credit = 0.0
self.setCancellationAmount(destination_credit < 0)
self.setDestinationTotalAssetPrice( - destination_credit) self.setDestinationTotalAssetPrice( - destination_credit)
# Item Access (tracking) # Item Access (tracking)
......
...@@ -95,6 +95,7 @@ class Amount: ...@@ -95,6 +95,7 @@ class Amount:
{ 'id' : 'cancellation_amount', { 'id' : 'cancellation_amount',
'description' : 'defines if this quantity is used in order to cancel another one', 'description' : 'defines if this quantity is used in order to cancel another one',
'type' : 'boolean', 'type' : 'boolean',
'default': False,
'mode' : 'w' }, 'mode' : 'w' },
# quantity_sign is used by QuantitySignMovementGroup # quantity_sign is used by QuantitySignMovementGroup
# When comparing a delivery to a property_dict coming from a MovementGroup, # When comparing a delivery to a property_dict coming from a MovementGroup,
......
...@@ -270,7 +270,8 @@ WHERE\n ...@@ -270,7 +270,8 @@ WHERE\n
</dtml-if>\n </dtml-if>\n
\n \n
<dtml-if omit_input>\n <dtml-if omit_input>\n
AND stock.quantity < 0\n AND ( ( stock.is_cancellation AND stock.quantity > 0 )\n
OR ( not stock.is_cancellation AND stock.quantity < 0 ))\n
AND ( stock.node_uid <> stock.mirror_node_uid\n AND ( stock.node_uid <> stock.mirror_node_uid\n
OR stock.section_uid <> stock.mirror_section_uid\n OR stock.section_uid <> stock.mirror_section_uid\n
OR stock.mirror_node_uid IS NULL\n OR stock.mirror_node_uid IS NULL\n
...@@ -278,7 +279,8 @@ WHERE\n ...@@ -278,7 +279,8 @@ WHERE\n
OR stock.payment_uid IS NOT NULL )\n OR stock.payment_uid IS NOT NULL )\n
</dtml-if>\n </dtml-if>\n
<dtml-if omit_output>\n <dtml-if omit_output>\n
AND stock.quantity > 0\n AND ( ( stock.is_cancellation AND stock.quantity < 0 )\n
OR ( not stock.is_cancellation AND stock.quantity > 0 ))\n
AND ( stock.node_uid <> stock.mirror_node_uid\n AND ( stock.node_uid <> stock.mirror_node_uid\n
OR stock.section_uid <> stock.mirror_section_uid\n OR stock.section_uid <> stock.mirror_section_uid\n
OR stock.mirror_node_uid IS NULL\n OR stock.mirror_node_uid IS NULL\n
...@@ -410,7 +412,8 @@ WHERE\n ...@@ -410,7 +412,8 @@ WHERE\n
</dtml-if>\n </dtml-if>\n
\n \n
<dtml-if omit_input>\n <dtml-if omit_input>\n
AND stock.quantity < 0\n AND ( ( stock.is_cancellation AND stock.quantity > 0 )\n
OR ( not stock.is_cancellation AND stock.quantity < 0 ))\n
AND ( stock.node_uid <> stock.mirror_node_uid\n AND ( stock.node_uid <> stock.mirror_node_uid\n
OR stock.section_uid <> stock.mirror_section_uid\n OR stock.section_uid <> stock.mirror_section_uid\n
OR stock.mirror_node_uid IS NULL\n OR stock.mirror_node_uid IS NULL\n
...@@ -418,7 +421,8 @@ WHERE\n ...@@ -418,7 +421,8 @@ WHERE\n
OR stock.payment_uid IS NOT NULL )\n OR stock.payment_uid IS NOT NULL )\n
</dtml-if>\n </dtml-if>\n
<dtml-if omit_output>\n <dtml-if omit_output>\n
AND stock.quantity > 0\n AND ( ( stock.is_cancellation AND stock.quantity < 0 )\n
OR ( not stock.is_cancellation AND stock.quantity > 0 ))\n
AND ( stock.node_uid <> stock.mirror_node_uid\n AND ( stock.node_uid <> stock.mirror_node_uid\n
OR stock.section_uid <> stock.mirror_section_uid\n OR stock.section_uid <> stock.mirror_section_uid\n
OR stock.mirror_node_uid IS NULL\n OR stock.mirror_node_uid IS NULL\n
......
...@@ -700,7 +700,8 @@ WHERE\n ...@@ -700,7 +700,8 @@ WHERE\n
</dtml-if>\n </dtml-if>\n
\n \n
<dtml-if omit_input>\n <dtml-if omit_input>\n
AND stock.quantity < 0\n AND ( ( stock.is_cancellation AND stock.quantity > 0 )\n
OR ( not stock.is_cancellation AND stock.quantity < 0 ))\n
AND ( stock.node_uid <> stock.mirror_node_uid\n AND ( stock.node_uid <> stock.mirror_node_uid\n
OR stock.section_uid <> stock.mirror_section_uid\n OR stock.section_uid <> stock.mirror_section_uid\n
OR stock.mirror_node_uid IS NULL\n OR stock.mirror_node_uid IS NULL\n
...@@ -708,7 +709,8 @@ WHERE\n ...@@ -708,7 +709,8 @@ WHERE\n
OR stock.payment_uid IS NOT NULL )\n OR stock.payment_uid IS NOT NULL )\n
</dtml-if>\n </dtml-if>\n
<dtml-if omit_output>\n <dtml-if omit_output>\n
AND stock.quantity > 0\n AND ( ( stock.is_cancellation AND stock.quantity < 0 )\n
OR ( not stock.is_cancellation AND stock.quantity > 0 ))\n
AND ( stock.node_uid <> stock.mirror_node_uid\n AND ( stock.node_uid <> stock.mirror_node_uid\n
OR stock.section_uid <> stock.mirror_section_uid\n OR stock.section_uid <> stock.mirror_section_uid\n
OR stock.mirror_node_uid IS NULL\n OR stock.mirror_node_uid IS NULL\n
...@@ -858,7 +860,8 @@ WHERE\n ...@@ -858,7 +860,8 @@ WHERE\n
</dtml-if>\n </dtml-if>\n
\n \n
<dtml-if omit_input>\n <dtml-if omit_input>\n
AND stock.quantity < 0\n AND ( ( stock.is_cancellation AND stock.quantity > 0 )\n
OR ( not stock.is_cancellation AND stock.quantity < 0 ))\n
AND ( stock.node_uid <> stock.mirror_node_uid\n AND ( stock.node_uid <> stock.mirror_node_uid\n
OR stock.section_uid <> stock.mirror_section_uid\n OR stock.section_uid <> stock.mirror_section_uid\n
OR stock.mirror_node_uid IS NULL\n OR stock.mirror_node_uid IS NULL\n
...@@ -866,7 +869,8 @@ WHERE\n ...@@ -866,7 +869,8 @@ WHERE\n
OR stock.payment_uid IS NOT NULL )\n OR stock.payment_uid IS NOT NULL )\n
</dtml-if>\n </dtml-if>\n
<dtml-if omit_output>\n <dtml-if omit_output>\n
AND stock.quantity > 0\n AND ( ( stock.is_cancellation AND stock.quantity < 0 )\n
OR ( not stock.is_cancellation AND stock.quantity > 0 ))\n
AND ( stock.node_uid <> stock.mirror_node_uid\n AND ( stock.node_uid <> stock.mirror_node_uid\n
OR stock.section_uid <> stock.mirror_section_uid\n OR stock.section_uid <> stock.mirror_section_uid\n
OR stock.mirror_node_uid IS NULL\n OR stock.mirror_node_uid IS NULL\n
......
...@@ -161,6 +161,12 @@ ...@@ -161,6 +161,12 @@
<dictionary/> <dictionary/>
</value> </value>
</item> </item>
<item>
<key> <string>isCancellationAmount</string> </key>
<value>
<dictionary/>
</value>
</item>
<item> <item>
<key> <string>uid</string> </key> <key> <string>uid</string> </key>
<value> <value>
...@@ -182,6 +188,7 @@ ...@@ -182,6 +188,7 @@
<string>getSourceSectionUid</string> <string>getSourceSectionUid</string>
<string>getDestinationSectionUid</string> <string>getDestinationSectionUid</string>
<string>isMovement</string> <string>isMovement</string>
<string>isCancellationAmount</string>
<string>isInventoryMovement</string> <string>isInventoryMovement</string>
<string>getSourcePaymentUid</string> <string>getSourcePaymentUid</string>
<string>getDestinationPaymentUid</string> <string>getDestinationPaymentUid</string>
...@@ -222,6 +229,7 @@ getDestinationUid\r\n ...@@ -222,6 +229,7 @@ getDestinationUid\r\n
getSourceSectionUid\r\n getSourceSectionUid\r\n
getDestinationSectionUid\r\n getDestinationSectionUid\r\n
isMovement\r\n isMovement\r\n
isCancellationAmount\r\n
isInventoryMovement\r\n isInventoryMovement\r\n
getSourcePaymentUid\r\n getSourcePaymentUid\r\n
getDestinationPaymentUid\r\n getDestinationPaymentUid\r\n
...@@ -304,6 +312,7 @@ WHERE\n ...@@ -304,6 +312,7 @@ WHERE\n
getSourceUid[loop_item], \n getSourceUid[loop_item], \n
getResourceUid[loop_item],\n getResourceUid[loop_item],\n
getInventoriatedQuantity[loop_item],\n getInventoriatedQuantity[loop_item],\n
isCancellationAmount[loop_item],\n
getStopDate[loop_item], \n getStopDate[loop_item], \n
getStartDate[loop_item], \n getStartDate[loop_item], \n
getDestinationInventoriatedTotalAssetPrice[loop_item], \n getDestinationInventoriatedTotalAssetPrice[loop_item], \n
...@@ -326,6 +335,7 @@ WHERE\n ...@@ -326,6 +335,7 @@ WHERE\n
getDestinationUid[loop_item], \n getDestinationUid[loop_item], \n
getResourceUid[loop_item],\n getResourceUid[loop_item],\n
-(getInventoriatedQuantity[loop_item] or 0), \n -(getInventoriatedQuantity[loop_item] or 0), \n
isCancellationAmount[loop_item],\n
getStartDate[loop_item], \n getStartDate[loop_item], \n
getStopDate[loop_item],\n getStopDate[loop_item],\n
getSourceInventoriatedTotalAssetPrice[loop_item], \n getSourceInventoriatedTotalAssetPrice[loop_item], \n
...@@ -354,13 +364,14 @@ VALUES\n ...@@ -354,13 +364,14 @@ VALUES\n
<dtml-sqlvar expr="row_item[8]" type="int" optional>,\n <dtml-sqlvar expr="row_item[8]" type="int" optional>,\n
<dtml-sqlvar expr="row_item[9]" type="int">, \n <dtml-sqlvar expr="row_item[9]" type="int">, \n
<dtml-sqlvar expr="row_item[10]" type="float" optional>,\n <dtml-sqlvar expr="row_item[10]" type="float" optional>,\n
<dtml-sqlvar expr="row_item[11]" type="datetime" optional>,\n <dtml-sqlvar expr="row_item[11]" type="int">, \n
<dtml-sqlvar expr="row_item[12]" type="datetime" optional>,\n <dtml-sqlvar expr="row_item[12]" type="datetime" optional>,\n
<dtml-sqlvar expr="row_item[13]" type="float" optional>,\n <dtml-sqlvar expr="row_item[13]" type="datetime" optional>,\n
<dtml-sqlvar expr="row_item[14]" type="string" optional>,\n <dtml-sqlvar expr="row_item[14]" type="float" optional>,\n
<dtml-sqlvar expr="row_item[15]" type="string" optional>,\n <dtml-sqlvar expr="row_item[15]" type="string" optional>,\n
<dtml-sqlvar expr="row_item[16]" type="string" optional>,\n <dtml-sqlvar expr="row_item[16]" type="string" optional>,\n
<dtml-sqlvar expr="row_item[17]" type="string" optional>\n <dtml-sqlvar expr="row_item[17]" type="string" optional>,\n
<dtml-sqlvar expr="row_item[18]" type="string" optional>\n
)\n )\n
<dtml-if sequence-end><dtml-else>,</dtml-if>\n <dtml-if sequence-end><dtml-else>,</dtml-if>\n
</dtml-in>\n </dtml-in>\n
...@@ -433,6 +444,7 @@ WHERE\n ...@@ -433,6 +444,7 @@ WHERE\n
getSourceUid[loop_item], \n getSourceUid[loop_item], \n
getResourceUid[loop_item],\n getResourceUid[loop_item],\n
getInventoriatedQuantity[loop_item],\n getInventoriatedQuantity[loop_item],\n
isCancellationAmount[loop_item],\n
getStopDate[loop_item], \n getStopDate[loop_item], \n
getStartDate[loop_item], \n getStartDate[loop_item], \n
getDestinationInventoriatedTotalAssetPrice[loop_item], \n getDestinationInventoriatedTotalAssetPrice[loop_item], \n
...@@ -455,6 +467,7 @@ WHERE\n ...@@ -455,6 +467,7 @@ WHERE\n
getDestinationUid[loop_item], \n getDestinationUid[loop_item], \n
getResourceUid[loop_item],\n getResourceUid[loop_item],\n
-(getInventoriatedQuantity[loop_item] or 0), \n -(getInventoriatedQuantity[loop_item] or 0), \n
isCancellationAmount[loop_item],\n
getStartDate[loop_item], \n getStartDate[loop_item], \n
getStopDate[loop_item],\n getStopDate[loop_item],\n
getSourceInventoriatedTotalAssetPrice[loop_item], \n getSourceInventoriatedTotalAssetPrice[loop_item], \n
...@@ -483,13 +496,14 @@ VALUES\n ...@@ -483,13 +496,14 @@ VALUES\n
<dtml-sqlvar expr="row_item[8]" type="int" optional>,\n <dtml-sqlvar expr="row_item[8]" type="int" optional>,\n
<dtml-sqlvar expr="row_item[9]" type="int">, \n <dtml-sqlvar expr="row_item[9]" type="int">, \n
<dtml-sqlvar expr="row_item[10]" type="float" optional>,\n <dtml-sqlvar expr="row_item[10]" type="float" optional>,\n
<dtml-sqlvar expr="row_item[11]" type="datetime" optional>,\n <dtml-sqlvar expr="row_item[11]" type="int">, \n
<dtml-sqlvar expr="row_item[12]" type="datetime" optional>,\n <dtml-sqlvar expr="row_item[12]" type="datetime" optional>,\n
<dtml-sqlvar expr="row_item[13]" type="float" optional>,\n <dtml-sqlvar expr="row_item[13]" type="datetime" optional>,\n
<dtml-sqlvar expr="row_item[14]" type="string" optional>,\n <dtml-sqlvar expr="row_item[14]" type="float" optional>,\n
<dtml-sqlvar expr="row_item[15]" type="string" optional>,\n <dtml-sqlvar expr="row_item[15]" type="string" optional>,\n
<dtml-sqlvar expr="row_item[16]" type="string" optional>,\n <dtml-sqlvar expr="row_item[16]" type="string" optional>,\n
<dtml-sqlvar expr="row_item[17]" type="string" optional>\n <dtml-sqlvar expr="row_item[17]" type="string" optional>,\n
<dtml-sqlvar expr="row_item[18]" type="string" optional>\n
)\n )\n
<dtml-if sequence-end><dtml-else>,</dtml-if>\n <dtml-if sequence-end><dtml-else>,</dtml-if>\n
</dtml-in>\n </dtml-in>\n
......
...@@ -97,7 +97,8 @@ CREATE TABLE `stock` (\n ...@@ -97,7 +97,8 @@ CREATE TABLE `stock` (\n
`mirror_section_uid` BIGINT UNSIGNED,\n `mirror_section_uid` BIGINT UNSIGNED,\n
`mirror_node_uid` BIGINT UNSIGNED,\n `mirror_node_uid` BIGINT UNSIGNED,\n
`resource_uid` BIGINT UNSIGNED,\n `resource_uid` BIGINT UNSIGNED,\n
`quantity` real ,\n `quantity` real,\n
`is_cancellation` BOOLEAN,\n
`date` datetime,\n `date` datetime,\n
`mirror_date` datetime,\n `mirror_date` datetime,\n
`total_price` real ,\n `total_price` real ,\n
...@@ -171,7 +172,8 @@ CREATE TABLE `stock` (\n ...@@ -171,7 +172,8 @@ CREATE TABLE `stock` (\n
`mirror_section_uid` BIGINT UNSIGNED,\n `mirror_section_uid` BIGINT UNSIGNED,\n
`mirror_node_uid` BIGINT UNSIGNED,\n `mirror_node_uid` BIGINT UNSIGNED,\n
`resource_uid` BIGINT UNSIGNED,\n `resource_uid` BIGINT UNSIGNED,\n
`quantity` real ,\n `quantity` real,\n
`is_cancellation` BOOLEAN,\n
`date` datetime,\n `date` datetime,\n
`mirror_date` datetime,\n `mirror_date` datetime,\n
`total_price` real ,\n `total_price` real ,\n
......
138 139
\ No newline at end of file \ No newline at end of file
...@@ -810,6 +810,22 @@ class TestTransactionValidation(AccountingTestCase): ...@@ -810,6 +810,22 @@ class TestTransactionValidation(AccountingTestCase):
doActionFor(accounting_transaction, 'stop_action') doActionFor(accounting_transaction, 'stop_action')
self.assertEquals('stopped', accounting_transaction.getSimulationState()) self.assertEquals('stopped', accounting_transaction.getSimulationState())
def test_CancellationAmount(self):
accounting_transaction = self._makeOne(
portal_type='Accounting Transaction',
start_date=DateTime('2007/01/02'),
destination_section_value=self.organisation_module.client_1,
lines=(dict(source_value=self.account_module.payable,
source_debit=500,)
dict(source_value=self.account_module.receivable,
source_debit=-500,
cancellation_amount=True
)))
self.assertEquals([], accounting_transaction.checkConsistency())
self.portal.portal_workflow.doActionFor(accounting_transaction,
'stop_action')
class TestClosingPeriod(AccountingTestCase): class TestClosingPeriod(AccountingTestCase):
"""Various tests for closing the period. """Various tests for closing the period.
......
...@@ -385,6 +385,110 @@ class TestMovement(ERP5TypeTestCase): ...@@ -385,6 +385,110 @@ class TestMovement(ERP5TypeTestCase):
self.assertEquals(0.0, mvt.getDestinationAssetDebit()) self.assertEquals(0.0, mvt.getDestinationAssetDebit())
self.assertEquals(200, mvt.getDestinationDebit()) self.assertEquals(200, mvt.getDestinationDebit())
def testCancellationAmountGetDestinationCredit(self):
mvt = self._makeOne('mvt')
mvt.setCancellationAmount(True)
mvt.setQuantity(10)
self.assertEquals(mvt.getQuantity(), 10)
self.assertEquals(mvt.getDestinationDebit(), 0)
self.assertEquals(mvt.getDestinationCredit(), -10)
def testCancellationAmountGetDestinationDebit(self):
mvt = self._makeOne('mvt')
mvt.setCancellationAmount(True)
mvt.setQuantity(-10)
self.assertEquals(mvt.getQuantity(), -10)
self.assertEquals(mvt.getDestinationDebit(), -10)
self.assertEquals(mvt.getDestinationCredit(), 0)
def testCancellationAmountGetSourceCredit(self):
mvt = self._makeOne('mvt')
mvt.setCancellationAmount(True)
mvt.setQuantity(-10)
self.assertEquals(mvt.getQuantity(), -10)
self.assertEquals(mvt.getSourceDebit(), 0)
self.assertEquals(mvt.getSourceCredit(), -10)
def testCancellationAmountGetSourceDebit(self):
mvt = self._makeOne('mvt')
mvt.setCancellationAmount(True)
mvt.setQuantity(10)
self.assertEquals(mvt.getQuantity(), 10)
self.assertEquals(mvt.getSourceDebit(), -10)
self.assertEquals(mvt.getSourceCredit(), 0)
def testCancellationAmountSetDestinationCredit(self):
mvt = self._makeOne('mvt')
mvt.setDestinationCredit(-10)
self.assertTrue(mvt.isCancellationAmount())
self.assertEquals(mvt.getDestinationDebit(), 0)
self.assertEquals(mvt.getDestinationCredit(), -10)
mvt.setDestinationCredit(10)
self.assertFalse(mvt.isCancellationAmount())
self.assertEquals(mvt.getDestinationDebit(), 0)
self.assertEquals(mvt.getDestinationCredit(), 10)
def testCancellationAmountSetDestinationDebit(self):
mvt = self._makeOne('mvt')
mvt.setDestinationDebit(-10)
self.assertTrue(mvt.isCancellationAmount())
self.assertEquals(mvt.getDestinationDebit(), -10)
self.assertEquals(mvt.getDestinationCredit(), 0)
mvt.setDestinationDebit(10)
self.assertFalse(mvt.isCancellationAmount())
self.assertEquals(mvt.getDestinationDebit(), 10)
self.assertEquals(mvt.getDestinationCredit(), 0)
def testCancellationAmountSetDestinationDebitCredit(self):
mvt = self._makeOne('mvt')
mvt.edit(destination_debit=-10, destination_credit=0)
self.assertTrue(mvt.isCancellationAmount())
self.assertEquals(mvt.getDestinationDebit(), -10)
self.assertEquals(mvt.getDestinationCredit(), 0)
mvt.edit(destination_debit=-10, destination_credit=None)
self.assertTrue(mvt.isCancellationAmount())
self.assertEquals(mvt.getDestinationDebit(), -10)
self.assertEquals(mvt.getDestinationCredit(), 0)
def testCancellationAmountSetSourceCredit(self):
mvt = self._makeOne('mvt')
mvt.setSourceCredit(-10)
self.assertTrue(mvt.isCancellationAmount())
self.assertEquals(mvt.getSourceDebit(), 0)
self.assertEquals(mvt.getSourceCredit(), -10)
mvt.setSourceCredit(10)
self.assertFalse(mvt.isCancellationAmount())
self.assertEquals(mvt.getSourceDebit(), 0)
self.assertEquals(mvt.getSourceCredit(), 10)
def testCancellationAmountSetSourceDebit(self):
mvt = self._makeOne('mvt')
mvt.setSourceDebit(-10)
self.assertTrue(mvt.isCancellationAmount())
self.assertEquals(mvt.getSourceDebit(), -10)
self.assertEquals(mvt.getSourceCredit(), 0)
mvt.setSourceDebit(10)
self.assertFalse(mvt.isCancellationAmount())
self.assertEquals(mvt.getSourceDebit(), 10)
self.assertEquals(mvt.getSourceCredit(), 0)
def testCancellationAmountSetSourceDebitCredit(self):
mvt = self._makeOne('mvt')
mvt.edit(source_debit=-10, source_credit=0)
self.assertTrue(mvt.isCancellationAmount())
self.assertEquals(mvt.getSourceDebit(), -10)
self.assertEquals(mvt.getSourceCredit(), 0)
mvt.edit(source_debit=-10, source_credit=None)
self.assertTrue(mvt.isCancellationAmount())
self.assertEquals(mvt.getSourceDebit(), -10)
self.assertEquals(mvt.getSourceCredit(), 0)
class TestAccountingTransactionLine(TestMovement): class TestAccountingTransactionLine(TestMovement):
"""Tests for Accounting Transaction Line class, which have an overloaded """Tests for Accounting Transaction Line class, which have an overloaded
...@@ -522,6 +626,47 @@ class TestAccountingTransactionLine(TestMovement): ...@@ -522,6 +626,47 @@ class TestAccountingTransactionLine(TestMovement):
self.assertEquals(0, mvt.getDestinationInventoriatedTotalAssetCredit()) self.assertEquals(0, mvt.getDestinationInventoriatedTotalAssetCredit())
self.assertEquals(200, mvt.getDestinationInventoriatedTotalAssetPrice()) self.assertEquals(200, mvt.getDestinationInventoriatedTotalAssetPrice())
def testDestinationAssetDebitCancellation(self):
mvt = self._makeOne('mvt')
mvt.edit(destination_asset_debit=-100)
self.assertTrue(mvt.isCancellationAmount())
self.assertEquals(-100, mvt.getDestinationAssetDebit())
self.assertEquals(0, mvt.getQuantity())
self.assertEquals(-100, mvt.getDestinationInventoriatedTotalAssetDebit())
self.assertEquals(0, mvt.getDestinationInventoriatedTotalAssetCredit())
self.assertEquals(-100, mvt.getDestinationInventoriatedTotalAssetPrice())
def testDestinationAssetCreditCancellation(self):
mvt = self._makeOne('mvt')
mvt.edit(destination_asset_credit=-100)
self.assertTrue(mvt.isCancellationAmount())
self.assertEquals(-100, mvt.getDestinationAssetCredit())
self.assertEquals(0, mvt.getQuantity())
self.assertEquals(-100, mvt.getDestinationInventoriatedTotalAssetCredit())
self.assertEquals(0, mvt.getDestinationInventoriatedTotalAssetDebit())
self.assertEquals(100, mvt.getDestinationInventoriatedTotalAssetPrice())
def testSourceAssetDebitCancellation(self):
mvt = self._makeOne('mvt')
mvt.edit(source_asset_debit=-100)
self.assertTrue(mvt.isCancellationAmount())
self.assertEquals(-100, mvt.getSourceAssetDebit())
self.assertEquals(0, mvt.getQuantity())
self.assertEquals(-100, mvt.getSourceInventoriatedTotalAssetDebit())
self.assertEquals(0, mvt.getSourceInventoriatedTotalAssetCredit())
self.assertEquals(-100, mvt.getSourceInventoriatedTotalAssetPrice())
def testSourceAssetCreditCancellation(self):
mvt = self._makeOne('mvt')
mvt.edit(source_asset_credit=-100)
self.assertTrue(mvt.isCancellationAmount())
self.assertEquals(-100, mvt.getSourceAssetCredit())
self.assertEquals(0, mvt.getQuantity())
self.assertEquals(-100, mvt.getSourceInventoriatedTotalAssetCredit())
self.assertEquals(0, mvt.getSourceInventoriatedTotalAssetDebit())
self.assertEquals(100, mvt.getSourceInventoriatedTotalAssetPrice())
def test_suite(): def test_suite():
suite = unittest.TestSuite() suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(TestAmount)) suite.addTest(unittest.makeSuite(TestAmount))
......
...@@ -599,6 +599,19 @@ class TestInventory(InventoryAPITestCase): ...@@ -599,6 +599,19 @@ class TestInventory(InventoryAPITestCase):
payment_uid=self.other_payment_node.getUid(), payment_uid=self.other_payment_node.getUid(),
omit_output=1)) omit_output=1))
def test_OmitInputOmitOutputCancellationAmount(self):
getInventory = self.getSimulationTool().getInventory
self._makeMovement(quantity=-1, price=1, cancellation_amount=True)
self._makeMovement(quantity=2, price=1, cancellation_amount=True)
self.assertEquals(2, getInventory(node_uid=self.node.getUid(),
omit_input=1))
self.assertEquals(-1, getInventory(node_uid=self.node.getUid(),
omit_output=1))
# omit_output & omit_input return nothing in that case
self.assertEquals(0, getInventory(node_uid=self.node.getUid(),
omit_input=1,
omit_output=1))
def test_OmitInputOmitOutputWithDifferentPaymentSameNodeSameSection(self): def test_OmitInputOmitOutputWithDifferentPaymentSameNodeSameSection(self):
getInventory = self.getSimulationTool().getInventory getInventory = self.getSimulationTool().getInventory
self._makeMovement(quantity=2, price=1, self._makeMovement(quantity=2, price=1,
...@@ -790,6 +803,24 @@ class TestInventoryList(InventoryAPITestCase): ...@@ -790,6 +803,24 @@ class TestInventoryList(InventoryAPITestCase):
self.assertEquals(-2, inventory_list[0].total_price) self.assertEquals(-2, inventory_list[0].total_price)
self.assertEquals(-2, inventory_list[0].total_quantity) self.assertEquals(-2, inventory_list[0].total_quantity)
def test_OmitInputOmitOutputCancellationAmount(self):
getInventoryList = self.getSimulationTool().getInventoryList
self._makeMovement(quantity=-1, price=1, cancellation_amount=True)
self._makeMovement(quantity=2, price=1, cancellation_amount=True)
inventory_list = getInventoryList(node_uid=self.node.getUid(),
omit_input=1)
self.assertEquals(1, len(inventory_list))
self.assertEquals(2, inventory_list[0].total_price)
self.assertEquals(2, inventory_list[0].total_quantity)
# omit output ignores movement going to this node
inventory_list = getInventoryList(node_uid=self.node.getUid(),
omit_output=1)
self.assertEquals(1, len(inventory_list))
self.assertEquals(-1, inventory_list[0].total_price)
self.assertEquals(-1, inventory_list[0].total_quantity)
def test_CurentAvailableFutureInventoryList(self): def test_CurentAvailableFutureInventoryList(self):
def makeMovement(simulation_state=None, quantity=None): def makeMovement(simulation_state=None, quantity=None):
self._makeMovement(quantity=quantity, price=1, self._makeMovement(quantity=quantity, price=1,
...@@ -831,6 +862,7 @@ class TestInventoryList(InventoryAPITestCase): ...@@ -831,6 +862,7 @@ class TestInventoryList(InventoryAPITestCase):
checkInventory(line=3, type='Future', source=1, quantity=-9) checkInventory(line=3, type='Future', source=1, quantity=-9)
checkInventory(line=3, type='Future', destination=1, quantity=9) checkInventory(line=3, type='Future', destination=1, quantity=9)
class TestMovementHistoryList(InventoryAPITestCase): class TestMovementHistoryList(InventoryAPITestCase):
"""Tests Movement history list methods. """Tests Movement history list methods.
""" """
...@@ -1441,6 +1473,28 @@ class TestMovementHistoryList(InventoryAPITestCase): ...@@ -1441,6 +1473,28 @@ class TestMovementHistoryList(InventoryAPITestCase):
self.assertEquals(-2, movement_history_list[0].total_price) self.assertEquals(-2, movement_history_list[0].total_price)
self.assertEquals(-2, movement_history_list[0].total_quantity) self.assertEquals(-2, movement_history_list[0].total_quantity)
def test_OmitInputOmitOutputCancellationAmount(self):
getMovementHistoryList = self.getSimulationTool().getMovementHistoryList
self._makeMovement(quantity=-1, price=1, cancellation_amount=True)
self._makeMovement(quantity=2, price=1, cancellation_amount=True)
mvt_history_list = getMovementHistoryList(node_uid=self.node.getUid(),
omit_input=1)
self.assertEquals(1, len(mvt_history_list))
self.assertEquals(2, mvt_history_list[0].total_price)
self.assertEquals(2, mvt_history_list[0].total_quantity)
mvt_history_list = getMovementHistoryList(node_uid=self.node.getUid(),
omit_output=1)
self.assertEquals(1, len(mvt_history_list))
self.assertEquals(-1, mvt_history_list[0].total_price)
self.assertEquals(-1, mvt_history_list[0].total_quantity)
self.assertEquals(0, len(getMovementHistoryList(
node_uid=self.node.getUid(),
omit_input=1,
omit_output=1)))
class TestNextNegativeInventoryDate(InventoryAPITestCase): class TestNextNegativeInventoryDate(InventoryAPITestCase):
"""Tests getInventory methods. """Tests getInventory methods.
""" """
......
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