wuttapos/wuttapos/controls/txnitem.py
Lance Edgar 9340e0d1bc Add button for "Adjust Price"
so far no constraints: any user, any item, any price
2023-10-05 20:04:29 -05:00

143 lines
4.8 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# -*- coding: utf-8; -*-
################################################################################
#
# WuttaPOS -- Pythonic Point of Sale System
# Copyright © 2023 Lance Edgar
#
# This file is part of WuttaPOS.
#
# WuttaPOS is free software: you can redistribute it and/or modify it under the
# terms of the GNU General Public License as published by the Free Software
# Foundation, either version 3 of the License, or (at your option) any later
# version.
#
# WuttaPOS is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
# details.
#
# You should have received a copy of the GNU General Public License along with
# WuttaPOS. If not, see <http://www.gnu.org/licenses/>.
#
################################################################################
"""
WuttaPOS - txn item control
"""
import flet as ft
from .base import WuttaControl
class WuttaTxnItem(WuttaControl):
"""
Control for displaying a transaction line item within main POS
items list.
"""
font_size = 24
def __init__(self, config, row, *args, **kwargs):
super().__init__(config, *args, **kwargs)
self.row = row
def build(self):
self.major_style = ft.TextStyle(size=self.font_size,
weight=ft.FontWeight.BOLD)
self.minor_style = ft.TextStyle(size=int(self.font_size * 0.8),
italic=True)
if self.row.row_type == self.enum.POS_ROW_TYPE_SELL:
return self.build_item_sell()
elif self.row.row_type in (self.enum.POS_ROW_TYPE_TENDER,
self.enum.POS_ROW_TYPE_CHANGE_BACK):
return self.build_item_tender()
def build_item_sell(self):
self.quantity = ft.TextSpan(style=self.minor_style)
self.txn_price = ft.TextSpan(style=self.minor_style)
self.sales_total_style = ft.TextStyle(size=self.font_size,
weight=ft.FontWeight.BOLD)
self.sales_total = ft.TextSpan(style=self.sales_total_style)
# set initial text display values
self.refresh(update=False)
return ft.Row(
[
ft.Text(
spans=[
ft.TextSpan(f"{self.row.description}",
style=self.major_style),
ft.TextSpan("× ", style=self.minor_style),
self.quantity,
ft.TextSpan(" @ ", style=self.minor_style),
self.txn_price,
],
),
ft.Text(
spans=[
self.sales_total,
],
),
],
alignment=ft.MainAxisAlignment.SPACE_BETWEEN,
)
def build_item_tender(self):
return ft.Row(
[
ft.Text(
spans=[
ft.TextSpan(f"{self.row.description}",
style=self.major_style),
],
),
ft.Text(
spans=[
ft.TextSpan(self.app.render_currency(self.row.tender_total),
style=self.major_style),
],
),
],
alignment=ft.MainAxisAlignment.SPACE_BETWEEN,
)
def refresh(self, update=True):
if self.row.void:
self.major_style.color = 'red'
self.major_style.decoration = ft.TextDecoration.LINE_THROUGH
self.minor_style.color = 'red'
self.minor_style.decoration = ft.TextDecoration.LINE_THROUGH
else:
self.major_style.color = None
self.major_style.decoration = None
self.minor_style.color = None
self.minor_style.decoration = None
if self.row.row_type == self.enum.POS_ROW_TYPE_SELL:
self.quantity.text = self.app.render_quantity(self.row.quantity)
self.txn_price.text = self.app.render_currency(self.row.txn_price)
self.sales_total.text = self.app.render_currency(self.row.sales_total)
if self.row.void:
self.sales_total_style.color = 'red'
self.sales_total_style.decoration = ft.TextDecoration.LINE_THROUGH
else:
if self.row.txn_price < self.row.reg_price:
self.sales_total_style.color = 'green'
else:
self.sales_total_style.color = None
self.sales_total_style.decoration = None
if update:
self.update()