Example #1
0
    def data_edit(self, event):
        _product_id = self.textbox_product_id.GetValue()
        if not _product_id:
            return dialogs.launch_error(
                self, u'Eh necessário especificar o ID do produto!')

        product_id = int(_product_id)
        product = self.database_inventory.inventory_search_id(product_id)
        if not product:
            return dialogs.launch_error(self, u'ID inválido!')

        _amount = core.amount2float(self.textbox_product_amount.GetValue())
        try:
            amount = float(_amount)
        except ValueError:
            self.textbox_product_amount.Clear()
            return dialogs.launch_error(self, u'Quantidade inválida!')

        unit_price = core.format_cash_user(product.price, currency=True)
        unit = self.textbox_product_unit.GetValue()

        self.list_update.SetStringItem(self.item, 0,
                                       core.format_id_user(product.ID))
        self.list_update.SetStringItem(self.item, 1, product.description)
        self.list_update.SetStringItem(
            self.item, 2, core.format_amount_user(amount, unit=unit))
        self.list_update.SetStringItem(self.item, 3, unit_price)

        self.list_update.SetItemData(self.item, product_id)

        self.data_editor_disable(event)
Example #2
0
    def setup_monthly_list(self, data_type):

        month = core.format_date_internal(
            self.combobox_month_displayed.GetValue())
        date = core.datetime_today()[0]

        lists = {EXPENSE: self.list_expenses, INCOME: self.list_incomes}
        list_ctrl = lists[data_type]

        list_ctrl.DeleteAllItems()

        db = database.TransactionsDB()
        transaction_registered = db.monthly_transactions_list(month, data_type)
        for _transaction in transaction_registered:

            category = db.categories_search_id(_transaction.category)
            item = list_ctrl.Append(
                (_transaction.description, core.format_id_user(
                    _transaction.ID), category.category if category else u'',
                 core.format_cash_user(_transaction.value, currency=True),
                 core.format_date_user(_transaction.transaction_date),
                 u'OK' if not _transaction.payment_pendant else u'Pendente'))

            # Atribui uma cor ao item caso o pagamento ainda não tenha sido realizado
            if _transaction.payment_pendant:
                self.setup_item_color(item, data_type)

        db.close()
Example #3
0
    def data_insert(self, event):
        _product_id = self.textbox_product_id.GetValue()
        if not _product_id:
            return dialogs.launch_error(
                self, u'Eh necessário especificar o ID do produto!')

        product_id = int(_product_id)
        product = self.database_inventory.inventory_search_id(product_id)
        if not product:
            return dialogs.launch_error(self, u'ID inválido!')

        _amount = self.textbox_product_amount.GetValue()
        try:
            amount = core.amount2float(_amount)
        except ValueError:
            self.textbox_product_amount.Clear()
            return dialogs.launch_error(self, u'Quantidade inválida!')

        unit = self.textbox_product_unit.GetValue()

        unit_price = core.format_cash_user(product.price, currency=True)
        item = self.list_update.Append(
            (core.format_id_user(product.ID), product.description,
             core.format_amount_user(amount, unit=unit), unit_price))
        self.list_update.SetItemData(item, product_id)

        self.textbox_product_amount.Clear()
        self.textbox_product_id.Clear()
        self.textbox_product_description.Clear()
        self.textbox_product_price.SetValue(u"0,00")
        self.textbox_product_unit.Clear()
Example #4
0
    def process_click(self, event):
        selection = self.GetSelection()
        tree_data = self.GetItemData(selection)
        if not tree_data:
            event.Skip()
            return
        data = tree_data.GetData()

        if isinstance(data, data_types.SaleData):
            sale.Sale(self.parent, data=data, editable=False)
        elif isinstance(data, data_types.ProductData):
            inventory.ProductData(self.parent,
                                  data.description,
                                  data=data,
                                  editable=False)
        elif isinstance(data, str):
            inventory.ProductData(self.parent,
                                  core.format_id_user(data),
                                  product_id=int(data),
                                  editable=False)
        elif isinstance(data, data_types.ProductCategoryData):
            categories.ProductCategoryData(self.parent,
                                           data.category,
                                           data=data)
        elif isinstance(data, data_types.WasteData):
            waste.Waste(self.parent, data=data)
        elif isinstance(data, data_types.ExpenseData):
            expense.Expense(self.parent, data=data)
Example #5
0
 def data_select(self, event):
     g = self.list_clients.GetFocusedItem()
     if g == -1:
         return
     name = self.list_clients.GetItemText(g, 0)
     client_id = self.list_clients.GetItemText(g, 1)
     cpf = self.list_clients.GetItemText(g, 2)
     self.parent.textbox_client_name.SetValue(name)
     self.parent.textbox_client_cpf.SetValue(cpf)
     self.parent.textbox_client_id.SetValue(core.format_id_user(client_id))
     self.exit(None)
Example #6
0
    def setup_selection_2(self):
        month_user = self.combobox_month_option.GetValue()
        date = core.format_date_internal(month_user)
        if not month_user:
            month_user = u"---------"
        main_root = self.list_edited_data.AddRoot(month_user)
        self.list_edited_data.SetItemText(main_root, u"Registros Apagados", 2)

        db = database.TransactionsDB()
        transactions = db.monthly_transactions_list(date, deleted=True)
        categories = db.categories_list(deleted=True)
        db.close()

        incomes_counter = 0
        expenses_counter = 0
        categories_counter = len(categories)

        expenses_value = 0.0
        expenses_root = self.list_edited_data.AppendItem(
            main_root, u"---------")
        self.list_edited_data.SetItemText(expenses_root, u"Gastos", 2)
        self.list_edited_data.SetItemText(expenses_root, str(expenses_counter),
                                          3)
        self.list_edited_data.SetItemFont(
            expenses_root, wx.Font(11, wx.SWISS, wx.NORMAL, wx.BOLD))

        incomes_value = 0.0
        income_root = self.list_edited_data.AppendItem(main_root, u"---------")
        self.list_edited_data.SetItemText(income_root, u"Entrada", 2)
        self.list_edited_data.SetItemText(income_root, str(expenses_counter),
                                          3)
        self.list_edited_data.SetItemFont(
            income_root, wx.Font(11, wx.SWISS, wx.NORMAL, wx.BOLD))
        for data in transactions:
            if data.type == data_types.EXPENSE:
                parent = expenses_root
                expenses_counter += 1
                expenses_value += data.value
            elif data.type == data_types.INCOME:
                parent = income_root
                incomes_counter += 1
                incomes_value += data.value
            else:
                parent = main_root

            item = self.list_edited_data.AppendItem(parent,
                                                    data.transaction_date)
            self.list_edited_data.SetItemFont(
                item, wx.Font(9, wx.SWISS, wx.NORMAL, wx.BOLD))

            self.list_edited_data.SetItemText(item,
                                              core.format_id_user(data.ID), 1)
            self.list_edited_data.SetItemText(item, data.description, 2)
            self.list_edited_data.SetItemText(
                item, core.format_cash_user(data.value, currency=True), 4)
            self.list_edited_data.SetItemData(item, wx.TreeItemData(data))

        self.list_edited_data.SetItemText(
            income_root, core.format_cash_user(incomes_value, currency=True),
            4)
        self.list_edited_data.SetItemText(
            expenses_root, core.format_cash_user(expenses_value,
                                                 currency=True), 4)

        categories_root = self.list_edited_data.AppendItem(
            main_root, u"---------")
        self.list_edited_data.SetItemText(categories_root, u"Categorias", 2)
        self.list_edited_data.SetItemText(categories_root,
                                          str(categories_counter), 3)
        self.list_edited_data.SetItemFont(
            categories_root, wx.Font(11, wx.SWISS, wx.NORMAL, wx.BOLD))
        for data in categories:

            item = self.list_edited_data.AppendItem(categories_root,
                                                    u"---------")
            self.list_edited_data.SetItemFont(
                item, wx.Font(9, wx.SWISS, wx.NORMAL, wx.BOLD))

            self.list_edited_data.SetItemText(item,
                                              core.format_id_user(data.ID), 1)
            self.list_edited_data.SetItemText(item, data.category, 2)

            self.list_edited_data.SetItemData(item, wx.TreeItemData(data))

        self.list_edited_data.SetItemText(
            main_root, str(incomes_counter + expenses_counter), 3)
        self.list_edited_data.Expand(main_root)
        self.list_edited_data.SetItemFont(
            main_root, wx.Font(12, wx.SWISS, wx.NORMAL, wx.BOLD))
Example #7
0
    def setup_selection_1(self):
        main_root = self.list_edited_data.AddRoot(u"---------")
        self.list_edited_data.SetItemText(main_root, u"Registros Apagados", 2)

        db = database.InventoryDB()
        products = db.product_list(deleted=True)
        categories = db.categories_list(deleted=True)
        db.close()

        db = database.ClientsDB()
        clients = db.clients_list(deleted=True)
        db.close()

        clients_counter = len(clients)
        products_counter = len(products)
        categories_counter = len(categories)

        clients_root = self.list_edited_data.AppendItem(
            main_root, u"---------")
        self.list_edited_data.SetItemText(clients_root, u"Clientes", 2)
        self.list_edited_data.SetItemText(clients_root, str(clients_counter),
                                          3)
        self.list_edited_data.SetItemFont(
            clients_root, wx.Font(11, wx.SWISS, wx.NORMAL, wx.BOLD))
        for data in clients:

            item = self.list_edited_data.AppendItem(clients_root, u"---------")
            self.list_edited_data.SetItemFont(
                item, wx.Font(9, wx.SWISS, wx.NORMAL, wx.BOLD))

            self.list_edited_data.SetItemText(item,
                                              core.format_id_user(data.ID), 1)
            self.list_edited_data.SetItemText(item, data.name, 2)

            self.list_edited_data.SetItemData(item, wx.TreeItemData(data))

        products_root = self.list_edited_data.AppendItem(
            main_root, u"---------")
        self.list_edited_data.SetItemText(products_root, u"Produtos", 2)
        self.list_edited_data.SetItemText(products_root, str(products_counter),
                                          3)
        self.list_edited_data.SetItemFont(
            products_root, wx.Font(11, wx.SWISS, wx.NORMAL, wx.BOLD))
        for data in products:

            item = self.list_edited_data.AppendItem(products_root,
                                                    u"---------")
            self.list_edited_data.SetItemFont(
                item, wx.Font(9, wx.SWISS, wx.NORMAL, wx.BOLD))

            self.list_edited_data.SetItemText(item,
                                              core.format_id_user(data.ID), 1)
            self.list_edited_data.SetItemText(item, data.description, 2)
            self.list_edited_data.SetItemText(
                item, core.format_amount_user(data.amount), 3)
            self.list_edited_data.SetItemText(
                item, core.format_cash_user(data.price, currency=True), 4)

            self.list_edited_data.SetItemData(item, wx.TreeItemData(data))

        categories_root = self.list_edited_data.AppendItem(
            main_root, u"---------")
        self.list_edited_data.SetItemText(categories_root, u"Categorias", 2)
        self.list_edited_data.SetItemText(categories_root,
                                          str(categories_counter), 3)
        self.list_edited_data.SetItemFont(
            categories_root, wx.Font(11, wx.SWISS, wx.NORMAL, wx.BOLD))
        for data in categories:

            item = self.list_edited_data.AppendItem(categories_root,
                                                    u"---------")
            self.list_edited_data.SetItemFont(
                item, wx.Font(9, wx.SWISS, wx.NORMAL, wx.BOLD))

            self.list_edited_data.SetItemText(item,
                                              core.format_id_user(data.ID), 1)
            self.list_edited_data.SetItemText(item, data.category, 2)

            self.list_edited_data.SetItemData(item, wx.TreeItemData(data))

        self.list_edited_data.SetItemFont(
            main_root, wx.Font(12, wx.SWISS, wx.NORMAL, wx.BOLD))
        self.list_edited_data.SetItemText(
            main_root,
            str(categories_counter + products_counter + clients_counter), 3)
        self.list_edited_data.Expand(main_root)
Example #8
0
    def setup_selection_0(self):
        date_user = self.combobox_day_option.GetValue()
        date = core.format_date_internal(date_user)
        if not date_user:
            date_user = u"---------"
        main_root = self.list_edited_data.AddRoot(date_user)
        self.list_edited_data.SetItemText(main_root, u"Registros Apagados", 2)

        db = database.TransactionsDB()
        sales = db.daily_sales_list(date, deleted=True)
        expenses = db.daily_expenses_list(date, deleted=True)
        wastes = db.daily_wastes_list(date, deleted=True)
        db.close()

        sales_counter = len(sales)
        expenses_counter = len(expenses)
        wastes_counter = len(wastes)

        value = 0.0
        sales_root = self.list_edited_data.AppendItem(main_root, u"---------")
        self.list_edited_data.SetItemText(sales_root, u"Vendas", 2)
        self.list_edited_data.SetItemText(sales_root, str(sales_counter), 3)
        self.list_edited_data.SetItemFont(
            sales_root, wx.Font(11, wx.SWISS, wx.NORMAL, wx.BOLD))
        for data in sales:
            value += data.value

            item = self.list_edited_data.AppendItem(sales_root,
                                                    data.record_time)
            self.list_edited_data.SetItemFont(
                item, wx.Font(9, wx.SWISS, wx.NORMAL, wx.BOLD))

            self.list_edited_data.SetItemText(item,
                                              core.format_id_user(data.ID), 1)
            self.list_edited_data.SetItemText(item,
                                              str(len(data.products_IDs)), 3)
            self.list_edited_data.SetItemText(
                item, core.format_cash_user(data.value, currency=True), 4)

            self.list_edited_data.SetItemData(item, wx.TreeItemData(data))
            for i in range(len(data.products_IDs)):
                price = data.amounts[i] * data.prices[i]
                product = self.list_edited_data.AppendItem(item, u"---------")
                self.list_edited_data.SetItemText(
                    product, core.format_id_user(data.products_IDs[i]), 1)
                self.list_edited_data.SetItemText(
                    product, core.format_amount_user(data.amounts[i]), 3)
                self.list_edited_data.SetItemText(
                    product, core.format_cash_user(price, currency=True), 4)

            if data.discount != 0:
                extra = self.list_edited_data.AppendItem(item, u"---------")
                self.list_edited_data.SetItemText(extra, u'Desconto', 2)
                self.list_edited_data.SetItemText(
                    extra, core.format_cash_user(data.discount, currency=True),
                    4)
            if data.taxes != 0:
                extra = self.list_edited_data.AppendItem(item, u"---------")
                self.list_edited_data.SetItemText(extra, u'Taixas adicionais',
                                                  2)
                self.list_edited_data.SetItemText(
                    extra, core.format_cash_user(data.discount, currency=True),
                    4)

        self.list_edited_data.SetItemText(
            sales_root, core.format_cash_user(value, currency=True), 4)

        value = 0.0
        expenses_root = self.list_edited_data.AppendItem(
            main_root, u"---------")
        self.list_edited_data.SetItemText(expenses_root, u"Gastos", 2)
        self.list_edited_data.SetItemText(expenses_root, str(expenses_counter),
                                          3)
        self.list_edited_data.SetItemFont(
            expenses_root, wx.Font(11, wx.SWISS, wx.NORMAL, wx.BOLD))
        for data in expenses:
            value += data.value

            item = self.list_edited_data.AppendItem(expenses_root,
                                                    data.record_time)
            self.list_edited_data.SetItemFont(
                item, wx.Font(9, wx.SWISS, wx.NORMAL, wx.BOLD))

            self.list_edited_data.SetItemText(item,
                                              core.format_id_user(data.ID), 1)
            self.list_edited_data.SetItemText(item, data.description, 2)
            self.list_edited_data.SetItemText(
                item, core.format_cash_user(data.value, currency=True), 4)

            self.list_edited_data.SetItemData(item, wx.TreeItemData(data))

        self.list_edited_data.SetItemText(
            expenses_root, core.format_cash_user(value, currency=True), 4)

        wastes_root = self.list_edited_data.AppendItem(main_root, u"---------")
        self.list_edited_data.SetItemText(wastes_root, u"Desperdícios", 2)
        self.list_edited_data.SetItemText(wastes_root, str(expenses_counter),
                                          3)
        self.list_edited_data.SetItemFont(
            wastes_root, wx.Font(11, wx.SWISS, wx.NORMAL, wx.BOLD))
        for data in wastes:

            item = self.list_edited_data.AppendItem(wastes_root,
                                                    data.record_time)
            self.list_edited_data.SetItemFont(
                item, wx.Font(9, wx.SWISS, wx.NORMAL, wx.BOLD))

            self.list_edited_data.SetItemText(item,
                                              core.format_id_user(data.ID), 1)
            self.list_edited_data.SetItemText(
                item, core.format_id_user(data.product_ID), 2)
            self.list_edited_data.SetItemText(
                item, core.format_amount_user(data.amount), 3)

            self.list_edited_data.SetItemData(item, wx.TreeItemData(data))

        self.list_edited_data.SetItemText(
            main_root, str(sales_counter + wastes_counter + expenses_counter),
            3)
        self.list_edited_data.Expand(main_root)
        self.list_edited_data.SetItemFont(
            main_root, wx.Font(12, wx.SWISS, wx.NORMAL, wx.BOLD))
Example #9
0
    def setup_incomes(self):
        sales_db = database.TransactionsDB()
        sales = sales_db.monthly_sales_list(self.month)
        incomes = sales_db.monthly_transactions_list(self.month,
                                                     transaction.INCOME)
        sales_db.close()

        self.AddColumn(u'Data/Horário', 250)
        self.AddColumn(u'Pagamento', 150)
        self.AddColumn(u'Descrição', 250)
        self.AddColumn(u'Quantidade', 100)
        self.AddColumn(u'Valor', 150)
        root = self.AddRoot(u'Ganhos de %s' %
                            core.date_reverse(self.month).replace('-', '/'))
        self.SetItemFont(root, wx.Font(14, wx.SWISS, wx.NORMAL, wx.BOLD))

        a = 0.0
        b = 0
        days = {}
        saturdays = core.week_end(self.month)
        weeks = {}

        for sale_ in sales:
            for day in saturdays:
                if day >= int(sale_.record_date.split('-')[2]):
                    week = saturdays.index(day) + 1
                    break
            if week not in weeks:
                we = self.AppendItem(root, u'%iª Semana' % week)
                self.SetItemFont(we, wx.Font(12, wx.SWISS, wx.NORMAL, wx.BOLD))
                weeks[week] = [we, 0.0, 0]
            if sale_.record_date not in days:
                item = self.AppendItem(
                    weeks[week][0], core.format_date_user(sale_.record_date))
                self.SetItemFont(item, wx.Font(11, wx.SWISS, wx.NORMAL,
                                               wx.BOLD))
                days[sale_.record_date] = [item, 0.0, 0]

            b += 1
            a += sale_.value
            weeks[week][1] += sale_.value
            weeks[week][2] += 1
            days[sale_.record_date][1] += sale_.value
            days[sale_.record_date][2] += 1

            father = self.AppendItem(days[sale_.record_date][0],
                                     sale_.record_time)
            self.SetItemFont(father, wx.Font(10, wx.SWISS, wx.NORMAL, wx.BOLD))
            self.SetItemText(father, sale_.payment, 1)
            self.SetItemText(father, u'-----------', 2)
            self.SetItemText(father, str(len(sale_.products_IDs)), 3)
            self.SetItemText(father,
                             core.format_cash_user(sale_.value, currency=True),
                             4)

            self.SetItemData(father, wx.TreeItemData(sale_))

            for i in range(len(sale_.products_IDs)):
                kid = self.AppendItem(father, u'-----------')
                self.SetItemText(kid, u'-----------', 1)
                self.SetItemText(kid,
                                 core.format_id_user(sale_.products_IDs[i]), 2)
                self.SetItemText(kid,
                                 core.format_amount_user(sale_.amounts[i]), 3)
                self.SetItemText(
                    kid, core.format_cash_user(sale_.prices[i], currency=True),
                    4)

                self.SetItemData(kid,
                                 wx.TreeItemData(str(sale_.products_IDs[i])))

        for j in weeks:
            self.SetItemText(weeks[j][0], str(weeks[j][2]), 3)
            self.SetItemText(weeks[j][0],
                             core.format_cash_user(weeks[j][1], currency=True),
                             4)
        for j in days:
            self.SetItemText(days[j][0], str(days[j][2]), 3)
            self.SetItemText(days[j][0],
                             core.format_cash_user(days[j][1], currency=True),
                             4)
            self.SortChildren(days[j][0])

        if len(incomes):
            parent = self.AppendItem(root, u'Outras entradas de dinheiro')
            self.SetItemFont(parent, wx.Font(12, wx.SWISS, wx.NORMAL, wx.BOLD))
            for income in incomes:
                b += 1
                a += income.value

                payment = u'RECEBIDO'
                payment = payment if not income.payment_pendant else u'AINDA NÃO ' + payment

                father = self.AppendItem(
                    parent, core.format_date_user(income.transaction_date))
                self.SetItemFont(father,
                                 wx.Font(10, wx.SWISS, wx.NORMAL, wx.BOLD))
                self.SetItemText(father, payment, 1)
                self.SetItemText(father, income.description, 2)
                self.SetItemText(
                    father, core.format_cash_user(income.value, currency=True),
                    4)

                self.SetItemData(father, wx.TreeItemData(income))

        self.SetItemText(root, str(b), 3)
        self.SetItemText(root, core.format_cash_user(a, currency=True), 4)
        self.Expand(root)
        self.SortChildren(root)
Example #10
0
    def setup_products(self):
        inventory_db = database.InventoryDB()

        sales_db = database.TransactionsDB()
        sale_list = sales_db.monthly_sales_list(self.month)
        sales_db.close()

        plist = {}
        categories_dict = {}
        for sale_ in sale_list:
            for i in range(len(sale_.products_IDs)):
                key = sale_.products_IDs[i]
                if key in plist:
                    plist[key][0] += sale_.amounts[i]
                    plist[key][1] += sale_.prices[i]
                    plist[key][2] += 1
                else:
                    product = inventory_db.inventory_search_id(key)
                    plist[key] = [
                        sale_.amounts[i], sale_.prices[i], 1,
                        product.description, product.price, product
                    ]

                category_id = plist[key][5].category_ID

                if category_id in categories_dict:
                    categories_dict[category_id][0] += sale_.amounts[i]
                    categories_dict[category_id][1] += sale_.prices[i]
                    categories_dict[category_id][2] += 1
                else:
                    category = inventory_db.categories_search_id(category_id)
                    categories_dict[category_id] = [
                        sale_.amounts[i], sale_.prices[i], 1,
                        category.category, category, None
                    ]

        inventory_db.close()
        self.AddColumn(u'ID', 100)
        self.AddColumn(u'Descrição', 300)
        self.AddColumn(u'Preço Unitário', 100)
        self.AddColumn(u'Quantidade vendida', 135)
        self.AddColumn(u'Quantidade de vezes vendido', 180)
        self.AddColumn(u'Valor', 115)
        root = self.AddRoot(u'------')
        self.SetItemText(
            root,
            u'Produtos Vendidos em %s' % core.format_date_user(self.month), 1)
        self.SetItemFont(root, wx.Font(14, wx.SWISS, wx.NORMAL, wx.BOLD))
        a = 0.0
        b = 0.0
        counter = 0
        for product_id in plist:
            data = plist[product_id]
            category_id = data[5].category_ID
            data_category = categories_dict[category_id]

            if not data_category[5]:
                aux = self.AppendItem(root, core.format_id_user(category_id))
                self.SetItemText(aux, data_category[3], 1)
                self.SetItemText(
                    aux,
                    core.format_amount_user(data[0],
                                            unit=data_category[4].unit), 3)
                self.SetItemText(aux, str(data_category[2]), 4)
                self.SetItemText(
                    aux, core.format_cash_user(data_category[1],
                                               currency=True), 5)
                self.SetItemData(aux, wx.TreeItemData(data_category[4]))
                self.SetItemFont(aux, wx.Font(11, wx.SWISS, wx.NORMAL,
                                              wx.BOLD))
                data_category[5] = aux

            parent = data_category[5]
            item = self.AppendItem(parent, core.format_id_user(product_id))
            self.SetItemText(item, data[3], 1)
            self.SetItemText(item, core.format_cash_user(data[4],
                                                         currency=True), 2)
            self.SetItemText(
                item,
                core.format_amount_user(data[0], unit=data_category[4].unit),
                3)
            self.SetItemText(item, str(data[2]), 4)
            self.SetItemText(item, core.format_cash_user(data[1],
                                                         currency=True), 5)

            self.SetItemData(item, wx.TreeItemData(data[5]))

            a += plist[product_id][1]
            b += plist[product_id][0]
            counter += 1
        self.SetItemText(root, core.format_amount_user(b), 3)
        self.SetItemText(root, str(counter), 4)
        self.SetItemText(root, core.format_cash_user(a, currency=True), 5)
        self.Expand(root)
        self.SortChildren(root)
Example #11
0
def enviar_venda_ao_sat(sale):
    """

    :param sale:
    :type sale: data_types.SaleData
    :return:
    """

    # DESTINATÁRIO
    destinatario = Destinatario(
        CPF=sale.client_cpf) if sale.client_cpf else None

    # PAGAMENTOS
    modo_pagamento = None
    if sale.payment == u"Dinheiro":
        modo_pagamento = constantes.WA03_DINHEIRO
    elif sale.payment == u"Cartão de Crédito":
        modo_pagamento = constantes.WA03_CARTAO_CREDITO
    elif sale.payment == u"Cartão de Débito":
        modo_pagamento = constantes.WA03_CARTAO_DEBITO
    elif sale.payment == u"Cheque":
        modo_pagamento = constantes.WA03_CHEQUE
    elif sale.payment == u"Outra":
        modo_pagamento = constantes.WA03_OUTROS
    pagamentos = [
        MeioPagamento(
            cMP=modo_pagamento,
            vMP=Decimal("%.2f" % sale.value))
    ]

    # DETALHAMENTOS
    detalhamentos = []
    vCFeLei12741 = Decimal("0.00")
    for i in range(len(sale.products_IDs)):
        product_id = sale.products_IDs[i]
        inventory_db = InventoryDB()
        product = inventory_db.inventory_search_id(product_id)
        categoria = inventory_db.categories_search_id(product.category_ID)
        vItem12741 = Decimal("%.2f" % ((categoria.imposto_total / 100) * product.price * sale.amounts[i]))

        print(product.amount)

        detalhamento = Detalhamento(
            produto=ProdutoServico(
                cProd=str(product.ID),
                xProd=product.description,
                CFOP=str(categoria.cfop),
                uCom=categoria.unit,
                qCom=Decimal("%.4f" % sale.amounts[i]),
                vUnCom=Decimal("%.2f" % product.price),
                indRegra='A'
            ),
            imposto=Imposto(
                icms=ICMSSN102(Orig='0', CSOSN='102'),
                pis=PISSN(CST='49'),
                cofins=COFINSSN(CST='49'),
                vItem12741=vItem12741
            )
        )
        vCFeLei12741 += vItem12741
        detalhamentos.append(detalhamento)

    # DESCONTOS_ACRESCIMOS_SUBTOTAL
    # DEBUG - mano, e o vCFeLei12741, onde vai ? Por que ta aqui ? E quando é None ????
    if sale.discount - sale.taxes > 0:
        descontos_acrescimos_subtotal = DescAcrEntr(
            vDescSubtot=Decimal(str(sale.discount - sale.taxes)),
            vCFeLei12741=vCFeLei12741)
    elif sale.discount - sale.taxes < 0:
        descontos_acrescimos_subtotal = DescAcrEntr(
            vAcresSubtot=Decimal(str(sale.taxes - sale.discount)),
            vCFeLei12741=vCFeLei12741)
    else:
        descontos_acrescimos_subtotal = None

    resp = enviar_dados_venda(detalhamentos=detalhamentos, pagamentos=pagamentos, destinatario=destinatario,
                              entrega=None, descontos_acrescimos_subtotal=descontos_acrescimos_subtotal)

    print(resp.mensagem)

    # Salva o xml, gerado pelo SAT depois da compra, no HD
    import core
    xml_path = core.directory_paths['cupons_fiscais'] + core.format_id_user(sale.ID) + ".xml"
    with open(xml_path, "w") as xml:
        xml.write(resp.xml())
Example #12
0
 def sale_view(self, event):
     t = self.list_bought.GetFocusedItem()
     if t == -1:
         return
     sale_id = self.list_bought.GetItemData(t)
     sale.Sale(self, core.format_id_user(sale_id), key=sale_id, editable=False)