Skip to content

Commit

Permalink
Ensure VendorProduct uniqueness test is for new products only
Browse files Browse the repository at this point in the history
Update Error message on duplicate - feedback from ops.
  • Loading branch information
sei-vsarvepalli committed Apr 21, 2023
1 parent 6e12387 commit 6138197
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
5 changes: 3 additions & 2 deletions vince/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -3886,8 +3886,9 @@ class Meta:
unique_together = (('name', 'organization'),)

def save(self, *args, **kwargs):
if VendorProduct.objects.filter(organization=self.organization,
name__iexact=self.name):
dup = VendorProduct.objects.filter(organization=self.organization,
name__iexact=self.name)
if self._state.adding and dup:
logger.debug(f"Ignoring duplicate VendorProduct {self.name}")
return
return super(VendorProduct, self).save(*args, **kwargs)
Expand Down
5 changes: 3 additions & 2 deletions vince/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -9758,8 +9758,9 @@ def post(self, request, *args, **kwargs):
sectors = self.request.POST.getlist('sector')

if VendorProduct.objects.filter(organization=contact,name__iexact=name):
messages.error(self.request,_("Duplicate product names not allowed"))
return HttpResponseRedirect(reverse('vince:contact', args=[self.kwargs["pk"]]))
messages.error(self.request,_("Product (case insensitive) and Vendor tuple shoud be unique!"))
return HttpResponseRedirect(reverse('vince:contact', args=[self.kwargs["pk"]]) + '#products')


product = VendorProduct(name=name,
sector=sectors,
Expand Down

0 comments on commit 6138197

Please sign in to comment.