Add counter to controller
This commit is contained in:
@@ -184,6 +184,81 @@ class PurchaseTradeTestCase(ModuleTestCase):
|
||||
self.assertEqual(
|
||||
PurchaseLine.default_pricing_rule(), 'Default pricing rule')
|
||||
|
||||
def test_party_execution_achieved_percent_uses_real_area_statistics(self):
|
||||
'party execution achieved percent reflects the controller share in its area'
|
||||
PartyExecution = Pool().get('party.execution')
|
||||
execution = PartyExecution()
|
||||
execution.party = Mock(id=1)
|
||||
execution.area = Mock(id=10)
|
||||
|
||||
shipments = [
|
||||
Mock(controller=Mock(id=1)),
|
||||
Mock(controller=Mock(id=2)),
|
||||
Mock(controller=Mock(id=1)),
|
||||
Mock(controller=Mock(id=2)),
|
||||
Mock(controller=Mock(id=1)),
|
||||
]
|
||||
shipment_model = Mock()
|
||||
shipment_model.search.return_value = shipments
|
||||
|
||||
with patch(
|
||||
'trytond.modules.purchase_trade.party.Pool'
|
||||
) as PoolMock:
|
||||
PoolMock.return_value.get.return_value = shipment_model
|
||||
|
||||
self.assertEqual(
|
||||
execution.get_percent('achieved_percent'),
|
||||
Decimal('60.00'))
|
||||
|
||||
def test_get_controller_prioritizes_controller_farthest_from_target(self):
|
||||
'shipment controller selection prioritizes the most under-target rule'
|
||||
Shipment = Pool().get('stock.shipment.in')
|
||||
Party = Pool().get('party.party')
|
||||
PartyExecution = Pool().get('party.execution')
|
||||
|
||||
shipment = Shipment()
|
||||
shipment.to_location = Mock(
|
||||
country=Mock(region=Mock(id=20, parent=Mock(id=10, parent=None))))
|
||||
|
||||
party_a = Party()
|
||||
party_a.id = 1
|
||||
rule_a = PartyExecution()
|
||||
rule_a.party = party_a
|
||||
rule_a.area = Mock(id=10)
|
||||
rule_a.percent = Decimal('80')
|
||||
rule_a.compute_achieved_percent = Mock(return_value=Decimal('40'))
|
||||
party_a.execution = [rule_a]
|
||||
|
||||
party_b = Party()
|
||||
party_b.id = 2
|
||||
rule_b = PartyExecution()
|
||||
rule_b.party = party_b
|
||||
rule_b.area = Mock(id=10)
|
||||
rule_b.percent = Decimal('50')
|
||||
rule_b.compute_achieved_percent = Mock(return_value=Decimal('45'))
|
||||
party_b.execution = [rule_b]
|
||||
|
||||
category_model = Mock()
|
||||
category_model.search.return_value = [Mock(id=99)]
|
||||
party_category_model = Mock()
|
||||
party_category_model.search.return_value = [
|
||||
Mock(party=party_b),
|
||||
Mock(party=party_a),
|
||||
]
|
||||
|
||||
with patch(
|
||||
'trytond.modules.purchase_trade.stock.Pool'
|
||||
) as PoolMock:
|
||||
def get_model(name):
|
||||
return {
|
||||
'party.category': category_model,
|
||||
'party.party-party.category': party_category_model,
|
||||
}[name]
|
||||
|
||||
PoolMock.return_value.get.side_effect = get_model
|
||||
|
||||
self.assertIs(shipment.get_controller(), party_a)
|
||||
|
||||
def test_sale_report_multi_line_helpers_aggregate_all_lines(self):
|
||||
'sale report helpers aggregate quantity, price lines and shipment periods'
|
||||
Sale = Pool().get('sale.sale')
|
||||
|
||||
Reference in New Issue
Block a user