Crop bug
This commit is contained in:
@@ -49,7 +49,7 @@ class ContractFactory:
|
||||
parts = c.currency_unit.split("_")
|
||||
contract.currency = int(parts[0]) or 1
|
||||
contract.party = c.party
|
||||
contract.crop = c.crop
|
||||
contract.crop = cls._get_crop(c, base_contract)
|
||||
contract.tol_min = cls._get_tolerance(c, 'tol_min')
|
||||
contract.tol_max = cls._get_tolerance(c, 'tol_max')
|
||||
contract.payment_term = c.payment_term
|
||||
@@ -197,6 +197,13 @@ class ContractFactory:
|
||||
value = getattr(party, field, None)
|
||||
return value if value is not None else Decimal(0)
|
||||
|
||||
@staticmethod
|
||||
def _get_crop(contract_detail, base_contract):
|
||||
crop = getattr(contract_detail, 'crop', None)
|
||||
if crop:
|
||||
return crop
|
||||
return getattr(base_contract, 'crop', None)
|
||||
|
||||
@staticmethod
|
||||
def _normalize_quantity(quantity):
|
||||
return abs(Decimal(str(quantity or 0))).quantize(Decimal('0.00001'))
|
||||
|
||||
@@ -2776,6 +2776,16 @@ class PurchaseTradeTestCase(ModuleTestCase):
|
||||
ContractFactory._get_tolerance(contract_detail, 'tol_max'),
|
||||
Decimal('5'))
|
||||
|
||||
def test_contract_factory_uses_base_crop_when_line_is_empty(self):
|
||||
'hidden crop falls back to the source contract crop'
|
||||
crop = Mock()
|
||||
contract_detail = Mock(crop=None)
|
||||
base_contract = Mock(crop=crop)
|
||||
|
||||
self.assertEqual(
|
||||
ContractFactory._get_crop(contract_detail, base_contract),
|
||||
crop)
|
||||
|
||||
def test_contract_factory_delivery_dates_fallback_to_period(self):
|
||||
'hidden delivery dates are still derived from delivery period'
|
||||
period = Mock(beg_date='2026-05-01', end_date='2026-05-31')
|
||||
|
||||
Reference in New Issue
Block a user