def calculate_biscuit_price(): data = {'data': []} produced_biscuits = ProduceBiscuit.objects.filter(for_price='un_calculate') each_price_for_biscuit = Decimal(calculate_expense() / len(produced_biscuits)) staff_salary_for_biscuit = Decimal(staff_salary() / len(produced_biscuits)) technological_man_salary = Decimal(technological_salary() / len(produced_biscuits)) for produced_biscuit in produced_biscuits: total_price = 0 biscuit = produced_biscuit.biscuit quantity = produced_biscuit.quantity recipes = get_biscuit_recipe(biscuit) for recipe in recipes: product = recipe.product value = recipe.value product_price = get_product_price(product) total_price = Decimal(total_price + product_price * value * quantity + each_price_for_biscuit + staff_salary_for_biscuit + technological_man_salary) / Decimal(quantity) data['data'].append({ 'biscuit': biscuit.id, 'biscuit_cost': total_price }) return data
def add_manufactured_product(instance): product = get_manufactured_product(instance.product.id) ware_product = get_warehouse_manufactured_product(product) recipe = get_product_recipe(product) for i in recipe: product = i.product value = i.value warehouse = get_warehouse_product(product) price = get_product_price(product) quantity_value = Decimal(instance.quantity) * Decimal(value) new_total_price = Decimal(price) * quantity_value if check_warehouse_product_quantity(recipe, instance.quantity) == len(recipe): warehouse.quantity -= Decimal(quantity_value) warehouse.total_price -= Decimal(new_total_price) warehouse.save() if check_warehouse_product_quantity(recipe, instance.quantity) == len(recipe): ware_product.add_quantity(Decimal(instance.quantity)) ware_product.set_total_price() ware_product.set_average_price() ware_product.save() return True else: return False
def subtract_quantity_unfit_biscuit(instance): obj = AddUnFitBiscuitLog.objects.get(unfit_biscuit_id=instance.id) unfit_biscuit, _ = get_or_create_unfit_biscuit(instance.biscuit, instance.status) unfit_biscuit.subtract_quantity(obj.quantity) unfit_biscuit.set_total_price() unfit_biscuit.save() recipe = get_biscuit_recipe(instance.biscuit) for i in recipe: product = i.product value = i.value warehouse = get_warehouse_product(product) price = get_product_price(product) quantity_value = obj.quantity * value warehouse.quantity += quantity_value new_total_price = price * quantity_value warehouse.total_price += new_total_price new_quantity_value = instance.quantity * value warehouse.quantity -= new_quantity_value new_total_price = price * new_quantity_value warehouse.total_price -= new_total_price warehouse.save() unfit_biscuit.add_quantity(instance.quantity) unfit_biscuit.set_total_price() unfit_biscuit.save() obj.quantity = instance.quantity obj.save()
def unfit_biscuit_add_quantity(validated_data, unfit_biscuit): recipe = get_biscuit_recipe(validated_data.get('biscuit')) for i in recipe: product = i.product value = i.value warehouse = get_warehouse_product(product) price = get_product_price(product) quantity_value = validated_data.get('quantity') * value warehouse.quantity -= quantity_value new_total_price = price * quantity_value warehouse.total_price -= new_total_price warehouse.save() unfit_biscuit.add_quantity(validated_data.get('quantity')) unfit_biscuit.set_total_price() unfit_biscuit.save()
def add_quantity_unfit_biscuit(instance): unfit_biscuit, _ = get_or_create_unfit_biscuit(instance.biscuit, instance.status) recipe = get_biscuit_recipe(instance.biscuit) for i in recipe: product = i.product value = i.value warehouse = get_warehouse_product(product) price = get_product_price(product) quantity_value = instance.quantity * value warehouse.quantity -= quantity_value new_total_price = price * quantity_value warehouse.total_price -= new_total_price warehouse.save() unfit_biscuit.add_quantity(instance.quantity) unfit_biscuit.set_total_price() unfit_biscuit.save()
def subtract_product(validated_data): biscuit = validated_data.get('biscuit') ware_biscuit = get_warehouse_biscuit(biscuit) recipe = get_biscuit_recipe(biscuit) for i in recipe: product = i.product value = i.value warehouse = get_warehouse_product(product) price = get_product_price(product) quantity_value = validated_data.get('quantity') * value new_total_price = price * quantity_value warehouse.quantity -= quantity_value warehouse.total_price -= new_total_price warehouse.save() ware_biscuit.add_quantity(validated_data.get('quantity')) ware_biscuit.set_total_price() ware_biscuit.save()
def unfit_biscuit_subtract_quantity(instance, validated_data): unfit_biscuit, _ = get_or_create_unfit_biscuit(instance.biscuit, instance.status) unfit_biscuit.subtract_quantity(instance.quantity) unfit_biscuit.set_total_price() unfit_biscuit.save() old_recipe = get_biscuit_recipe(instance.biscuit) for i in old_recipe: product = i.product value = i.value warehouse = get_warehouse_product(product) price = get_product_price(product) quantity_value = instance.quantity * value warehouse.quantity += quantity_value new_total_price = price * quantity_value warehouse.total_price += new_total_price warehouse.save() unfit_biscuit, _ = get_or_create_unfit_biscuit(validated_data.get('biscuit'), validated_data.get('status')) unfit_biscuit_add_quantity(validated_data, unfit_biscuit)
def subtract_product_update(instance, validated_data): biscuit = instance.biscuit old_recipe = get_biscuit_recipe(biscuit) ware_biscuit = get_warehouse_biscuit(biscuit) ware_biscuit.subtract_quantity(instance.quantity) ware_biscuit.set_total_price() ware_biscuit.save() for i in old_recipe: product = i.product value = i.value warehouse = get_warehouse_product(product) price = get_product_price(product) quantity_value = instance.quantity * value warehouse.quantity += quantity_value new_total_price = price * quantity_value warehouse.total_price += new_total_price warehouse.save() subtract_product(validated_data)
def manufactured_product_add_update(instance, validated_data): product = instance.product ware_product = get_warehouse_manufactured_product(product) recipe = get_product_recipe(product) ware_product.subtract_quantity(instance.quantity) ware_product.set_total_price() ware_product.set_average_price() ware_product.save() for i in recipe: product = i.product value = i.value warehouse = get_warehouse_product(product) price = get_product_price(product) quantity_value = instance.quantity * value warehouse.quantity += quantity_value new_total_price = price * quantity_value warehouse.total_price += new_total_price warehouse.save() manufactured_product_add(validated_data)
def manufactured_product_add(validated_data): product = validated_data.get('product') ware_product = get_warehouse_manufactured_product(product) recipe = get_product_recipe(product) for i in recipe: product = i.product value = i.value warehouse = get_warehouse_product(product) price = get_product_price(product) quantity_value = Decimal( validated_data.get('quantity')) * Decimal(value) new_total_price = Decimal(price) * quantity_value warehouse.quantity -= Decimal(quantity_value) warehouse.total_price -= Decimal(new_total_price) warehouse.save() ware_product.add_quantity(Decimal(validated_data.get('quantity'))) ware_product.set_total_price() ware_product.set_average_price() ware_product.save()
def subtract_manufactured_product(instance): obj = AddManufacturedProductLog.objects.get( manufactured_product_id=instance.id) product = get_manufactured_product(instance.product.id) ware_product = get_warehouse_manufactured_product(product) recipe = get_product_recipe(product) if check_warehouse_product_quantity(recipe, instance.quantity) == len(recipe): ware_product.subtract_quantity(obj.quantity) ware_product.set_total_price() ware_product.set_average_price() ware_product.save() for i in recipe: product = i.product value = i.value warehouse = get_warehouse_product(product) price = get_product_price(product) quantity_value = obj.quantity * value warehouse.quantity += quantity_value new_total_price = price * quantity_value warehouse.total_price += new_total_price new_quantity_value = instance.quantity * value if check_warehouse_product_quantity(recipe, instance.quantity) == len(recipe): warehouse.quantity -= new_quantity_value new_total_price = price * new_quantity_value warehouse.total_price -= new_total_price warehouse.save() if check_warehouse_product_quantity(recipe, instance.quantity) == len(recipe): ware_product.add_quantity(instance.quantity) ware_product.set_total_price() ware_product.set_average_price() ware_product.save() obj.quantity = instance.quantity obj.product = instance.product obj.save()