Example #1
0
    def _update_or_create_item(self, **kwds):
        item_options_list = [
            'price', 'wholesale_price', 'quantity', 'barcode',
            'identifier', 'short_description', 'name', 'slug',
        ]
        item_options = {}
        for k, v in kwds.iteritems():
            if k in item_options_list:
                item_options[k] = v
        item_options['slug'] = urlify(kwds['name'])
        
        if kwds['identifier'] in self.data['item_by_identifier']:
            item = self.data['item_by_identifier'][kwds['identifier']]
            for k, v in item_options.iteritems():
                setattr(item, k, v)
            item.save()
 
            self.data['item_by_identifier'].update({item.identifier: item})
            logging.debug('[U] %s' % kwds['name'])
            # True if created
            return False
        else:
            item = Item(**item_options)
            item.save()

            tree_item = TreeItem(parent=kwds['parent'], content_object=item)
            tree_item.save()
            
            self.data['item_by_identifier'].update({item.identifier: item})
            logging.debug('[S] %s' % item.name)
            # True if created
            return True
Example #2
0
def add_item(item, box_name_text):
    try:
        box_name = BoxName.objects.get(name=box_name_text)
    except:
        print '[ERROR] BoxName not found'
    try:    
        item = Item.objects.get(name=item, box_name=box_name)
    except:
        item = Item(name=item, box_name=box_name)
        item.save()
    return item
Example #3
0
 def create(self, request, id, multiverse_id):
     name = Card.objects.get(multiverse_id=multiverse_id).card_details.name
     catalog = Catalog.objects.get(id=id)
     if catalog.items.filter(identifier=multiverse_id).count() == 0:
         item = Item(name=name, quantity=1, identifier=multiverse_id)
         item.save()
         catalog.items.add(item)
     else:
         item = catalog.items.get(identifier=multiverse_id)
         item.quantity = item.quantity + 1
         item.save()
     return HttpResponse(json.dumps({"success": True}), content_type="application/json")
Example #4
0
def item_save(request, item_id):
    categories = Category.objects.all().order_by('name')
    error = False
    error_message = []

    if(item_id == 0 or item_id == '0'):
        item = Item()
        item.state = STATE_AVAILABLE
    else:
        item = get_object_or_404(Item, pk=item_id)
    item.name = request.POST['name']
    item.description = request.POST['description']
    item.condition = request.POST['condition']

    if len(item.name) == 0:
        error = True
        error_message.append("El nombre es requerido")

    if len(item.condition) == 0:
        error = True
        error_message.append("La condicion es requerida")

    article_id = request.POST['article']
    if article_id != 0 and article_id != '0':
        item.article = Article.objects.get(id=article_id)
    else:
        item.article = None

    if error:
        articles = Article.objects.all().order_by('name')
        context = {
            'categories': categories,
            'item': item,
            'error_message': error_message,
            'articles': articles,
        }
        return render(request, 'item_add.html', context)
    else:
        item.save()
        article = Article.objects.get(pk=item.article.id)
        context = {
            'categories': categories,
            'article': article,
            'success_message': 'El item ' + item.name + ' ha sido eliminado exitosamente.',
        }
        return render(request, 'article.html', context)
Example #5
0
def create_item(request, box_name, item_name, description):
    if box_name == '' or item_name == '':
        return simplejson.dumps({'message': 'Box Name and item name are required.', 'success': 0})

    try:
        box = BoxName.objects.get(name=box_name)
    except BoxName.DoesNotExist:
        return simplejson.dumps({'message':'Box Name "%s" does not exist' % box_name, 'success': 0})

    if Item.objects.filter(name=item_name).filter(box_name = box).count() > 0:
        return simplejson.dumps({'message':'Item "%s" already exists' % item_name, 'success': 0})

    new_item = Item(name=item_name,
                    description=description,
                    box_name=BoxName.objects.get(name=box_name))
    new_item.save()

    return simplejson.dumps({'message':'%s has been added.' % item_name, 'success': 1})
Example #6
0
    def create_item(self, item_params):
        try:
            target_tree_item = TreeItem.objects.get(name=u'Импорт')
        except TreeItem.DoesNotExist:
            target_tree_item = TreeItem(parent_id=None, name=u'Импорт')
            target_tree_item.save()
            target_section = Section(is_meta_item=False)
            target_section.save()
            target_tree_item.section = target_section
            target_tree_item.save()

        new_tree_item = TreeItem(name=item_params['name'][:200],
                                 parent=target_tree_item)
        new_item = Item(
            price=item_params['price'],
            identifier=item_params['identifier'],
            quantity=item_params['quantity'],
        )
        new_tree_item.save()
        new_item.save()
        new_tree_item.item = new_item
        new_tree_item.save()
Example #7
0
 def create_item(self, item_params):
     try:
         target_tree_item = TreeItem.objects.get(name=u'Импорт')
     except TreeItem.DoesNotExist:
         target_tree_item = TreeItem(parent_id=None, name=u'Импорт')
         target_tree_item.save()
         target_section = Section(is_meta_item=False)
         target_section.save()
         target_tree_item.section = target_section
         target_tree_item.save()
         
     new_tree_item = TreeItem(name = item_params['name'][:200],
         parent=target_tree_item)
     new_item = Item(
         price = item_params['price'],
         identifier = item_params['identifier'],
         quantity = item_params['quantity'],
     )
     new_tree_item.save()
     new_item.save()
     new_tree_item.item = new_item
     new_tree_item.save()
Example #8
0
    def _update_or_create_item(self, **kwds):
        item_options_list = [
            'price',
            'wholesale_price',
            'quantity',
            'barcode',
            'identifier',
            'short_description',
            'name',
            'slug',
        ]
        item_options = {}
        for k, v in kwds.iteritems():
            if k in item_options_list:
                item_options[k] = v
        item_options['slug'] = urlify(kwds['name'])

        if kwds['identifier'] in self.data['item_by_identifier']:
            item = self.data['item_by_identifier'][kwds['identifier']]
            for k, v in item_options.iteritems():
                setattr(item, k, v)
            item.save()

            self.data['item_by_identifier'].update({item.identifier: item})
            logging.debug('[U] %s' % kwds['name'])
            # True if created
            return False
        else:
            item = Item(**item_options)
            item.save()

            tree_item = TreeItem(parent=kwds['parent'], content_object=item)
            tree_item.save()

            self.data['item_by_identifier'].update({item.identifier: item})
            logging.debug('[S] %s' % item.name)
            # True if created
            return True
Example #9
0
    ('Compound Benzoin Tincture Swabsticks','Z', True,False),
    ('Skin Protectant Swabsticks','Z', True,False),
    ('Skin Prep Pads & Protective Barrier Wipes','Z', True,False),
    ('Petroleum Jelly','Z', True,False),
    ('Q-Tips & Cotton-Tipped Applicators','Z', True,False),
    ('Tongue Depressors','Z', True,False),
    ('Band-Aids, Steri-Strips','Z', True,False),
    ('Blades/Scalpels','Z', True,False),
    ('Fish/Bowel Protector','Z', True,False),
    ('Goggles','Z', True,True),
    ('Hot/Cold Packs','Z', True,True),
    ('Lubricating Gel & Surgical Lubricant','Z', True,False),
    ('Spill Kits','Z', True,True),
    ('Ultrasound Gel','Z', True,False),
    ('Large Equipment','#',False,False),
    ('Small Equipment','#',False,False)
    )

for pair in box_name_mapping:
    box_name = BoxName(name=pair[0], category=Category.objects.get(letter=pair[1]), can_expire=pair[2], can_count=pair[3])
    box_name.save()

item_file = file('/var/www/MediVol/catalog/item_list.txt', 'r')
box_name = None
for line in item_file:
    if ':' in line:
        box_name = BoxName.objects.get(name=line.split(":")[0]) 
    else:
        item = Item(box_name=box_name, name=line.strip(), description='')
        item.save()