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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
|
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from datetime import date, datetime, timedelta
from odoo.tests.common import Form, SavepointCase
class TestReportsCommon(SavepointCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.partner = cls.env['res.partner'].create({'name': 'Partner'})
cls.ModelDataObj = cls.env['ir.model.data']
cls.picking_type_in = cls.env['stock.picking.type'].browse(cls.ModelDataObj.xmlid_to_res_id('stock.picking_type_in'))
cls.picking_type_out = cls.env['stock.picking.type'].browse(cls.ModelDataObj.xmlid_to_res_id('stock.picking_type_out'))
cls.supplier_location = cls.env['stock.location'].browse(cls.ModelDataObj.xmlid_to_res_id('stock.stock_location_suppliers'))
cls.stock_location = cls.env['stock.location'].browse(cls.ModelDataObj.xmlid_to_res_id('stock.stock_location_stock'))
product_form = Form(cls.env['product.product'])
product_form.type = 'product'
product_form.name = 'Product'
cls.product = product_form.save()
cls.product_template = cls.product.product_tmpl_id
def get_report_forecast(self, product_template_ids=False, product_variant_ids=False, context=False):
if product_template_ids:
report = self.env['report.stock.report_product_template_replenishment']
product_ids = product_template_ids
elif product_variant_ids:
report = self.env['report.stock.report_product_product_replenishment']
product_ids = product_template_ids
if context:
report = report.with_context(context)
report_values = report._get_report_values(docids=product_ids)
docs = report_values['docs']
lines = docs['lines']
return report_values, docs, lines
class TestReports(TestReportsCommon):
def test_reports(self):
product1 = self.env['product.product'].create({
'name': 'Mellohi',
'default_code': 'C418',
'type': 'product',
'categ_id': self.env.ref('product.product_category_all').id,
'tracking': 'lot',
'barcode': 'scan_me'
})
lot1 = self.env['stock.production.lot'].create({
'name': 'Volume-Beta',
'product_id': product1.id,
'company_id': self.env.company.id,
})
report = self.env.ref('stock.label_lot_template')
target = b'\n\n\n^XA\n^FO100,50\n^A0N,44,33^FD[C418]Mellohi^FS\n^FO100,100\n^A0N,44,33^FDLN/SN:Volume-Beta^FS\n^FO100,150^BY3\n^BCN,100,Y,N,N\n^FDVolume-Beta^FS\n^XZ\n\n\n'
rendering, qweb_type = report._render_qweb_text(lot1.id)
self.assertEqual(target, rendering.replace(b' ', b''), 'The rendering is not good')
self.assertEqual(qweb_type, 'text', 'the report type is not good')
def test_report_quantity_1(self):
product_form = Form(self.env['product.product'])
product_form.type = 'product'
product_form.name = 'Product'
product = product_form.save()
warehouse = self.env['stock.warehouse'].search([], limit=1)
stock = self.env['stock.location'].create({
'name': 'New Stock',
'usage': 'internal',
'location_id': warehouse.view_location_id.id,
})
# Inventory Adjustement of 50.0 today.
self.env['stock.quant'].with_context(inventory_mode=True).create({
'product_id': product.id,
'location_id': stock.id,
'inventory_quantity': 50
})
self.env['stock.move'].flush()
report_records_today = self.env['report.stock.quantity'].read_group(
[('product_id', '=', product.id), ('date', '=', date.today())],
['product_qty'], [], lazy=False)
report_records_tomorrow = self.env['report.stock.quantity'].read_group(
[('product_id', '=', product.id), ('date', '=', date.today() + timedelta(days=1))],
['product_qty'], [])
report_records_yesterday = self.env['report.stock.quantity'].read_group(
[('product_id', '=', product.id), ('date', '=', date.today() - timedelta(days=1))],
['product_qty'], [])
self.assertEqual(sum([r['product_qty'] for r in report_records_today]), 50.0)
self.assertEqual(sum([r['product_qty'] for r in report_records_tomorrow]), 50.0)
self.assertEqual(sum([r['product_qty'] for r in report_records_yesterday]), 0.0)
# Delivery of 20.0 units tomorrow
move_out = self.env['stock.move'].create({
'name': 'Move Out 20',
'date': datetime.now() + timedelta(days=1),
'location_id': stock.id,
'location_dest_id': self.env.ref('stock.stock_location_customers').id,
'product_id': product.id,
'product_uom': product.uom_id.id,
'product_uom_qty': 20.0,
})
self.env['stock.move'].flush()
report_records_tomorrow = self.env['report.stock.quantity'].read_group(
[('product_id', '=', product.id), ('date', '=', date.today() + timedelta(days=1))],
['product_qty'], [])
self.assertEqual(sum([r['product_qty'] for r in report_records_tomorrow]), 50.0)
move_out._action_confirm()
self.env['stock.move'].flush()
report_records_tomorrow = self.env['report.stock.quantity'].read_group(
[('product_id', '=', product.id), ('date', '=', date.today() + timedelta(days=1))],
['product_qty', 'state'], ['state'], lazy=False)
self.assertEqual(sum([r['product_qty'] for r in report_records_tomorrow if r['state'] == 'forecast']), 30.0)
self.assertEqual(sum([r['product_qty'] for r in report_records_tomorrow if r['state'] == 'out']), -20.0)
report_records_today = self.env['report.stock.quantity'].read_group(
[('product_id', '=', product.id), ('date', '=', date.today())],
['product_qty', 'state'], ['state'], lazy=False)
self.assertEqual(sum([r['product_qty'] for r in report_records_today if r['state'] == 'forecast']), 50.0)
# Receipt of 10.0 units tomorrow
move_in = self.env['stock.move'].create({
'name': 'Move In 10',
'date': datetime.now() + timedelta(days=1),
'location_id': self.env.ref('stock.stock_location_suppliers').id,
'location_dest_id': stock.id,
'product_id': product.id,
'product_uom': product.uom_id.id,
'product_uom_qty': 10.0,
})
move_in._action_confirm()
self.env['stock.move'].flush()
report_records_tomorrow = self.env['report.stock.quantity'].read_group(
[('product_id', '=', product.id), ('date', '=', date.today() + timedelta(days=1))],
['product_qty', 'state'], ['state'], lazy=False)
self.assertEqual(sum([r['product_qty'] for r in report_records_tomorrow if r['state'] == 'forecast']), 40.0)
self.assertEqual(sum([r['product_qty'] for r in report_records_tomorrow if r['state'] == 'out']), -20.0)
self.assertEqual(sum([r['product_qty'] for r in report_records_tomorrow if r['state'] == 'in']), 10.0)
report_records_today = self.env['report.stock.quantity'].read_group(
[('product_id', '=', product.id), ('date', '=', date.today())],
['product_qty', 'state'], ['state'], lazy=False)
self.assertEqual(sum([r['product_qty'] for r in report_records_today if r['state'] == 'forecast']), 50.0)
# Delivery of 20.0 units tomorrow
move_out = self.env['stock.move'].create({
'name': 'Move Out 30 - Day-1',
'date': datetime.now() - timedelta(days=1),
'location_id': stock.id,
'location_dest_id': self.env.ref('stock.stock_location_customers').id,
'product_id': product.id,
'product_uom': product.uom_id.id,
'product_uom_qty': 30.0,
})
move_out._action_confirm()
self.env['stock.move'].flush()
report_records_today = self.env['report.stock.quantity'].read_group(
[('product_id', '=', product.id), ('date', '=', date.today())],
['product_qty', 'state'], ['state'], lazy=False)
report_records_tomorrow = self.env['report.stock.quantity'].read_group(
[('product_id', '=', product.id), ('date', '=', date.today() + timedelta(days=1))],
['product_qty', 'state'], ['state'], lazy=False)
report_records_yesterday = self.env['report.stock.quantity'].read_group(
[('product_id', '=', product.id), ('date', '=', date.today() - timedelta(days=1))],
['product_qty', 'state'], ['state'], lazy=False)
self.assertEqual(sum([r['product_qty'] for r in report_records_yesterday if r['state'] == 'forecast']), -30.0)
self.assertEqual(sum([r['product_qty'] for r in report_records_yesterday if r['state'] == 'out']), -30.0)
self.assertEqual(sum([r['product_qty'] for r in report_records_yesterday if r['state'] == 'in']), 0.0)
self.assertEqual(sum([r['product_qty'] for r in report_records_today if r['state'] == 'forecast']), 20.0)
self.assertEqual(sum([r['product_qty'] for r in report_records_today if r['state'] == 'out']), 0.0)
self.assertEqual(sum([r['product_qty'] for r in report_records_today if r['state'] == 'in']), 0.0)
self.assertEqual(sum([r['product_qty'] for r in report_records_tomorrow if r['state'] == 'forecast']), 10.0)
self.assertEqual(sum([r['product_qty'] for r in report_records_tomorrow if r['state'] == 'out']), -20.0)
self.assertEqual(sum([r['product_qty'] for r in report_records_tomorrow if r['state'] == 'in']), 10.0)
def test_report_quantity_2(self):
""" Not supported case.
"""
product_form = Form(self.env['product.product'])
product_form.type = 'product'
product_form.name = 'Product'
product = product_form.save()
warehouse = self.env['stock.warehouse'].search([], limit=1)
stock = self.env['stock.location'].create({
'name': 'Stock Under Warehouse',
'usage': 'internal',
'location_id': warehouse.view_location_id.id,
})
stock_without_wh = self.env['stock.location'].create({
'name': 'Stock Outside Warehouse',
'usage': 'internal',
'location_id': self.env.ref('stock.stock_location_locations').id,
})
self.env['stock.quant'].with_context(inventory_mode=True).create({
'product_id': product.id,
'location_id': stock.id,
'inventory_quantity': 50
})
self.env['stock.quant'].with_context(inventory_mode=True).create({
'product_id': product.id,
'location_id': stock_without_wh.id,
'inventory_quantity': 50
})
move = self.env['stock.move'].create({
'name': 'Move outside warehouse',
'location_id': stock.id,
'location_dest_id': stock_without_wh.id,
'product_id': product.id,
'product_uom': product.uom_id.id,
'product_uom_qty': 10.0,
})
move._action_confirm()
self.env['stock.move'].flush()
report_records = self.env['report.stock.quantity'].read_group(
[('product_id', '=', product.id), ('date', '=', date.today()), ('warehouse_id', '!=', False)],
['product_qty', 'state'], ['state'], lazy=False)
self.assertEqual(sum([r['product_qty'] for r in report_records if r['state'] == 'forecast']), 40.0)
report_records = self.env['report.stock.quantity'].read_group(
[('product_id', '=', product.id), ('date', '=', date.today())],
['product_qty', 'state'], ['state'], lazy=False)
self.assertEqual(sum([r['product_qty'] for r in report_records if r['state'] == 'forecast']), 40.0)
move = self.env['stock.move'].create({
'name': 'Move outside warehouse',
'location_id': stock_without_wh.id,
'location_dest_id': self.env.ref('stock.stock_location_customers').id,
'product_id': product.id,
'product_uom': product.uom_id.id,
'product_uom_qty': 10.0,
})
move._action_confirm()
self.env['stock.move'].flush()
report_records = self.env['report.stock.quantity'].read_group(
[('product_id', '=', product.id), ('date', '=', date.today())],
['product_qty', 'state'], ['state'], lazy=False)
self.assertEqual(sum([r['product_qty'] for r in report_records if r['state'] == 'forecast']), 40.0)
def test_report_quantity_3(self):
product_form = Form(self.env['product.product'])
product_form.type = 'product'
product_form.name = 'Product'
product = product_form.save()
warehouse = self.env['stock.warehouse'].search([], limit=1)
stock = self.env['stock.location'].create({
'name': 'Rack',
'usage': 'view',
'location_id': warehouse.view_location_id.id,
})
stock_real_loc = self.env['stock.location'].create({
'name': 'Drawer',
'usage': 'internal',
'location_id': stock.id,
})
self.env['stock.move'].flush()
report_records = self.env['report.stock.quantity'].read_group(
[('product_id', '=', product.id), ('date', '=', date.today())],
['product_qty'], [], lazy=False)
self.assertEqual(sum([r['product_qty'] for r in report_records if r['product_qty']]), 0.0)
# Receipt of 20.0 units tomorrow
move_in = self.env['stock.move'].create({
'name': 'Move In 20',
'location_id': self.env.ref('stock.stock_location_suppliers').id,
'location_dest_id': stock.id,
'product_id': product.id,
'product_uom': product.uom_id.id,
'product_uom_qty': 20.0,
})
move_in._action_confirm()
move_in.move_line_ids.location_dest_id = stock_real_loc.id
move_in.move_line_ids.qty_done = 20.0
move_in._action_done()
self.env['stock.move'].flush()
report_records = self.env['report.stock.quantity'].read_group(
[('product_id', '=', product.id), ('date', '=', date.today())],
['product_qty'], [], lazy=False)
self.assertEqual(sum([r['product_qty'] for r in report_records]), 20.0)
# Delivery of 10.0 units tomorrow
move_out = self.env['stock.move'].create({
'name': 'Move Out 10',
'location_id': stock.id,
'location_dest_id': self.env.ref('stock.stock_location_customers').id,
'product_id': product.id,
'product_uom': product.uom_id.id,
'product_uom_qty': 10.0,
})
move_out._action_confirm()
move_out._action_assign()
move_out.move_line_ids.qty_done = 10.0
move_out._action_done()
self.env['stock.move'].flush()
report_records = self.env['report.stock.quantity'].read_group(
[('product_id', '=', product.id), ('date', '=', date.today())],
['product_qty'], [], lazy=False)
self.assertEqual(sum([r['product_qty'] for r in report_records]), 10.0)
def test_report_forecast_1(self):
""" Checks report data for product is empty. Then creates and process
some operations and checks the report data accords rigthly these operations.
"""
report_values, docs, lines = self.get_report_forecast(product_template_ids=self.product_template.ids)
draft_picking_qty = docs['draft_picking_qty']
self.assertEqual(len(lines), 0, "Must have 0 line.")
self.assertEqual(draft_picking_qty['in'], 0)
self.assertEqual(draft_picking_qty['out'], 0)
# Creates a receipt then checks draft picking quantities.
receipt_form = Form(self.env['stock.picking'].with_context(
force_detailed_view=True
), view='stock.view_picking_form')
receipt_form.partner_id = self.partner
receipt_form.picking_type_id = self.picking_type_in
receipt = receipt_form.save()
with receipt_form.move_ids_without_package.new() as move_line:
move_line.product_id = self.product
move_line.product_uom_qty = 2
receipt = receipt_form.save()
report_values, docs, lines = self.get_report_forecast(product_template_ids=self.product_template.ids)
draft_picking_qty = docs['draft_picking_qty']
self.assertEqual(len(lines), 0, "Must have 0 line.")
self.assertEqual(draft_picking_qty['in'], 2)
self.assertEqual(draft_picking_qty['out'], 0)
# Creates a delivery then checks draft picking quantities.
delivery_form = Form(self.env['stock.picking'].with_context(
force_detailed_view=True
), view='stock.view_picking_form')
delivery_form.partner_id = self.partner
delivery_form.picking_type_id = self.picking_type_out
delivery = delivery_form.save()
with delivery_form.move_ids_without_package.new() as move_line:
move_line.product_id = self.product
move_line.product_uom_qty = 5
delivery = delivery_form.save()
report_values, docs, lines = self.get_report_forecast(product_template_ids=self.product_template.ids)
draft_picking_qty = docs['draft_picking_qty']
self.assertEqual(len(lines), 0, "Must have 0 line.")
self.assertEqual(draft_picking_qty['in'], 2)
self.assertEqual(draft_picking_qty['out'], 5)
# Confirms the delivery: must have one report line and no more pending qty out now.
delivery.action_confirm()
report_values, docs, lines = self.get_report_forecast(product_template_ids=self.product_template.ids)
draft_picking_qty = docs['draft_picking_qty']
self.assertEqual(len(lines), 1, "Must have 1 line.")
self.assertEqual(draft_picking_qty['in'], 2)
self.assertEqual(draft_picking_qty['out'], 0)
delivery_line = lines[0]
self.assertEqual(delivery_line['quantity'], 5)
self.assertEqual(delivery_line['replenishment_filled'], False)
self.assertEqual(delivery_line['document_out'].id, delivery.id)
# Confirms the receipt, must have two report lines now:
# - line with 2 qty (from the receipt to the delivery)
# - line with 3 qty (delivery, unavailable)
receipt.action_confirm()
report_values, docs, lines = self.get_report_forecast(product_template_ids=self.product_template.ids)
draft_picking_qty = docs['draft_picking_qty']
self.assertEqual(len(lines), 2, "Must have 2 line.")
self.assertEqual(draft_picking_qty['in'], 0)
self.assertEqual(draft_picking_qty['out'], 0)
fulfilled_line = lines[0]
unavailable_line = lines[1]
self.assertEqual(fulfilled_line['replenishment_filled'], True)
self.assertEqual(fulfilled_line['quantity'], 2)
self.assertEqual(fulfilled_line['document_in'].id, receipt.id)
self.assertEqual(fulfilled_line['document_out'].id, delivery.id)
self.assertEqual(unavailable_line['replenishment_filled'], False)
self.assertEqual(unavailable_line['quantity'], 3)
self.assertEqual(unavailable_line['document_out'].id, delivery.id)
# Creates a new receipt for the remaining quantity, confirm it...
receipt_form = Form(self.env['stock.picking'].with_context(
force_detailed_view=True
), view='stock.view_picking_form')
receipt_form.partner_id = self.partner
receipt_form.picking_type_id = self.picking_type_in
with receipt_form.move_ids_without_package.new() as move_line:
move_line.product_id = self.product
move_line.product_uom_qty = 3
receipt2 = receipt_form.save()
receipt2.action_confirm()
# ... and valid the first one.
receipt_form = Form(receipt)
with receipt_form.move_ids_without_package.edit(0) as move_line:
move_line.quantity_done = 2
receipt = receipt_form.save()
receipt.button_validate()
report_values, docs, lines = self.get_report_forecast(product_template_ids=self.product_template.ids)
draft_picking_qty = docs['draft_picking_qty']
self.assertEqual(len(lines), 2, "Still must have 2 line.")
self.assertEqual(draft_picking_qty['in'], 0)
self.assertEqual(draft_picking_qty['out'], 0)
line1 = lines[0]
line2 = lines[1]
# First line must be fulfilled thanks to the stock on hand.
self.assertEqual(line1['quantity'], 2)
self.assertEqual(line1['replenishment_filled'], True)
self.assertEqual(line1['document_in'], False)
self.assertEqual(line1['document_out'].id, delivery.id)
# Second line must be linked to the second receipt.
self.assertEqual(line2['quantity'], 3)
self.assertEqual(line2['replenishment_filled'], True)
self.assertEqual(line2['document_in'].id, receipt2.id)
self.assertEqual(line2['document_out'].id, delivery.id)
def test_report_forecast_2_replenishments_order(self):
""" Creates a receipt then creates a delivery using half of the receipt quantity.
Checks replenishment lines are correctly sorted (assigned first, unassigned at the end).
"""
# Creates a receipt then checks draft picking quantities.
receipt_form = Form(self.env['stock.picking'].with_context(
force_detailed_view=True
), view='stock.view_picking_form')
receipt_form.partner_id = self.partner
receipt_form.picking_type_id = self.picking_type_in
with receipt_form.move_ids_without_package.new() as move_line:
move_line.product_id = self.product
move_line.product_uom_qty = 6
receipt = receipt_form.save()
receipt.action_confirm()
# Creates a delivery then checks draft picking quantities.
delivery_form = Form(self.env['stock.picking'].with_context(
force_detailed_view=True
), view='stock.view_picking_form')
delivery_form.partner_id = self.partner
delivery_form.picking_type_id = self.picking_type_out
with delivery_form.move_ids_without_package.new() as move_line:
move_line.product_id = self.product
move_line.product_uom_qty = 3
delivery = delivery_form.save()
delivery.action_confirm()
report_values, docs, lines = self.get_report_forecast(product_template_ids=self.product_template.ids)
self.assertEqual(len(lines), 2, "Must have 2 line.")
line_1 = lines[0]
line_2 = lines[1]
self.assertEqual(line_1['document_in'].id, receipt.id)
self.assertEqual(line_1['document_out'].id, delivery.id)
self.assertEqual(line_2['document_in'].id, receipt.id)
self.assertEqual(line_2['document_out'], False)
def test_report_forecast_3_sort_by_date(self):
""" Creates some deliveries with different dates and checks the report
lines are correctly sorted by date. Then, creates some receipts and
check their are correctly linked according to their date.
"""
today = datetime.today()
one_hours = timedelta(hours=1)
one_day = timedelta(days=1)
one_month = timedelta(days=30)
# Creates a bunch of deliveries with different date.
delivery_form = Form(self.env['stock.picking'].with_context(
force_detailed_view=True
), view='stock.view_picking_form')
delivery_form.partner_id = self.partner
delivery_form.picking_type_id = self.picking_type_out
delivery_form.scheduled_date = today
with delivery_form.move_ids_without_package.new() as move_line:
move_line.product_id = self.product
move_line.product_uom_qty = 5
delivery_1 = delivery_form.save()
delivery_1.action_confirm()
delivery_form = Form(self.env['stock.picking'].with_context(
force_detailed_view=True
), view='stock.view_picking_form')
delivery_form.partner_id = self.partner
delivery_form.picking_type_id = self.picking_type_out
delivery_form.scheduled_date = today + one_hours
with delivery_form.move_ids_without_package.new() as move_line:
move_line.product_id = self.product
move_line.product_uom_qty = 5
delivery_2 = delivery_form.save()
delivery_2.action_confirm()
delivery_form = Form(self.env['stock.picking'].with_context(
force_detailed_view=True
), view='stock.view_picking_form')
delivery_form.partner_id = self.partner
delivery_form.picking_type_id = self.picking_type_out
delivery_form.scheduled_date = today - one_hours
with delivery_form.move_ids_without_package.new() as move_line:
move_line.product_id = self.product
move_line.product_uom_qty = 5
delivery_3 = delivery_form.save()
delivery_3.action_confirm()
delivery_form = Form(self.env['stock.picking'].with_context(
force_detailed_view=True
), view='stock.view_picking_form')
delivery_form.partner_id = self.partner
delivery_form.picking_type_id = self.picking_type_out
delivery_form.scheduled_date = today + one_day
with delivery_form.move_ids_without_package.new() as move_line:
move_line.product_id = self.product
move_line.product_uom_qty = 5
delivery_4 = delivery_form.save()
delivery_4.action_confirm()
delivery_form = Form(self.env['stock.picking'].with_context(
force_detailed_view=True
), view='stock.view_picking_form')
delivery_form.partner_id = self.partner
delivery_form.picking_type_id = self.picking_type_out
delivery_form.scheduled_date = today - one_day
with delivery_form.move_ids_without_package.new() as move_line:
move_line.product_id = self.product
move_line.product_uom_qty = 5
delivery_5 = delivery_form.save()
delivery_5.action_confirm()
delivery_form = Form(self.env['stock.picking'].with_context(
force_detailed_view=True
), view='stock.view_picking_form')
delivery_form.partner_id = self.partner
delivery_form.picking_type_id = self.picking_type_out
delivery_form.scheduled_date = today + one_month
with delivery_form.move_ids_without_package.new() as move_line:
move_line.product_id = self.product
move_line.product_uom_qty = 5
delivery_6 = delivery_form.save()
delivery_6.action_confirm()
delivery_form = Form(self.env['stock.picking'].with_context(
force_detailed_view=True
), view='stock.view_picking_form')
delivery_form.partner_id = self.partner
delivery_form.picking_type_id = self.picking_type_out
delivery_form.scheduled_date = today - one_month
with delivery_form.move_ids_without_package.new() as move_line:
move_line.product_id = self.product
move_line.product_uom_qty = 5
delivery_7 = delivery_form.save()
delivery_7.action_confirm()
# Order must be: 7, 5, 3, 1, 2, 4, 6
report_values, docs, lines = self.get_report_forecast(product_template_ids=self.product_template.ids)
draft_picking_qty = docs['draft_picking_qty']
self.assertEqual(len(lines), 7, "The report must have 7 line.")
self.assertEqual(draft_picking_qty['in'], 0)
self.assertEqual(draft_picking_qty['out'], 0)
self.assertEqual(lines[0]['document_out'].id, delivery_7.id)
self.assertEqual(lines[1]['document_out'].id, delivery_5.id)
self.assertEqual(lines[2]['document_out'].id, delivery_3.id)
self.assertEqual(lines[3]['document_out'].id, delivery_1.id)
self.assertEqual(lines[4]['document_out'].id, delivery_2.id)
self.assertEqual(lines[5]['document_out'].id, delivery_4.id)
self.assertEqual(lines[6]['document_out'].id, delivery_6.id)
# Creates 3 receipts for 20 units.
receipt_form = Form(self.env['stock.picking'].with_context(
force_detailed_view=True
), view='stock.view_picking_form')
receipt_form.partner_id = self.partner
receipt_form.picking_type_id = self.picking_type_in
receipt_form.scheduled_date = today + one_month
with receipt_form.move_ids_without_package.new() as move_line:
move_line.product_id = self.product
move_line.product_uom_qty = 5
receipt_1 = receipt_form.save()
receipt_1.action_confirm()
receipt_form = Form(self.env['stock.picking'].with_context(
force_detailed_view=True
), view='stock.view_picking_form')
receipt_form.partner_id = self.partner
receipt_form.picking_type_id = self.picking_type_in
receipt_form.scheduled_date = today - one_month
with receipt_form.move_ids_without_package.new() as move_line:
move_line.product_id = self.product
move_line.product_uom_qty = 5
receipt_2 = receipt_form.save()
receipt_2.action_confirm()
receipt_form = Form(self.env['stock.picking'].with_context(
force_detailed_view=True
), view='stock.view_picking_form')
receipt_form.partner_id = self.partner
receipt_form.picking_type_id = self.picking_type_in
receipt_form.scheduled_date = today - one_hours
with receipt_form.move_ids_without_package.new() as move_line:
move_line.product_id = self.product
move_line.product_uom_qty = 10
receipt_3 = receipt_form.save()
receipt_3.action_confirm()
# Check report lines (link and order).
report_values, docs, lines = self.get_report_forecast(product_template_ids=self.product_template.ids)
draft_picking_qty = docs['draft_picking_qty']
self.assertEqual(len(lines), 7, "The report must have 7 line.")
self.assertEqual(draft_picking_qty['in'], 0)
self.assertEqual(draft_picking_qty['out'], 0)
self.assertEqual(lines[0]['document_out'].id, delivery_7.id)
self.assertEqual(lines[0]['document_in'].id, receipt_2.id)
self.assertEqual(lines[0]['is_late'], False)
self.assertEqual(lines[1]['document_out'].id, delivery_5.id)
self.assertEqual(lines[1]['document_in'].id, receipt_3.id)
self.assertEqual(lines[1]['is_late'], True)
self.assertEqual(lines[2]['document_out'].id, delivery_3.id)
self.assertEqual(lines[2]['document_in'].id, receipt_3.id)
self.assertEqual(lines[2]['is_late'], False)
self.assertEqual(lines[3]['document_out'].id, delivery_1.id)
self.assertEqual(lines[3]['document_in'].id, receipt_1.id)
self.assertEqual(lines[3]['is_late'], True)
self.assertEqual(lines[4]['document_out'].id, delivery_2.id)
self.assertEqual(lines[4]['document_in'], False)
self.assertEqual(lines[5]['document_out'].id, delivery_4.id)
self.assertEqual(lines[5]['document_in'], False)
self.assertEqual(lines[6]['document_out'].id, delivery_6.id)
self.assertEqual(lines[6]['document_in'], False)
def test_report_forecast_4_intermediate_transfers(self):
""" Create a receipt in 3 steps and check the report line.
"""
grp_multi_loc = self.env.ref('stock.group_stock_multi_locations')
grp_multi_routes = self.env.ref('stock.group_adv_location')
self.env.user.write({'groups_id': [(4, grp_multi_loc.id)]})
self.env.user.write({'groups_id': [(4, grp_multi_routes.id)]})
# Warehouse config.
warehouse = self.env.ref('stock.warehouse0')
warehouse.reception_steps = 'three_steps'
# Product config.
self.product.write({'route_ids': [(4, self.env.ref('stock.route_warehouse0_mto').id)]})
# Create a RR
pg1 = self.env['procurement.group'].create({})
reordering_rule = self.env['stock.warehouse.orderpoint'].create({
'name': 'Product RR',
'location_id': warehouse.lot_stock_id.id,
'product_id': self.product.id,
'product_min_qty': 5,
'product_max_qty': 10,
'group_id': pg1.id,
})
reordering_rule.action_replenish()
report_values, docs, lines = self.get_report_forecast(product_template_ids=self.product_template.ids)
pickings = self.env['stock.picking'].search([('product_id', '=', self.product.id)])
receipt = pickings.filtered(lambda p: p.picking_type_id.id == self.picking_type_in.id)
# The Forecasted Report don't show intermediate moves, it must display only ingoing/outgoing documents.
self.assertEqual(len(lines), 1, "The report must have only 1 line.")
self.assertEqual(lines[0]['document_in'].id, receipt.id, "The report must only show the receipt.")
self.assertEqual(lines[0]['document_out'], False)
self.assertEqual(lines[0]['quantity'], reordering_rule.product_max_qty)
def test_report_forecast_5_multi_warehouse(self):
""" Create some transfer for two different warehouses and check the
report display the good moves according to the selected warehouse.
"""
# Warehouse config.
wh_2 = self.env['stock.warehouse'].create({
'name': 'Evil Twin Warehouse',
'code': 'ETWH',
})
picking_type_out_2 = self.env['stock.picking.type'].search([
('code', '=', 'outgoing'),
('warehouse_id', '=', wh_2.id),
])
# Creates a delivery then checks draft picking quantities.
delivery_form = Form(self.env['stock.picking'].with_context(
force_detailed_view=True
), view='stock.view_picking_form')
delivery_form.partner_id = self.partner
delivery_form.picking_type_id = self.picking_type_out
delivery = delivery_form.save()
with delivery_form.move_ids_without_package.new() as move_line:
move_line.product_id = self.product
move_line.product_uom_qty = 5
delivery = delivery_form.save()
report_values, docs, lines = self.get_report_forecast(product_template_ids=self.product_template.ids)
draft_picking_qty = docs['draft_picking_qty']
self.assertEqual(len(lines), 0, "Must have 0 line.")
self.assertEqual(draft_picking_qty['out'], 5)
report_values, docs, lines = self.get_report_forecast(
product_template_ids=self.product_template.ids,
context={'warehouse': wh_2.id},
)
draft_picking_qty = docs['draft_picking_qty']
self.assertEqual(len(lines), 0)
self.assertEqual(draft_picking_qty['out'], 0)
# Confirm the delivery -> The report must now have 1 line.
delivery.action_confirm()
report_values, docs, lines = self.get_report_forecast(product_template_ids=self.product_template.ids)
draft_picking_qty = docs['draft_picking_qty']
self.assertEqual(len(lines), 1)
self.assertEqual(draft_picking_qty['out'], 0)
self.assertEqual(lines[0]['document_out'].id, delivery.id)
self.assertEqual(lines[0]['quantity'], 5)
report_values, docs, lines = self.get_report_forecast(
product_template_ids=self.product_template.ids,
context={'warehouse': wh_2.id},
)
draft_picking_qty = docs['draft_picking_qty']
self.assertEqual(len(lines), 0)
self.assertEqual(draft_picking_qty['out'], 0)
# Creates a delivery for the second warehouse.
delivery_form = Form(self.env['stock.picking'].with_context(
force_detailed_view=True
), view='stock.view_picking_form')
delivery_form.partner_id = self.partner
delivery_form.picking_type_id = picking_type_out_2
delivery_2 = delivery_form.save()
with delivery_form.move_ids_without_package.new() as move_line:
move_line.product_id = self.product
move_line.product_uom_qty = 8
delivery_2 = delivery_form.save()
report_values, docs, lines = self.get_report_forecast(product_template_ids=self.product_template.ids)
draft_picking_qty = docs['draft_picking_qty']
self.assertEqual(len(lines), 1)
self.assertEqual(draft_picking_qty['out'], 0)
self.assertEqual(lines[0]['document_out'].id, delivery.id)
self.assertEqual(lines[0]['quantity'], 5)
report_values, docs, lines = self.get_report_forecast(
product_template_ids=self.product_template.ids,
context={'warehouse': wh_2.id},
)
draft_picking_qty = docs['draft_picking_qty']
self.assertEqual(len(lines), 0)
self.assertEqual(draft_picking_qty['out'], 8)
# Confirm the second delivery -> The report must now have 1 line.
delivery_2.action_confirm()
report_values, docs, lines = self.get_report_forecast(product_template_ids=self.product_template.ids)
draft_picking_qty = docs['draft_picking_qty']
self.assertEqual(len(lines), 1)
self.assertEqual(draft_picking_qty['out'], 0)
self.assertEqual(lines[0]['document_out'].id, delivery.id)
self.assertEqual(lines[0]['quantity'], 5)
report_values, docs, lines = self.get_report_forecast(
product_template_ids=self.product_template.ids,
context={'warehouse': wh_2.id},
)
draft_picking_qty = docs['draft_picking_qty']
self.assertEqual(len(lines), 1)
self.assertEqual(draft_picking_qty['out'], 0)
self.assertEqual(lines[0]['document_out'].id, delivery_2.id)
self.assertEqual(lines[0]['quantity'], 8)
def test_report_forecast_6_multi_company(self):
""" Create transfers for two different companies and check report
display the right transfers.
"""
# Configure second warehouse.
company_2 = self.env['res.company'].create({'name': 'Aperture Science'})
wh_2 = self.env['stock.warehouse'].search([('company_id', '=', company_2.id)])
wh_2_picking_type_in = wh_2.in_type_id
# Creates a receipt then checks draft picking quantities.
receipt_form = Form(self.env['stock.picking'].with_context(
force_detailed_view=True
), view='stock.view_picking_form')
receipt_form.partner_id = self.partner
receipt_form.picking_type_id = self.picking_type_in
wh_1_receipt = receipt_form.save()
with receipt_form.move_ids_without_package.new() as move_line:
move_line.product_id = self.product
move_line.product_uom_qty = 2
wh_1_receipt = receipt_form.save()
# Creates a receipt then checks draft picking quantities.
receipt_form = Form(self.env['stock.picking'].with_context(
force_detailed_view=True
), view='stock.view_picking_form')
receipt_form.partner_id = self.partner
receipt_form.picking_type_id = wh_2_picking_type_in
wh_2_receipt = receipt_form.save()
with receipt_form.move_ids_without_package.new() as move_line:
move_line.product_id = self.product
move_line.product_uom_qty = 5
wh_2_receipt = receipt_form.save()
report_values, docs, lines = self.get_report_forecast(product_template_ids=self.product_template.ids)
draft_picking_qty = docs['draft_picking_qty']
self.assertEqual(len(lines), 0, "Must have 0 line.")
self.assertEqual(draft_picking_qty['in'], 2)
self.assertEqual(draft_picking_qty['out'], 0)
report_values, docs, lines = self.get_report_forecast(
product_template_ids=self.product_template.ids,
context={'warehouse': wh_2.id},
)
draft_picking_qty = docs['draft_picking_qty']
self.assertEqual(len(lines), 0, "Must have 0 line.")
self.assertEqual(draft_picking_qty['in'], 5)
self.assertEqual(draft_picking_qty['out'], 0)
# Confirm the receipts -> The report must now have one line for each company.
wh_1_receipt.action_confirm()
wh_2_receipt.action_confirm()
report_values, docs, lines = self.get_report_forecast(product_template_ids=self.product_template.ids)
self.assertEqual(len(lines), 1, "Must have 1 line.")
self.assertEqual(lines[0]['document_in'].id, wh_1_receipt.id)
self.assertEqual(lines[0]['quantity'], 2)
report_values, docs, lines = self.get_report_forecast(
product_template_ids=self.product_template.ids,
context={'warehouse': wh_2.id},
)
self.assertEqual(len(lines), 1, "Must have 1 line.")
self.assertEqual(lines[0]['document_in'].id, wh_2_receipt.id)
self.assertEqual(lines[0]['quantity'], 5)
def test_report_forecast_7_multiple_variants(self):
""" Create receipts for different variant products and check the report
work well with them.Also, check the receipt/delivery lines are correctly
linked depending of their product variant.
"""
# Create some variant's attributes.
product_attr_color = self.env['product.attribute'].create({'name': 'Color'})
color_gray = self.env['product.attribute.value'].create({
'name': 'Old Fashioned Gray',
'attribute_id': product_attr_color.id,
})
color_blue = self.env['product.attribute.value'].create({
'name': 'Electric Blue',
'attribute_id': product_attr_color.id,
})
product_attr_size = self.env['product.attribute'].create({'name': 'size'})
size_pocket = self.env['product.attribute.value'].create({
'name': 'Pocket',
'attribute_id': product_attr_size.id,
})
size_xl = self.env['product.attribute.value'].create({
'name': 'XL',
'attribute_id': product_attr_size.id,
})
# Create a new product and set some variants on the product.
product_template = self.env['product.template'].create({
'name': 'Game Joy',
'type': 'product',
'attribute_line_ids': [
(0, 0, {
'attribute_id': product_attr_color.id,
'value_ids': [(6, 0, [color_gray.id, color_blue.id])]
}),
(0, 0, {
'attribute_id': product_attr_size.id,
'value_ids': [(6, 0, [size_pocket.id, size_xl.id])]
}),
],
})
gamejoy_pocket_gray = product_template.product_variant_ids[0]
gamejoy_xl_gray = product_template.product_variant_ids[1]
gamejoy_pocket_blue = product_template.product_variant_ids[2]
gamejoy_xl_blue = product_template.product_variant_ids[3]
# Create two receipts.
receipt_form = Form(self.env['stock.picking'].with_context(
force_detailed_view=True
), view='stock.view_picking_form')
receipt_form.partner_id = self.partner
receipt_form.picking_type_id = self.picking_type_in
with receipt_form.move_ids_without_package.new() as move_line:
move_line.product_id = gamejoy_pocket_gray
move_line.product_uom_qty = 8
with receipt_form.move_ids_without_package.new() as move_line:
move_line.product_id = gamejoy_pocket_blue
move_line.product_uom_qty = 4
receipt_1 = receipt_form.save()
receipt_1.action_confirm()
receipt_form = Form(self.env['stock.picking'].with_context(
force_detailed_view=True
), view='stock.view_picking_form')
receipt_form.partner_id = self.partner
receipt_form.picking_type_id = self.picking_type_in
with receipt_form.move_ids_without_package.new() as move_line:
move_line.product_id = gamejoy_pocket_gray
move_line.product_uom_qty = 2
with receipt_form.move_ids_without_package.new() as move_line:
move_line.product_id = gamejoy_xl_gray
move_line.product_uom_qty = 10
with receipt_form.move_ids_without_package.new() as move_line:
move_line.product_id = gamejoy_xl_blue
move_line.product_uom_qty = 12
receipt_2 = receipt_form.save()
receipt_2.action_confirm()
report_values, docs, lines = self.get_report_forecast(product_template_ids=product_template.ids)
self.assertEqual(len(lines), 5, "Must have 5 lines.")
self.assertEqual(docs['product_variants'].ids, product_template.product_variant_ids.ids)
# Create a delivery for one of these products and check the report lines
# are correctly linked to the good receipts.
delivery_form = Form(self.env['stock.picking'].with_context(
force_detailed_view=True
), view='stock.view_picking_form')
delivery_form.partner_id = self.partner
delivery_form.picking_type_id = self.picking_type_out
with delivery_form.move_ids_without_package.new() as move_line:
move_line.product_id = gamejoy_pocket_gray
move_line.product_uom_qty = 10
delivery = delivery_form.save()
delivery.action_confirm()
report_values, docs, lines = self.get_report_forecast(product_template_ids=product_template.ids)
self.assertEqual(len(lines), 5, "Still must have 5 lines.")
self.assertEqual(docs['product_variants'].ids, product_template.product_variant_ids.ids)
# First and second lines should be about the "Game Joy Pocket (gray)"
# and must link the delivery with the two receipt lines.
line_1 = lines[0]
line_2 = lines[1]
self.assertEqual(line_1['product']['id'], gamejoy_pocket_gray.id)
self.assertEqual(line_1['quantity'], 8)
self.assertTrue(line_1['replenishment_filled'])
self.assertEqual(line_1['document_in'].id, receipt_1.id)
self.assertEqual(line_1['document_out'].id, delivery.id)
self.assertEqual(line_2['product']['id'], gamejoy_pocket_gray.id)
self.assertEqual(line_2['quantity'], 2)
self.assertTrue(line_2['replenishment_filled'])
self.assertEqual(line_2['document_in'].id, receipt_2.id)
self.assertEqual(line_2['document_out'].id, delivery.id)
def test_report_forecast_8_delivery_to_receipt_link(self):
"""
Create 2 deliveries, and 1 receipt tied to the second delivery.
The report should show the source document as the 2nd delivery, and show the first
delivery completely unfilled.
"""
delivery_form = Form(self.env['stock.picking'].with_context(
force_detailed_view=True
), view='stock.view_picking_form')
delivery_form.partner_id = self.partner
delivery_form.picking_type_id = self.picking_type_out
with delivery_form.move_ids_without_package.new() as move_line:
move_line.product_id = self.product
move_line.product_uom_qty = 100
delivery = delivery_form.save()
delivery.action_confirm()
delivery_form = Form(self.env['stock.picking'].with_context(
force_detailed_view=True
), view='stock.view_picking_form')
delivery_form.partner_id = self.partner
delivery_form.picking_type_id = self.picking_type_out
with delivery_form.move_ids_without_package.new() as move_line:
move_line.product_id = self.product
move_line.product_uom_qty = 200
delivery2 = delivery_form.save()
delivery2.action_confirm()
receipt_form = Form(self.env['stock.picking'].with_context(
force_detailed_view=True
), view='stock.view_picking_form')
receipt_form.partner_id = self.partner
receipt_form.picking_type_id = self.picking_type_in
receipt = receipt_form.save()
with receipt_form.move_ids_without_package.new() as move_line:
move_line.product_id = self.product
move_line.product_uom_qty = 200
receipt = receipt_form.save()
receipt.move_lines[0].write({
'move_dest_ids': [(4, delivery2.move_lines[0].id)],
})
receipt.action_confirm()
self.env['base'].flush()
_, _, lines = self.get_report_forecast(product_template_ids=self.product_template.ids)
self.assertEqual(len(lines), 2, 'Only 2 lines')
delivery_line = [l for l in lines if l['document_out'].id == delivery.id][0]
self.assertTrue(delivery_line, 'No line for delivery 1')
self.assertFalse(delivery_line['replenishment_filled'])
delivery2_line = [l for l in lines if l['document_out'].id == delivery2.id][0]
self.assertTrue(delivery2_line, 'No line for delivery 2')
self.assertTrue(delivery2_line['replenishment_filled'])
def test_report_forecast_9_delivery_to_receipt_link_over_received(self):
"""
Create 2 deliveries, and 1 receipt tied to the second delivery.
Set the quantity on the receipt to be enough for BOTH deliveries.
For example, this can happen if they have manually increased the quantity on the generated PO.
The report should show both deliveries fulfilled.
"""
delivery_form = Form(self.env['stock.picking'].with_context(
force_detailed_view=True
), view='stock.view_picking_form')
delivery_form.partner_id = self.partner
delivery_form.picking_type_id = self.picking_type_out
with delivery_form.move_ids_without_package.new() as move_line:
move_line.product_id = self.product
move_line.product_uom_qty = 100
delivery = delivery_form.save()
delivery.action_confirm()
delivery_form = Form(self.env['stock.picking'].with_context(
force_detailed_view=True
), view='stock.view_picking_form')
delivery_form.partner_id = self.partner
delivery_form.picking_type_id = self.picking_type_out
with delivery_form.move_ids_without_package.new() as move_line:
move_line.product_id = self.product
move_line.product_uom_qty = 200
delivery2 = delivery_form.save()
delivery2.action_confirm()
receipt_form = Form(self.env['stock.picking'].with_context(
force_detailed_view=True
), view='stock.view_picking_form')
receipt_form.partner_id = self.partner
receipt_form.picking_type_id = self.picking_type_in
receipt = receipt_form.save()
with receipt_form.move_ids_without_package.new() as move_line:
move_line.product_id = self.product
move_line.product_uom_qty = 300
receipt = receipt_form.save()
receipt.move_lines[0].write({
'move_dest_ids': [(4, delivery2.move_lines[0].id)],
})
receipt.action_confirm()
self.env['base'].flush()
_, _, lines = self.get_report_forecast(product_template_ids=self.product_template.ids)
self.assertEqual(len(lines), 2, 'Only 2 lines')
delivery_line = [l for l in lines if l['document_out'].id == delivery.id][0]
self.assertTrue(delivery_line, 'No line for delivery 1')
self.assertTrue(delivery_line['replenishment_filled'])
delivery2_line = [l for l in lines if l['document_out'].id == delivery2.id][0]
self.assertTrue(delivery2_line, 'No line for delivery 2')
self.assertTrue(delivery2_line['replenishment_filled'])
|