Skip to content
Snippets Groups Projects
Commit c24faafd authored by Tomáš Valenta's avatar Tomáš Valenta
Browse files

delete to-be-approved notice

parent d6f2e9f7
No related branches found
No related tags found
No related merge requests found
Pipeline #13844 passed
...@@ -314,6 +314,7 @@ class ContractAdmin( ...@@ -314,6 +314,7 @@ class ContractAdmin(
def save_model(self, request, obj, form, change): def save_model(self, request, obj, form, change):
is_new = obj.created_by is None is_new = obj.created_by is None
print(is_new)
# Need to generate primary keys first # Need to generate primary keys first
parent_save_response = super().save_model(request, obj, form, change) parent_save_response = super().save_model(request, obj, form, change)
...@@ -336,56 +337,56 @@ class ContractAdmin( ...@@ -336,56 +337,56 @@ class ContractAdmin(
from users.models import User from users.models import User
if is_new or obj.status != form.initial["status"]: headers = {
headers = { "Authorization": f"Token {settings.NASTENKA_API_TOKEN}",
"Authorization": f"Token {settings.NASTENKA_API_TOKEN}", "Content-Type": "application/json",
"Content-Type": "application/json", }
}
if not is_new and obj.status == obj.StatusTypes.WORK_IN_PROGRESS:
if obj.status == obj.StatusTypes.WORK_IN_PROGRESS: try:
try: user = User.objects.filter(id=obj.created_by.id).first()
user = User.objects.filter(id=obj.created_by.id).first()
notice = requests.post(
notice = requests.post( settings.NASTENKA_API_URL,
settings.NASTENKA_API_URL, data=json.dumps(
data=json.dumps( {
{ "name": f"Smlouva vrácena k úpravě - {obj.name}",
"name": f"Smlouva vrácena k úpravě - {obj.name}", "description": (
"description": ( obj.summary
obj.summary if obj.summary not in (None, "")
if obj.summary not in (None, "") else "Bez popisu."
else "Bez popisu." ),
), "contract_id": obj.id,
"contract_id": obj.id, "sso_ids": [user.sso_id],
"sso_ids": [user.sso_id], }
} ),
), headers=headers,
).raise_for_status()
if obj.after_approval_nastenka_notice_id is not None:
requests.delete(
f"{settings.NASTENKA_API_URL}/{obj.after_approval_nastenka_notice_id}",
headers=headers, headers=headers,
).raise_for_status() ).raise_for_status()
if obj.after_approval_nastenka_notice_id is not None: obj.after_approval_nastenka_notice_id = None
requests.delete( obj.save()
f"{settings.NASTENKA_API_URL}/{obj.after_approval_nastenka_notice_id}",
headers=headers,
).raise_for_status()
obj.after_approval_nastenka_notice_id = None
obj.save()
if obj.to_be_approved_nastenka_notice_id is not None: if obj.to_be_approved_nastenka_notice_id is not None:
requests.delete( requests.delete(
f"{settings.NASTENKA_API_URL}/{obj.to_be_approved_nastenka_notice_id}", f"{settings.NASTENKA_API_URL}/{obj.to_be_approved_nastenka_notice_id}",
headers=headers, headers=headers,
).raise_for_status() ).raise_for_status()
obj.to_be_approved_nastenka_notice_id = None obj.to_be_approved_nastenka_notice_id = None
obj.save() obj.save()
except Exception as exception: except Exception as exception:
logger.error( logger.error(
'Failed to send out "contract returned for editing" Nástěnka notification: %s', 'Failed to send out "contract returned for editing" Nástěnka notification: %s',
str(exception), str(exception),
) )
elif obj.status == obj.StatusTypes.TO_BE_APPROVED: elif is_new or obj.status != form.initial["status"]:
if obj.status == obj.StatusTypes.TO_BE_APPROVED:
try: try:
sso_ids = [] sso_ids = []
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment