Beispiel #1
0
    def unity_price_change(self):
        """Handle the change in unity price, validating and updating other
        values.
        """
        # Get information.
        price_input = self.ids['unity_price']
        price_text = price_input.text

        # Check if changed and update information.
        if format_brl(self.unity_price) != price_text:
            self.unity_price = parse_brl(price_text)
            self.total_price = self.quantity * self.unity_price
            self.ids['total'].text = format_brl(self.total_price)
            self.ids['unity_price'].text = format_brl(self.unity_price)
            self.parent.compute_total()
Beispiel #2
0
 def on_pre_enter(self):
     """Update informations before entering the screen."""
     client = self.manager.client
     total = sum(Decimal(i.total) for i in client.orders)
     paid = sum(Decimal(i.amount) for i in client.payments)
     orders = [{
         "order_id": order.id,
         "local": order.local,
         "delivered": order.delivered,
         "total": order.total
     } for order in client.orders]
     self.ids['name'].text = client.name
     self.ids['phone'].text = client.phone
     self.ids['total'].text = format_brl(total)
     self.ids['paid'].text = format_brl(paid)
     self.ids['orders'].data = reversed(orders)
Beispiel #3
0
    def total_change(self):
        """Handle the change in price, validating and updating other values."""
        # Get information.
        total_input = self.ids['total']
        total_text = total_input.text

        # Check if changed and update information.
        if format_brl(self.total_price) != total_text:
            self.total_price = parse_brl(total_text)
            self.ids['total'].text = format_brl(self.total_price)

            # Prevent division by zero.
            if self.quantity:
                self.unity_price = self.total_price / self.quantity
                self.ids['unity_price'].text = format_brl(self.unity_price)
            self.parent.compute_total()
Beispiel #4
0
    def quantity_change(self):
        """Handle the change in quantity, validating and updating other values."""
        quantity_input = self.ids['quantity']
        quantity_text = quantity_input.text

        # Prevent errors for empty inputs.
        if not quantity_text:
            quantity_text = '0'

        # Prevent error parsing decimal because of commas.
        quantity_text = quantity_text.replace(',', '.')

        # Remove more than one dots.
        while quantity_text.count('.') > 1:
            quantity_text = quantity_text[::-1].replace('.', '', 1)[::-1]

        # Prevent the decimal dot to be removed when parsing decimal.
        if quantity_text[-1] == '.':
            quantity_input.text = quantity_text
        else:
            # If the exception InvalidOperation or Overflow is raised, do not
            # changed the values, making it not changed.
            try:
                self.quantity = abs(Decimal(quantity_text))
                self.total_price = self.quantity * self.unity_price
            except (InvalidOperation, Overflow):
                pass

            # Update the values.
            quantity_input.text = str(self.quantity)
            self.ids['total'].text = format_brl(self.total_price)
            self.parent.compute_total()
Beispiel #5
0
    def on_pre_enter(self):
        """Update the itens before entering screen."""
        # Get the itens from the session
        app = App.get_running_app()
        itens = app.session.query(Iten).all()

        # Parse the itens and update the RecycleView data
        itens = [{'name': i.name, 'price': format_brl(i.price)} for i in itens]
        self.ids['itens'].data = itens
Beispiel #6
0
    def on_pre_enter(self):
        """Update the information before entering the screen."""
        # Get the data
        client = self.manager.client
        payments = client.payments
        total = sum(Decimal(i.total) for i in client.orders)
        paid = sum(Decimal(i.amount) for i in payments)
        data = [{
            "payment_id": p.id,
            "amount": p.amount,
            "date": p.date.strftime("%d/%m/%Y")
        } for p in payments]

        # Set the data
        self.ids['name'].text = client.name
        self.ids['phone'].text = client.phone
        self.ids['total'].text = format_brl(total)
        self.ids['paid'].text = format_brl(paid)
        self.ids['remaining'].text = format_brl(total - paid)
        self.ids['payments'].data = reversed(data)
Beispiel #7
0
 def on_pre_enter(self):
     """Update all information before entering."""
     order = self.manager.order
     itens = [{
         'name': iten['name'],
         'quantity': Decimal(iten['quantity']),
         'price': Decimal(iten['price'])
     } for iten in order.itens]
     self.ids['title'].text = f"Detalhes da encomenda número {order.id}."
     self.ids['delivered'].text = "Sim" if order.delivered else "Não"
     self.ids['local'].text = order.local
     self.ids['info'].text = order.extra_info
     self.ids['total'].text = format_brl(order.total)
     self.ids['itens'].data = itens
Beispiel #8
0
 def compute_total(self):
     """Calculate the total."""
     app = App.get_running_app()
     label = app.new_order.sm.current_screen.ids['total']
     label.text = format_brl(sum(iten.total_price for iten in self.itens))