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()
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()
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()
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()
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)
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)