fix(interventions): import Contract and ContractPost in admin to fix OperationTemplate change view
This commit is contained in:
parent
c8349a3171
commit
ce924d7af4
2 changed files with 28 additions and 2 deletions
|
|
@ -41,6 +41,7 @@ from .services import generate_interventions_excel
|
|||
|
||||
from common.models import Thematic
|
||||
from assets.models import AssetCategory
|
||||
from contracts.models import Contract, ContractPost
|
||||
from interventions.views.preventive_import import process_worksheet as _process_worksheet
|
||||
import json
|
||||
from django.contrib.contenttypes.models import ContentType
|
||||
|
|
@ -944,7 +945,6 @@ class ContractOperationTemplatePostInlineForm(forms.ModelForm):
|
|||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
from contracts.models import ContractPost
|
||||
contract_id = None
|
||||
if self.instance and self.instance.pk and self.instance.contract_id:
|
||||
contract_id = self.instance.contract_id
|
||||
|
|
@ -1036,7 +1036,6 @@ class ContractOperationTemplatePostAdminForm(forms.ModelForm):
|
|||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
from contracts.models import ContractPost
|
||||
contract_id = None
|
||||
if self.instance and self.instance.pk and self.instance.contract_id:
|
||||
contract_id = self.instance.contract_id
|
||||
|
|
|
|||
|
|
@ -1238,6 +1238,33 @@ class ContractOperationTemplatePostTests(TestCase):
|
|||
self.assertIn(self.contract.id, contract_ids)
|
||||
self.assertNotIn(self.contract_other.id, contract_ids)
|
||||
|
||||
def test_operation_template_admin_change_view(self):
|
||||
"""Test that OperationTemplate admin change view renders without NameError."""
|
||||
self.user.is_staff = True
|
||||
self.user.is_superuser = True
|
||||
self.user.save()
|
||||
self.client.login(username='test_user_posts', password='password123')
|
||||
url = reverse('admin:interventions_operationtemplate_change', args=[self.template_a.id])
|
||||
res = self.client.get(url, {'_changelist_filters': f'thematic__id__exact={self.thematic.id}'})
|
||||
self.assertEqual(res.status_code, 200)
|
||||
|
||||
def test_contract_operation_template_post_admin_change_view(self):
|
||||
"""Test that ContractOperationTemplatePost admin change view renders without NameError."""
|
||||
self.user.is_staff = True
|
||||
self.user.is_superuser = True
|
||||
self.user.save()
|
||||
self.client.login(username='test_user_posts', password='password123')
|
||||
mapping = ContractOperationTemplatePost.objects.create(
|
||||
operation_template=self.template_a,
|
||||
contract=self.contract,
|
||||
contract_post=self.post_1,
|
||||
default_quantity=Decimal('2.00'),
|
||||
)
|
||||
url = reverse('admin:interventions_contractoperationtemplatepost_change', args=[mapping.id])
|
||||
res = self.client.get(url)
|
||||
self.assertEqual(res.status_code, 200)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue