Commit 2ba8ba76 authored by Jérome Perrin's avatar Jérome Perrin

support setting asset_debit and asset_credit if one of them is empty


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@39021 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 65cbfc57
......@@ -865,6 +865,20 @@ class Movement(XMLObject, Amount, CompositionMixin):
quantity += (destination_debit - destination_credit)
kw['quantity'] = quantity
kw['cancellation_amount'] = (destination_credit < 0 or destination_debit < 0)
# If both asset debit and asset credit are passed, we have to take care not
# to erase the asset price if one of them is unset.
if kw.get('source_asset_debit') or kw.get('source_asset_credit'):
if kw.get('source_asset_debit') in (None, ''):
kw.pop('source_asset_debit', None)
if kw.get('source_asset_credit') in (None, ''):
kw.pop('source_asset_credit', None)
if kw.get('destination_asset_debit') or kw.get('destination_asset_credit'):
if kw.get('destination_asset_debit') in (None, ''):
kw.pop('destination_asset_debit', None)
if kw.get('destination_asset_credit') in (None, ''):
kw.pop('destination_asset_credit', None)
if not edit_order:
edit_order = ('variation_category_list', )
return XMLObject._edit(self, edit_order=edit_order, **kw)
......
......@@ -355,6 +355,17 @@ class TestMovement(ERP5TypeTestCase):
self.assertEquals(0.0, mvt.getSourceAssetDebit())
self.assertEquals(200, mvt.getSourceDebit())
def testEditSourceAssetDebitAndCredit(self):
mvt = self._makeOne('mvt')
mvt.edit(source_asset_debit=100, source_asset_credit=None)
self.assertEquals(100, mvt.getSourceAssetDebit())
mvt.edit(source_asset_debit=None, source_asset_credit=100)
self.assertEquals(100, mvt.getSourceAssetCredit())
mvt.edit(source_asset_debit=100, source_asset_credit='')
self.assertEquals(100, mvt.getSourceAssetDebit())
mvt.edit(source_asset_debit='', source_asset_credit=100)
self.assertEquals(100, mvt.getSourceAssetCredit())
def testDestinationAssetCredit(self):
mvt = self._makeOne('mvt')
mvt.edit(destination_asset_credit=100)
......@@ -381,6 +392,17 @@ class TestMovement(ERP5TypeTestCase):
self.assertEquals(0.0, mvt.getDestinationAssetDebit())
self.assertEquals(200, mvt.getDestinationDebit())
def testEditDestinationAssetDebitAndCredit(self):
mvt = self._makeOne('mvt')
mvt.edit(destination_asset_debit=100, destination_asset_credit=None)
self.assertEquals(100, mvt.getDestinationAssetDebit())
mvt.edit(destination_asset_debit=None, destination_asset_credit=100)
self.assertEquals(100, mvt.getDestinationAssetCredit())
mvt.edit(destination_asset_debit=100, destination_asset_credit='')
self.assertEquals(100, mvt.getDestinationAssetDebit())
mvt.edit(destination_asset_debit='', destination_asset_credit=100)
self.assertEquals(100, mvt.getDestinationAssetCredit())
def testCancellationAmountGetDestinationCredit(self):
mvt = self._makeOne('mvt')
mvt.setCancellationAmount(True)
......
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