示例#1
0
    def save(self):
        log.debug("Saving new product:")
        log.debug("cleaned data = %s" % self.cleaned_data)
        product = self.cleaned_data['product']
        product.producer = self._supplier
        product.save()

        stock = SupplierStock(
            product = product,
            price = self.cleaned_data['price'],
            units_minimum_amount = self.cleaned_data['units_minimum_amount'],
            units_per_box = self.cleaned_data['units_per_box'],
            detail_minimum_amount = self.cleaned_data['detail_minimum_amount'],
            detail_step = self.cleaned_data['detail_step'],
            supplier = self._supplier,
            code = self.cleaned_data.get('code'),
            amount_available = self.cleaned_data['amount_available'],
            supplier_category = self.cleaned_data.get('supplier_category')
        )
        stock.save()
示例#2
0
    def save(self):
        log.debug("Saving new product:")
        log.debug("cleaned data = %s" % self.cleaned_data)
        product = self.cleaned_data["product"]
        product.producer = self._supplier
        product.save()

        stock = SupplierStock(
            product=product,
            price=self.cleaned_data["price"],
            units_minimum_amount=self.cleaned_data["units_minimum_amount"],
            units_per_box=self.cleaned_data["units_per_box"],
            detail_minimum_amount=self.cleaned_data["detail_minimum_amount"],
            detail_step=self.cleaned_data["detail_step"],
            supplier=self._supplier,
            code=self.cleaned_data.get("code"),
            amount_available=self.cleaned_data["amount_available"],
            supplier_category=self.cleaned_data.get("supplier_category"),
        )
        stock.save()
示例#3
0
    def save(self):
        log.info(u"[%s] user:%s, cleaned_data:%s" %
                 (self.__class__.__name__, self.request.user.username,
                  tuple(u"%s=%s" % (k, unicode(v))
                        for k, v in self.cleaned_data.items())))
        product = self.cleaned_data['product']
        product.producer = self._supplier
        product.save()

        stock = SupplierStock(
            product=product,
            price=self.cleaned_data['price'],
            units_minimum_amount=self.cleaned_data['units_minimum_amount'],
            units_per_box=self.cleaned_data['units_per_box'],
            detail_minimum_amount=self.cleaned_data['detail_minimum_amount'],
            detail_step=self.cleaned_data['detail_step'],
            supplier=self._supplier,
            code=self.cleaned_data.get('code'),
            amount_available=self.cleaned_data['amount_available'],
            supplier_category=self.cleaned_data.get('supplier_category'))
        stock.save()
示例#4
0
    def save(self):
        log.info(u"[%s] user:%s, cleaned_data:%s" % (
            self.__class__.__name__,
            self.request.user.username, 
            tuple(u"%s=%s" % (k,unicode(v)) for k,v in self.cleaned_data.items())
        ))
        product = self.cleaned_data['product']
        product.producer = self._supplier
        product.save()

        stock = SupplierStock(
            product = product,
            price = self.cleaned_data['price'],
            units_minimum_amount = self.cleaned_data['units_minimum_amount'],
            units_per_box = self.cleaned_data['units_per_box'],
            detail_minimum_amount = self.cleaned_data['detail_minimum_amount'],
            detail_step = self.cleaned_data['detail_step'],
            supplier = self._supplier,
            code = self.cleaned_data.get('code'),
            amount_available = self.cleaned_data['amount_available'],
            supplier_category = self.cleaned_data.get('supplier_category')
        )
        stock.save()
示例#5
0
    def handle(self, *args, **options):

        try:
            csv_filename_suppliers = args[0]
            csv_filename_products = args[1]
        except:
            raise CommandError("Usage import_suppliers: %s" % (self.args))

        if len(args) > 2:
            delimiter = args[2]
        else:
            delimiter = ";"

        if len(args) == 4:
            tmpl_1 = args[3]
        else:
            tmpl_1 = "%(fake_id_supplier)s %(name)s %(flavour)s %(city)s %(phone)s %(email)s  %(address)s %(certification)s %(website)s %(iban)s %(n_employers)s %(vat_number)s %(ssn)s %(image)s %(description)s"

        if len(args) == 5:
            tmpl_2 = args[4]
        else:
            tmpl_2 = "%(fake_id_supplier)s %(name)s %(price)s %(vat)s %(pu)s %(mu)s  %(muppu)s %(category)s %(code)s  %(units_minimum_amount)s  %(units_per_box)s  %(detail_minimum_amount)s %(detail_step)s"

        # STEP 0: prepare data in dicts
        data_suppliers = self._prepare_data(csv_filename_suppliers, delimiter,
                                            tmpl_1)
        data_products = self._prepare_data(csv_filename_products, delimiter,
                                           tmpl_2)

        # Data prepared
        with transaction.commit_on_success():
            i = 0
            sum_sup = 0
            sum_pro = 0
            sum_pro_all = 0
            for sup_d in data_suppliers:
                i += 1
                try:
                    #log.info(pprint("#### ---- start new supplier import (%s)... ----####\n --> %s" % (i, sup_d)))
                    log.info(
                        pprint(
                            "#### ---- start new supplier import (%s)... ----####"
                            % (i)))
                    sups = Supplier.objects.filter(
                        name__icontains=sup_d['name'])
                    if sups.count():
                        print "Found suppliers with name %s" % sups.values(
                            'name')
                        continue
                        #raise CommandError("Found suppliers with name %s" % sups.values('name'))

                    else:
                        sum_sup += 1
                        sum_pro = 0
                        log.info(
                            pprint("-------------Supplier(%s) [%s]" %
                                   (sum_sup, sup_d['name'])))

                        #'phone','email'
                        contacts = self._get_or_create_contacts(sup_d)
                        #'city','address'
                        place = self._get_or_create_place(sup_d)

                        #{"pk":81,"model":"supplier.supplier", "fields": {"name":"Ittingrosso","website":"","flavour":" COOPERATING","seat":89,"vat_number": " 1336220437" ,"contact_set": [81,162,405] ,"certifications": [4]  ,"frontman": 82 } },
                        s = Supplier(
                            name=sup_d['name'],
                            #flavour=sup_d['flavour'],Error: Supplier Key 'choices' is REQUIRED.
                            seat=place,
                            website=sup_d['website'],
                            vat_number=sup_d['vat_number'],
                            iban=sup_d['iban'],
                            ssn=sup_d['ssn'],
                            description=sup_d['description'],
                            n_employers=self._avoid_empty(
                                sup_d['n_employers'], None),
                            #FIXME: certifications= self._get_certification(sup_d),
                        )
                        #TODO: frontman=sup_d['name' and 'surname' --> Person],
                        s.save()
                        s.contact_set.add(*contacts)
                        log.info(
                            pprint(
                                ("CREATED SUPPLIER %s" % s).decode(ENCODING)))

                        for product_d in data_products:
                            try:
                                sup_pk = sup_d['fake_id_supplier']
                                pro_pk = product_d['fake_id_supplier']
                                if pro_pk != sup_pk:
                                    continue
                                else:
                                    sum_pro += 1
                                    sum_pro_all += 1
                                    log.info(
                                        pprint(
                                            "     %s=%s product [%s]   (%s-%s-%s)"
                                            %
                                            (sup_pk, pro_pk, product_d['name'],
                                             sum_sup, sum_pro, sum_pro_all)))

                                    # Create product and bind to producer(Supplier)
                                    #{"pk":1,"model":"supplier.product", "fields": {"name":"Olio ", "category":37, "producer":1, "mu":4, "pu":6, "muppu_is_variable":false, "vat_percent":"0.04" }  } ,
                                    #tmpl_2 = "%(fake_id_supplier)s %(name)s %(vat)s %(pu)s %(mu)s  %(muppu)s

                                    p = Product(
                                        name=product_d['name'],
                                        producer=s,
                                        category=self._get_category(
                                            product_d['category']),
                                        mu=self._get_mu(product_d['mu']),
                                        pu=self._get_pu(product_d['pu']),
                                        muppu=self._avoid_empty(
                                            product_d['muppu'], None),
                                        #muppu_is_variable=self._bool(product_d['muppu_is_variable'], True),
                                        vat_percent=self._avoid_empty(
                                            product_d['vat'], None),
                                    )
                                    #p.save()

                                    # Create stock and bind to product and supplier
                                    #{"pk": 1,"model": "supplier.supplierstock","fields": {"product": 1,"supplier":1,"amount_available":0,"price":"25.00", "units_per_box" : " 1" , "detail_minimum_amount" : "1.00" , "detail_step" :" 1.00 "  }  } ,
                                    #tmpl_2 = %(price)s  %(units_minimum_amount)s  %(units_per_box)s  %(detail_minimum_amount)s %(detail_step)s"
                                    log.info(
                                        pprint(
                                            "PASS Product %s step(%s)" %
                                            (p.pk, product_d['detail_step'])))

                                    s_s = SupplierStock(
                                        product=p,
                                        supplier=s,
                                        code=product_d['code'],
                                        amount_available=product_d[
                                            'units_minimum_amount'],
                                        #FIXME: django.core.exceptions.ValidationError: [u'This value must be a decimal number.']
                                        #FIXME: raise TypeError("Cannot convert %r to Decimal" % value)
                                        price=decimal.Decimal(
                                            self._avoid_empty(
                                                product_d['price'], 0.0)),
                                        #units_per_box=self._get_pretty(product_d['units_per_box'], STEP),
                                        #detail_minimum_amount=self._get_pretty(product_d['detail_minimum_amount'], STEP),
                                        #detail_step=self._get_pretty(product_d['detail_step'], STEP),
                                    )
                                    #s_s.save()

                                    #    price = CurrencyField(verbose_name=_("price"))
                                    #    code = models.CharField(verbose_name=_("code"), max_length=128, null=True, blank=True, help_text=_("Product
                                    #    amount_available = models.PositiveIntegerField(verbose_name=_("availability"), default=ALWAYS_AVAILABLE)
                                    #    units_minimum_amount = models.PositiveIntegerField(default=1, verbose_name = _('units minimum amount'))
                                    #    units_per_box = PrettyDecimalField(default=1, max_digits=5, decimal_places=2
                                    #    detail_minimum_amount = PrettyDecimalField(default=1, verbose_name = _('detail minimum amount'),
                                    #    detail_step = PrettyDecimalField(null=True, blank=True, default=1

                                    log.info(
                                        pprint("PASS SupplierStock %s " %
                                               (s_s.pk)))

                            except KeyError, e:
                                raise CommandError(
                                    "Product Key '%s' is REQUIRED." %
                                    e.message)

                except KeyError, e:
                    raise CommandError("Supplier Key '%s' is REQUIRED." %
                                       e.message)
    def handle(self, *args, **options):

        simulate = False
        delimiter = ";"
        tmpl_1 = "%(ID)s %(Active (0/1))s %(Name *)s %(Description)s %(Short description)s %(Meta title)s %(Meta keywords)s %(Meta description)s %(ImageURL)s"
        tmpl_2 = "%(ID)s %(Active (0/1))s %(Name *)s %(Categories (x,y,z...))s %(Price tax excluded or Price tax included)s %(Tax rules ID)s %(Wholesale price)s %(On sale (0/1)s %(Discount amount)s %(Discount percent)s %(Discount from (yyyy-mm-dd))s %(Discount to (yyyy-mm-dd))s %(Reference #)s %(Supplier reference #)s %(Supplier)s %(Manufacturer)s %(EAN13)s %(UPC)s %(Ecotax)s %(Width)s %(Height)s %(Depth)s %(Weight)s %(Quantity)s %(Minimal quantity)s %(Visibility)s %(Additional shipping cost)s %(Unity)s %(Unit price)s %(Short description)s %(Description)s %(Tags (x,y,z...))s %(Meta title)s %(Meta keywords)s %(Meta description)s %(URL rewritten)s %(Text when in stock)s %(Text when backorder allowed)s %(Available for order (0 = No, 1 = Yes))s %(Product available date)s %(Product creation date)s %(Show price (0 = No, 1 = Yes))s %(Image URLs (x,y,z...))s %(Delete existing images (0 = No, 1 = Yes))s %(Feature(Name:Value:Position))s %(Available online only (0 = No, 1 = Yes))s %(Condition)s %(Customizable (0 = No, 1 = Yes))s %(Uploadable files (0 = No, 1 = Yes))s %(Text fields (0 = No, 1 = Yes))s %(Out of stock)s %(ID / Name of shop)s %(Advanced stock management)s %(Depends On Stock)s %(Warehouse)s "
        try:
            csv_filename_suppliers = args[0]
            csv_filename_products = args[1]
        except:
            raise CommandError("Usage import_suppliers: %s" % (self.args))

        try:
            i = 2
            while i < 6:
                arg = args[i].split("=")
                if arg[0] == "delimiter":
                    delimiter = arg[1]
                elif arg[0] == "simulate":
                    simulate = self._bool(arg[1], False)
                elif arg[0] == "python_template":
                    tmpl_1 = arg[1]
                elif arg[0] == "python_template2":
                    tmpl_2 = arg[1]
                i += 1
        except IndexError as e:
            pass

        # STEP 0: prepare data in dicts
        data_suppliers = self._prepare_data(csv_filename_suppliers, delimiter, tmpl_1)
        data_products = self._prepare_data(csv_filename_products, delimiter, tmpl_2)

        # Data prepared
        with transaction.commit_on_success():
            i = 0
            sum_sup = 0
            sum_pro = 0
            sum_pro_all = 0
            for sup_d in data_suppliers:
                i += 1
                try:
                    log.info(pprint("#### ---- start new supplier import (%s)... ----####" % (i)))
                    sum_sup += 1
                    sum_pro = 0
                    log.info(pprint("-------------Supplier(%s) [%s]" % (sum_sup, sup_d["Name *"])))

                    s = Supplier(
                        name=sup_d["Name *"],
                        website="",
                        iban="",
                        description=sup_d["Description"],
                        logo=sup_d["ImageURL"],
                    )

                    if not simulate:
                        s.save()
                        log.info(pprint(("CREATED Supplier %s with pk [%s]" % (s, s.pk)).decode(ENCODING)))
                    else:
                        log.info(pprint(("SIMULATED Supplier %s with pk [%s]" % (s, s.pk)).decode(ENCODING)))

                    for product_d in data_products:
                        try:
                            sup_name = sup_d["Name *"]
                            pro_name = product_d["Manufacturer"]
                            if pro_name != sup_name:
                                continue
                            else:
                                sum_pro += 1
                                sum_pro_all += 1
                                log.info(
                                    pprint(
                                        "     %s=%s product [%s]   (%s-%s-%s)"
                                        % (sup_name, pro_name, product_d["Name *"], sum_sup, sum_pro, sum_pro_all)
                                    )
                                )

                                p = Product(
                                    name=product_d["Name *"],
                                    producer=s,
                                    category=self._get_category(product_d["Categories (x,y,z..."]),
                                    mu=self._get_mu(None),
                                    pu=self._get_pu(None),
                                    muppu=self._avoid_empty(None, None),
                                )

                                if not simulate:
                                    p.save()
                                    log.info(pprint("CREATED Product with pk: [%s]" % p.pk))
                                else:
                                    log.info(pprint("SIMULATED Product with pk: [%s]" % p.pk))

                                log.info(pprint("PASS Product %s step(%s)" % (p.pk, product_d["Minimal quantity"])))

                                s_s = SupplierStock(
                                    product=p,
                                    supplier=s,
                                    amount_available=product_d["Quantity"],
                                    detail_step=product_d["Minimal quantity"],
                                    price=decimal.Decimal(
                                        self._avoid_empty(product_d["Price tax excluded or Price tax included"], 0.0)
                                    ),
                                )

                                if not simulate:
                                    s_s.save()
                                    log.info(pprint("CREATED SupplierStock with pk: [%s]" % s_s.pk))
                                else:
                                    log.info(pprint("SIMULATED SupplierStock with pk: [%s]" % s_s.pk))

                                log.info(pprint("PASS SupplierStock %s " % (s_s.pk)))

                        except KeyError, e:
                            raise CommandError("Product Key '%s' is REQUIRED." % e.message)

                except KeyError, e:
                    raise CommandError("Supplier Key '%s' is REQUIRED." % e.message)
示例#7
0
    def handle(self, *args, **options):

        simulate = False
        delimiter = ';'
        tmpl_1 = "%(ID)s %(Active (0/1))s %(Name *)s %(Description)s %(Short description)s %(Meta title)s %(Meta keywords)s %(Meta description)s %(ImageURL)s"
        tmpl_2 = "%(ID)s %(Active (0/1))s %(Name *)s %(Categories (x,y,z...))s %(Price tax excluded or Price tax included)s %(Tax rules ID)s %(Wholesale price)s %(On sale (0/1)s %(Discount amount)s %(Discount percent)s %(Discount from (yyyy-mm-dd))s %(Discount to (yyyy-mm-dd))s %(Reference #)s %(Supplier reference #)s %(Supplier)s %(Manufacturer)s %(EAN13)s %(UPC)s %(Ecotax)s %(Width)s %(Height)s %(Depth)s %(Weight)s %(Quantity)s %(Minimal quantity)s %(Visibility)s %(Additional shipping cost)s %(Unity)s %(Unit price)s %(Short description)s %(Description)s %(Tags (x,y,z...))s %(Meta title)s %(Meta keywords)s %(Meta description)s %(URL rewritten)s %(Text when in stock)s %(Text when backorder allowed)s %(Available for order (0 = No, 1 = Yes))s %(Product available date)s %(Product creation date)s %(Show price (0 = No, 1 = Yes))s %(Image URLs (x,y,z...))s %(Delete existing images (0 = No, 1 = Yes))s %(Feature(Name:Value:Position))s %(Available online only (0 = No, 1 = Yes))s %(Condition)s %(Customizable (0 = No, 1 = Yes))s %(Uploadable files (0 = No, 1 = Yes))s %(Text fields (0 = No, 1 = Yes))s %(Out of stock)s %(ID / Name of shop)s %(Advanced stock management)s %(Depends On Stock)s %(Warehouse)s "
        try:
            csv_filename_suppliers = args[0]
            csv_filename_products = args[1]
        except:
            raise CommandError("Usage import_suppliers: %s" % (self.args))

        try:
            i = 2
            while (i < 6):
                arg = args[i].split('=')
                if arg[0] == 'delimiter':
                    delimiter = arg[1]
                elif arg[0] == 'simulate':
                    simulate = self._bool(arg[1], False)
                elif arg[0] == 'python_template':
                    tmpl_1 = arg[1]
                elif arg[0] == 'python_template2':
                    tmpl_2 = arg[1]
                i += 1
        except IndexError as e:
            pass

        # STEP 0: prepare data in dicts
        data_suppliers = self._prepare_data(csv_filename_suppliers, delimiter,
                                            tmpl_1)
        data_products = self._prepare_data(csv_filename_products, delimiter,
                                           tmpl_2)

        # Data prepared
        with transaction.commit_on_success():
            i = 0
            sum_sup = 0
            sum_pro = 0
            sum_pro_all = 0
            for sup_d in data_suppliers:
                i += 1
                try:
                    log.info(
                        pprint(
                            "#### ---- start new supplier import (%s)... ----####"
                            % (i)))
                    sum_sup += 1
                    sum_pro = 0
                    log.info(
                        pprint("-------------Supplier(%s) [%s]" %
                               (sum_sup, sup_d['Name *'])))

                    s = Supplier(
                        name=sup_d['Name *'],
                        website='',
                        iban='',
                        description=sup_d['Description'],
                        logo=sup_d['ImageURL'],
                    )

                    if not simulate:
                        s.save()
                        log.info(
                            pprint(("CREATED Supplier %s with pk [%s]" %
                                    (s, s.pk)).decode(ENCODING)))
                    else:
                        log.info(
                            pprint(("SIMULATED Supplier %s with pk [%s]" %
                                    (s, s.pk)).decode(ENCODING)))

                    for product_d in data_products:
                        try:
                            sup_name = sup_d['Name *']
                            pro_name = product_d['Manufacturer']
                            if pro_name != sup_name:
                                continue
                            else:
                                sum_pro += 1
                                sum_pro_all += 1
                                log.info(
                                    pprint(
                                        "     %s=%s product [%s]   (%s-%s-%s)"
                                        % (sup_name, pro_name,
                                           product_d['Name *'], sum_sup,
                                           sum_pro, sum_pro_all)))

                                p = Product(
                                    name=product_d['Name *'],
                                    producer=s,
                                    category=self._get_category(
                                        product_d['Categories (x,y,z...']),
                                    mu=self._get_mu(None),
                                    pu=self._get_pu(None),
                                    muppu=self._avoid_empty(None, None),
                                )

                                if not simulate:
                                    p.save()
                                    log.info(
                                        pprint(
                                            "CREATED Product with pk: [%s]" %
                                            p.pk))
                                else:
                                    log.info(
                                        pprint(
                                            "SIMULATED Product with pk: [%s]" %
                                            p.pk))

                                log.info(
                                    pprint(
                                        "PASS Product %s step(%s)" %
                                        (p.pk, product_d['Minimal quantity'])))

                                s_s = SupplierStock(
                                    product=p,
                                    supplier=s,
                                    amount_available=product_d['Quantity'],
                                    detail_step=product_d['Minimal quantity'],
                                    price=decimal.Decimal(
                                        self._avoid_empty(
                                            product_d[
                                                'Price tax excluded or Price tax included'],
                                            0.0)),
                                )

                                if not simulate:
                                    s_s.save()
                                    log.info(
                                        pprint(
                                            "CREATED SupplierStock with pk: [%s]"
                                            % s_s.pk))
                                else:
                                    log.info(
                                        pprint(
                                            "SIMULATED SupplierStock with pk: [%s]"
                                            % s_s.pk))

                                log.info(
                                    pprint("PASS SupplierStock %s " %
                                           (s_s.pk)))

                        except KeyError, e:
                            raise CommandError(
                                "Product Key '%s' is REQUIRED." % e.message)

                except KeyError, e:
                    raise CommandError("Supplier Key '%s' is REQUIRED." %
                                       e.message)