Esempio n. 1
0
    def test_sale_return_report(self):
        today = datetime.date(2013, 1, 1)

        client = self.create_client()

        # new sale
        sale = self.create_sale(branch=get_current_branch(self.store))
        sale.identifier = 123
        sale.client = client
        sale.open_date = today
        sale.discount_value = Decimal('15')
        sale.surcharge_value = Decimal('8')

        # Product
        item_ = self.create_sale_item(sale, product=True)
        self.create_storable(item_.sellable.product, sale.branch, 1)

        # Payments
        payment = self.add_payments(sale, date=today)[0]
        payment.identifier = 999
        payment.group.payer = client.person

        sale.order(self.current_user)
        sale.confirm(self.current_user)
        sale.group.pay()

        sale.confirm_date = today
        payment.paid_date = today

        date = datetime.date(2013, 2, 2)

        # return sale
        returned_sale = sale.create_sale_return_adapter(self.current_branch, self.current_user,
                                                        self.current_station)
        returned_sale.return_(self.current_user)
        returned_sale.return_date = date

        model = self.store.find(SaleView,
                                SaleView.id == returned_sale.sale.id).one()

        returned_items = list(ReturnedSaleItemsView.find_by_sale(self.store,
                                                                 sale))

        self._diff_expected(SaleReturnReport, 'sale-return-report', self.store,
                            client, model, returned_items)
Esempio n. 2
0
    def test_sale_return_report(self):
        today = datetime.date(2013, 1, 1)

        client = self.create_client()

        # new sale
        sale = self.create_sale(branch=get_current_branch(self.store))
        sale.identifier = 123
        sale.client = client
        sale.open_date = today
        sale.discount_value = Decimal('15')
        sale.surcharge_value = Decimal('8')

        # Product
        item_ = self.create_sale_item(sale, product=True)
        self.create_storable(item_.sellable.product, sale.branch, 1)

        # Payments
        payment = self.add_payments(sale, date=today)[0]
        payment.identifier = 999
        payment.group.payer = client.person

        sale.order()
        sale.confirm()
        sale.group.pay()

        sale.confirm_date = today
        payment.paid_date = today

        date = datetime.date(2013, 2, 2)

        # return sale
        returned_sale = sale.create_sale_return_adapter()
        returned_sale.return_()
        returned_sale.return_date = date

        model = self.store.find(SaleView,
                                SaleView.id == returned_sale.sale.id).one()

        returned_items = list(ReturnedSaleItemsView.find_by_sale(self.store,
                                                                 sale))

        self._diff_expected(SaleReturnReport, 'sale-return-report', self.store,
                            client, model, returned_items)
Esempio n. 3
0
    def _setup_widgets(self):
        if not self.model.client_id:
            self.details_button.set_sensitive(False)
        self._setup_columns()

        self.sale_order = self.model.sale
        if self.sale_order.status == Sale.STATUS_RENEGOTIATED:
            self.status_details_button.show()
        else:
            self.status_details_button.hide()

        parent_items = SaleItemsView.find_parent_items(self.store, self.sale_order)
        for parent_item in parent_items:
            self.items_list.append(None, parent_item)
            if parent_item.product and not parent_item.product.is_package:
                # Prevent Production components to be shown
                continue
            for children in parent_item.get_children():
                self.items_list.append(parent_item, children)

        notes = []
        details = self.sale_order.get_details_str()
        if details:
            notes.append(details)

        # Information about the original sale (in this case, this sale was
        # created as a trade for some items)
        returned_sale = self.store.find(ReturnedSale, new_sale=self.model.id).one()
        if returned_sale:
            if returned_sale.sale:
                traded_sale = returned_sale.sale.identifier
            else:
                traded_sale = _("Unknown")
            trade_notes = [
                "* %s" % _("Items traded for this sale"),
                _("Date: %s") % get_full_date(returned_sale.return_date),
                _("Traded sale: %s") % traded_sale,
                _("Invoice number: %s") % returned_sale.invoice.invoice_number,
                _("Reason: %s") % returned_sale.reason,
            ]
            notes.append("\n".join(trade_notes))

        returned_items = ReturnedSaleItemsView.find_parent_items(self.store, self.sale_order)
        seen_set = set()
        for item in returned_items:
            self.returned_items_list.append(None, item)
            if not item.is_package():
                continue
            for child in item.get_children():
                self.returned_items_list.append(item, child)
            if item.invoice_number in seen_set:
                continue

            fmt = _("Itens returned on %s")
            return_notes = ["* %s" % (fmt % (get_full_date(item.return_date)))]
            if item.new_sale:
                fmt = _("Traded for sale: %s")
                return_notes.append(fmt % (item.new_sale.identifier))

            return_notes.extend([_("Invoice number: %s") % item.invoice_number, _("Reason: %s") % item.reason])

            notes.append("\n".join(return_notes))
            seen_set.add(item.invoice_number)
        if len(list(self.returned_items_list)) == 0:
            page_no = self.details_notebook.page_num(self.returned_items_vbox)
            self.details_notebook.remove_page(page_no)

        buffer = gtk.TextBuffer()
        buffer.set_text("\n\n".join(notes))
        self.notes.set_buffer(buffer)

        self.payments_list.add_list(self._get_payments(self.sale_order))
        changes = PaymentChangeHistoryView.find_by_group(self.store, self.sale_order.group)
        self.payments_info_list.add_list(changes)

        for widget, method_name in [(self.print_bills, u"bill"), (self.print_booklets, u"store_credit")]:
            widget.set_visible(
                any([p.method.method_name == method_name and not p.is_cancelled() for p in self.payments_list])
            )

        self._refresh_comments()
        self.comment_info.set_sensitive(False)
Esempio n. 4
0
    def _setup_widgets(self):
        if not self.model.client_id:
            self.details_button.set_sensitive(False)
        self._setup_columns()

        self.sale_order = self.store.get(Sale, self.model.id)

        if self.sale_order.status == Sale.STATUS_RENEGOTIATED:
            self.status_details_button.show()
        else:
            self.status_details_button.hide()

        sale_items = self.sale_order.get_items()
        self.items_list.add_list(sale_items)

        notes = []
        details = self.sale_order.get_details_str()
        if details:
            notes.append(details)

        returned_sale = self.store.find(ReturnedSale,
                                        new_sale=self.model.id).one()
        if returned_sale:
            if returned_sale.sale:
                traded_sale = returned_sale.sale.identifier
            else:
                traded_sale = _("Unknown")
            trade_notes = [
                '====== %s ======' % _("Items traded for this sale"),
                _("Date: %s") % returned_sale.return_date.strftime('%x'),
                _("Traded sale: %s") % traded_sale,
                _("Invoice number: %s") % returned_sale.invoice_number,
                _("Reason: %s") % returned_sale.reason,
            ]
            notes.append('\n'.join(trade_notes))

        returned_items = list(
            ReturnedSaleItemsView.find_by_sale(self.store, self.sale_order))
        if returned_items:
            self.returned_items_list.add_list(returned_items)
            seen_set = set()
            for item in returned_items:
                if item.invoice_number in seen_set:
                    continue

                fmt = _("Itens returned on %s")
                return_notes = [
                    '====== %s ======' % (fmt %
                                          (item.return_date.strftime('%x')))
                ]
                if item.new_sale:
                    fmt = _("Traded for sale: %s")
                    return_notes.append(fmt % (item.new_sale.identifier))

                return_notes.extend([
                    _("Invoice number: %s") % item.invoice_number,
                    _("Reason: %s") % item.reason,
                ])

                notes.append('\n'.join(return_notes))
                seen_set.add(item.invoice_number)
        else:
            page_no = self.details_notebook.page_num(self.returned_items_vbox)
            self.details_notebook.remove_page(page_no)

        buffer = gtk.TextBuffer()
        buffer.set_text('\n\n'.join(notes))
        self.notes.set_buffer(buffer)

        self.payments_list.add_list(self._get_payments(self.sale_order))
        changes = PaymentChangeHistoryView.find_by_group(
            self.store, self.sale_order.group)
        self.payments_info_list.add_list(changes)

        for widget, method_name in [(self.print_bills, u'bill'),
                                    (self.print_booklets, u'store_credit')]:
            widget.set_visible(
                any([
                    p.method.method_name == method_name
                    for p in self.payments_list
                ]))
Esempio n. 5
0
    def _setup_widgets(self):
        if not self.model.client_id:
            self.details_button.set_sensitive(False)
        self._setup_columns()

        self.sale_order = self.model.sale
        if self.sale_order.status == Sale.STATUS_RENEGOTIATED:
            self.status_details_button.show()
        else:
            self.status_details_button.hide()

        parent_items = SaleItemsView.find_parent_items(self.store, self.sale_order)
        for parent_item in parent_items:
            self.items_list.append(None, parent_item)
            if parent_item.product and not parent_item.product.is_package:
                # Prevent Production components to be shown
                continue
            for children in parent_item.get_children():
                self.items_list.append(parent_item, children)

        notes = []
        details = self.sale_order.get_details_str()
        if details:
            notes.append(details)

        # Information about the original sale (in this case, this sale was
        # created as a trade for some items)
        returned_sale = self.store.find(ReturnedSale,
                                        new_sale=self.model.id).one()
        if returned_sale:
            if returned_sale.sale:
                traded_sale = returned_sale.sale.identifier
            else:
                traded_sale = _("Unknown")
            trade_notes = [
                '* %s' % _("Items traded for this sale"),
                _("Date: %s") % get_full_date(returned_sale.return_date),
                _("Traded sale: %s") % traded_sale,
                _("Invoice number: %s") % returned_sale.invoice_number,
                _("Reason: %s") % returned_sale.reason,
            ]
            notes.append('\n'.join(trade_notes))

        returned_items = ReturnedSaleItemsView.find_parent_items(self.store,
                                                                 self.sale_order)
        seen_set = set()
        for item in returned_items:
            self.returned_items_list.append(None, item)
            if not item.is_package():
                continue
            for child in item.get_children():
                self.returned_items_list.append(item, child)
            if item.invoice_number in seen_set:
                continue

            fmt = _("Itens returned on %s")
            return_notes = ['* %s' % (
                fmt % (get_full_date(item.return_date)))]
            if item.new_sale:
                fmt = _("Traded for sale: %s")
                return_notes.append(fmt % (item.new_sale.identifier))

            return_notes.extend([
                _("Invoice number: %s") % item.invoice_number,
                _("Reason: %s") % item.reason,
            ])

            notes.append('\n'.join(return_notes))
            seen_set.add(item.invoice_number)
        if len(list(self.returned_items_list)) == 0:
            page_no = self.details_notebook.page_num(self.returned_items_vbox)
            self.details_notebook.remove_page(page_no)

        buffer = gtk.TextBuffer()
        buffer.set_text('\n\n'.join(notes))
        self.notes.set_buffer(buffer)

        self.payments_list.add_list(self._get_payments(self.sale_order))
        changes = PaymentChangeHistoryView.find_by_group(self.store,
                                                         self.sale_order.group)
        self.payments_info_list.add_list(changes)

        for widget, method_name in [(self.print_bills, u'bill'),
                                    (self.print_booklets, u'store_credit')]:
            widget.set_visible(any(
                [p.method.method_name == method_name and not p.is_cancelled()
                 for p in self.payments_list]))

        self._refresh_comments()
        self.comment_info.set_sensitive(False)
Esempio n. 6
0
    def _setup_widgets(self):
        if not self.model.client_id:
            self.details_button.set_sensitive(False)
        self._setup_columns()

        self.sale_order = self.store.get(Sale, self.model.id)

        if self.sale_order.status == Sale.STATUS_RENEGOTIATED:
            self.status_details_button.show()
        else:
            self.status_details_button.hide()

        sale_items = self.sale_order.get_items()
        self.items_list.add_list(sale_items)

        notes = []
        details = self.sale_order.get_details_str()
        if details:
            notes.append(details)

        returned_sale = self.store.find(ReturnedSale,
                                        new_sale=self.model.id).one()
        if returned_sale:
            if returned_sale.sale:
                traded_sale = returned_sale.sale.identifier
            else:
                traded_sale = _("Unknown")
            trade_notes = [
                '====== %s ======' % _("Items traded for this sale"),
                _("Date: %s") % returned_sale.return_date.strftime('%x'),
                _("Traded sale: %s") % traded_sale,
                _("Invoice number: %s") % returned_sale.invoice_number,
                _("Reason: %s") % returned_sale.reason,
            ]
            notes.append('\n'.join(trade_notes))

        returned_items = list(ReturnedSaleItemsView.find_by_sale(self.store,
                                                                 self.sale_order))
        if returned_items:
            self.returned_items_list.add_list(returned_items)
            seen_set = set()
            for item in returned_items:
                if item.invoice_number in seen_set:
                    continue

                return_notes = ['====== %s ======' % (
                                _("Itens returned on %s") % (
                                item.return_date.strftime('%x')))]
                if item.new_sale:
                    return_notes.append(_("Traded for sale: %s") % (
                                        item.new_sale.identifier))
                return_notes.extend([
                    _("Invoice number: %s") % item.invoice_number,
                    _("Reason: %s") % item.reason,
                ])

                notes.append('\n'.join(return_notes))
                seen_set.add(item.invoice_number)
        else:
            page_no = self.details_notebook.page_num(self.returned_items_vbox)
            self.details_notebook.remove_page(page_no)

        buffer = gtk.TextBuffer()
        buffer.set_text('\n\n'.join(notes))
        self.notes.set_buffer(buffer)

        self.payments_list.add_list(self._get_payments(self.sale_order))
        changes = PaymentChangeHistoryView.find_by_group(self.store,
                                                         self.sale_order.group)
        self.payments_info_list.add_list(changes)

        for widget, method_name in [(self.print_bills, u'bill'),
                                    (self.print_booklets, u'store_credit')]:
            widget.set_visible(any([p.method.method_name == method_name
                                    for p in self.payments_list]))