def create_product(self): if not self.is_valid: return # Decide on unit & amount unit = self.data['unit'] unit_amount, unit = find_unit(unit) prod = Product.objects.create( name=self.data['name'], description=self.data['description'] if self.data['description'] else "", unit=unit, unit_amount=unit_amount, base_price=self.data['base_price'], maximum_total_order=self.data['maximum_total_order'], supplier=self.supplier, order_round=self.order_round, ) if self.data['category']: try: prod.category = ProductCategory.objects.get(name=self.data['category']) prod.save() except ProductCategory.DoesNotExist: pass return prod
def create_product(self): if not self.is_valid: return # Decide on unit & amount unit = self.data['unit'] unit_amount, unit = find_unit(unit) prod = Product.objects.create( name=self.data['name'], description=(self.data['description'] if self.data['description'] else ""), unit=unit, unit_amount=unit_amount, base_price=self.data['base_price'], maximum_total_order=self.data['maximum_total_order'], supplier=self.supplier, order_round=self.order_round, ) if self.data['category']: try: prod.category = ProductCategory.objects.get( name=self.data['category']) prod.save() except ProductCategory.DoesNotExist: pass return prod
def convert_units(apps, schema_editor): Product = apps.get_model("ordering", "Product") ProductUnit = apps.get_model("ordering", "ProductUnit") for p in Product.objects.all(): old_unit = p.unit_of_measurement try: amount, new_unit = find_unit(old_unit) except RuntimeError: amount = 1 new_unit = ProductUnit.objects.get(name="Stuk") new_unit = ProductUnit.objects.get(id=new_unit.id) p.temp_unit = new_unit p.unit_amount = amount p.save()
def _valid_unit(self, unit): try: find_unit(unit) return True except (RuntimeError, TypeError): return False
def _valid_unit(unit): try: find_unit(unit) return True except (RuntimeError, TypeError): return False