pricing: reduction rate mode, apply min pricing from matrix (#89605)
gitea/lingo/pipeline/head This commit looks good
Details
gitea/lingo/pipeline/head This commit looks good
Details
This commit is contained in:
parent
f07f664e0c
commit
6448b16220
|
@ -717,14 +717,14 @@ class Pricing(WithApplicationMixin, models.Model):
|
|||
|
||||
new_pricing = round(pricing * (100 - reduction_rate) / 100, 2)
|
||||
adjusted_pricing = new_pricing
|
||||
if self.min_pricing is not None:
|
||||
adjusted_pricing = max(adjusted_pricing, self.min_pricing)
|
||||
min_pricing, dummy = self.compute_min_pricing(context=context)
|
||||
adjusted_pricing = max(adjusted_pricing, min_pricing)
|
||||
|
||||
return adjusted_pricing, {
|
||||
'computed_pricing': pricing,
|
||||
'reduction_rate': reduction_rate,
|
||||
'reduced_pricing': new_pricing,
|
||||
'min_pricing': self.min_pricing,
|
||||
'min_pricing': min_pricing,
|
||||
'bounded_pricing': adjusted_pricing,
|
||||
}
|
||||
|
||||
|
|
|
@ -27,6 +27,7 @@ from lingo.pricing.models import (
|
|||
PricingEffortRateTargetError,
|
||||
PricingEffortRateTargetFormatError,
|
||||
PricingEffortRateTargetValueError,
|
||||
PricingError,
|
||||
PricingEventNotCheckedError,
|
||||
PricingMatrix,
|
||||
PricingMatrixCell,
|
||||
|
@ -808,7 +809,8 @@ def test_compute_reduction_rate(mock_send, context, nocache):
|
|||
assert 'filter-bar=35&' in mock_send.call_args_list[0][0][0].url
|
||||
|
||||
|
||||
def test_apply_reduction_rate(context):
|
||||
@mock.patch('lingo.pricing.models.Pricing.compute_min_pricing')
|
||||
def test_apply_reduction_rate(mock_compute, context):
|
||||
pricing = Pricing.objects.create(
|
||||
date_start=datetime.date(year=2021, month=9, day=1),
|
||||
date_end=datetime.date(year=2021, month=10, day=1),
|
||||
|
@ -825,7 +827,7 @@ def test_apply_reduction_rate(context):
|
|||
payer_external_id='parent:35',
|
||||
) == (42, {})
|
||||
|
||||
pricing.kind = 'reduction'
|
||||
pricing.kind = 'effort'
|
||||
pricing.save()
|
||||
assert pricing.apply_reduction_rate(
|
||||
pricing=42,
|
||||
|
@ -846,8 +848,7 @@ def test_apply_reduction_rate(context):
|
|||
payer_external_id='parent:35',
|
||||
) == (42, {})
|
||||
|
||||
# template with correct value
|
||||
pricing.kind = 'reduction'
|
||||
pricing.kind = 'effort'
|
||||
pricing.reduction_rate = '{{ foo }}'
|
||||
pricing.save()
|
||||
assert pricing.apply_reduction_rate(
|
||||
|
@ -856,38 +857,25 @@ def test_apply_reduction_rate(context):
|
|||
context={'foo': '50'},
|
||||
user_external_id='child:42',
|
||||
payer_external_id='parent:35',
|
||||
) == (
|
||||
21,
|
||||
{
|
||||
'computed_pricing': 42,
|
||||
'reduction_rate': 50,
|
||||
'reduced_pricing': 21,
|
||||
'min_pricing': None,
|
||||
'bounded_pricing': 21,
|
||||
},
|
||||
)
|
||||
) == (42, {})
|
||||
|
||||
# with a min value
|
||||
pricing.min_pricing = 22
|
||||
pricing.save()
|
||||
assert pricing.apply_reduction_rate(
|
||||
pricing=42,
|
||||
request=context['request'],
|
||||
context={'foo': '50'},
|
||||
user_external_id='child:42',
|
||||
payer_external_id='parent:35',
|
||||
) == (
|
||||
22,
|
||||
{
|
||||
'computed_pricing': 42,
|
||||
'reduction_rate': 50,
|
||||
'reduced_pricing': 21,
|
||||
'min_pricing': 22,
|
||||
'bounded_pricing': 22,
|
||||
},
|
||||
)
|
||||
pricing.min_pricing = 21
|
||||
# template with correct value
|
||||
mock_compute.side_effect = PricingDataError
|
||||
pricing.kind = 'reduction'
|
||||
pricing.reduction_rate = '{{ foo }}'
|
||||
pricing.save()
|
||||
with pytest.raises(PricingError):
|
||||
pricing.apply_reduction_rate(
|
||||
pricing=42,
|
||||
request=context['request'],
|
||||
context={'foo': '50'},
|
||||
user_external_id='child:42',
|
||||
payer_external_id='parent:35',
|
||||
)
|
||||
assert mock_compute.call_args_list == [mock.call(context={'foo': '50'})]
|
||||
|
||||
mock_compute.side_effect = None
|
||||
mock_compute.return_value = (21, 'criterias')
|
||||
assert pricing.apply_reduction_rate(
|
||||
pricing=42,
|
||||
request=context['request'],
|
||||
|
|
Loading…
Reference in New Issue