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
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
|
# -*- coding: utf-8 -*-
##############################################################################
#
# Copyright (C) 2011 MSF, TeMPO Consulting
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
import tools
from datetime import datetime, timedelta, date
from dateutil.relativedelta import relativedelta, relativedelta
from osv import osv, fields
from osv.orm import browse_record, browse_null
from tools.translate import _
import decimal_precision as dp
import netsvc
import pooler
import time
from mx import DateTime
# warning messages
SHORT_SHELF_LIFE_MESS = 'Product with Short Shelf Life, check the accuracy of the order quantity, frequency and mode of transport.'
class sale_order_line(osv.osv):
'''
override to add message at sale order creation and update
'''
_inherit = 'sale.order.line'
def _kc_dg(self, cr, uid, ids, name, arg, context=None):
'''
return 'KC' if cold chain or 'DG' if dangerous goods
'''
result = {}
for id in ids:
result[id] = ''
for sol in self.browse(cr, uid, ids, context=context):
if sol.product_id:
if sol.product_id.heat_sensitive_item:
result[sol.id] = 'KC'
elif sol.product_id.dangerous_goods:
result[sol.id] = 'DG'
return result
_columns = {'kc_dg': fields.function(_kc_dg, method=True, string='KC/DG', type='char'),}
def product_id_change(self, cr, uid, ids, pricelist, product, qty=0,
uom=False, qty_uos=0, uos=False, name='', partner_id=False,
lang=False, update_tax=True, date_order=False, packaging=False, fiscal_position=False, flag=False):
'''
if the product is short shelf life we display a warning
'''
# call to super
result = super(sale_order_line, self).product_id_change(cr, uid, ids, pricelist, product, qty,
uom, qty_uos, uos, name, partner_id, lang, update_tax, date_order, packaging, fiscal_position, flag)
# if the product is short shelf life, display a warning
if product:
prod_obj = self.pool.get('product.product')
if prod_obj.browse(cr, uid, product).short_shelf_life:
warning = {
'title': 'Short Shelf Life product',
'message': _(SHORT_SHELF_LIFE_MESS)
}
result.update(warning=warning)
return result
sale_order_line()
class sale_order(osv.osv):
'''
add message when so is written, i.e when we add new so lines
'''
_inherit = 'sale.order'
def write(self, cr, uid, ids, vals, context=None):
'''
display message if contains short shelf life
'''
if isinstance(ids, (int, long)):
ids = [ids]
for obj in self.browse(cr, uid, ids, context=context):
for line in obj.order_line:
# log the message
if line.product_id.short_shelf_life:
# log the message
self.log(cr, uid, obj.id, _(SHORT_SHELF_LIFE_MESS))
return super(sale_order, self).write(cr, uid, ids, vals, context=context)
sale_order()
class purchase_order_line(osv.osv):
'''
override to add message at purchase order creation and update
'''
_inherit = 'purchase.order.line'
def _kc_dg(self, cr, uid, ids, name, arg, context=None):
'''
return 'KC' if cold chain or 'DG' if dangerous goods
'''
result = {}
for id in ids:
result[id] = ''
for pol in self.browse(cr, uid, ids, context=context):
if pol.product_id:
if pol.product_id.heat_sensitive_item:
result[pol.id] = 'KC'
elif pol.product_id.dangerous_goods:
result[pol.id] = 'DG'
return result
_columns = {'kc_dg': fields.function(_kc_dg, method=True, string='KC/DG', type='char'),}
def product_id_change(self, cr, uid, ids, pricelist, product, qty, uom,
partner_id, date_order=False, fiscal_position=False, date_planned=False,
name=False, price_unit=False, notes=False):
'''
if the product is short shelf life we display a warning
'''
# call to super
result = super(purchase_order_line, self).product_id_change(cr, uid, ids, pricelist, product, qty, uom,
partner_id, date_order, fiscal_position, date_planned,
name, price_unit, notes)
# if the product is short shelf life, display a warning
if product:
prod_obj = self.pool.get('product.product')
if prod_obj.browse(cr, uid, product).short_shelf_life:
warning = {
'title': 'Short Shelf Life product',
'message': _(SHORT_SHELF_LIFE_MESS)
}
result.update(warning=warning)
return result
purchase_order_line()
class purchase_order(osv.osv):
'''
add message when po is written, i.e when we add new po lines
no need to modify the wkf_confirm_order as the wrtie method is called during the workflow
'''
_inherit = 'purchase.order'
def write(self, cr, uid, ids, vals, context=None):
'''
display message if contains short shelf life
'''
if isinstance(ids, (int, long)):
ids = [ids]
for obj in self.browse(cr, uid, ids, context=context):
for line in obj.order_line:
# log the message
if line.product_id.short_shelf_life:
# log the message
self.log(cr, uid, obj.id, _(SHORT_SHELF_LIFE_MESS))
return super(purchase_order, self).write(cr, uid, ids, vals, context=context)
purchase_order()
class stock_warehouse_orderpoint(osv.osv):
'''
add message
'''
_inherit = 'stock.warehouse.orderpoint'
def create(self, cr, uid, vals, context=None):
'''
add message
'''
new_id = super(stock_warehouse_orderpoint, self).create(cr, uid, vals, context=context)
product_obj = self.pool.get('product.product')
product_id = vals.get('product_id', False)
if product_id:
if product_obj.browse(cr, uid, product_id, context=context).short_shelf_life:
self.log(cr, uid, new_id, _(SHORT_SHELF_LIFE_MESS))
return new_id
def write(self, cr, uid, ids, vals, context=None):
'''
add message
'''
result = super(stock_warehouse_orderpoint, self).write(cr, uid, ids, vals, context=context)
if isinstance(ids, (int, long)):
ids = [ids]
product_obj = self.pool.get('product.product')
product_id = vals.get('product_id', False)
if product_id:
if product_obj.browse(cr, uid, product_id, context=context).short_shelf_life:
for obj in self.browse(cr, uid, ids, context=context):
self.log(cr, uid, obj.id, _(SHORT_SHELF_LIFE_MESS))
return result
stock_warehouse_orderpoint()
class stock_warehouse_automatic_supply(osv.osv):
'''
add message
'''
_inherit = 'stock.warehouse.automatic.supply'
def create(self, cr, uid, vals, context=None):
'''
add message
'''
new_id = super(stock_warehouse_automatic_supply, self).create(cr, uid, vals, context=context)
product_obj = self.pool.get('product.product')
product_id = vals.get('product_id', False)
if product_id:
if product_obj.browse(cr, uid, product_id, context=context).short_shelf_life:
self.log(cr, uid, new_id, _(SHORT_SHELF_LIFE_MESS))
return new_id
def write(self, cr, uid, ids, vals, context=None):
'''
add message
'''
result = super(stock_warehouse_automatic_supply, self).write(cr, uid, ids, vals, context=context)
if isinstance(ids, (int, long)):
ids = [ids]
product_obj = self.pool.get('product.product')
product_id = vals.get('product_id', False)
if product_id:
if product_obj.browse(cr, uid, product_id, context=context).short_shelf_life:
for obj in self.browse(cr, uid, ids, context=context):
self.log(cr, uid, obj.id, _(SHORT_SHELF_LIFE_MESS))
return result
stock_warehouse_automatic_supply()
class stock_warehouse_order_cycle(osv.osv):
'''
add message
'''
_inherit = 'stock.warehouse.order.cycle'
def create(self, cr, uid, vals, context=None):
'''
add message
'''
new_id = super(stock_warehouse_order_cycle, self).create(cr, uid, vals, context=context)
product_obj = self.pool.get('product.product')
product_id = vals.get('product_id', False)
if product_id:
if product_obj.browse(cr, uid, product_id, context=context).short_shelf_life:
self.log(cr, uid, new_id, _(SHORT_SHELF_LIFE_MESS))
return new_id
def write(self, cr, uid, ids, vals, context=None):
'''
add message
'''
if context is None:
context = {}
result = super(stock_warehouse_order_cycle, self).write(cr, uid, ids, vals, context=context)
if isinstance(ids, (int, long)):
ids = [ids]
product_obj = self.pool.get('product.product')
product_id = vals.get('product_id', False)
if product_id:
if product_obj.browse(cr, uid, product_id, context=context).short_shelf_life:
for obj in self.browse(cr, uid, ids, context=context):
self.log(cr, uid, obj.id, _(SHORT_SHELF_LIFE_MESS))
return result
stock_warehouse_order_cycle()
class stock_picking(osv.osv):
'''
modify hook function
'''
_inherit = 'stock.picking'
def _do_partial_hook(self, cr, uid, ids, context, *args, **kwargs):
'''
hook to update defaults data
'''
# variable parameters
move = kwargs.get('move')
assert move, 'missing move'
partial_datas = kwargs.get('partial_datas')
assert partial_datas, 'missing partial_datas'
# calling super method
defaults = super(stock_picking, self)._do_partial_hook(cr, uid, ids, context, *args, **kwargs)
assetId = partial_datas.get('move%s'%(move.id), False).get('asset_id')
if assetId:
defaults.update({'asset_id': assetId})
return defaults
_columns = {}
stock_picking()
class stock_move(osv.osv):
'''
add kc/dg
'''
_inherit = 'stock.move'
def create(self, cr, uid, vals, context=None):
'''
complete info normally generated by javascript on_change function
'''
prod_obj = self.pool.get('product.product')
if vals.get('product_id', False):
# complete hidden flags - needed if not created from GUI
product = prod_obj.browse(cr, uid, vals.get('product_id'), context=context)
if product.batch_management:
vals.update(hidden_batch_management_mandatory=True)
elif product.perishable:
vals.update(hidden_perishable_mandatory=True)
else:
vals.update(hidden_batch_management_mandatory=False,
hidden_perishable_mandatory=False,
)
# call super
result = super(stock_move, self).create(cr, uid, vals, context=context)
return result
def write(self, cr, uid, ids, vals, context=None):
'''
complete info normally generated by javascript on_change function
'''
prod_obj = self.pool.get('product.product')
if vals.get('product_id', False):
# complete hidden flags - needed if not created from GUI
product = prod_obj.browse(cr, uid, vals.get('product_id'), context=context)
if product.batch_management:
vals.update(hidden_batch_management_mandatory=True)
elif product.perishable:
vals.update(hidden_perishable_mandatory=True)
else:
vals.update(hidden_batch_management_mandatory=False,
hidden_perishable_mandatory=False,
)
# call super
result = super(stock_move, self).write(cr, uid, ids, vals, context=context)
return result
def _kc_dg(self, cr, uid, ids, name, arg, context=None):
'''
return 'KC' if cold chain or 'DG' if dangerous goods
'''
result = {}
for id in ids:
result[id] = ''
for move in self.browse(cr, uid, ids, context=context):
if move.product_id:
if move.product_id.heat_sensitive_item:
result[move.id] = 'KC'
elif move.product_id.dangerous_goods:
result[move.id] = 'DG'
return result
def _check_batch_management(self, cr, uid, ids, context=None):
"""
check for batch management
@return: True or False
"""
for move in self.browse(cr, uid, ids, context=context):
if move.state == 'done':
if move.product_id.batch_management:
if not move.prodlot_id and move.product_qty:
return False
return True
def _check_perishable(self, cr, uid, ids, context=None):
"""
check for perishable
@return: True or False
"""
for move in self.browse(cr, uid, ids, context=context):
if move.state == 'done':
if move.product_id.perishable:
if not move.prodlot_id and move.product_qty:
return False
return True
def _check_prodlot_need(self, cr, uid, ids, context=None):
"""
If the move has a prodlot but does not need one, return False.
"""
for move in self.browse(cr, uid, ids, context=context):
if move.prodlot_id:
if not move.product_id.perishable and not move.product_id.batch_management:
return False
return True
def _check_prodlot_need_batch_management(self, cr, uid, ids, context=None):
"""
If the product is batch management while the selected prodlot is 'internal'.
"""
for move in self.browse(cr, uid, ids, context=context):
if move.prodlot_id:
if move.prodlot_id.type == 'internal' and move.product_id.batch_management:
return False
return True
def _check_prodlot_need_perishable(self, cr, uid, ids, context=None):
"""
If the product is perishable ONLY while the selected prodlot is 'standard'.
"""
for move in self.browse(cr, uid, ids, context=context):
if move.prodlot_id:
if move.prodlot_id.type == 'standard' and not move.product_id.batch_management and move.product_id.perishable:
return False
return True
def onchange_product_id(self, cr, uid, ids, prod_id=False, loc_id=False, loc_dest_id=False, address_id=False):
'''
the product changes, set the hidden flag if necessary
'''
result = super(stock_move, self).onchange_product_id(cr, uid, ids, prod_id, loc_id,
loc_dest_id, address_id)
# product changes, prodlot is always cleared
result.setdefault('value', {})['prodlot_id'] = False
# reset the hidden flag
result.setdefault('value', {})['hidden_batch_management_mandatory'] = False
result.setdefault('value', {})['hidden_perishable_mandatory'] = False
if prod_id:
product = self.pool.get('product.product').browse(cr, uid, prod_id)
if product.batch_management:
result.setdefault('value', {})['hidden_batch_management_mandatory'] = True
result['warning'] = {'title': _('Info'),
'message': _('The selected product is Batch Management.')}
elif product.perishable:
result.setdefault('value', {})['hidden_perishable_mandatory'] = True
result['warning'] = {'title': _('Info'),
'message': _('The selected product is Perishable.')}
# quantities are set to False
result.setdefault('value', {}).update({'product_qty': 0.00,
'product_uos_qty': 0.00,
})
return result
def _get_checks_all(self, cr, uid, ids, name, arg, context=None):
'''
function for KC/SSL/DG/NP products
'''
result = {}
for id in ids:
result[id] = {}
for f in name:
result[id].update({f: False})
for obj in self.browse(cr, uid, ids, context=context):
# keep cool
if obj.product_id.heat_sensitive_item:
result[obj.id]['kc_check'] = True
# ssl
if obj.product_id.short_shelf_life:
result[obj.id]['ssl_check'] = True
# dangerous goods
if obj.product_id.dangerous_goods:
result[obj.id]['dg_check'] = True
# narcotic
if obj.product_id.narcotic:
result[obj.id]['np_check'] = True
return result
def _check_tracking(self, cr, uid, ids, context=None):
""" Checks if production lot is assigned to stock move or not.
@return: True or False
"""
for move in self.browse(cr, uid, ids, context=context):
if not move.prodlot_id and move.product_qty and \
(move.state == 'done' and \
( \
(move.product_id.track_production and move.location_id.usage == 'production') or \
(move.product_id.track_production and move.location_dest_id.usage == 'production') or \
(move.product_id.track_incoming and move.location_id.usage == 'supplier') or \
(move.product_id.track_outgoing and move.location_dest_id.usage == 'customer') \
)):
return False
return True
_columns = {
'kc_dg': fields.function(_kc_dg, method=True, string='KC/DG', type='char'),
# if prodlot needs to be mandatory, add 'required': ['|', ('hidden_batch_management_mandatory','=',True), ('hidden_perishable_mandatory','=',True)] in attrs
'hidden_batch_management_mandatory': fields.boolean(string='Hidden Flag for Batch Management product',),
'hidden_perishable_mandatory': fields.boolean(string='Hidden Flag for Perishable product',),
'kc_check': fields.function(_get_checks_all, method=True, string='KC', type='boolean', readonly=True, multi="m"),
'ssl_check': fields.function(_get_checks_all, method=True, string='SSL', type='boolean', readonly=True, multi="m"),
'dg_check': fields.function(_get_checks_all, method=True, string='DG', type='boolean', readonly=True, multi="m"),
'np_check': fields.function(_get_checks_all, method=True, string='NP', type='boolean', readonly=True, multi="m"),
'prodlot_id': fields.many2one('stock.production.lot', 'Batch', states={'done': [('readonly', True)]}, help="Batch number is used to put a serial number on the production", select=True),
}
_constraints = [(_check_batch_management,
'You must assign a Batch Number for this product (Batch Number Mandatory)',
['prodlot_id']),
(_check_perishable,
'You must assign an Expiry Date for this product (Expiry Date Mandatory)',
['prodlot_id']),
(_check_prodlot_need,
'The selected product is neither Batch Number Mandatory nor Expiry Date Mandatory',
['prodlot_id']),
(_check_prodlot_need_batch_management,
'The selected product is Batch Number Mandatory while the selected Batch number corresponds to Expiry Date Mandatory.',
['prodlot_id']),
(_check_prodlot_need_perishable,
'The selected product is Expiry Date Mandatory while the selected Batch number corresponds to Batch Number Mandatory.',
['prodlot_id']),
(_check_tracking,
'You must assign a batch number for this product',
['prodlot_id']),
]
stock_move()
class stock_production_lot(osv.osv):
'''
productin lot modifications
'''
_inherit = 'stock.production.lot'
def fields_view_get(self, cr, uid, view_id=None, view_type='form', context=None, toolbar=False, submenu=False):
"""
Correct fields in order to have those from account_statement_from_invoice_lines (in case where account_statement_from_invoice is used)
"""
if context is None:
context = {}
# warehouse wizards or inventory screen
if view_type == 'tree' and ((context.get('expiry_date_check', False) and not context.get('batch_number_check', False)) or context.get('hidden_perishable_mandatory')):
view = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'specific_rules', 'view_production_lot_expiry_date_tree')
if view:
view_id = view[1]
result = super(osv.osv, self).fields_view_get(cr, uid, view_id, view_type, context=context, toolbar=toolbar, submenu=submenu)
return result
def copy(self, cr, uid, id, default=None, context=None):
'''
increase the batch number
create a new sequence
'''
if default is None:
default = {}
# original reference
lot_name = self.read(cr, uid, id, ['name'])['name']
default.update(name='%s (copy)'%lot_name, date=time.strftime('%Y-%m-%d'))
return super(stock_production_lot, self).copy(cr, uid, id, default, context=context)
def copy_data(self, cr, uid, id, default=None, context=None):
'''
clear the revisions
'''
if default is None:
default = {}
default.update(revisions=[])
return super(stock_production_lot, self).copy_data(cr, uid, id, default, context=context)
def create_sequence(self, cr, uid, vals, context=None):
"""
Create new entry sequence for every new order
@param cr: cursor to database
@param user: id of current user
@param ids: list of record ids to be process
@param context: context arguments, like lang, time zone
@return: return a result
"""
seq_pool = self.pool.get('ir.sequence')
seq_typ_pool = self.pool.get('ir.sequence.type')
name = 'Batch number'
code = 'stock.production.lot'
types = {
'name': name,
'code': code
}
seq_typ_pool.create(cr, uid, types)
seq = {
'name': name,
'code': code,
'prefix': '',
'padding': 0,
}
return seq_pool.create(cr, uid, seq)
def create(self, cr, uid, vals, context=None):
'''
create the sequence for the version management
'''
if context is None:
context = {}
sequence = self.create_sequence(cr, uid, vals, context=context)
vals.update({'sequence_id': sequence,})
if context.get('update_mode') in ['init', 'update']:
if not vals.get('life_date'):
# default value to today
vals.update(life_date=time.strftime('%Y-%m-%d'))
return super(stock_production_lot, self).create(cr, uid, vals, context=context)
def write(self, cr, uid, ids, vals, context=None):
'''
update the sequence for the version management
'''
if isinstance(ids, (int, long)):
ids = [ids]
revision_obj = self.pool.get('stock.production.lot.revision')
for lot in self.browse(cr, uid, ids, context=context):
# create revision object for each lot
version_number = lot.sequence_id.get_id(test='id', context=context)
values = {'name': 'Auto Revision Logging',
'description': 'The batch number has been modified, this revision log has been created automatically.',
'date': time.strftime('%Y-%m-%d'),
'indice': version_number,
'author_id': uid,
'lot_id': lot.id,}
revision_obj.create(cr, uid, values, context=context)
return super(stock_production_lot, self).write(cr, uid, ids, vals, context=context)
def remove_flag(self, flag, _list):
'''
if we do not remove the flag, we fall into an infinite loop
'''
args2 = []
for arg in _list:
if arg[0] != flag:
args2.append(arg)
return args2
def search_check_type(self, cr, uid, obj, name, args, context=None):
'''
modify the query to take the type of prodlot into account according to product's attributes
'Batch Number mandatory' and 'Expiry Date Mandatory'
if batch management: display only 'standard' lot
if expiry and not batch management: display only 'internal' lot
else: display normally
'''
product_obj = self.pool.get('product.product')
product_id = context.get('product_id', False)
# remove flag avoid infinite loop
args = self.remove_flag('check_type', args)
if not product_id:
return args
# check the product
product = product_obj.browse(cr, uid, product_id, context=context)
if product.batch_management:
# standard lots
args.append(('type', '=', 'standard'))
elif product.perishable:
# internal lots
args.append(('type', '=', 'internal'))
return args
def _get_false(self, cr, uid, ids, field_name, arg, context=None):
'''
return false for each id
'''
if isinstance(ids,(long, int)):
ids = [ids]
result = {}
for id in ids:
result[id] = False
return result
def _stock_search_virtual(self, cr, uid, obj, name, args, context=None):
""" Searches Ids of products
@return: Ids of locations
"""
if context is None:
context = {}
# when the location_id = False results now in showing stock for all internal locations
# *previously*, was showing the location of no location (= 0.0 for all prodlot)
if 'location_id' not in context or not context['location_id']:
locations = self.pool.get('stock.location').search(cr, uid, [('usage', '=', 'internal')], context=context)
else:
locations = context['location_id'] and [context['location_id']] or []
ids = [('id', 'in', [])]
if locations:
cr.execute('''select
prodlot_id,
sum(qty)
from
stock_report_prodlots_virtual
where
location_id IN %s group by prodlot_id
having sum(qty) '''+ str(args[0][1]) + str(args[0][2]),(tuple(locations),))
res = cr.fetchall()
ids = [('id', 'in', map(lambda x: x[0], res))]
return ids
def _stock_search(self, cr, uid, obj, name, args, context=None):
'''
call super method, as fields.function does not work with inheritance
'''
return super(stock_production_lot, self)._stock_search(cr, uid, obj, name, args, context=context)
def _get_stock_virtual(self, cr, uid, ids, field_name, arg, context=None):
""" Gets stock of products for locations
@return: Dictionary of values
"""
if context is None:
context = {}
# when the location_id = False results now in showing stock for all internal locations
# *previously*, was showing the location of no location (= 0.0 for all prodlot)
if 'location_id' not in context or not context['location_id']:
locations = self.pool.get('stock.location').search(cr, uid, [('usage', '=', 'internal')], context=context)
else:
locations = context['location_id'] and [context['location_id']] or []
if isinstance(ids, (int, long)):
ids = [ids]
res = {}.fromkeys(ids, 0.0)
if locations:
cr.execute('''select
prodlot_id,
sum(qty)
from
stock_report_prodlots_virtual
where
location_id IN %s and prodlot_id IN %s group by prodlot_id''',(tuple(locations),tuple(ids),))
res.update(dict(cr.fetchall()))
return res
def _get_stock(self, cr, uid, ids, field_name, arg, context=None):
'''
call super method, as fields.function does not work with inheritance
'''
return super(stock_production_lot, self)._get_stock(cr, uid, ids, field_name, arg, context=context)
def _get_checks_all(self, cr, uid, ids, name, arg, context=None):
'''
function for KC/SSL/DG/NP products
'''
result = {}
for id in ids:
result[id] = {}
for f in name:
result[id].update({f: False})
for obj in self.browse(cr, uid, ids, context=context):
# keep cool
if obj.product_id.heat_sensitive_item:
result[obj.id]['kc_check'] = True
# ssl
if obj.product_id.short_shelf_life:
result[obj.id]['ssl_check'] = True
# dangerous goods
if obj.product_id.dangerous_goods:
result[obj.id]['dg_check'] = True
# narcotic
if obj.product_id.narcotic:
result[obj.id]['np_check'] = True
return result
_columns = {'check_type': fields.function(_get_false, fnct_search=search_check_type, string='Check Type', type="boolean", readonly=True, method=True),
'type': fields.selection([('standard', 'Standard'),('internal', 'Internal'),], string="Type"),
#'expiry_date': fields.date('Expiry Date'),
'name': fields.char('Batch Number', size=1024, required=True, help="Unique batch number, will be displayed as: PREFIX/SERIAL [INT_REF]"),
'date': fields.datetime('Auto Creation Date', required=True),
'sequence_id': fields.many2one('ir.sequence', 'Batch Sequence', required=True,),
'stock_virtual': fields.function(_get_stock_virtual, method=True, type="float", string="Available Stock", select=True,
help="Current available quantity of products with this Batch Numbre Number in company warehouses",
digits_compute=dp.get_precision('Product UoM'), readonly=True,
fnct_search=_stock_search_virtual,),
'stock_available': fields.function(_get_stock, fnct_search=_stock_search, method=True, type="float", string="Real Stock", select=True,
help="Current real quantity of products with this Batch Number in company warehouses",
digits_compute=dp.get_precision('Product UoM')),
'kc_check': fields.function(_get_checks_all, method=True, string='KC', type='boolean', readonly=True, multi="m"),
'ssl_check': fields.function(_get_checks_all, method=True, string='SSL', type='boolean', readonly=True, multi="m"),
'dg_check': fields.function(_get_checks_all, method=True, string='DG', type='boolean', readonly=True, multi="m"),
'np_check': fields.function(_get_checks_all, method=True, string='NP', type='boolean', readonly=True, multi="m"),
}
_defaults = {'type': 'standard',
'company_id': lambda s,cr,uid,c: s.pool.get('res.company')._company_default_get(cr, uid, 'stock.production.lot', context=c),
'name': False,
'life_date': False,
}
_sql_constraints = [('name_uniq', 'unique (name)', 'The Batch Number must be unique !'),
]
def search(self, cr, uid, args=[], offset=0, limit=None, order=None, context=None, count=False):
'''
search function of production lot
'''
result = super(stock_production_lot, self).search(cr, uid, args=args, offset=offset, limit=limit, order=order, context=context, count=count)
return result
def name_get(self, cr, uid, ids, context=None):
if not ids:
return []
if context is None:
context = {}
reads = self.read(cr, uid, ids, ['name', 'prefix', 'ref', 'life_date'], context)
res = []
# TODO replace by _get_format in uf-651
if context.get('with_expiry'):
user_obj = self.pool.get('res.users')
lang_obj = self.pool.get('res.lang')
user_lang = user_obj.read(cr, uid, uid, ['context_lang'], context=context)['context_lang']
lang_id = lang_obj.search(cr, uid, [('code','=',user_lang)])
date_format = lang_id and lang_obj.read(cr, uid, lang_id[0], ['date_format'], context=context)['date_format'] or '%m/%d/%Y'
for record in reads:
if context.get('with_expiry') and record['life_date']:
name = '%s - %s'%(record['name'], DateTime.strptime(record['life_date'],'%Y-%m-%d').strftime(date_format))
else:
name = record['name']
res.append((record['id'], name))
return res
stock_production_lot()
class stock_location(osv.osv):
'''
override stock location to add:
- stock_real
- stock_virtual
'''
_inherit = 'stock.location'
def replace_field_key(self, fieldsDic, search, replace):
'''
will replace 'stock_real' by 'stock_real_specific'
and 'stock_virtual' by 'stock_virtual_specific'
and return a new dictionary
'''
return dict((replace if key == search else key, (self.replace_field_key(value, search, replace) if isinstance(value, dict) else value)) for key, value in fieldsDic.items())
def _product_value_specific_rules(self, cr, uid, ids, field_names, arg, context=None):
'''
add two fields for custom stock computation, if no product selected, both stock are set to 0.0
'''
if context is None:
context = {}
# initialize data
result = {}
for id in ids:
result[id] = {}
for f in field_names:
result[id].update({f: False,})
# if product is set to False, it does not make sense to return a stock value, return False for each location
if 'product_id' in context and not context['product_id']:
return result
result = super(stock_location, self)._product_value(cr, uid, ids, ['stock_real', 'stock_virtual'], arg, context=context)
# replace stock real
result = self.replace_field_key(result, 'stock_real', 'stock_real_specific')
# replace stock virtual
result = self.replace_field_key(result, 'stock_virtual', 'stock_virtual_specific')
return result
def fields_view_get(self, cr, uid, view_id=None, view_type='form', context=None, toolbar=False, submenu=False):
"""
display the modified stock values (stock_real_specific, stock_virtual_specific) if needed
"""
if context is None:
context = {}
# warehouse wizards or inventory screen
if view_type == 'tree' and context.get('specific_rules_tree_view', False):
view = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'specific_rules', 'view_location_tree2')
if view:
view_id = view[1]
result = super(osv.osv, self).fields_view_get(cr, uid, view_id, view_type, context=context, toolbar=toolbar, submenu=submenu)
return result
_columns = {'stock_real_specific': fields.function(_product_value_specific_rules, method=True, type='float', string='Real Stock', multi="get_vals_specific_rules"),
'stock_virtual_specific': fields.function(_product_value_specific_rules, method=True, type='float', string='Virtual Stock', multi="get_vals_specific_rules"),
}
stock_location()
class stock_production_lot_revision(osv.osv):
_inherit = 'stock.production.lot.revision'
_order = 'indice desc'
stock_production_lot_revision()
class stock_inventory(osv.osv):
'''
override the action_confirm to create the production lot if needed
'''
_inherit = 'stock.inventory'
def action_confirm(self, cr, uid, ids, context=None):
'''
if the line is perishable without prodlot, we create the prodlot
'''
prodlot_obj = self.pool.get('stock.production.lot')
# treat the needed production lot
for obj in self.browse(cr, uid, ids, context=context):
for line in obj.inventory_line_id:
# if perishable product
if line.hidden_perishable_mandatory and not line.hidden_batch_management_mandatory:
# integrity test
assert line.product_id.perishable, 'product is not perishable but line is'
assert line.expiry_date, 'expiry date is not set'
# if no production lot, we create a new one
if not line.prod_lot_id:
# double check to find the corresponding prodlot
prodlot_ids = prodlot_obj.search(cr, uid, [('life_date', '=', line.expiry_date),
('type', '=', 'internal'),
('product_id', '=', line.product_id.id)], context=context)
# no prodlot, create a new one
if not prodlot_ids:
vals = {'product_id': line.product_id.id,
'life_date': line.expiry_date,
'name': self.pool.get('ir.sequence').get(cr, uid, 'stock.lot.serial'),
'type': 'internal',
}
prodlot_id = prodlot_obj.create(cr, uid, vals, context=context)
else:
prodlot_id = prodlot_ids[0]
# update the line
line.write({'prod_lot_id': prodlot_id,},)
# super function after production lot creation - production lot are therefore taken into account at stock move creation
result = super(stock_inventory, self).action_confirm(cr, uid, ids, context=context)
return result
stock_inventory()
class stock_inventory_line(osv.osv):
'''
add mandatory or readonly behavior to prodlot
'''
_inherit = 'stock.inventory.line'
def common_on_change(self, cr, uid, ids, location_id, product, prod_lot_id, uom=False, to_date=False, result=None):
'''
commmon qty computation
'''
if result is None:
result = {}
if not product:
return result
product_obj = self.pool.get('product.product').browse(cr, uid, product)
uom = uom or product_obj.uom_id.id
stock_context = {'uom': uom, 'to_date': to_date,
'prodlot_id':prod_lot_id,}
if location_id:
# if a location is specified, we do not list the children locations, otherwise yes
stock_context.update({'compute_child': False,})
amount = self.pool.get('stock.location')._product_get(cr, uid, location_id, [product], stock_context)[product]
result.setdefault('value', {}).update({'product_qty': amount, 'product_uom': uom})
return result
def change_lot(self, cr, uid, ids, location_id, product, prod_lot_id, uom=False, to_date=False,):
'''
prod lot changes, update the expiry date
'''
prodlot_obj = self.pool.get('stock.production.lot')
result = {'value':{}}
# reset expiry date or fill it
if prod_lot_id:
result['value'].update(expiry_date=prodlot_obj.browse(cr, uid, prod_lot_id).life_date)
else:
result['value'].update(expiry_date=False)
# compute qty
result = self.common_on_change(cr, uid, ids, location_id, product, prod_lot_id, uom, to_date, result=result)
return result
def change_expiry(self, cr, uid, id, expiry_date, product_id, type_check, context=None):
'''
expiry date changes, find the corresponding internal prod lot
'''
prodlot_obj = self.pool.get('stock.production.lot')
result = {'value':{}}
if expiry_date and product_id:
prod_ids = prodlot_obj.search(cr, uid, [('life_date', '=', expiry_date),
('type', '=', 'internal'),
('product_id', '=', product_id)], context=context)
if not prod_ids:
if type_check == 'in':
# the corresponding production lot will be created afterwards
result['warning'] = {'title': _('Info'),
'message': _('The selected Expiry Date does not exist in the system. It will be created during validation process.')}
# clear prod lot
result['value'].update(prod_lot_id=False)
else:
# display warning
result['warning'] = {'title': _('Error'),
'message': _('The selected Expiry Date does not exist in the system.')}
# clear date
result['value'].update(expiry_date=False, prod_lot_id=False)
else:
# return first prodlot
result['value'].update(prod_lot_id=prod_ids[0])
else:
# clear expiry date, we clear production lot
result['value'].update(prod_lot_id=False,
expiry_date=False,
)
return result
def on_change_location_id(self, cr, uid, ids, location_id, product, prod_lot_id, uom=False, to_date=False,):
""" Changes UoM and name if product_id changes.
@param location_id: Location id
@param product: Changed product_id
@param uom: UoM product
@return: Dictionary of changed values
"""
result = {}
if not product:
# do nothing
result.setdefault('value', {}).update({'product_qty': 0.0,})
return result
# compute qty
result = self.common_on_change(cr, uid, ids, location_id, product, prod_lot_id, uom, to_date, result=result)
return result
def on_change_product_id_specific_rules(self, cr, uid, ids, location_id, product, prod_lot_id, uom=False, to_date=False,):
'''
the product changes, set the hidden flag if necessary
'''
result = super(stock_inventory_line, self).on_change_product_id(cr, uid, ids, location_id, product, uom, to_date)
# product changes, prodlot is always cleared
result.setdefault('value', {})['prod_lot_id'] = False
result.setdefault('value', {})['expiry_date'] = False
# reset the hidden flags
result.setdefault('value', {})['hidden_batch_management_mandatory'] = False
result.setdefault('value', {})['hidden_perishable_mandatory'] = False
if product:
product_obj = self.pool.get('product.product').browse(cr, uid, product)
if product_obj.batch_management:
result.setdefault('value', {})['hidden_batch_management_mandatory'] = True
elif product_obj.perishable:
result.setdefault('value', {})['hidden_perishable_mandatory'] = True
# if not product, result is 0.0 by super
# compute qty
result = self.common_on_change(cr, uid, ids, location_id, product, prod_lot_id, uom, to_date, result=result)
return result
def create(self, cr, uid, vals, context=None):
'''
complete info normally generated by javascript on_change function
'''
prod_obj = self.pool.get('product.product')
if vals.get('product_id', False):
# complete hidden flags - needed if not created from GUI
product = prod_obj.browse(cr, uid, vals.get('product_id'), context=context)
if product.batch_management:
vals.update(hidden_batch_management_mandatory=True)
elif product.perishable:
vals.update(hidden_perishable_mandatory=True)
else:
vals.update(hidden_batch_management_mandatory=False,
hidden_perishable_mandatory=False,
)
# complete expiry date from production lot - needed if not created from GUI
prodlot_obj = self.pool.get('stock.production.lot')
if vals.get('prod_lot_id', False):
vals.update(expiry_date=prodlot_obj.browse(cr, uid, vals.get('prod_lot_id'), context=context).life_date)
# call super
result = super(stock_inventory_line, self).create(cr, uid, vals, context=context)
return result
def write(self, cr, uid, ids, vals, context=None):
'''
complete info normally generated by javascript on_change function
'''
prod_obj = self.pool.get('product.product')
if vals.get('product_id', False):
# complete hidden flags - needed if not created from GUI
product = prod_obj.browse(cr, uid, vals.get('product_id'), context=context)
if product.batch_management:
vals.update(hidden_batch_management_mandatory=True)
elif product.perishable:
vals.update(hidden_perishable_mandatory=True)
else:
vals.update(hidden_batch_management_mandatory=False,
hidden_perishable_mandatory=False,
)
# complete expiry date from production lot - needed if not created from GUI
prodlot_obj = self.pool.get('stock.production.lot')
if vals.get('prod_lot_id', False):
vals.update(expiry_date=prodlot_obj.browse(cr, uid, vals.get('prod_lot_id'), context=context).life_date)
# call super
result = super(stock_inventory_line, self).write(cr, uid, ids, vals, context=context)
return result
def _get_checks_all(self, cr, uid, ids, name, arg, context=None):
'''
function for KC/SSL/DG/NP products
'''
result = {}
for id in ids:
result[id] = {}
for f in name:
result[id].update({f: False,})
for obj in self.browse(cr, uid, ids, context=context):
# keep cool
if obj.product_id.heat_sensitive_item:
result[obj.id]['kc_check'] = True
# ssl
if obj.product_id.short_shelf_life:
result[obj.id]['ssl_check'] = True
# dangerous goods
if obj.product_id.dangerous_goods:
result[obj.id]['dg_check'] = True
# narcotic
if obj.product_id.narcotic:
result[obj.id]['np_check'] = True
return result
def _check_batch_management(self, cr, uid, ids, context=None):
'''
check for batch management
'''
for obj in self.browse(cr, uid, ids, context=context):
if obj.product_id.batch_management:
if not obj.prod_lot_id or obj.prod_lot_id.type != 'standard':
return False
return True
def _check_perishable(self, cr, uid, ids, context=None):
"""
check for perishable ONLY
"""
for obj in self.browse(cr, uid, ids, context=context):
if obj.product_id.perishable and not obj.product_id.batch_management:
if (not obj.prod_lot_id and not obj.expiry_date) or (obj.prod_lot_id and obj.prod_lot_id.type != 'internal'):
return False
return True
def _check_prodlot_need(self, cr, uid, ids, context=None):
"""
If the inv line has a prodlot but does not need one, return False.
"""
for obj in self.browse(cr, uid, ids, context=context):
if obj.prod_lot_id:
if not obj.product_id.perishable and not obj.product_id.batch_management:
return False
return True
_columns = {
'hidden_perishable_mandatory': fields.boolean(string='Hidden Flag for Perishable product',),
'hidden_batch_management_mandatory': fields.boolean(string='Hidden Flag for Batch Management product',),
'prod_lot_id': fields.many2one('stock.production.lot', 'Batch', domain="[('product_id','=',product_id)]"),
'expiry_date': fields.date(string='Expiry Date'),
'type_check': fields.char(string='Type Check', size=1024,),
'kc_check': fields.function(_get_checks_all, method=True, string='KC', type='boolean', readonly=True, multi="m"),
'ssl_check': fields.function(_get_checks_all, method=True, string='SSL', type='boolean', readonly=True, multi="m"),
'dg_check': fields.function(_get_checks_all, method=True, string='DG', type='boolean', readonly=True, multi="m"),
'np_check': fields.function(_get_checks_all, method=True, string='NP', type='boolean', readonly=True, multi="m"),
}
_defaults = {# in is used, meaning a new prod lot will be created if the specified expiry date does not exist
'type_check': 'in',
}
_constraints = [(_check_batch_management,
'You must assign a Batch Number which corresponds to Batch Number Mandatory Products.',
['prod_lot_id']),
(_check_perishable,
'You must assign a Batch Numbre which corresponds to Expiry Date Mandatory Products.',
['prod_lot_id']),
(_check_prodlot_need,
'The selected product is neither Batch Number Mandatory nor Expiry Date Mandatory',
['prod_lot_id']),
]
stock_inventory_line()
class report_stock_inventory(osv.osv):
'''
UF-565: add group by expired_date
'''
_inherit = "report.stock.inventory"
def init(self, cr):
tools.drop_view_if_exists(cr, 'report_stock_inventory')
cr.execute("""
CREATE OR REPLACE view report_stock_inventory AS (
(SELECT
min(m.id) as id, m.date as date,
m.expired_date as expired_date,
m.address_id as partner_id, m.location_id as location_id,
m.product_id as product_id, pt.categ_id as product_categ_id, l.usage as location_type,
m.company_id,
m.state as state, m.prodlot_id as prodlot_id,
coalesce(sum(-pt.standard_price * m.product_qty)::decimal, 0.0) as value,
CASE when pt.uom_id = m.product_uom
THEN
coalesce(sum(-m.product_qty)::decimal, 0.0)
ELSE
coalesce(sum(-m.product_qty * pu.factor)::decimal, 0.0) END as product_qty
FROM
stock_move m
LEFT JOIN stock_picking p ON (m.picking_id=p.id)
LEFT JOIN product_product pp ON (m.product_id=pp.id)
LEFT JOIN product_template pt ON (pp.product_tmpl_id=pt.id)
LEFT JOIN product_uom pu ON (pt.uom_id=pu.id)
LEFT JOIN product_uom u ON (m.product_uom=u.id)
LEFT JOIN stock_location l ON (m.location_id=l.id)
GROUP BY
m.id, m.product_id, m.product_uom, pt.categ_id, m.address_id, m.location_id, m.location_dest_id,
m.prodlot_id, m.expired_date, m.date, m.state, l.usage, m.company_id,pt.uom_id
) UNION ALL (
SELECT
-m.id as id, m.date as date,
m.expired_date as expired_date,
m.address_id as partner_id, m.location_dest_id as location_id,
m.product_id as product_id, pt.categ_id as product_categ_id, l.usage as location_type,
m.company_id,
m.state as state, m.prodlot_id as prodlot_id,
coalesce(sum(pt.standard_price * m.product_qty )::decimal, 0.0) as value,
CASE when pt.uom_id = m.product_uom
THEN
coalesce(sum(m.product_qty)::decimal, 0.0)
ELSE
coalesce(sum(m.product_qty * pu.factor)::decimal, 0.0) END as product_qty
FROM
stock_move m
LEFT JOIN stock_picking p ON (m.picking_id=p.id)
LEFT JOIN product_product pp ON (m.product_id=pp.id)
LEFT JOIN product_template pt ON (pp.product_tmpl_id=pt.id)
LEFT JOIN product_uom pu ON (pt.uom_id=pu.id)
LEFT JOIN product_uom u ON (m.product_uom=u.id)
LEFT JOIN stock_location l ON (m.location_dest_id=l.id)
GROUP BY
m.id, m.product_id, m.product_uom, pt.categ_id, m.address_id, m.location_id, m.location_dest_id,
m.prodlot_id, m.expired_date, m.date, m.state, l.usage, m.company_id,pt.uom_id
)
);
""")
_columns = {
'prodlot_id': fields.many2one('stock.production.lot', 'Batch', readonly=True),
'expired_date': fields.date(string='Expiry Date',),
}
def read(self, cr, uid, ids, fields=None, context=None, load='_classic_read'):
if context is None:
context = {}
if fields is None:
fields = []
context['with_expiry'] = 1
return super(report_stock_inventory, self).read(cr, uid, ids, fields, context, load)
report_stock_inventory()
|