def update_item(self): """ Called from save function. Updates an existing item Exception handled in parent function """ response = reply_object() item_type = object_or_none("ItemType", self.cleaned_data["item_type"]) company = object_or_none("Company", self.cleaned_data["company"]) location = object_or_none("ItemLocation", self.cleaned_data["location"]) showroom = object_or_none("ShowRoom", self.cleaned_data["showroom"]) unit = object_or_none("ItemUnit", self.cleaned_data["item_unit"]) item = Item.objects.get(pk = self.cleaned_data["item_object_id"]) item.name = self.cleaned_data["name"] item.cost_price = self.cleaned_data["cost_price"] item.selling_price = self.cleaned_data["selling_price"] item.purchase_date = self.cleaned_data["purchase_date"] item.sold_date = self.cleaned_data["sold_date"] item.item_type = item_type item.item_code = self.generate_item_code() item.location = location item.guarantee_period_months = \ self.cleaned_data["guarantee_period_months"] item.guarantee_start_date = \ self.cleaned_data["guarantee_start_date"] item.paid = self.cleaned_data["paid"] item.sold = self.cleaned_data["sold"] item.company = company item.showroom = showroom item.unit = unit item.save() response["code"] = settings.APP_CODE["UPDATED"] response["item_object_id"] = item.id return response
def save_item(self): """ Called from save function. Creates a new item Exception handled in parent function """ response = reply_object() item_type = object_or_none("ItemType", self.cleaned_data["item_type"]) company = object_or_none("Company", self.cleaned_data["company"]) location = object_or_none("ItemLocation", self.cleaned_data["location"]) showroom = object_or_none("ShowRoom", self.cleaned_data["showroom"]) unit = object_or_none("ItemUnit", self.cleaned_data["item_unit"]) item = Item.objects.create(name = self.cleaned_data["name"], cost_price = self.cleaned_data["cost_price"], selling_price = self.cleaned_data["selling_price"], purchase_date = self.cleaned_data["purchase_date"], sold_date = self.cleaned_data["sold_date"], item_type = item_type, item_code = self.generate_item_code(), location = location, guarantee_period_months = \ self.cleaned_data["guarantee_period_months"], guarantee_start_date = \ self.cleaned_data["guarantee_start_date"], paid = self.cleaned_data["paid"], sold = self.cleaned_data["sold"], company = company, showroom = showroom, unit = unit) item.save() response["code"] = settings.APP_CODE["SAVED"] response["item_object_id"] = item.id return response
def save_object(self): response = reply_object() city_obj = object_or_none("City", self.cleaned_data["city"]) state_obj = object_or_none("State", self.cleaned_data["state"]) distributor_obj = Distributor.objects.create(name = self.cleaned_data["name"], phone_number = self.cleaned_data["phone_number"], state = state_obj, city = city_obj) distributor_obj.save() response["object_id"] = distributor_obj.id response["code"] = settings.APP_CODE["SAVED"] return response
def update_object(self): response = reply_object() city_obj = object_or_none("City", self.cleaned_data["city"]) state_obj = object_or_none("State", self.cleaned_data["state"]) distributor_obj = Distributor.objects.get\ (pk = self.cleaned_data["object_id"]) distributor_obj.name = self.cleaned_data["name"] distributor_obj.phone_number = self.cleaned_data["phone_number"] distributor_obj.state = state_obj distributor_obj.city = city_obj distributor_obj.save() response["object_id"] = distributor_obj.id response["code"] = settings.APP_CODE["UPDATED"] return response