1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
from mock import Mock
from openerp.tests.common import BaseCase
from openerp.osv.orm import browse_record
class TestGroupOrders(BaseCase):
def setUp(self):
super(TestGroupOrders, self).setUp()
self.order1 = Mock()
self.order2 = Mock()
self.order1.order_line = self.order2.order_line = []
self.order1.origin = self.order2.origin = ''
self.order1.notes = self.order2.notes = ''
# I have to use the registry to get an instance of a model. I cannot
# use the class constructor because that is modified to return nothing.
self.po = self.registry('purchase.order')
def test_no_orders(self):
"""Group an empty list of orders as an empty dictionary."""
grouped = self.po._group_orders([])
self.assertEquals(grouped, {})
def test_one_order(self):
"""A single order will not be grouped."""
grouped = self.po._group_orders([self.order1])
self.assertEquals(grouped, {})
def test_two_similar_orders(self):
"""Two orders with the right conditions can be merged.
We do not care about the order lines here.
"""
self.order1.partner_id = self.order2.partner_id = Mock(
spec=browse_record, id=1)
self.order1.location_id = self.order2.location_id = Mock(
spec=browse_record, id=2)
self.order1.pricelist_id = self.order2.pricelist_id = Mock(
spec=browse_record, id=3)
self.order1.id = 51
self.order2.id = 52
grouped = self.po._group_orders([self.order1, self.order2])
expected_key = (('location_id', 2), ('partner_id', 1),
('pricelist_id', 3))
self.assertEquals(grouped.keys(), [expected_key])
self.assertEquals(grouped[expected_key][1], [51, 52])
def test_merge_origin_and_notes(self):
self.order1.origin = 'ORIGIN1'
self.order2.origin = 'ORIGIN2'
self.order1.notes = 'Notes1'
self.order2.notes = 'Notes2'
self.order1.partner_id = self.order2.partner_id = Mock(
spec=browse_record, id=1)
self.order1.location_id = self.order2.location_id = Mock(
spec=browse_record, id=2)
self.order1.pricelist_id = self.order2.pricelist_id = Mock(
spec=browse_record, id=3)
grouped = self.po._group_orders([self.order1, self.order2])
expected_key = (('location_id', 2), ('partner_id', 1),
('pricelist_id', 3))
merged_data = grouped[expected_key][0]
self.assertEquals(merged_data['origin'], 'ORIGIN1 ORIGIN2')
self.assertEquals(merged_data['notes'], 'Notes1\nNotes2')