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):
"""
result = self.getSourceInventoriatedTotalAssetPrice()
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 0.0
......@@ -384,7 +386,9 @@ class Movement(XMLObject, Amount):
"""
result = self.getSourceInventoriatedTotalAssetPrice()
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 0.0
......@@ -416,7 +420,9 @@ class Movement(XMLObject, Amount):
"""
result = self.getDestinationInventoriatedTotalAssetPrice()
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 0.0
......@@ -428,7 +434,9 @@ class Movement(XMLObject, Amount):
"""
result = self.getDestinationInventoriatedTotalAssetPrice()
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 0.0
......@@ -762,8 +770,7 @@ class Movement(XMLObject, Amount):
return - quantity
elif quantity > 0 and self.isCancellationAmount():
return - quantity
else:
return 0.0
return 0.0
security.declareProtected( Permissions.AccessContentsInformation,
'getSourceCredit')
......@@ -779,8 +786,7 @@ class Movement(XMLObject, Amount):
if quantity < 0 and not self.isCancellationAmount() \
or quantity > 0 and self.isCancellationAmount():
return 0.0
else:
return quantity
return quantity
security.declareProtected( Permissions.AccessContentsInformation,
'getDestinationDebit', 'getDestinationCredit')
......@@ -798,6 +804,7 @@ class Movement(XMLObject, Amount):
source_debit = float(source_debit)
except TypeError:
source_debit = 0.0
self.setCancellationAmount(source_debit < 0)
self.setQuantity(- source_debit)
security.declareProtected(Permissions.ModifyPortalContent, 'setSourceCredit')
......@@ -811,6 +818,7 @@ class Movement(XMLObject, Amount):
source_credit = float(source_credit)
except TypeError:
source_credit = 0.0
self.setCancellationAmount(source_credit < 0)
self.setQuantity(source_credit)
security.declareProtected( Permissions.ModifyPortalContent,
......@@ -827,13 +835,17 @@ class Movement(XMLObject, Amount):
"""
quantity = 0
if kw.has_key('source_debit') and kw.has_key('source_credit'):
quantity += ((kw.pop('source_credit') or 0) -
(kw.pop('source_debit') or 0))
source_credit = kw.pop('source_credit') or 0
source_debit = kw.pop('source_debit') or 0
quantity += (source_credit - source_debit)
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'):
quantity += (kw.pop('destination_debit') or 0 -
kw.pop('destination_credit') or 0)
destination_credit = kw.pop('destination_credit') or 0
destination_debit = kw.pop('destination_debit') or 0
quantity += (destination_debit - destination_credit)
kw['quantity'] = quantity
kw['cancellation_amount'] = (destination_credit < 0 or destination_debit < 0)
if not edit_order:
edit_order = ('variation_category_list', )
return XMLObject._edit(self, edit_order=edit_order, **kw)
......@@ -854,10 +866,10 @@ class Movement(XMLObject, Amount):
quantity = float(quantity)
except TypeError:
quantity = 0.0
if quantity < 0:
if quantity < 0 and not self.isCancellationAmount() \
or quantity > 0 and self.isCancellationAmount():
return 0.0
else:
return quantity
return quantity
security.declareProtected( Permissions.AccessContentsInformation,
'getSourceAssetCredit' )
......@@ -874,10 +886,11 @@ class Movement(XMLObject, Amount):
quantity = float(quantity)
except TypeError:
quantity = 0.0
if quantity < 0:
if (quantity < 0 and not self.isCancellationAmount()):
return - quantity
else:
return 0.0
elif quantity > 0 and self.isCancellationAmount():
return - quantity
return 0.0
security.declareProtected( Permissions.AccessContentsInformation,
'getDestinationAssetDebit' )
......@@ -894,10 +907,10 @@ class Movement(XMLObject, Amount):
quantity = float(quantity)
except TypeError:
quantity = 0.0
if quantity < 0:
if quantity < 0 and not self.isCancellationAmount() \
or quantity > 0 and self.isCancellationAmount():
return 0.0
else:
return quantity
return quantity
security.declareProtected( Permissions.AccessContentsInformation,
'getDestinationAssetCredit' )
......@@ -914,10 +927,11 @@ class Movement(XMLObject, Amount):
quantity = float(quantity)
except TypeError:
quantity = 0.0
if quantity < 0:
return -quantity
else:
return 0.0
if (quantity < 0 and not self.isCancellationAmount()):
return - quantity
elif quantity > 0 and self.isCancellationAmount():
return - quantity
return 0.0
security.declareProtected( Permissions.ModifyPortalContent,
'setSourceAssetDebit' )
......@@ -932,6 +946,7 @@ class Movement(XMLObject, Amount):
source_debit = float(source_debit)
except TypeError:
source_debit = 0.0
self.setCancellationAmount(source_debit < 0)
self.setSourceTotalAssetPrice(source_debit)
security.declareProtected( Permissions.ModifyPortalContent,
......@@ -947,6 +962,7 @@ class Movement(XMLObject, Amount):
source_credit = float(source_credit)
except TypeError:
source_credit = 0.0
self.setCancellationAmount(source_credit < 0)
self.setSourceTotalAssetPrice( - source_credit)
security.declareProtected( Permissions.ModifyPortalContent,
......@@ -962,6 +978,7 @@ class Movement(XMLObject, Amount):
destination_debit = float(destination_debit)
except TypeError:
destination_debit = 0.0
self.setCancellationAmount(destination_debit < 0)
self.setDestinationTotalAssetPrice(destination_debit)
security.declareProtected( Permissions.ModifyPortalContent,
......@@ -977,6 +994,7 @@ class Movement(XMLObject, Amount):
destination_credit = float(destination_credit)
except TypeError:
destination_credit = 0.0
self.setCancellationAmount(destination_credit < 0)
self.setDestinationTotalAssetPrice( - destination_credit)
# Item Access (tracking)
......
......@@ -95,6 +95,7 @@ class Amount:
{ 'id' : 'cancellation_amount',
'description' : 'defines if this quantity is used in order to cancel another one',
'type' : 'boolean',
'default': False,
'mode' : 'w' },
# quantity_sign is used by QuantitySignMovementGroup
# When comparing a delivery to a property_dict coming from a MovementGroup,
......
......@@ -270,7 +270,8 @@ WHERE\n
</dtml-if>\n
\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
OR stock.section_uid <> stock.mirror_section_uid\n
OR stock.mirror_node_uid IS NULL\n
......@@ -278,7 +279,8 @@ WHERE\n
OR stock.payment_uid IS NOT NULL )\n
</dtml-if>\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
OR stock.section_uid <> stock.mirror_section_uid\n
OR stock.mirror_node_uid IS NULL\n
......@@ -410,7 +412,8 @@ WHERE\n
</dtml-if>\n
\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
OR stock.section_uid <> stock.mirror_section_uid\n
OR stock.mirror_node_uid IS NULL\n
......@@ -418,7 +421,8 @@ WHERE\n
OR stock.payment_uid IS NOT NULL )\n
</dtml-if>\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
OR stock.section_uid <> stock.mirror_section_uid\n
OR stock.mirror_node_uid IS NULL\n
......
......@@ -700,7 +700,8 @@ WHERE\n
</dtml-if>\n
\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
OR stock.section_uid <> stock.mirror_section_uid\n
OR stock.mirror_node_uid IS NULL\n
......@@ -708,7 +709,8 @@ WHERE\n
OR stock.payment_uid IS NOT NULL )\n
</dtml-if>\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
OR stock.section_uid <> stock.mirror_section_uid\n
OR stock.mirror_node_uid IS NULL\n
......@@ -858,7 +860,8 @@ WHERE\n
</dtml-if>\n
\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
OR stock.section_uid <> stock.mirror_section_uid\n
OR stock.mirror_node_uid IS NULL\n
......@@ -866,7 +869,8 @@ WHERE\n
OR stock.payment_uid IS NOT NULL )\n
</dtml-if>\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
OR stock.section_uid <> stock.mirror_section_uid\n
OR stock.mirror_node_uid IS NULL\n
......
......@@ -161,6 +161,12 @@
<dictionary/>
</value>
</item>
<item>
<key> <string>isCancellationAmount</string> </key>
<value>
<dictionary/>
</value>
</item>
<item>
<key> <string>uid</string> </key>
<value>
......@@ -182,6 +188,7 @@
<string>getSourceSectionUid</string>
<string>getDestinationSectionUid</string>
<string>isMovement</string>
<string>isCancellationAmount</string>
<string>isInventoryMovement</string>
<string>getSourcePaymentUid</string>
<string>getDestinationPaymentUid</string>
......@@ -222,6 +229,7 @@ getDestinationUid\r\n
getSourceSectionUid\r\n
getDestinationSectionUid\r\n
isMovement\r\n
isCancellationAmount\r\n
isInventoryMovement\r\n
getSourcePaymentUid\r\n
getDestinationPaymentUid\r\n
......@@ -304,6 +312,7 @@ WHERE\n
getSourceUid[loop_item], \n
getResourceUid[loop_item],\n
getInventoriatedQuantity[loop_item],\n
isCancellationAmount[loop_item],\n
getStopDate[loop_item], \n
getStartDate[loop_item], \n
getDestinationInventoriatedTotalAssetPrice[loop_item], \n
......@@ -326,6 +335,7 @@ WHERE\n
getDestinationUid[loop_item], \n
getResourceUid[loop_item],\n
-(getInventoriatedQuantity[loop_item] or 0), \n
isCancellationAmount[loop_item],\n
getStartDate[loop_item], \n
getStopDate[loop_item],\n
getSourceInventoriatedTotalAssetPrice[loop_item], \n
......@@ -354,13 +364,14 @@ VALUES\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[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[13]" type="float" optional>,\n
<dtml-sqlvar expr="row_item[14]" type="string" optional>,\n
<dtml-sqlvar expr="row_item[13]" type="datetime" 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[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
<dtml-if sequence-end><dtml-else>,</dtml-if>\n
</dtml-in>\n
......@@ -433,6 +444,7 @@ WHERE\n
getSourceUid[loop_item], \n
getResourceUid[loop_item],\n
getInventoriatedQuantity[loop_item],\n
isCancellationAmount[loop_item],\n
getStopDate[loop_item], \n
getStartDate[loop_item], \n
getDestinationInventoriatedTotalAssetPrice[loop_item], \n
......@@ -455,6 +467,7 @@ WHERE\n
getDestinationUid[loop_item], \n
getResourceUid[loop_item],\n
-(getInventoriatedQuantity[loop_item] or 0), \n
isCancellationAmount[loop_item],\n
getStartDate[loop_item], \n
getStopDate[loop_item],\n
getSourceInventoriatedTotalAssetPrice[loop_item], \n
......@@ -483,13 +496,14 @@ VALUES\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[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[13]" type="float" optional>,\n
<dtml-sqlvar expr="row_item[14]" type="string" optional>,\n
<dtml-sqlvar expr="row_item[13]" type="datetime" 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[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
<dtml-if sequence-end><dtml-else>,</dtml-if>\n
</dtml-in>\n
......
......@@ -97,7 +97,8 @@ CREATE TABLE `stock` (\n
`mirror_section_uid` BIGINT UNSIGNED,\n
`mirror_node_uid` BIGINT UNSIGNED,\n
`resource_uid` BIGINT UNSIGNED,\n
`quantity` real ,\n
`quantity` real,\n
`is_cancellation` BOOLEAN,\n
`date` datetime,\n
`mirror_date` datetime,\n
`total_price` real ,\n
......@@ -171,7 +172,8 @@ CREATE TABLE `stock` (\n
`mirror_section_uid` BIGINT UNSIGNED,\n
`mirror_node_uid` BIGINT UNSIGNED,\n
`resource_uid` BIGINT UNSIGNED,\n
`quantity` real ,\n
`quantity` real,\n
`is_cancellation` BOOLEAN,\n
`date` datetime,\n
`mirror_date` datetime,\n
`total_price` real ,\n
......
138
\ No newline at end of file
139
\ No newline at end of file
......@@ -810,6 +810,22 @@ class TestTransactionValidation(AccountingTestCase):
doActionFor(accounting_transaction, 'stop_action')
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):
"""Various tests for closing the period.
......
......@@ -384,6 +384,110 @@ class TestMovement(ERP5TypeTestCase):
mvt.edit(destination_asset_debit=None, destination_debit=200)
self.assertEquals(0.0, mvt.getDestinationAssetDebit())
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):
......@@ -522,6 +626,47 @@ class TestAccountingTransactionLine(TestMovement):
self.assertEquals(0, mvt.getDestinationInventoriatedTotalAssetCredit())
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():
suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(TestAmount))
......
......@@ -599,6 +599,19 @@ class TestInventory(InventoryAPITestCase):
payment_uid=self.other_payment_node.getUid(),
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):
getInventory = self.getSimulationTool().getInventory
self._makeMovement(quantity=2, price=1,
......@@ -790,6 +803,24 @@ class TestInventoryList(InventoryAPITestCase):
self.assertEquals(-2, inventory_list[0].total_price)
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 makeMovement(simulation_state=None, quantity=None):
self._makeMovement(quantity=quantity, price=1,
......@@ -831,6 +862,7 @@ class TestInventoryList(InventoryAPITestCase):
checkInventory(line=3, type='Future', source=1, quantity=-9)
checkInventory(line=3, type='Future', destination=1, quantity=9)
class TestMovementHistoryList(InventoryAPITestCase):
"""Tests Movement history list methods.
"""
......@@ -1441,6 +1473,28 @@ class TestMovementHistoryList(InventoryAPITestCase):
self.assertEquals(-2, movement_history_list[0].total_price)
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):
"""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