Esempio n. 1
0
    def get_or_create_rate_chart(self, listing_id):
        try:
            rate_chart_map = ListingRateChartMap.objects.get(
                listing_id=listing_id)
            if rate_chart_map.rate_chart:
                return rate_chart_map.rate_chart
        except ListingRateChartMap.DoesNotExist:
            pass

        results = listing_solr_search('id:%s' % listing_id)
        if results and results.results and len(results.results) > 0:
            listing = results.results[0]
            product = Product()
            product.title = listing.get('title', '')
            product.description = listing.get('description', '')
            product.currency = listing.get('currency', 'inr')
            product.brand = self.get_other_brand('Other')
            product.model = ''
            product.category = self.get_other_category('Other')
            product.type = 'normal'
            product.status = 'unavailable'
            product.save()

            rate_chart = SellerRateChart()
            rate_chart.listing_id = listing_id
            rate_chart.product = product
            rate_chart.seller = self.get_seller(listing.get('userId', 0))
            rate_chart.status = 'unavailable'
            rate_chart.sku = listing.get('sku', '')
            rate_chart.condition = 'new'
            rate_chart.is_prefered = True
            rate_chart.list_price = Decimal(str(listing.get('mrp', 0)))
            rate_chart.offer_price = Decimal(str(listing.get('askingPrice',
                                                             0)))
            if rate_chart.offer_price > rate_chart.list_price:
                rate_chart.list_price = rate_chart.offer_price
            rate_chart.warranty = listing.get('warranty', '')
            rate_chart.gift_title = listing.get('gifts', '')
            rate_chart.shipping_charges = Decimal(
                str(listing.get('shippingCharges', '0.0')))
            rate_chart.shipping_duration = listing.get('shippingDuration',
                                                       '7-10 working days')
            rate_chart.availability = self.get_available_every_where()
            rate_chart.stock_status = 'notavailable'
            rate_chart.status = 'deleted'
            rate_chart.save()

            listing_rate_chart_map = ListingRateChartMap(listing_id=listing_id,
                                                         rate_chart=rate_chart)
            listing_rate_chart_map.save()

            return rate_chart

        return None
Esempio n. 2
0
    def get_or_create_rate_chart(self, listing_id):
        try:
            rate_chart_map = ListingRateChartMap.objects.get(
                    listing_id = listing_id)
            if rate_chart_map.rate_chart:
                return rate_chart_map.rate_chart
        except ListingRateChartMap.DoesNotExist:
            pass

        results = listing_solr_search('id:%s' % listing_id)
        if results and results.results and len(results.results) > 0:
            listing = results.results[0]
            product = Product()
            product.title = listing.get('title','')
            product.description = listing.get('description','')
            product.currency = listing.get('currency','inr')
            product.brand = self.get_other_brand('Other')
            product.model = ''
            product.category = self.get_other_category('Other')
            product.type = 'normal'
            product.status = 'unavailable'
            product.save()

            rate_chart = SellerRateChart()
            rate_chart.listing_id = listing_id
            rate_chart.product = product
            rate_chart.seller = self.get_seller(listing.get('userId',0))
            rate_chart.status = 'unavailable'
            rate_chart.sku = listing.get('sku', '')
            rate_chart.condition = 'new'
            rate_chart.is_prefered = True
            rate_chart.list_price = Decimal(str(listing.get('mrp',0)))
            rate_chart.offer_price = Decimal(str(listing.get('askingPrice',0)))
            if rate_chart.offer_price > rate_chart.list_price:
                rate_chart.list_price = rate_chart.offer_price
            rate_chart.warranty = listing.get('warranty','')
            rate_chart.gift_title = listing.get('gifts','')
            rate_chart.shipping_charges = Decimal(str(listing.get('shippingCharges','0.0')))
            rate_chart.shipping_duration = listing.get('shippingDuration','7-10 working days')
            rate_chart.availability = self.get_available_every_where()
            rate_chart.stock_status = 'notavailable'
            rate_chart.status = 'deleted'
            rate_chart.save()

            listing_rate_chart_map = ListingRateChartMap(listing_id=listing_id, rate_chart=rate_chart)
            listing_rate_chart_map.save()

            return rate_chart

        return None
Esempio n. 3
0
File: feed.py Progetto: daasara/riba
    def create_update_seller_rate_chart(self, master, data, rc=None, sync=None):
        cleaned_data = data['cleaned_data']

        changes = {}
        action = 'edited'
        if not rc:
            rc = SellerRateChart()
            action = 'added'
        else:
            changes = self.get_rc_changes(rc, data)

        rc.product = master
        rc.sku = cleaned_data['sku']
        if 'external_product_id' in cleaned_data:
            rc.external_product_id = cleaned_data['external_product_id']
        if 'external_product_link' in cleaned_data:
            rc.external_product_link = cleaned_data['external_product_link']
        rc.seller = self.get_account()
        rc.is_prefered = cleaned_data['is_prefered']

        # prices
        rc.offer_price = cleaned_data['offer_price']
        rc.list_price = cleaned_data['list_price']
        rc.transfer_price = cleaned_data['transfer_price']
        rc.warranty = cleaned_data['warranty']
        rc.gift_desc = cleaned_data['gift_desc']
        rc.gift_title = cleaned_data['gift_title']
        rc.shipping_charges = cleaned_data['shipping_charges']
        rc.shipping_duration = cleaned_data['shipping_duration']
        if 'stock_status' in cleaned_data:
            rc.stock_status = cleaned_data['stock_status']

        rc.cod_charge = cleaned_data['cod_charge']
        rc.payment_collection_charges = cleaned_data['payment_collection_charges']
        #rc.visibility_status = cleaned_data['visibility_status']
        rc.shipping_paid_by = cleaned_data['shipping_paid_by']
        rc.payment_charges_paid_by = cleaned_data['payment_charges_paid_by']
        if 'status' in cleaned_data and cleaned_data['status'] in ['active','deactive']:
            rc.status = cleaned_data['status']
        rc.availability = cleaned_data['availability']
        if 'min_qty' in cleaned_data:
            rc.min_qty = cleaned_data['min_qty']

        rc.short_desc = cleaned_data.get('short_desc','')
        rc.detailed_desc = cleaned_data.get('detailed_desc','')
        rc.key_feature = cleaned_data.get('key_feature','')
        rc.article_id = cleaned_data.get('article_id','')
        rc.is_cod_available = cleaned_data.get('is_cod_available',False)
        rc.is_fmemi_available = cleaned_data.get('is_fmemi_available',False)
        rc.whats_in_the_box = cleaned_data.get('in_the_box','')
        rc.ship_local_only = cleaned_data.get('ship_local_only','')
        rc.otc = cleaned_data.get('otc','')
        #Populating shipping related info in SellerRateChart
        #rc.is_free_shipping = cleaned_data.get('is_free_shipping',False)
        #if not rc.is_free_shipping:
        #    rc.shipping_percent = cleaned_data.get('percent',Decimal("0.0"))
        #    rc.min_shipping = cleaned_data.get('min_shipping',Decimal("0.0"))
        #    rc.max_shipping = cleaned_data.get('max_shipping',Decimal("0.0"))
        rc.save(using='default')

        if sync:
        #    sync_rc_mapping = SyncEventRateChartMapping(sync_event=sync,
        #            rate_chart=rc, action=action)
        #    sync_rc_mapping.item_title = cleaned_data['title']
        #    sync_rc_mapping.sku = cleaned_data['sku']
            
            # nothing to save its not a real edit
            if action == 'edited' and changes:
                sync.edits += 1
                #sync_rc_mapping.change_log = simplejson.dumps(changes)
                #sync_rc_mapping.save(using='default')
                sync.save(using='default')
            if action == 'added':
                sync.adds += 1
                #sync_rc_mapping.save(using='default')
                sync.save(using='default')

        reindex = False
        if action == 'added' or changes:
            reindex = True

        return rc, reindex