13
13
class dm_campaign_group(osv.osv):
14
14
_name = "dm.campaign.group"
16
def _quantity_estimated_total(self, cr, uid, ids, name, args, context={}):
18
groups = self.browse(cr,uid,ids)
20
for campaign in group.campaign_ids:
23
if campaign.quantity_estimated_total.isdigit():
24
quantity += int(campaign.quantity_estimated_total)
26
result[group.id]='Check Segments'
30
result[group.id]=str(quantity)
31
print "Estimated : ",result
34
def _quantity_wanted_total(self, cr, uid, ids, name, args, context={}):
36
groups = self.browse(cr,uid,ids)
39
for campaign in group.campaign_ids:
42
print "wanted total : ", campaign.quantity_wanted_total
43
if campaign.quantity_wanted_total.isdigit():
44
quantity += int(campaign.quantity_wanted_total)
45
elif campaign.quantity_wanted_total == "AAA for a Segment":
46
result[group.id]='AAA for a Segment'
50
result[group.id]='Check Segments'
54
result[group.id]=str(quantity)
55
print "Wanted : ",result
58
def _quantity_delivered_total(self, cr, uid, ids, name, args, context={}):
60
groups = self.browse(cr,uid,ids)
62
for campaign in group.campaign_ids:
65
if campaign.quantity_delivered_total.isdigit():
66
quantity += int(campaign.quantity_delivered_total)
68
result[group.id]='Check Segments'
72
result[group.id]=str(quantity)
73
print "Delivered : ",result
76
def _quantity_usable_total(self, cr, uid, ids, name, args, context={}):
78
groups = self.browse(cr,uid,ids)
80
for campaign in group.campaign_ids:
83
if campaign.quantity_usable_total.isdigit():
84
quantity += int(campaign.quantity_usable_total)
86
result[group.id]='Check Segments'
90
result[group.id]=str(quantity)
91
print "Usable : ",result
16
94
def _camp_group_code(self, cr, uid, ids, name, args, context={}):
22
100
dt = time.strftime('%Y-%m-%d')
23
101
date = dt.split('-')
289
362
domain=[('type','ilike','DTP')], context={'type':'DTP'}),
290
363
'manufacturing_task_ids': one2many_mod_task('project.task', 'project_id', "Manufacturing tasks",
291
364
domain=[('type','ilike','Mailing Manufacturing')],context={'type':'Mailing Manufacturing'}),
292
'cust_file_task_ids': one2many_mod_task('project.task', 'project_id', "Customer Lists tasks",
293
domain=[('type','ilike','Customers List')], context={'type':'Customers List'}),
294
'quantity_theorical_total' : fields.function(_quantity_theorical_total, string='Total Theorical Quantity',type="char",size="64",method=True,readonly=True),
365
'cust_file_task_ids': one2many_mod_task('project.task', 'project_id', "Customer Files tasks",
366
domain=[('type','ilike','Customers File')], context={'type':'Customers File'}),
367
'quantity_estimated_total' : fields.function(_quantity_estimated_total, string='Total Estimated Quantity',type="char",size="64",method=True,readonly=True),
295
368
'quantity_wanted_total' : fields.function(_quantity_wanted_total, string='Total Wanted Quantity',type="char",size="64",method=True,readonly=True),
296
369
'quantity_delivered_total' : fields.function(_quantity_delivered_total, string='Total Delivered Quantity',type="char",size="64",method=True,readonly=True),
297
'quantity_real_total' : fields.function(_quantity_real_total, string='Total Real Quantity',type="char",size="64",method=True,readonly=True),
370
'quantity_usable_total' : fields.function(_quantity_usable_total, string='Total Usable Quantity',type="char",size="64",method=True,readonly=True),
807
883
pline = self.browse(cr, uid, ids)[0]
808
if not pline.campaign_id:
809
raise osv.except_osv('Warning', "You must first save this Purchase Line and the campaign before using this button")
884
# if not pline.campaign_id:
885
# raise osv.except_osv('Warning', "You must first save this Purchase Line and the campaign before using this button")
887
if pline.campaign_group_id:
888
obj = pline.campaign_group_id
890
obj = pline.campaign_group_id
811
892
if pline.type_quantity == 'quantity_free':
813
elif pline.type_quantity == 'quantity_theorical':
814
if pline.campaign_id.quantity_theorical_total.isdigit():
815
quantity = pline.campaign_id.quantity_theorical_total
895
elif pline.type_quantity == 'quantity_estimated':
896
if obj.quantity_estimated_total.isdigit():
897
quantity = obj.quantity_estimated_total
817
899
raise osv.except_osv('Warning',
818
900
'Cannot get wanted quantity, check prososition segments')
819
901
elif pline.type_quantity == 'quantity_wanted':
820
if pline.campaign_id.quantity_wanted_total.isdigit():
821
quantity = pline.campaign_id.quantity_wanted_total
822
elif pline.campaign_id.quantity_wanted_total == 'AAA for a Segment':
902
if obj.quantity_wanted_total.isdigit():
903
quantity = obj.quantity_wanted_total
904
elif obj.quantity_wanted_total == 'AAA for a Segment':
825
907
raise osv.except_osv('Warning',
826
908
"Cannot get wanted quantity, check prososition segments")
827
909
elif pline.type_quantity == 'quantity_delivered':
828
if pline.campaign_id.quantity_delivered_total.isdigit():
829
quantity = pline.campaign_id.quantity_delivered_total
910
if obj.quantity_delivered_total.isdigit():
911
quantity = obj.quantity_delivered_total
831
913
raise osv.except_osv('Warning',
832
914
"Cannot get delivered quantity, check prososition segments")
833
elif pline.type_quantity == 'quantity_real':
834
if pline.campaign_id.quantity_real_total.isdigit():
835
quantity = pline.campaign_id.quantity_real_total
915
elif pline.type_quantity == 'quantity_usable':
916
if obj.quantity_usable_total.isdigit():
917
quantity = obj.quantity_usable_total
837
919
raise osv.except_osv('Warning',
838
"Cannot get real quantity, check prososition segments")
920
"Cannot get usable quantity, check prososition segments")
840
922
raise osv.except_osv('Warning','Error getting quantity')
865
952
address_id = self.pool.get('res.partner').address_get(cr, uid, [partner.id], ['default'])['default']
866
953
if not address_id:
867
954
raise osv.except_osv('Warning', "There's no default address defined for this partner : %s" % (partner.name,) )
955
delivery_address = address_id
868
956
pricelist_id = partner.property_product_pricelist_purchase.id
869
957
if not pricelist_id:
870
958
raise osv.except_osv('Warning', "There's no purchase pricelist defined for this partner : %s" % (partner.name,) )
871
959
price = self.pool.get('product.pricelist').price_get(cr, uid, [pricelist_id], pline.product_id.id, pline.quantity, False, {'uom': pline.uom_id.id})[pricelist_id]
872
960
newdate = DateTime.strptime(pline.date_planned, '%Y-%m-%d %H:%M:%S') - DateTime.RelativeDateTime(days=pline.product_id.product_tmpl_id.seller_delay or 0.0)
874
963
if not pline.campaign_id.offer_id:
875
964
raise osv.except_osv('Warning', "There's no offer defined for this campaign : %s" % (pline.campaign_id.name,) )
876
965
if not pline.campaign_id.proposition_ids:
877
966
raise osv.except_osv('Warning', "There's no proposition defined for this campaign : %s" % (pline.campaign_id.name,) )
969
# if in a group, obj = 1st campaign of the group, if not it's the campaing
970
if pline.campaign_group_id:
971
obj = pline.campaign_group_id.campaign_ids[0]
972
code = pline.campaign_group_id.code
973
print "First campaign of group : ", obj.name
975
obj = pline.campaign_id
976
code = pline.campaign_id.code1
879
978
# Get constraints
881
980
if pline.type_product == 'Mailing Manufacturing':
882
for step in pline.campaign_id.offer_id.step_ids:
981
for step in obj.offer_id.step_ids:
883
982
for const in step.manufacturing_constraint_ids:
884
983
if not const.country_ids:
885
984
constraints.append("---------------------------------------------------------------------------")
886
985
constraints.append(const.name)
887
986
constraints.append(const.constraint)
888
elif pline.campaign_id.country_id in const.country_ids:
987
elif obj.country_id in const.country_ids:
889
988
constraints.append("---------------------------------------------------------------------------")
890
constraints.append(const.name + ' for country :' + pline.campaign_id.country_id.name)
989
constraints.append(const.name + ' for country :' + obj.country_id.name)
891
990
constraints.append(const.constraint)
893
992
constraints.append("---------------------------------------------------------------------------")
931
1043
if pline.type_product == 'Translation':
932
1044
line = self.pool.get('purchase.order.line').create(cr, uid, {
933
1045
'order_id': purchase_id,
934
'name': pline.campaign_id.code1,
935
1047
'product_qty': pline.quantity,
936
1048
'product_id': pline.product_id.id,
937
1049
'product_uom': pline.uom_id.id,
938
1050
'price_unit': price,
939
1051
'date_planned': newdate.strftime('%Y-%m-%d %H:%M:%S'),
940
1052
'taxes_id': [(6, 0, [x.id for x in pline.product_id.product_tmpl_id.supplier_taxes_id])],
941
'account_analytic_id': pline.campaign_id.analytic_account_id,
1053
# 'account_analytic_id': obj.analytic_account_id,
943
1055
elif pline.type_product == 'Mailing Manufacturing':
944
''' Create po lines for each proposition'''
946
for propo in pline.campaign_id.proposition_ids:
947
line_name = propo.code1 + '-' + propo.type
949
if pline.type_quantity == 'quantity_free':
950
line_quantity = pline.quantity
951
elif pline.type_quantity == 'quantity_theorical':
952
if propo.quantity_theorical.isdigit():
953
quantity = propo.quantity_theorical
955
raise osv.except_osv('Warning',
956
'Cannot get theorical quantity, check prososition %s' % (propo.name,))
957
elif pline.type_quantity == 'quantity_wanted':
958
if propo.quantity_wanted.isdigit():
959
quantity = propo.quantity_wanted
960
elif propo.quantity_wanted == 'AAA for a Segment':
962
line_name = propo.code1 + '-' + propo.type + '-AAA (All Addresses Available)'
964
raise osv.except_osv('Warning',
965
'Cannot get wanted quantity, check prososition %s' % (propo.name,))
966
elif pline.type_quantity == 'quantity_delivered':
967
if propo.quantity_delivered.isdigit():
968
quantity = propo.quantity_delivered
970
raise osv.except_osv('Warning',
971
'Cannot get delivered quantity, check prososition %s' % (propo.name,))
972
elif pline.type_quantity == 'quantity_real':
973
if propo.quantity_real.isdigit():
974
quantity = propo.quantity_real
976
raise osv.except_osv('Warning',
977
'Cannot get delivered quantity, check prososition %s' % (propo.name,))
979
raise osv.except_osv('Warning','Error getting quantity for proposition %s' % (propo.name,))
981
line = self.pool.get('purchase.order.line').create(cr, uid, {
982
'order_id': purchase_id,
984
'product_qty': quantity,
985
'product_id': pline.product_id.id,
986
'product_uom': pline.uom_id.id,
988
'date_planned': newdate.strftime('%Y-%m-%d %H:%M:%S'),
989
'taxes_id': [(6, 0, [x.id for x in pline.product_id.product_tmpl_id.supplier_taxes_id])],
990
'account_analytic_id': propo.analytic_account_id,
1056
''' Create po lines for each proposition (of each campaign if group)'''
1058
if pline.campaign_group_id:
1059
print "Creating PO line for group"
1060
for campaign in pline.campaign_group_id.campaign_ids:
1061
for propo in campaign.proposition_ids:
1062
line_name = propo.code1 + '-' + propo.type
1063
if pline.type_quantity == 'quantity_free':
1064
line_quantity = pline.quantity
1065
elif pline.type_quantity == 'quantity_estimated':
1066
if propo.quantity_estimated.isdigit():
1067
quantity = propo.quantity_estimated
1069
raise osv.except_osv('Warning',
1070
'Cannot get estimated quantity, check prososition %s' % (propo.name,))
1071
elif pline.type_quantity == 'quantity_wanted':
1072
if propo.quantity_wanted.isdigit():
1073
quantity = propo.quantity_wanted
1074
elif propo.quantity_wanted == 'AAA for a Segment':
1076
line_name = propo.code1 + '-' + propo.type + '- All Addresses Available'
1078
raise osv.except_osv('Warning',
1079
'Cannot get wanted quantity, check prososition %s' % (propo.name,))
1080
elif pline.type_quantity == 'quantity_delivered':
1081
if propo.quantity_delivered.isdigit():
1082
quantity = propo.quantity_delivered
1084
raise osv.except_osv('Warning',
1085
'Cannot get delivered quantity, check prososition %s' % (propo.name,))
1086
elif pline.type_quantity == 'quantity_usable':
1087
if propo.quantity_usable.isdigit():
1088
quantity = propo.quantity_usable
1090
raise osv.except_osv('Warning',
1091
'Cannot get delivered quantity, check prososition %s' % (propo.name,))
1093
raise osv.except_osv('Warning','Error getting quantity for proposition %s' % (propo.name,))
1095
line = self.pool.get('purchase.order.line').create(cr, uid, {
1096
'order_id': purchase_id,
1098
'product_qty': quantity,
1099
'product_id': pline.product_id.id,
1100
'product_uom': pline.uom_id.id,
1101
'price_unit': price,
1102
'date_planned': newdate.strftime('%Y-%m-%d %H:%M:%S'),
1103
'taxes_id': [(6, 0, [x.id for x in pline.product_id.product_tmpl_id.supplier_taxes_id])],
1104
'account_analytic_id': propo.analytic_account_id,
1107
for propo in obj.proposition_ids:
1108
line_name = propo.code1 + '-' + propo.type
1110
if pline.type_quantity == 'quantity_free':
1111
line_quantity = pline.quantity
1112
elif pline.type_quantity == 'quantity_estimated':
1113
if propo.quantity_estimated.isdigit():
1114
quantity = propo.quantity_estimated
1116
raise osv.except_osv('Warning',
1117
'Cannot get estimated quantity, check prososition %s' % (propo.name,))
1118
elif pline.type_quantity == 'quantity_wanted':
1119
if propo.quantity_wanted.isdigit():
1120
quantity = propo.quantity_wanted
1121
elif propo.quantity_wanted == 'AAA for a Segment':
1123
line_name = propo.code1 + '-' + propo.type + '- All Addresses Available'
1125
raise osv.except_osv('Warning',
1126
'Cannot get wanted quantity, check prososition %s' % (propo.name,))
1127
elif pline.type_quantity == 'quantity_delivered':
1128
if propo.quantity_delivered.isdigit():
1129
quantity = propo.quantity_delivered
1131
raise osv.except_osv('Warning',
1132
'Cannot get delivered quantity, check prososition %s' % (propo.name,))
1133
elif pline.type_quantity == 'quantity_usable':
1134
if propo.quantity_usable.isdigit():
1135
quantity = propo.quantity_usable
1137
raise osv.except_osv('Warning',
1138
'Cannot get delivered quantity, check prososition %s' % (propo.name,))
1140
raise osv.except_osv('Warning','Error getting quantity for proposition %s' % (propo.name,))
1142
line = self.pool.get('purchase.order.line').create(cr, uid, {
1143
'order_id': purchase_id,
1145
'product_qty': quantity,
1146
'product_id': pline.product_id.id,
1147
'product_uom': pline.uom_id.id,
1148
'price_unit': price,
1149
'date_planned': newdate.strftime('%Y-%m-%d %H:%M:%S'),
1150
'taxes_id': [(6, 0, [x.id for x in pline.product_id.product_tmpl_id.supplier_taxes_id])],
1151
'account_analytic_id': propo.analytic_account_id,
1153
elif pline.type_product == 'Customers File':
1155
if pline.campaign_group_id:
1156
for campaign in pline.campaign_group_id.campaign_ids:
1157
for propo in campaign.proposition_ids:
1158
for segment in propo.segment_ids:
1159
line_name = propo.code1 + ' - ' + segment.list_id.name
1160
if pline.type_quantity == 'quantity_free':
1161
raise osv.except_osv('Warning',
1162
'You cannot use a free quantity for a customers file order')
1163
elif pline.type_quantity == 'quantity_estimated':
1164
quantity = segment.quantity_estimated
1165
elif pline.type_quantity == 'quantity_wanted':
1166
quantity = segment.quantity_wanted
1169
line_name = propo.code1 + ' - ' + segment.list_id.name + ' - All Addresses Available'
1170
elif pline.type_quantity == 'quantity_delivered':
1171
quantity = segment.quantity_delivered
1172
elif pline.type_quantity == 'quantity_usable':
1173
quantity = segment.quantity_usable
1175
raise osv.except_osv('Warning','Error getting quantity for proposition %s' % (propo.name,))
1177
line = self.pool.get('purchase.order.line').create(cr, uid, {
1178
'order_id': purchase_id,
1180
'product_qty': quantity,
1181
'product_id': pline.product_id.id,
1182
'product_uom': pline.uom_id.id,
1183
'price_unit': price,
1184
'date_planned': newdate.strftime('%Y-%m-%d %H:%M:%S'),
1185
'taxes_id': [(6, 0, [x.id for x in pline.product_id.product_tmpl_id.supplier_taxes_id])],
1186
'account_analytic_id': propo.analytic_account_id,
1189
for propo in obj.proposition_ids:
1190
for segment in propo.segment_ids:
1191
line_name = propo.code1 + ' - ' + segment.list_id.name
1192
if pline.type_quantity == 'quantity_free':
1193
raise osv.except_osv('Warning',
1194
'You cannot use a free quantity for a customers file order')
1195
elif pline.type_quantity == 'quantity_estimated':
1196
quantity = segment.quantity_estimated
1197
elif pline.type_quantity == 'quantity_wanted':
1198
quantity = segment.quantity_wanted
1201
line_name = propo.code1 + ' - ' + segment.list_id.name + ' - All Addresses Available'
1202
elif pline.type_quantity == 'quantity_delivered':
1203
quantity = propo.quantity_delivered
1204
elif pline.type_quantity == 'quantity_usable':
1205
quantity = propo.quantity_usable
1207
raise osv.except_osv('Warning','Error getting quantity for proposition %s' % (propo.name,))
1209
line = self.pool.get('purchase.order.line').create(cr, uid, {
1210
'order_id': purchase_id,
1212
'product_qty': quantity,
1213
'product_id': pline.product_id.id,
1214
'product_uom': pline.uom_id.id,
1215
'price_unit': price,
1216
'date_planned': newdate.strftime('%Y-%m-%d %H:%M:%S'),
1217
'taxes_id': [(6, 0, [x.id for x in pline.product_id.product_tmpl_id.supplier_taxes_id])],
1218
'account_analytic_id': propo.analytic_account_id,
993
1221
if pline.type_document == 'po':
994
1222
print "Set as Purchase Order"