Skip to content

Commit

Permalink
Merge pull request #3772 from lukaszkarykowski/sim_cards_add_transiti…
Browse files Browse the repository at this point in the history
…on_and_bulk_edit

ITS-432085 | added features to bulk edit and added new transition action in sim cards.
  • Loading branch information
jetalone85 authored May 16, 2023
2 parents 52ba954 + b9da35d commit 26589d0
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/ralph/sim_cards/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class SIMCardAdmin(
search_fields = ['card_number', 'phone_number', 'user__first_name',
'user__last_name', 'user__username']

bulk_edit_list = ['status', 'warehouse', 'user', 'owner']
bulk_edit_list = ['status', 'warehouse', 'user', 'owner', 'features']

list_filter = [
'status', 'features', 'phone_number', 'card_number', 'warehouse',
Expand Down
27 changes: 27 additions & 0 deletions src/ralph/sim_cards/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -354,3 +354,30 @@ def card_number_to_notes(cls, instances, **kwargs):
instance.remarks, instance.card_number
)
instance.card_number = kwargs['card number']

@classmethod
@transition_action(
form_fields={
'user': {
'field': forms.CharField(label=_('User')),
'autocomplete_field': 'user',
},
'owner': {
'field': forms.CharField(label=_('Owner')),
'autocomplete_field': 'owner',
'condition': lambda obj, actions: bool(obj.owner),
}
}
)
def change_user_and_owner(cls, instances, **kwargs):
UserModel = get_user_model() # noqa
user_id = kwargs.get('user', None)
user = UserModel.objects.get(id=user_id)
owner_id = kwargs.get('owner', None)
for instance in instances:
instance.user = user
if not owner_id:
instance.owner = user
else:
instance.owner = UserModel.objects.get(id=owner_id)
instance.location = user.location

0 comments on commit 26589d0

Please sign in to comment.