Example #1
0
 def data(self, index, role=Qt.DisplayRole):
     '''Refer to QAbstractItemModel.data.
     '''
     if not index.isValid() or \
     not (0 <= index.row() < self.rowCount()):
         return None
     line_item = self.line_items[index.row()]
     column = index.column()
     if role == Qt.DisplayRole or role == Qt.EditRole:
         if column == self.ORDER_NUMBER_COLUMN:
             return line_item.purchase_order.order_number
         elif column == self.ORDER_DATE_COLUMN:
             return line_item.purchase_order.order_date.strftime("%Y-%m-%d")
         elif column == self.ORDER_STATUS_COLUMN:
             return line_item.purchase_order.order_status
         elif column == self.PROJECT_CODE_COLUMN:
             return line_item.purchase_order.project.code
         elif column == self.SUPPLIER_COMPANY_NAME_COLUMN:
             return line_item.purchase_order.supplier.company_name
         elif column == self.PART_NUMBER_COLUMN:
             return line_item.product.part_number
         elif column == self.DESCRIPTION_COLUMN:
             return line_item.product.product_description
         elif column == self.UNIT_PRICE_COLUMN:
             converted_value = monetary_int_to_decimal(line_item.unit_price, 
                                                       self.app_config)
             return "R {:,.2f}".format(converted_value)
         elif column == self.DISCOUNT_COLUMN:
             converted_value = percentage_int_to_decimal(line_item.discount)
             return "{:2.0%}".format(converted_value)
         elif column == self.QUANTITY_COLUMN:
             return str(line_item.quantity)
         elif column == self.LINE_PRICE_COLUMN:
             converted_unit_price = monetary_int_to_decimal(
                                                     line_item.unit_price,
                                                     self.app_config)
             converted_discount = percentage_int_to_decimal(
                                                     line_item.discount)
             line_price = self._calculate_line_price(converted_unit_price,
                                                     converted_discount,
                                                     line_item.quantity)
             return "R {:,.2f}".format(line_price)
     elif role == Qt.TextAlignmentRole:
         if column == self.ORDER_DATE_COLUMN:
             return Qt.AlignHCenter | Qt.AlignVCenter
         elif column == self.UNIT_PRICE_COLUMN:
             return Qt.AlignRight | Qt.AlignVCenter
         elif column == self.DISCOUNT_COLUMN:
             return Qt.AlignHCenter | Qt.AlignVCenter
         elif column == self.QUANTITY_COLUMN:
             return Qt.AlignHCenter | Qt.AlignVCenter
         elif column == self.LINE_PRICE_COLUMN:
             return Qt.AlignRight | Qt.AlignVCenter
         else:
             return Qt.AlignLeft | Qt.AlignVCenter
     else:
         return None
Example #2
0
 def data(self, index, role=Qt.DisplayRole):
     '''Refer to QAbstractItemModel.data.
     '''
     if not index.isValid() or \
     not (0 <= index.row() < self.rowCount()):
         return None
     product = self.products[index.row()]
     column = index.column()
     if role == Qt.DisplayRole:
         if column == self.PART_NUMBER_COLUMN:
             return product.part_number
         elif column == self.PRODUCT_DESCRIPTION_COLUMN:
             return product.product_description
         elif column == self.CURRENT_PRICE_COLUMN:
             converted_value = monetary_int_to_decimal(
                 product.current_price, self.app_config)
             return "R {:,.2f}".format(converted_value)
         elif column == self.CURRENT_DISCOUNT_COLUMN:
             converted_value = percentage_int_to_decimal(
                 product.current_discount)
             return "{:2.0%}".format(converted_value)
         elif column == self.ARCHIVED_COLUMN:
             return "Archived"
         else:
             return None
     elif role == Qt.EditRole:
         if column == self.PART_NUMBER_COLUMN:
             return product.part_number
         elif column == self.PRODUCT_DESCRIPTION_COLUMN:
             return product.product_description
         elif column == self.CURRENT_PRICE_COLUMN:
             converted_value = monetary_int_to_decimal(
                 product.current_price, self.app_config)
             return str(converted_value)
         elif column == self.CURRENT_DISCOUNT_COLUMN:
             converted_value = percentage_int_to_decimal(
                 product.current_discount)
             return converted_value
         elif column == self.ARCHIVED_COLUMN:
             return "Archived"
         else:
             return None
     elif role == Qt.TextAlignmentRole:
         if column == self.CURRENT_PRICE_COLUMN:
             return Qt.AlignRight | Qt.AlignVCenter
         elif column == self.CURRENT_DISCOUNT_COLUMN:
             return Qt.AlignHCenter | Qt.AlignVCenter
         else:
             return None
     elif role == Qt.CheckStateRole:
         if column == self.ARCHIVED_COLUMN:
             if product.archived:
                 return Qt.Checked
             else:
                 return Qt.Unchecked
     else:
         return None
Example #3
0
 def data(self, index, role=Qt.DisplayRole):
     '''Refer to QAbstractItemModel.data.
     '''
     if not index.isValid() or \
     not (0 <= index.row() < self.rowCount()):
         return None
     line_item = self.line_items[index.row()]
     column = index.column()
     if role == Qt.DisplayRole or role == Qt.EditRole:
         if column == self.ORDER_NUMBER_COLUMN:
             return line_item.purchase_order.order_number
         elif column == self.ORDER_DATE_COLUMN:
             return line_item.purchase_order.order_date.strftime("%Y-%m-%d")
         elif column == self.ORDER_STATUS_COLUMN:
             return line_item.purchase_order.order_status
         elif column == self.PROJECT_CODE_COLUMN:
             return line_item.purchase_order.project.code
         elif column == self.SUPPLIER_COMPANY_NAME_COLUMN:
             return line_item.purchase_order.supplier.company_name
         elif column == self.PART_NUMBER_COLUMN:
             return line_item.product.part_number
         elif column == self.DESCRIPTION_COLUMN:
             return line_item.product.product_description
         elif column == self.UNIT_PRICE_COLUMN:
             converted_value = monetary_int_to_decimal(
                 line_item.unit_price, self.app_config)
             return "R {:,.2f}".format(converted_value)
         elif column == self.DISCOUNT_COLUMN:
             converted_value = percentage_int_to_decimal(line_item.discount)
             return "{:2.0%}".format(converted_value)
         elif column == self.QUANTITY_COLUMN:
             return str(line_item.quantity)
         elif column == self.LINE_PRICE_COLUMN:
             converted_unit_price = monetary_int_to_decimal(
                 line_item.unit_price, self.app_config)
             converted_discount = percentage_int_to_decimal(
                 line_item.discount)
             line_price = self._calculate_line_price(
                 converted_unit_price, converted_discount,
                 line_item.quantity)
             return "R {:,.2f}".format(line_price)
     elif role == Qt.TextAlignmentRole:
         if column == self.ORDER_DATE_COLUMN:
             return Qt.AlignHCenter | Qt.AlignVCenter
         elif column == self.UNIT_PRICE_COLUMN:
             return Qt.AlignRight | Qt.AlignVCenter
         elif column == self.DISCOUNT_COLUMN:
             return Qt.AlignHCenter | Qt.AlignVCenter
         elif column == self.QUANTITY_COLUMN:
             return Qt.AlignHCenter | Qt.AlignVCenter
         elif column == self.LINE_PRICE_COLUMN:
             return Qt.AlignRight | Qt.AlignVCenter
         else:
             return Qt.AlignLeft | Qt.AlignVCenter
     else:
         return None
Example #4
0
 def calculate_total_value(self):
     '''Calculate the total value of the report line items (excluding tax).
     '''
     total_value = Decimal("0.0")
     for line_item in self.line_items:
         converted_unit_price = monetary_int_to_decimal(
             line_item.unit_price, self.app_config)
         converted_discount = percentage_int_to_decimal(line_item.discount)
         total_value += self._calculate_line_price(converted_unit_price,
                                                   converted_discount,
                                                   line_item.quantity)
     return total_value
Example #5
0
 def load_from_db_record(self, db_record):
     '''Load the LocaleSettings object with values from a database 
     record (UserConfig object).
     
     Copies each of the attributes of the UserConfig object to the 
     corresponding attributes in the LocaleSettings object.
     
     Args:
     :param db_record: The user config database record.
     :type db_record: userconfig.UserConfig
     '''
     if db_record:
         self.tax_rate = percentage_int_to_decimal(db_record.tax_rate)
Example #6
0
 def load_from_db_record(self, db_record):
     '''Load the LocaleSettings object with values from a database 
     record (UserConfig object).
     
     Copies each of the attributes of the UserConfig object to the 
     corresponding attributes in the LocaleSettings object.
     
     Args:
     :param db_record: The user config database record.
     :type db_record: userconfig.UserConfig
     '''
     if db_record:
         self.tax_rate = percentage_int_to_decimal(db_record.tax_rate)
Example #7
0
 def calculate_total_value(self):
     '''Calculate the total value of the report line items (excluding tax).
     '''
     total_value = Decimal("0.0")
     for line_item in self.line_items:
         converted_unit_price = monetary_int_to_decimal(
                                                     line_item.unit_price,
                                                     self.app_config)
         converted_discount = percentage_int_to_decimal(
                                                 line_item.discount)
         total_value += self._calculate_line_price(converted_unit_price,
                                                   converted_discount,
                                                   line_item.quantity)
     return total_value
Example #8
0
 def calculate_total_excluding_tax(self):
     '''Calculate the total price of the active purchase order's line items
     excluding tax. 
     
     Returns:
     :return: Total price of the active purchase order's line items 
         excluding tax
     :rtype: Decimal
     '''
     total_price = Decimal("0.0")
     for entry in self._po_prod_buffer:
         converted_unit_price = monetary_int_to_decimal(
             entry.po_product.unit_price, self.app_config)
         converted_discount = percentage_int_to_decimal(
             entry.po_product.discount)
         total_price += self._calculate_line_price(
             converted_unit_price, converted_discount,
             entry.po_product.quantity)
     return total_price
Example #9
0
 def calculate_total_excluding_tax(self):
     '''Calculate the total price of the active purchase order's line items
     excluding tax. 
     
     Returns:
     :return: Total price of the active purchase order's line items 
         excluding tax
     :rtype: Decimal
     '''
     total_price = Decimal("0.0")
     for entry in self._po_prod_buffer:
         converted_unit_price = monetary_int_to_decimal(
                                             entry.po_product.unit_price,
                                             self.app_config)
         converted_discount = percentage_int_to_decimal(
                                             entry.po_product.discount)
         total_price += self._calculate_line_price(
                                             converted_unit_price, 
                                             converted_discount, 
                                             entry.po_product.quantity)
     return total_price
Example #10
0
 def data(self, index, role=Qt.DisplayRole):
     '''Refer to QAbstractItemModel.data.
     '''
     if not index.isValid() or \
     not (0 <= index.row() < self.rowCount()):
         return None
     po_product = self._po_prod_buffer[index.row()].po_product
     column = index.column()
     if role == Qt.DisplayRole:
         if column == self.PART_NUMBER_COLUMN:
             if po_product.product:
                 return po_product.product.part_number
             else:
                 return None
         elif column == self.DESCRIPTION_COLUMN:
             if po_product.product:
                 return po_product.product.product_description
             else:
                 return None
         elif column == self.UNIT_PRICE_COLUMN:
             converted_value = monetary_int_to_decimal(
                 po_product.unit_price, self.app_config)
             return "R {:,.2f}".format(converted_value)
         elif column == self.DISCOUNT_COLUMN:
             converted_value = percentage_int_to_decimal(
                 po_product.discount)
             return "{:2.0%}".format(converted_value)
         elif column == self.QUANTITY_COLUMN:
             return po_product.quantity
         elif column == self.LINE_PRICE_COLUMN:
             converted_unit_price = monetary_int_to_decimal(
                 po_product.unit_price, self.app_config)
             converted_discount = percentage_int_to_decimal(
                 po_product.discount)
             line_price = self._calculate_line_price(
                 converted_unit_price, converted_discount,
                 po_product.quantity)
             return "R {:,.2f}".format(line_price)
         else:
             return None
     elif role == Qt.EditRole:
         if column == self.PART_NUMBER_COLUMN:
             if po_product.product:
                 return po_product.product.part_number
             else:
                 return None
         elif column == self.DESCRIPTION_COLUMN:
             if po_product.product:
                 return po_product.product.product_description
             else:
                 return None
         elif column == self.UNIT_PRICE_COLUMN:
             converted_value = monetary_int_to_decimal(
                 po_product.unit_price, self.app_config)
             return float(converted_value)
         elif column == self.DISCOUNT_COLUMN:
             converted_value = percentage_int_to_decimal(
                 po_product.discount)
             return converted_value
         elif column == self.QUANTITY_COLUMN:
             return po_product.quantity
         elif column == self.LINE_PRICE_COLUMN:
             converted_unit_price = monetary_int_to_decimal(
                 po_product.unit_price, self.app_config)
             converted_discount = percentage_int_to_decimal(
                 po_product.discount)
             line_price = self._calculate_line_price(
                 converted_unit_price, converted_discount,
                 po_product.quantity)
             return line_price
         else:
             return None
     elif role == Qt.TextAlignmentRole:
         if column == self.UNIT_PRICE_COLUMN:
             return Qt.AlignRight | Qt.AlignVCenter
         elif column == self.DISCOUNT_COLUMN:
             return Qt.AlignHCenter | Qt.AlignVCenter
         elif column == self.QUANTITY_COLUMN:
             return Qt.AlignHCenter | Qt.AlignVCenter
         elif column == self.LINE_PRICE_COLUMN:
             return Qt.AlignRight | Qt.AlignVCenter
         else:
             return Qt.AlignLeft | Qt.AlignVCenter
     else:
         return None
Example #11
0
 def data(self, index, role=Qt.DisplayRole):
     '''Refer to QAbstractItemModel.data.
     '''
     if not index.isValid() or \
     not (0 <= index.row() < self.rowCount()):
         return None
     order = self.purchase_orders[index.row()]
     column = index.column()
     if role == Qt.DisplayRole or role == Qt.EditRole:
         if column == self.ORDER_NUMBER_COLUMN:
             return order.order_number
         elif column == self.ORDER_DATE_COLUMN:
             date = QDate(order.order_date.year, order.order_date.month,
                          order.order_date.day)
             return date
         elif column == self.DELIVERY_ADDRESS_COLUMN:
             return order.delivery_address
         elif column == self.DELIVERY_ADDRESS_GPS_COORDINATES_COLUMN:
             return order.delivery_address_gps_coordinates
         elif column == self.DELIVERY_DATE_COLUMN:
             date = QDate(order.delivery_date.year,
                          order.delivery_date.month,
                          order.delivery_date.day)
             return datetime
         elif column == self.PAYMENT_TERMS_COLUMN:
             return order.payment_terms
         elif column == self.ORDER_STATUS_COLUMN:
             return order.order_status
         elif column == self.NOTES_COLUMN:
             return order.notes
         elif column == self.TAX_RATE_COLUMN:
             # Display tax rate as % with two digits and no decimal point.
             # The tax rate is in the referenced user config record.
             return "{:2.0%}".format(
                 percentage_int_to_decimal(order.user_config.tax_rate))
         elif column == self.TOTAL_EXCLUDING_TAX_COLUMN:
             # Display totals with two decimal places and comma separators.
             converted_value = monetary_int_to_decimal(
                 order.total_excluding_tax, self.app_config)
             return "R {:,.2f}".format(converted_value)
         elif column == self.TOTAL_TAX_COLUMN:
             converted_value = monetary_int_to_decimal(
                 order.total_tax, self.app_config)
             return "R {:,.2f}".format(converted_value)
         elif column == self.TOTAL_INCLUDING_TAX_COLUMN:
             converted_value = monetary_int_to_decimal(
                 order.total_including_tax, self.app_config)
             return "R {:,.2f}".format(converted_value)
         elif column == self.PROJECT_CODE_COLUMN:
             return order.project.code
         elif column == self.SUPPLIER_COMPANY_NAME_COLUMN:
             return order.supplier.company_name
         else:
             return None
     elif role == Qt.TextAlignmentRole:
         if column == self.TAX_RATE_COLUMN:
             return Qt.AlignHCenter | Qt.AlignVCenter
         elif column == self.TOTAL_EXCLUDING_TAX_COLUMN:
             return Qt.AlignRight | Qt.AlignVCenter
         elif column == self.TOTAL_TAX_COLUMN:
             return Qt.AlignRight | Qt.AlignVCenter
         elif column == self.TOTAL_INCLUDING_TAX_COLUMN:
             return Qt.AlignRight | Qt.AlignVCenter
     else:
         return None
Example #12
0
 def data(self, index, role=Qt.DisplayRole):
     '''Refer to QAbstractItemModel.data.
     '''
     if not index.isValid() or \
     not (0 <= index.row() < self.rowCount()):
         return None
     po_product = self._po_prod_buffer[index.row()].po_product
     column = index.column()
     if role == Qt.DisplayRole:
         if column == self.PART_NUMBER_COLUMN:
             if po_product.product:
                 return po_product.product.part_number
             else:
                 return None
         elif column == self.DESCRIPTION_COLUMN:
             if po_product.product:
                 return po_product.product.product_description
             else:
                 return None
         elif column == self.UNIT_PRICE_COLUMN:
             converted_value = monetary_int_to_decimal(po_product.unit_price, 
                                                       self.app_config)
             return "R {:,.2f}".format(converted_value)
         elif column == self.DISCOUNT_COLUMN:
             converted_value = percentage_int_to_decimal(po_product.discount)
             return "{:2.0%}".format(converted_value)
         elif column == self.QUANTITY_COLUMN:
             return po_product.quantity
         elif column == self.LINE_PRICE_COLUMN:
             converted_unit_price = monetary_int_to_decimal(
                                                     po_product.unit_price,
                                                     self.app_config)
             converted_discount = percentage_int_to_decimal(
                                                     po_product.discount)
             line_price = self._calculate_line_price(converted_unit_price, 
                                                     converted_discount, 
                                                     po_product.quantity)
             return "R {:,.2f}".format(line_price)
         else:
             return None
     elif role == Qt.EditRole:
         if column == self.PART_NUMBER_COLUMN:
             if po_product.product:
                 return po_product.product.part_number
             else:
                 return None
         elif column == self.DESCRIPTION_COLUMN:
             if po_product.product:
                 return po_product.product.product_description
             else:
                 return None
         elif column == self.UNIT_PRICE_COLUMN:
             converted_value = monetary_int_to_decimal(po_product.unit_price, 
                                                       self.app_config)
             return float(converted_value)
         elif column == self.DISCOUNT_COLUMN:
             converted_value = percentage_int_to_decimal(po_product.discount)
             return converted_value
         elif column == self.QUANTITY_COLUMN:
             return po_product.quantity
         elif column == self.LINE_PRICE_COLUMN:
             converted_unit_price = monetary_int_to_decimal(
                                                     po_product.unit_price,
                                                     self.app_config)
             converted_discount = percentage_int_to_decimal(
                                                     po_product.discount)
             line_price = self._calculate_line_price(converted_unit_price, 
                                                     converted_discount, 
                                                     po_product.quantity)
             return line_price
         else:
             return None
     elif role == Qt.TextAlignmentRole:
         if column == self.UNIT_PRICE_COLUMN:
             return Qt.AlignRight | Qt.AlignVCenter
         elif column == self.DISCOUNT_COLUMN:
             return Qt.AlignHCenter | Qt.AlignVCenter
         elif column == self.QUANTITY_COLUMN:
             return Qt.AlignHCenter | Qt.AlignVCenter
         elif column == self.LINE_PRICE_COLUMN:
             return Qt.AlignRight | Qt.AlignVCenter
         else:
             return Qt.AlignLeft | Qt.AlignVCenter
     else:
         return None
Example #13
0
 def data(self, index, role=Qt.DisplayRole):
     '''Refer to QAbstractItemModel.data.
     '''
     if not index.isValid() or \
     not (0 <= index.row() < self.rowCount()):
         return None
     order = self.purchase_orders[index.row()]
     column = index.column()
     if role == Qt.DisplayRole or role == Qt.EditRole:
         if column == self.ORDER_NUMBER_COLUMN:
             return order.order_number
         elif column == self.ORDER_DATE_COLUMN:
             date = QDate(order.order_date.year,
                          order.order_date.month,
                          order.order_date.day)
             return date
         elif column == self.DELIVERY_ADDRESS_COLUMN:
             return order.delivery_address
         elif column == self.DELIVERY_ADDRESS_GPS_COORDINATES_COLUMN:
             return order.delivery_address_gps_coordinates
         elif column == self.DELIVERY_DATE_COLUMN:
             date = QDate(order.delivery_date.year,
                          order.delivery_date.month,
                          order.delivery_date.day)
             return datetime
         elif column == self.PAYMENT_TERMS_COLUMN:
             return order.payment_terms
         elif column == self.ORDER_STATUS_COLUMN:
             return order.order_status
         elif column == self.NOTES_COLUMN:
             return order.notes
         elif column == self.TAX_RATE_COLUMN:
             # Display tax rate as % with two digits and no decimal point.
             # The tax rate is in the referenced user config record. 
             return "{:2.0%}".format(percentage_int_to_decimal(
                                             order.user_config.tax_rate))
         elif column == self.TOTAL_EXCLUDING_TAX_COLUMN:
             # Display totals with two decimal places and comma separators.
             converted_value = monetary_int_to_decimal(
                                                 order.total_excluding_tax, 
                                                 self.app_config)
             return "R {:,.2f}".format(converted_value)
         elif column == self.TOTAL_TAX_COLUMN:
             converted_value = monetary_int_to_decimal(
                                                 order.total_tax, 
                                                 self.app_config)
             return "R {:,.2f}".format(converted_value)
         elif column == self.TOTAL_INCLUDING_TAX_COLUMN:
             converted_value = monetary_int_to_decimal(
                                                 order.total_including_tax, 
                                                 self.app_config)
             return "R {:,.2f}".format(converted_value)
         elif column == self.PROJECT_CODE_COLUMN:
             return order.project.code
         elif column == self.SUPPLIER_COMPANY_NAME_COLUMN:
             return order.supplier.company_name
         else:
             return None
     elif role == Qt.TextAlignmentRole:
         if column == self.TAX_RATE_COLUMN:
             return Qt.AlignHCenter | Qt.AlignVCenter
         elif column == self.TOTAL_EXCLUDING_TAX_COLUMN:
             return Qt.AlignRight | Qt.AlignVCenter
         elif column == self.TOTAL_TAX_COLUMN:
             return Qt.AlignRight | Qt.AlignVCenter
         elif column == self.TOTAL_INCLUDING_TAX_COLUMN:
             return Qt.AlignRight | Qt.AlignVCenter
     else:
         return None