Matching
This commit is contained in:
@@ -2722,6 +2722,46 @@ class PurchaseTradeTestCase(ModuleTestCase):
|
||||
with self.assertRaises(UserError):
|
||||
lot_module.LotQt.match_lots([purchase_lot], [])
|
||||
|
||||
def test_lot_matching_available_includes_tolerance_remaining(self):
|
||||
'matching can use remaining purchase tolerance above open quantity'
|
||||
purchase = Mock(tol_max=Decimal('10'))
|
||||
line = Mock(
|
||||
purchase=purchase, inherit_tol=True,
|
||||
quantity_theorical=Decimal('100'), unit=None)
|
||||
vlot = Mock(id=10, line=line)
|
||||
lqt = Mock(lot_p=vlot, lot_quantity=Decimal('60'))
|
||||
matched_lqt = Mock(lot_quantity=Decimal('40'), lot_unit=None)
|
||||
|
||||
with patch.object(
|
||||
lot_module.LotQt, 'search', return_value=[matched_lqt]):
|
||||
self.assertEqual(
|
||||
lot_module.LotQt._matching_tolerated_available(
|
||||
lqt, 'purchase'),
|
||||
Decimal('70.00000'))
|
||||
|
||||
def test_lot_matching_accepts_purchase_quantity_within_tolerance(self):
|
||||
'apply matching can consume purchase quantity up to tolerance max'
|
||||
purchase = Mock(tol_max=Decimal('10'))
|
||||
line = Mock(
|
||||
purchase=purchase, inherit_tol=True,
|
||||
quantity_theorical=Decimal('100'), unit=None)
|
||||
vlot = Mock(id=10, line=line)
|
||||
lqt = Mock(lot_p=vlot, lot_s=None, lot_quantity=Decimal('100'))
|
||||
|
||||
class LotQtMock:
|
||||
def __call__(self, _id):
|
||||
return lqt
|
||||
|
||||
pool = Mock()
|
||||
pool.get.side_effect = (
|
||||
lambda name: LotQtMock() if name == 'lot.qt' else Mock())
|
||||
purchase_lot = Mock(
|
||||
lot_matched_qt=Decimal('105'), lot_r_id=1)
|
||||
|
||||
with patch.object(lot_module, 'Pool', return_value=pool), \
|
||||
patch.object(lot_module.LotQt, 'search', return_value=[]):
|
||||
lot_module.LotQt.match_lots([purchase_lot], [])
|
||||
|
||||
def test_go_matching_defaults_selected_open_lot_qts(self):
|
||||
'go to matching only preloads selected unmatched open lot.qt rows'
|
||||
purchase = Mock(id=10, party=Mock(id=20))
|
||||
|
||||
Reference in New Issue
Block a user