# -*- coding: utf-8 -*-
'''
Created on Feb 22, 2015

@author: ymh
'''
import logging

from django.db import transaction

from hdalab.models.renkan import HdalabRenkanStateTransition


logger = logging.getLogger(__name__)

@transaction.atomic
def change_renkan_state(hda_renkan, state, message=None, author=None):
    
    if state != hda_renkan.state:
        
        HdalabRenkanStateTransition.objects.create(renkan=hda_renkan, from_state=hda_renkan.state, to_state=state, message=message, author=author)
        hda_renkan.state = state
        hda_renkan.save()
        
