from django.http import HttpResponse

from LiveStock.helpers import convert_to_miladi
from LiveStock.models import LiveStock, LiveStockRolseProduct, LiveStockProduct, Rancher


def add_birthday(reqeust):
    live_stock=LiveStock.objects.filter(trash=False,birth_day_gh__isnull=True).only('birth_day')
    for l in live_stock:
        birth_day=l.birth_day.split('/')
        birth_day_gh=convert_to_miladi(year=int(birth_day[0]),month=int(birth_day[1]),day=int(birth_day[2]))
        l.birth_day_gh=birth_day_gh
        l.save()
    return HttpResponse('ok')

def add_live_stock(request):
    rancher=Rancher.objects.get(herd_code='139894930',trash=False)
    lve_stock=LiveStock.objects.filter(herd_code=rancher.herd_code,trash=False).first()
    for _i in range(110):
        live_stock=LiveStock(
            herd_code=lve_stock.herd_code,
            national_id_livestock_code=lve_stock.national_id_livestock_code,
            type=lve_stock.type,
            birth_day=lve_stock.birth_day,
            birth_day_gh=lve_stock.birth_day_gh,
            gender=lve_stock.gender,

        )
        live_stock.save()
    return HttpResponse('ok')
