-
-
Notifications
You must be signed in to change notification settings - Fork 792
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[FR] Calculating Subtotal of Sale Order Items for use in Sale Order Form #7608
Comments
I ended up adding a custom filters file to the template tags folder.
I then call the filter in the Sale Order template like so: |
This can also be implemented with a custom ReportMixin plugin by adding a context variable to the report. from plugin import InvenTreePlugin
from plugin.mixins import ReportMixin
from decimal import *
from djmoney.money import Money
from djmoney.contrib.exchange.models import convert_money
from common.currency import currency_code_default
class InvoiceReportPlugin(ReportMixin, InvenTreePlugin):
NAME = 'Invoice Report Plugin'
SLUG = 'invoicereportplugin'
TITLE = 'Invoice Report Plugin'
DESCRIPTION = 'A plugin which adds total_no_extra context variable to the report context.'
VERSION = '0.0.1'
def calculate_total_no_extra_lines(self, order, target_currency):
total = Money(0, target_currency)
for line in order.lines.all():
if not line.price:
continue
total += line.quantity * convert_money(line.price, target_currency)
return total
def add_report_context(self, report_instance, model_instance, request, context):
"""Add example content to the report instance."""
# We can add any extra context data we want to the report
# Generate a random string of data
if report_instance.model_type == 'salesorder':
target_currency = currency_code_default()
context['total_no_extra'] = self.calculate_total_no_extra_lines(model_instance, target_currency) |
This issue seems stale. Please react to show this is still important. |
Please verify that this feature request has NOT been suggested before.
Problem statement
Below is a code snippet from a sale order template. This snippet generates a table that has the sale order items and a separate area for the line order items. In my case, I am modeling this sale order template after a receipt. I would like to include the total of only the sale order items as a "subtotal" at the base of the sale order items portion of the table. The "total" will appear at the bottom off the extra line portion of the table. Currently, a variable to reference that "subtotal" does not exist. Only the
order.total_price
variable to get the overall total including extra line items.Suggested solution
After looking through the code on Github I think I have narrowed down the two files that would need to be altered to include this "subtotal" variable. The
admin.py
andmodels.py
inInvenTree/src/backend/InvenTree/order/
. I am trying to build a potential solution to this, but my unfamiliarity with the code and all references is making it challenging.Here are some of the relevant places I think the code would need altering.
Describe alternatives you've considered
The other way to achieve this is to open the template editor and open the respective sales order. Then create a
<p>
or<span>
and manually calculate and insert the value. I was trying to automate this, but this is an option.Examples of other systems
No response
Do you want to develop this?
The text was updated successfully, but these errors were encountered: