2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-06-17 12:35:46 +00:00

Remove old part pricing form

This commit is contained in:
Oliver Walters
2023-02-21 21:07:07 +11:00
parent 12c8c64414
commit 506ce8509d
3 changed files with 0 additions and 281 deletions

View File

@ -2088,9 +2088,6 @@ part_api_urls = [
# BOM download
re_path(r'^bom-download/?', views.BomDownload.as_view(), name='api-bom-download'),
# Old pricing endpoint
re_path(r'^pricing2/', views.PartPricing.as_view(), name='part-pricing'),
# Part detail endpoint
re_path(r'^.*$', PartDetail.as_view(), name='api-part-detail'),
])),

View File

@ -1,127 +0,0 @@
{% extends "modal_form.html" %}
{% load i18n inventree_extras %}
{% block pre_form_content %}
{% default_currency as currency %}
{% settings_value "PART_INTERNAL_PRICE" as show_internal_price %}
<table class='table table-striped table-condensed table-price-two'>
<tr>
<td><strong>{% trans 'Part' %}</strong></td>
<td>{{ part }}</td>
</tr>
<tr>
<td><strong>{% trans 'Quantity' %}</strong></td>
<td>{{ quantity }}</td>
</tr>
</table>
{% if part.supplier_count > 0 %}
<h4>{% trans 'Supplier Pricing' %}</h4>
<table class='table table-striped table-condensed table-price-three'>
{% if min_total_buy_price %}
<tr>
<td><strong>{% trans 'Unit Cost' %}</strong></td>
<td>Min: {% include "price.html" with price=min_unit_buy_price %}</td>
<td>Max: {% include "price.html" with price=max_unit_buy_price %}</td>
</tr>
{% if quantity > 1 %}
<tr>
<td><strong>{% trans 'Total Cost' %}</strong></td>
<td>Min: {% include "price.html" with price=min_total_buy_price %}</td>
<td>Max: {% include "price.html" with price=max_total_buy_price %}</td>
</tr>
{% endif %}
{% else %}
<tr>
<td colspan='3'>
<span class='warning-msg'><em>{% trans 'No supplier pricing available' %}</em></span>
</td>
</tr>
{% endif %}
</table>
{% endif %}
{% if part.bom_count > 0 %}
<h4>{% trans 'BOM Pricing' %}</h4>
<table class='table table-striped table-condensed table-price-three'>
{% if min_total_bom_price %}
<tr>
<td><strong>{% trans 'Unit Cost' %}</strong></td>
<td>Min: {% include "price.html" with price=min_unit_bom_price %}</td>
<td>Max: {% include "price.html" with price=max_unit_bom_price %}</td>
</tr>
{% if quantity > 1 %}
<tr>
<td><strong>{% trans 'Total Cost' %}</strong></td>
<td>Min: {% include "price.html" with price=min_total_bom_price %}</td>
<td>Max: {% include "price.html" with price=max_total_bom_price %}</td>
</tr>
{% endif %}
{% endif %}
{% if min_total_bom_purchase_price %}
<tr>
<td><strong>{% trans 'Unit Purchase Price' %}</strong></td>
<td>Min: {% include "price.html" with price=min_unit_bom_purchase_price %}</td>
<td>Max: {% include "price.html" with price=max_unit_bom_purchase_price %}</td>
</tr>
{% if quantity > 1 %}
<tr>
<td><strong>{% trans 'Total Purchase Price' %}</strong></td>
<td>Min: {% include "price.html" with price=min_total_bom_purchase_price %}</td>
<td>Max: {% include "price.html" with price=max_total_bom_purchase_price %}</td>
</tr>
{% endif %}
{% endif %}
{% if min_total_bom_price or min_total_bom_purchase_price %}
{% else %}
<tr>
<td colspan='3'>
<span class='warning-msg'><em>{% trans 'No BOM pricing available' %}</em></span>
</td>
</tr>
{% endif %}
</table>
{% endif %}
{% if show_internal_price and roles.sales_order.view %}
{% if total_internal_part_price %}
<h4>{% trans 'Internal Price' %}</h4>
<table class='table table-striped table-condensed table-price-two'>
<tr>
<td><strong>{% trans 'Unit Cost' %}</strong></td>
<td>{% include "price.html" with price=unit_internal_part_price %}</td>
</tr>
<tr>
<td><strong>{% trans 'Total Cost' %}</strong></td>
<td>{% include "price.html" with price=total_internal_part_price %}</td>
</tr>
</table>
{% endif %}
{% endif %}
{% if total_part_price %}
<h4>{% trans 'Sale Price' %}</h4>
<table class='table table-striped table-condensed table-price-two'>
<tr>
<td><strong>{% trans 'Unit Cost' %}</strong></td>
<td>{% include "price.html" with price=unit_part_price %}</td>
</tr>
<tr>
<td><strong>{% trans 'Total Cost' %}</strong></td>
<td>{% include "price.html" with price=total_part_price %}</td>
</tr>
</table>
{% endif %}
{% if min_unit_buy_price or min_unit_bom_price or min_unit_bom_purchase_price %}
{% else %}
<div class='alert alert-danger alert-block'>
{% trans 'No pricing information is available for this part.' %}
</div>
{% endif %}
<hr>
{% endblock %}

View File

@ -12,7 +12,6 @@ from django.utils.translation import gettext_lazy as _
from django.views.generic import DetailView, ListView
from common.files import FileManager
from common.models import InvenTreeSetting
from common.views import FileManagementAjaxView, FileManagementFormView
from company.models import SupplierPart
from InvenTree.helpers import str2bool, str2int
@ -495,156 +494,6 @@ class BomDownload(AjaxView):
}
class PartPricing(AjaxView):
"""View for inspecting part pricing information."""
model = Part
ajax_template_name = "part/part_pricing.html"
ajax_form_title = _("Part Pricing")
form_class = part_forms.PartPriceForm
role_required = ['sales_order.view', 'part.view']
def get_quantity(self):
"""Return set quantity in decimal format."""
return Decimal(self.request.POST.get('quantity', 1))
def get_part(self):
"""Return the Part instance associated with this view"""
try:
return Part.objects.get(id=self.kwargs['pk'])
except Part.DoesNotExist:
return None
def get_pricing(self, quantity=1, currency=None):
"""Returns context with pricing information."""
if quantity <= 0:
quantity = 1
# TODO - Capacity for price comparison in different currencies
currency = None
# Currency scaler
scaler = Decimal(1.0)
part = self.get_part()
ctx = {
'part': part,
'quantity': quantity,
'currency': currency,
}
if part is None:
return ctx
# Supplier pricing information
if part.supplier_count > 0:
buy_price = part.get_supplier_price_range(quantity)
if buy_price is not None:
min_buy_price, max_buy_price = buy_price
min_buy_price /= scaler
max_buy_price /= scaler
min_unit_buy_price = round(min_buy_price / quantity, 3)
max_unit_buy_price = round(max_buy_price / quantity, 3)
min_buy_price = round(min_buy_price, 3)
max_buy_price = round(max_buy_price, 3)
if min_buy_price:
ctx['min_total_buy_price'] = min_buy_price
ctx['min_unit_buy_price'] = min_unit_buy_price
if max_buy_price:
ctx['max_total_buy_price'] = max_buy_price
ctx['max_unit_buy_price'] = max_unit_buy_price
# BOM pricing information
if part.bom_count > 0:
use_internal = InvenTreeSetting.get_setting('PART_BOM_USE_INTERNAL_PRICE', False)
bom_price = part.get_bom_price_range(quantity, internal=use_internal)
purchase_price = part.get_bom_price_range(quantity, purchase=True)
if bom_price is not None:
min_bom_price, max_bom_price = bom_price
min_bom_price /= scaler
max_bom_price /= scaler
if min_bom_price:
ctx['min_total_bom_price'] = round(min_bom_price, 3)
ctx['min_unit_bom_price'] = round(min_bom_price / quantity, 3)
if max_bom_price:
ctx['max_total_bom_price'] = round(max_bom_price, 3)
ctx['max_unit_bom_price'] = round(max_bom_price / quantity, 3)
if purchase_price is not None:
min_bom_purchase_price, max_bom_purchase_price = purchase_price
min_bom_purchase_price /= scaler
max_bom_purchase_price /= scaler
if min_bom_purchase_price:
ctx['min_total_bom_purchase_price'] = round(min_bom_purchase_price, 3)
ctx['min_unit_bom_purchase_price'] = round(min_bom_purchase_price / quantity, 3)
if max_bom_purchase_price:
ctx['max_total_bom_purchase_price'] = round(max_bom_purchase_price, 3)
ctx['max_unit_bom_purchase_price'] = round(max_bom_purchase_price / quantity, 3)
# internal part pricing information
internal_part_price = part.get_internal_price(quantity)
if internal_part_price is not None:
ctx['total_internal_part_price'] = round(internal_part_price, 3)
ctx['unit_internal_part_price'] = round(internal_part_price / quantity, 3)
# part pricing information
part_price = part.get_price(quantity)
if part_price is not None:
ctx['total_part_price'] = round(part_price, 3)
ctx['unit_part_price'] = round(part_price / quantity, 3)
return ctx
def get_initials(self):
"""Returns initials for form."""
return {'quantity': self.get_quantity()}
def get(self, request, *args, **kwargs):
"""Perform custom GET action for this view"""
init = self.get_initials()
qty = self.get_quantity()
return self.renderJsonResponse(request, self.form_class(initial=init), context=self.get_pricing(qty))
def post(self, request, *args, **kwargs):
"""Perform custom POST action for this view"""
currency = None
quantity = self.get_quantity()
# Retain quantity value set by user
form = self.form_class(initial=self.get_initials())
# TODO - How to handle pricing in different currencies?
currency = None
# check if data is set
try:
data = self.data
except AttributeError:
data = {}
# Always mark the form as 'invalid' (the user may wish to keep getting pricing data)
data['form_valid'] = False
return self.renderJsonResponse(request, form, data=data, context=self.get_pricing(quantity, currency))
class CategoryDetail(InvenTreeRoleMixin, InvenTreePluginViewMixin, DetailView):
"""Detail view for PartCategory."""