forked from xlongfeng/manekineko
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ebay_item.py
1705 lines (1526 loc) · 73.3 KB
/
ebay_item.py
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
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
#
# 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 sys
import io
import base64
import urllib2
import uuid
import logging
from datetime import datetime, timedelta
import time
from jinja2 import Template
from openerp import SUPERUSER_ID
from openerp import pooler, tools
from openerp.osv import fields, osv, orm
from openerp.tools.translate import _
from openerp.tools.float_utils import float_round
import openerp.addons.decimal_precision as dp
import ebaysdk
from openerp.addons.ebay.ebay_utils import *
from ebaysdk.exception import ConnectionError, ConnectionResponseError
from requests.exceptions import RequestException
_logger = logging.getLogger(__name__)
class ebay_details(osv.osv):
_name = "ebay.details"
_description = "eBay details"
_columns = {
'name': fields.char('Name', required=True),
'site_id': fields.selection([
('0', 'US'),
('2', 'Canada',),
('3', 'UK'),
('15', 'Australia'),
('201', 'HongKong'),
], 'Site', required=True),
'sandbox': fields.boolean('Sandbox'),
# Category Feature
'ebay_details': fields.text('eBay Details', readonly=True),
}
_defaults = {
'name': 'ebay details',
'site_id': '0',
'sandbox': False
}
def action_update(self, cr, uid, ids, context=None):
ebay_ebay_obj = self.pool.get('ebay.ebay')
for details in self.browse(cr, uid, ids, context=context):
user = ebay_ebay_obj.get_arbitrary_auth_user(cr, uid, details.sandbox)
call_data = dict()
error_msg = 'Get the ebay details list for %s site' % details.site_id
resp = self.pool.get('ebay.ebay').call(cr, uid, user, 'GeteBayDetails', call_data, error_msg, context=context).response_content()
details.write(dict(ebay_details=resp))
ebay_details()
class ebay_category(osv.osv):
_name = "ebay.category"
_description = "eBay category"
_columns = {
'name': fields.char('Name', required=True),
'category_site_id': fields.selection([
('0', 'US'),
('2', 'Canada',),
('3', 'UK'),
('15', 'Australia'),
('201', 'HongKong'),
], 'Category Site', required=True),
'sandbox': fields.boolean('Sandbox'),
'category_id': fields.char('Category ID', size=10, required=True),
# Category Feature
'condition_enabled': fields.char('ConditionEnabled', readonly=True),
'condition_values': fields.text('ConditionValues'),
'free_gallery_plus_enabled': fields.boolean('FreeGalleryPlusEnabled', readonly=True),
'free_picture_pack_enabled': fields.boolean('FreePicturePackEnabled', readonly=True),
'handling_time_enabled': fields.boolean('HandlingTimeEnabled', readonly=True),
'item_specifics_enabled': fields.char('ItemSpecificsEnabled', readonly=True),
'variations_enabled': fields.boolean('VariationsEnabled', readonly=True),
'category_feature': fields.text('Category Feature', readonly=True),
}
_defaults = {
'category_site_id': '0',
'sandbox': False
}
_sql_constraints = [
('category_id_uniq', 'unique(category_id, sandbox)', 'Category ID must be unique!'),
]
def search_category(self, cr, uid, category_id, category_name, sandbox, context=None):
domain = [('category_id', '=', category_id), ('sandbox', '=', sandbox)]
ids = self.search(cr, uid, domain, context=context)
if ids:
id = ids[0]
else:
vals = dict(
name=category_name,
category_id=category_id,
sandbox=sandbox,
)
id = self.create(cr, uid, vals, context=context)
return id
def action_update(self, cr, uid, ids, context=None):
ebay_ebay_obj = self.pool.get('ebay.ebay')
for category in self.browse(cr, uid, ids, context=context):
user = ebay_ebay_obj.get_arbitrary_auth_user(cr, uid, category.sandbox)
call_data = dict()
call_data['AllFeaturesForCategory'] = True
call_data['CategoryID'] = category.category_id
call_data['ViewAllNodes'] = True
call_data['DetailLevel'] = 'ReturnAll'
error_msg = 'Get the category features for %s' % category.category_id
api = ebay_ebay_obj.call(cr, uid, user, 'GetCategoryFeatures', call_data, error_msg, context=context)
resp_dict = api.response_dict()
category_feature = resp_dict.Category
vals = dict()
if category_feature.has_key('ConditionEnabled'):
vals['condition_enabled'] = category_feature.ConditionEnabled
readability = "%s | %s\n" % ("DisplayName", "ID")
readability += "%s\n" % ("-" * 64,)
for condition in category_feature.ConditionValues.Condition:
readability += "%s | %s\n" % (condition.DisplayName, condition.ID)
vals['condition_values'] = readability
vals['free_gallery_plus_enabled'] = category_feature.get('FreeGalleryPlusEnabled', 'false') == 'true'
vals['free_picture_pack_enabled'] = category_feature.get('FreePicturePackEnabled', 'false') == 'true'
vals['handling_time_enabled'] = category_feature.get('HandlingTimeEnabled', 'false') == 'true'
vals['item_specifics_enabled'] = category_feature.get('ItemSpecificsEnabled', '')
vals['variations_enabled'] = category_feature.get('VariationsEnabled', 'false') == 'true'
vals['category_feature'] = api.response.content
category.write(vals)
ebay_category()
class ebay_buyerrequirementdetails(osv.osv):
_name = "ebay.buyerrequirementdetails"
_description = "eBay buyer requirement details"
_columns = {
'name': fields.char('Name', required=True),
'linked_paypal_account': fields.boolean('LinkedPayPalAccount'),
# MaximumBuyerPolicyViolations
'mbpv_count': fields.integer('Count'),
'mbpv_period': fields.selection([
('Days_30', '30 days'),
('Days_180', '180 days'),
],'Period'),
# MaximumItemRequirements
'mir_maximum_item_count': fields.integer('MaximumItemCount', help='As of Jan. 2013, the valid values for the US site are: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 25, 50, and 75.'),
'mir_minimum_feedback_score': fields.integer('MinimumFeedbackScore', help='Currently, the valid values for the US site are: 0, 1, 2, 3, 4, and 5.'),
# MaximumUnpaidItemStrikesInfo
'muisi_count': fields.integer('Count'),
'muisi_period': fields.selection([
('Days_30', '30 days'),
('Days_180', '180 days'),
('Days_360', '360 days'),
],'Period'),
'minimum_feedback_score': fields.integer('MinimumFeedbackScore'),
'ship2registration_country': fields.boolean('ShipToRegistrationCountry'),
# VerifiedUserRequirements
'vur_minimum_feedback_score': fields.integer('MinimumFeedbackScore'),
'vur_verified_user': fields.boolean('VerifiedUser'),
'zero_feedback_score': fields.boolean('ZeroFeedbackScore'),
'ebay_item_ids': fields.one2many('ebay.item', 'buyer_requirement_details_id', 'Item'),
}
_defaults = {
'linked_paypal_account': False,
'mbpv_count': 4,
'mbpv_period': 'Days_180',
'mir_maximum_item_count': 5,
'mir_minimum_feedback_score': 5,
'muisi_count': 2,
'muisi_period': 'Days_30',
'minimum_feedback_score': -1,
'ship2registration_country': True,
'vur_minimum_feedback_score': 5,
'vur_verified_user': True,
'zero_feedback_score': False,
}
def dict(self, cr, uid, ids, user, this, context=None):
buyer_requirement_details = dict(
LinkedPayPalAccount="true" if this.linked_paypal_account else "false",
MinimumFeedbackScore=this.minimum_feedback_score,
ShipToRegistrationCountry="true" if this.ship2registration_country else "false",
)
buyer_requirement_details['MaximumBuyerPolicyViolations'] = dict(
Count=this.mbpv_count,
Period=this.mbpv_period,
)
buyer_requirement_details['MaximumItemRequirements'] = dict(
MaximumItemCount=this.mir_maximum_item_count,
)
if this.mir_minimum_feedback_score:
buyer_requirement_details['MaximumItemRequirements']['MinimumFeedbackScore'] = this.mir_minimum_feedback_score
buyer_requirement_details['MaximumUnpaidItemStrikesInfo'] = dict(
Count=this.muisi_count,
Period=this.muisi_period,
)
'''
buyer_requirement_details['VerifiedUserRequirements'] = dict(
MinimumFeedbackScore=this.vur_minimum_feedback_score,
VerifiedUser=this.vur_verified_user,
)
'''
return buyer_requirement_details
ebay_buyerrequirementdetails()
class ebay_conditiondescription(osv.osv):
_name = "ebay.conditiondescription"
_description = "eBay condition description"
_columns = {
'name': fields.char('Name', required=True),
'description': fields.text('Description', size=1000, required=True),
'ebay_item_ids': fields.one2many('ebay.item', 'condition_description_id', 'Item'),
}
_defaults = {
}
ebay_conditiondescription()
class ebay_eps_picturesetmember(osv.osv):
_name = "ebay.eps.picturesetmember"
_description = "eBay EPS Picture"
_columns = {
'member_url': fields.char('URL'),
'picture_height': fields.integer('Height'),
'picture_width': fields.integer('Width'),
'ebay_eps_picture_id': fields.many2one('ebay.eps.picture', 'EPS Picture', ondelete='cascade'),
}
_rec_name = 'member_url'
ebay_eps_picturesetmember()
class ebay_eps_picture(osv.osv):
_name = "ebay.eps.picture"
_description = "eBay EPS Picture"
def _get_image(self, cr, uid, ids, name, args, context=None):
result = dict.fromkeys(ids, False)
for obj in self.browse(cr, uid, ids, context=context):
result[obj.id] = tools.image_get_resized_images(obj.image)
return result
def _set_image(self, cr, uid, id, name, value, args, context=None):
return self.write(cr, uid, [id], {'image': tools.image_resize_image_big(value)}, context=context)
def _has_image(self, cr, uid, ids, name, args, context=None):
result = {}
for obj in self.browse(cr, uid, ids, context=context):
result[obj.id] = obj.image != False
return result
_columns = {
'name': fields.char('Name', required=True),
'dummy': fields.boolean('Dummy', help="This a dummy picture for optimize speed sync seller active item, you must sync picture to fecth the real image"),
# image: all image fields are base64 encoded and PIL-supported
'image': fields.binary("Image", required=True,
help="This field holds the image used as avatar for this contact, limited to 1024x1024px"),
'image_medium': fields.function(_get_image, fnct_inv=_set_image,
string="Medium-sized image", type="binary", multi="_get_image",
store={
'ebay.eps.picture': (lambda self, cr, uid, ids, c={}: ids, ['image'], 10),
},
help="Medium-sized image of this contact. It is automatically "\
"resized as a 128x128px image, with aspect ratio preserved. "\
"Use this field in form views or some kanban views."),
'image_small': fields.function(_get_image, fnct_inv=_set_image,
string="Small-sized image", type="binary", multi="_get_image",
store={
'ebay.eps.picture': (lambda self, cr, uid, ids, c={}: ids, ['image'], 10),
},
help="Small-sized image of this contact. It is automatically "\
"resized as a 64x64px image, with aspect ratio preserved. "\
"Use this field anywhere a small image is required."),
'has_image': fields.function(_has_image, type="boolean"),
# SiteHostedPictureDetails
'base_url': fields.char('BaseURL', readonly=True),
'external_picture_url ': fields.char('ExternalPictureURL', readonly=True),
'full_url': fields.char('FullURL', readonly=True),
'picture_format': fields.char('PictureFormat', readonly=True),
'picturesetmember_ids': fields.one2many('ebay.eps.picturesetmember', 'ebay_eps_picture_id', 'PictureSetMember', readonly=True),
'use_by_date': fields.datetime('UseByDate', readonly=True),
'ebay_item_id': fields.many2one('ebay.item', 'Item', readonly=True, ondelete='cascade'),
}
_defaults = {
'dummy': False
}
_order = 'name'
def write(self, cr, uid, ids, vals, context=None):
if context is None:
context = {}
if not ids:
return True
if 'image' in vals:
vals['dummy'] = False
vals['use_by_date'] = fields.datetime.now()
return super(ebay_eps_picture, self).write(cr, uid, ids, vals, context=context)
def upload(self, cr, uid, ids, item, picture, context=None):
ebay_ebay_obj = self.pool.get('ebay.ebay')
ebay_eps_picturesetmember = self.pool.get('ebay.eps.picturesetmember')
user = item.ebay_user_id
active = item.state == 'Active'
now = datetime.now()
if not picture.use_by_date or (((ebay_strptime(picture.use_by_date) - now).days < 2) and (active != True)):
image = io.BytesIO(base64.b64decode(picture.image))
call_data = dict()
call_data['PictureSet'] = 'Supersize'
call_data['PictureSystemVersion'] = 2
#call_data['PictureUploadPolicy'] = 'Add'
call_name = 'UploadSiteHostedPictures'
api = ebay_ebay_obj.trading(cr, uid, user, call_name, context=context)
api.execute(call_name, call_data, files=dict(image=image))
reply = api.response.reply
site_hosted_picture_details = reply.SiteHostedPictureDetails
vals = dict()
vals['base_url'] = site_hosted_picture_details.BaseURL
#vals['external_picture_url'] = site_hosted_picture_details.ExternalPictureURL
vals['full_url'] = site_hosted_picture_details.FullURL
vals['picture_format'] = site_hosted_picture_details.PictureFormat
vals['use_by_date'] = site_hosted_picture_details.UseByDate
picture.write(vals)
picture.refresh()
picture_set_member = site_hosted_picture_details.PictureSetMember
cr.execute('delete from ebay_eps_picturesetmember where ebay_eps_picture_id=%s', (picture.id,))
for picture_set in picture_set_member:
vals = dict()
vals['member_url'] = picture_set.MemberURL
vals['picture_height'] = picture_set.PictureHeight
vals['picture_width'] = picture_set.PictureWidth
vals['ebay_eps_picture_id'] = picture.id
ebay_eps_picturesetmember.create(cr, uid, vals, context=context)
ebay_eps_picture()
class ebay_returnpolicy(osv.osv):
_name = "ebay.returnpolicy"
_description = "eBay return policy"
_columns = {
'name': fields.char('Name', required=True),
'description': fields.text('Description', size=5000),
'refund_option': fields.selection([
('MoneyBack', 'Money Back'),
('MoneyBackOrReplacement', 'Money back or replacement'),
('MoneyBackOrExchange', 'Money back or exchange'),
], 'RefundOption', required=True),
'restocking_feevalue_option': fields.char('RestockingFeeValueOption'),
'returns_accepted_option': fields.selection([
('ReturnsAccepted', 'Returns Accepted'),
('ReturnsNotAccepted', 'No returns accepted'),
], 'ReturnsAcceptedOption', required=True),
'returns_within_option': fields.selection([
('Days_14', '14 Days'),
('Days_30', '30 Days'),
('Days_60', '60 Days'),
], 'ReturnsWithinOption', required=True),
'shipping_cost_paid_by_option': fields.selection([
('Buyer', 'Buyer'),
('Seller', 'Seller'),
], 'ShippingCostPaidByOption', required=True),
'warranty_duration_option': fields.char('WarrantyDurationOption'),
'warranty_offered_option': fields.char('WarrantyOfferedOption'),
'warranty_type_option': fields.char('WarrantyTypeOption'),
'ebay_item_ids': fields.one2many('ebay.item', 'return_policy_id', 'Item'),
}
_defaults = {
}
def dict(self, cr, uid, ids, user, this, context=None):
return_policy = dict(
RefundOption=this.refund_option,
ReturnsAcceptedOption=this.returns_accepted_option,
ReturnsWithinOption=this.returns_within_option,
ShippingCostPaidByOption=this.shipping_cost_paid_by_option,
)
if this.description:
return_policy['description'] = '<![CDATA[' + this.description + ']]>'
return return_policy
ebay_returnpolicy()
class ebay_shippingdetails(osv.osv):
_name = "ebay.shippingdetails"
_description = "eBay shipping details"
_columns = {
'name': fields.char('Name', required=True),
'exclude_ship_to_location': fields.text('Exclude Ship To Location'),
# InternationalShippingServiceOption
# Shipping costs and options related to an international shipping service.
'isso_shipping_service': fields.char('Shipping Service', required=True),
'isso_shipping_service_additional_cost': fields.float('Additional Cost'),
'isso_shipping_service_cost': fields.float('Cost'),
'isso_shipping_service_priority': fields.integer('ShippingServicePriority'),
# ShippingServiceOptions
# Shipping costs and options related to domestic shipping services offered by the seller.
# Flat and calculated shipping.
'sso_free_shipping': fields.boolean('Free Shipping'),
'sso_shipping_service': fields.char('Shipping Service', required=True),
'sso_shipping_service_additional_Cost': fields.float('Additional Cost'),
'sso_shipping_service_cost': fields.float('Cost'),
'sso_shipping_service_priority': fields.integer('ShippingServicePriority'),
'shipping_type': fields.selection([
('Calculated', 'Calculated'),
('CalculatedDomesticFlatInternational', 'CalculatedDomesticFlatInternational'),
('CustomCode', 'CustomCode'),
('Flat', 'Flat'),
('FlatDomesticCalculatedInternational', 'FlatDomesticCalculatedInternational'),
('FreightFlat', 'FreightFlat'),
('NotSpecified', 'NotSpecified'),
], 'ShippingType', readonly=True),
'ebay_item_ids': fields.one2many('ebay.item', 'shipping_details_id', 'Item'),
}
_defaults = {
'isso_shipping_service': 'OtherInternational',
'isso_shipping_service_additional_cost': 0.0,
'isso_shipping_service_cost': 0.0,
'isso_shipping_service_priority': 1,
'sso_free_shipping': True,
'sso_shipping_service': 'EconomyShippingFromOutsideUS',
'sso_shipping_service_additional_Cost': 0.0,
'sso_shipping_service_cost': 0.0,
'sso_shipping_service_priority': 1,
'shipping_type': 'Flat',
}
def on_change_sso_free_shipping(self, cr, uid, id, sso_free_shipping, context=None):
if sso_free_shipping:
return {
'value': {
'sso_shipping_service_cost': 0.0,
'sso_shipping_service_additional_Cost': 0.0,
}
}
else:
return {
'value': {
}
}
def dict(self, cr, uid, ids, user, this, context=None):
shipping_details = dict()
shipping_details['InternationalShippingServiceOption'] = dict(
ShippingService=this.isso_shipping_service,
ShippingServiceAdditionalCost=this.sso_shipping_service_additional_Cost,
ShippingServiceCost=this.isso_shipping_service_cost,
ShippingServicePriority=this.isso_shipping_service_priority,
ShipToLocation='Worldwide'
)
exclude_ship_to_location = user.exclude_ship_to_location
if exclude_ship_to_location:
shipping_details['ExcludeShipToLocation'] = user.exclude_ship_to_location.split('|')
shipping_details['ShippingServiceOptions'] = dict(
ShippingService=this.sso_shipping_service,
ShippingServicePriority=this.sso_shipping_service_priority,
)
if this.sso_free_shipping:
shipping_details['ShippingServiceOptions']['FreeShipping'] = "true"
else:
shipping_details['ShippingServiceOptions']['ShippingServiceAdditionalCost'] = this.sso_shipping_service_additional_Cost
shipping_details['ShippingServiceOptions']['ShippingServiceCost'] = this.sso_shipping_service_cost
shipping_details['ShippingType'] = this.shipping_type
return shipping_details
ebay_shippingdetails()
class ebay_product(osv.osv):
_name = "ebay.product"
_description = "eBay product"
_columns = {
'product_id': fields.many2one('product.product', 'Product', required=True, ondelete='no action'),
'uos_coeff': fields.float('Unit of Sale Coeff', digits_compute= dp.get_precision('Product UoS'), required=True),
'ebay_item_id': fields.many2one('ebay.item', 'eBay Item', ondelete='cascade'),
}
_defaults = {
'uos_coeff': 1.0
}
def split_str(s, sep):
if not s:
return list()
if sep == '\n':
s_list = s.splitlines()
else:
s_list = s.split(sep)
d = list()
for l in s_list:
d.append(l.strip())
return d
class ebay_item_category(osv.osv):
def name_get(self, cr, uid, ids, context=None):
"""Return the categories' display name, including their direct
parent by default.
:param dict context: the ``partner_category_display`` key can be
used to select the short version of the
category name (without the direct parent),
when set to ``'short'``. The default is
the long version."""
if context is None:
context = {}
if context.get('partner_category_display') == 'short':
return super(ebay_item_category, self).name_get(cr, uid, ids, context=context)
if isinstance(ids, (int, long)):
ids = [ids]
reads = self.read(cr, uid, ids, ['name', 'parent_id'], context=context)
res = []
for record in reads:
name = record['name']
if record['parent_id']:
name = record['parent_id'][1] + ' / ' + name
res.append((record['id'], name))
return res
def name_search(self, cr, uid, name, args=None, operator='ilike', context=None, limit=100):
if not args:
args = []
if not context:
context = {}
if name:
# Be sure name_search is symetric to name_get
name = name.split(' / ')[-1]
ids = self.search(cr, uid, [('name', operator, name)] + args, limit=limit, context=context)
else:
ids = self.search(cr, uid, args, limit=limit, context=context)
return self.name_get(cr, uid, ids, context)
def _name_get_fnc(self, cr, uid, ids, prop, unknow_none, context=None):
res = self.name_get(cr, uid, ids, context=context)
return dict(res)
_description = 'eBay Item Categories'
_name = 'ebay.item.category'
_columns = {
'name': fields.char('Category Name', required=True, size=64, translate=True),
'parent_id': fields.many2one('ebay.item.category', 'Parent Category', select=True, ondelete='cascade'),
'complete_name': fields.function(_name_get_fnc, type="char", string='Full Name'),
'child_ids': fields.one2many('ebay.item.category', 'parent_id', 'Child Categories'),
'active': fields.boolean('Active', help="The active field allows you to hide the category without removing it."),
'parent_left': fields.integer('Left parent', select=True),
'parent_right': fields.integer('Right parent', select=True),
'ebay_item_ids': fields.many2many('ebay.item', id1='ebay_item_category_id', id2='ebay_item_id', string='eBay Items'),
}
_constraints = [
(osv.osv._check_recursion, 'Error ! You can not create recursive categories.', ['parent_id'])
]
_defaults = {
'active': 1,
}
_parent_store = True
_parent_order = 'name'
_order = 'parent_left'
ebay_item_category()
class ebay_item(osv.osv):
_name = "ebay.item"
_description = "eBay item"
def _get_item_view_url(self, cr, uid, ids, field_name, arg, context):
if context is None:
context = {}
res = dict.fromkeys(ids, False)
for record in self.browse(cr, uid, ids, context=context):
if record.item_id:
if record.ebay_user_id.sandbox:
res[record.id] = "http://cgi.sandbox.ebay.com/ws/eBayISAPI.dll?ViewItem&item=%s" % record.item_id
else:
res[record.id] = "http://cgi.ebay.com/ws/eBayISAPI.dll?ViewItem&item=%s" % record.item_id
return res
def _get_image(self, cr, uid, ids, name, args, context=None):
result = dict.fromkeys(ids, False)
for obj in self.browse(cr, uid, ids, context=context):
result[obj.id] = obj.eps_picture_ids[0][name]
return result
def _has_image(self, cr, uid, ids, name, args, context=None):
result = {}
for obj in self.browse(cr, uid, ids, context=context):
result[obj.id] = obj.eps_picture_ids != False
return result
_columns = {
#'auto_pay': fields.boolean('AutoPay'),
'buyer_requirement_details_id': fields.many2one('ebay.buyerrequirementdetails', 'Buyer Requirement', ondelete='set null'),
'buy_it_now_price': fields.float('BuyItNowPrice'),
'condition_description_id': fields.many2one('ebay.conditiondescription', 'Condition Description', ondelete='set null'),
'condition_id': fields.integer('Condition ID'),
'country': fields.char('Country', size=2),
'cross_border_trade': fields.char('CrossBorderTrade'),
'currency': fields.char('Currency', size=3),
'description': fields.html('Description'),
'disable_buyer_requirements': fields.boolean('DisableBuyerRequirements'),
'dispatch_time_max': fields.integer('DispatchTimeMax'),
'hit_counter': fields.selection([
('BasicStyle', 'BasicStyle'),
('CustomCode', 'CustomCode'),
('GreenLED', 'GreenLED'),
('Hidden', 'Hidden'),
('HiddenStyle', 'HiddenStyle'),
('HonestyStyle', 'HonestyStyle'),
('NoHitCounter', 'NoHitCounter'),
('RetroStyle', 'RetroStyle'),
], 'HitCounter'),
'include_recommendations': fields.boolean('IncludeRecommendations'),
'item_specifics': fields.text('ItemSpecifics', help="""
For example:
Name1=Value1
Name2=Value2
Name3=Value3
"""),
'listing_duration': fields.selection([
('Days_1', '1 days'),
('Days_3', '3 days'),
('Days_5', '5 days'),
('Days_7', '7 days'),
('Days_10', '10 days'),
('Days_30', '30 days'),
('GTC', 'GTC'),
],'Duration', help='''
1 days (only for Auction)
30 days (only for Fixed Price)
GTC (only for Fixed Price)
'''),
'listing_type': fields.selection([
#('AdType', 'AdType'),
('Chinese', 'Auction'),
#('CustomCode', 'CustomCode'),
('FixedPriceItem', 'Fixed Price'),
#('Half', 'Half'),
#('LeadGeneration', 'LeadGeneration'),
], 'Format', required=True),
'location': fields.char('Location'),
'out_of_stock_control': fields.boolean('OutOfStockControl'),
'payment_methods': fields.char('PaymentMethods'),
'paypal_email_address': fields.char('PayPalEmailAddress'),
'payment_methods': fields.char('PaymentMethods'),
#PictureDetails
'eps_picture_ids': fields.one2many('ebay.eps.picture', 'ebay_item_id', 'Picture'),
'postal_code': fields.char('PostalCode'),
'primary_category_id': fields.many2one('ebay.category', 'Category', ondelete='set null'),
'quantity': fields.integer('Quantity', required=True),
'return_policy_id': fields.many2one('ebay.returnpolicy', 'Return Policy', ondelete='set null'),
'schedule_time': fields.datetime('ScheduleTime'),
'secondary_category_id': fields.many2one('ebay.category', '2nd Category', ondelete='set null'),
'shipping_details_id': fields.many2one('ebay.shippingdetails', 'Shipping Details', ondelete='set null'),
'shipping_terms_in_description': fields.boolean('ShippingTermsInDescription'),
'site': fields.char('Site', size=16),
'start_price': fields.float('StartPrice', required=True),
# Storefront
'store_category2id': fields.integer('2nd Store Category'),
'store_category2name': fields.char('2nd Store Category'),
'store_category_id': fields.integer('Store Category'),
'store_category_name': fields.char('Store Category'),
'subtitle': fields.char('SubTitle', size=55),
'name': fields.char('Title', required=True, select=True),
'uuid': fields.char('UUID', size=32),
# Variations
'variation_invalid': fields.boolean('Variation Invalid'),
'variation': fields.boolean('Variation'),
'variation_modify_specific_name': fields.text('Modify Name', help='''
oldname1 | newname1
oldname2 | newname2
...
'''),
'variation_specific_name': fields.char('Names', help='Primary name | Secondary name ...'),
'variation_specifics_set': fields.text('Values', help='''
Primary value1 | Primary value2 ...
Secondary value1 | Secondary value2 ...
'''),
'parent_id': fields.many2one('ebay.item', 'Parent Item', select=True, ondelete='cascade'),
'child_ids': fields.one2many('ebay.item', 'parent_id', 'Child Item'),
'variation_deleted': fields.boolean('Delete'),
# SKU
'product_ids': fields.one2many('ebay.product', 'ebay_item_id', 'Product'),
# Item Status ------------
'bid_count': fields.integer('Bit Count', readonly=True),
'end_time': fields.datetime('End Time', readonly=True),
'hit_count': fields.integer('Hit Count', readonly=True),
'item_id': fields.char('Item ID', size=38),
'quantity_sold': fields.integer('Sold', readonly=True),
'quantity_surplus': fields.integer('Surplus', readonly=True),
'start_time': fields.datetime('Start Time', readonly=True),
'state': fields.selection([
('Draft', 'Draft'),
('Active', 'Active'),
('Completed', 'Completed'),
('Ended', 'Ended'),
], 'Status', readonly=True),
'time_left': fields.char('Time Left', readonly=True),
'need_to_be_updated': fields.boolean('Need to be updated'),
'revise_date': fields.datetime('Revise Date', readonly=True),
'update_date': fields.datetime('Update Date', readonly=True),
'view_item_url': fields.function(_get_item_view_url, type='char', method=True, string='View Item'),
'watch_count': fields.integer('Watch Count', readonly=True),
'severity_code_error': fields.boolean('Severity Code Error', readonly=True),
'severity_code_warning': fields.boolean('Severity Code Warning', readonly=True),
'error_message': fields.html('Error Message', readonly=True),
'response': fields.text('Response', readonly=True),
# Additional Info
'description_tmpl_id': fields.many2one('ebay.item.description.template', 'Template', ondelete='set null'),
'site': fields.selection([
('US', 'US'),
('Canada', 'Canada',),
('UK', 'UK'),
('Australia', 'Australia'),
('HongKong', 'HongKong'),
], 'Site', required=True),
'ebay_user_id': fields.many2one('ebay.user', 'Account', domain=[('ownership','=',True)], ondelete='set null'),
'ebay_item_category_id': fields.many2many('ebay.item.category', id1='ebay_item_id', id2='ebay_item_category_id', string='Tags'),
'image': fields.function(_get_image, type="binary", method=True, string='Image'),
'has_image': fields.function(_has_image, type="boolean"),
}
def _get_default_buyer_requirement_details_id(self, cr, uid, context=None):
res = self.pool.get('ebay.buyerrequirementdetails').search(cr, uid, [], context=context)
return res and res[0] or False
def _get_default_return_policy_id(self, cr, uid, context=None):
res = self.pool.get('ebay.returnpolicy').search(cr, uid, [], context=context)
return res and res[0] or False
def _get_default_shipping_details_id(self, cr, uid, context=None):
res = self.pool.get('ebay.shippingdetails').search(cr, uid, [], context=context)
return res and res[0] or False
def _get_default_description_tmpl_id(self, cr, uid, context=None):
res = self.pool.get('ebay.item.description.template').search(cr, uid, [], context=context)
return res and res[0] or False
def _default_ebay_item_category(self, cr, uid, context=None):
if context is None:
context = {}
if context.get('ebay_item_category_id'):
return [context['ebay_item_category_id']]
return False
_defaults = {
'buyer_requirement_details_id': _get_default_buyer_requirement_details_id,
'buy_it_now_price': 19.99,
'condition_id': 1000,
'cross_border_trade': 'North America',
'country': 'CN',
'currency': 'USD',
'disable_buyer_requirements': False,
'dispatch_time_max': 2,
'hit_counter': 'HiddenStyle',
'include_recommendations': True,
'listing_duration': 'GTC',
'listing_type': 'FixedPriceItem',
'location': 'ShenZhen',
'quantity': 99,
'return_policy_id': _get_default_return_policy_id,
'shipping_details_id': _get_default_shipping_details_id,
'uuid': lambda self, cr, uid, context: uuid.uuid1().hex,
'variation_invalid': True,
'variation_deleted': False,
'start_price': 9.99,
'state': 'Draft',
'need_to_be_updated': True,
'site': 'US',
'description_tmpl_id': _get_default_description_tmpl_id,
'ebay_item_category_id': _default_ebay_item_category,
}
def on_change_primary_category_id(self, cr, uid, id, primary_category_id, listing_type, context=None):
if not primary_category_id:
return False
value = dict()
variation_invalid = False
category = self.pool.get('ebay.category').browse(cr, uid, primary_category_id, context=context)
if listing_type == 'Chinese':
value['quantity'] = 1
value['listing_duration'] = 'Days_7'
else:
value['quantity'] = 99
value['listing_duration'] = 'GTC'
if listing_type == 'Chinese' or not category.variations_enabled:
value['variation_invalid'] = True
value['variation'] = False
else:
value['variation_invalid'] = False
value['variation'] = False
return {
'value': value
}
def on_change_listing_type(self, cr, uid, id, primary_category_id, listing_type, context=None):
return self.on_change_primary_category_id(cr, uid, id, primary_category_id, listing_type, context=context)
def on_change_variation_specifics_set(self, cr, uid, id, variation_specifics_set, context=None):
value = dict()
specifics_set = split_str(variation_specifics_set, '\n')
value['name'] = '[%s]' % ']['.join(specifics_set)
return {
'value': value
}
def copy(self, cr, uid, id, default=None, context=None):
if default is None:
default = {}
name = self.read(cr, uid, id, ['name'], context=context)['name']
default = default.copy()
default.update({
'name': name + _(' (Copy)'),
'item_id': '',
'state': 'Draft',
'need_to_be_updated': True,
'uuid': uuid.uuid1().hex,
'severity_code_error': False,
'severity_code_warning': False,
'error_message': '',
})
return super(ebay_item, self).copy(cr, uid, id, default, context)
def unlink(self, cr, uid, ids, context=None, check=True):
if check:
for item in self.browse(cr, uid, ids, context=context):
if not item.parent_id or item.state != 'Active':
item.unlink(check=False)
else:
item.write(dict(variation_deleted=True))
else:
return super(ebay_item, self).unlink(cr, uid, ids, context=context)
return True
def write(self, cr, uid, ids, vals, context=None):
if context is None:
context = {}
if not ids:
return True
keywords = set([
'buyer_requirement_details_id',
'buy_it_now_price',
'condition_description_id',
'condition_id',
'country',
'cross_border_trade',
'currency',
'description',
'disable_buyer_requirements',
'dispatch_time_max',
'hit_counter',
'item_specifics',
'listing_duration',
'listing_type',
'location',
'out_of_stock_control',
'payment_methods',
'paypal_email_address',
'payment_methods',
'eps_picture_ids',
'postal_code',
'primary_category_id',
'quantity',
'return_policy_id',
'schedule_time',
'secondary_category_id',
'shipping_details_id',
'shipping_terms_in_description',
'site',
'start_price',
'store_category2id',
'store_category2name',
'store_category_id',
'store_category_name',
'subtitle',
'name',
'uuid',
'variation_specifics_set',
'variation_deleted',
'child_ids',
])
if len(keywords & set(vals.keys())) > 0 or vals.get('variation_modify_specific_name', ''):
vals['need_to_be_updated'] = True
state = vals.get('state')
if state in ('Completed', 'Ended'):
vals['uuid'] = uuid.uuid1().hex
return super(ebay_item, self).write(cr, uid, ids, vals, context=context)
def item_variation_dict(self, cr, uid, ids, item, item_dict, context=None):
if not item.child_ids:
return True
user = item.ebay_user_id
item_dict['Item']['Variations'] = dict()
specific_names = split_str(item.variation_specific_name, '|')
pictures = dict()
variants = list()
for variant in item.child_ids:
index = 0
name_value_list = list()
for value in split_str(variant.variation_specifics_set, '\n'):
name_value_list.append(dict(
Name=specific_names[index],
Value=value,
))
index+=1
v = dict(
Quantity=variant.quantity,
SKU=variant.id,
StartPrice=variant.start_price,
VariationSpecifics=dict(
NameValueList=name_value_list if len(name_value_list) > 1 else name_value_list[0],
)
)
if variant.eps_picture_ids:
specific_value = name_value_list[0]['Value']
for _pic in variant.eps_picture_ids:
if not pictures.has_key(specific_value):
pictures[specific_value] = list()
pictures[specific_value].append(_pic.full_url)
if variant.variation_deleted:
if variant.quantity_sold > 0:
v['Quantity'] = 0
else:
v['Delete'] = 'true'
variants.append(v)
item_dict['Item']['Variations']['Variation'] = variants if len(variants) > 1 else variants[0]
if pictures:
picture_set = dict(
VariationSpecificName=specific_names[0],
VariationSpecificPictureSet=dict()
)
variation_specific_picture_set = list()
for key, value in pictures.items():
variation_specific_picture_set.append(dict(
PictureURL=value if len(value) > 1 else value[0],
VariationSpecificValue=key,
))
picture_set['VariationSpecificPictureSet'] = variation_specific_picture_set \
if len(variation_specific_picture_set) > 1 \
else variation_specific_picture_set[0]
item_dict['Item']['Variations']['Pictures'] = picture_set