Esempio n. 1
0
    def test_print(self, print_report):
        dialog = TillDailyMovementDialog(self.store)

        # Before doing any search, the print button should not be sensitive
        self.assertFalse(dialog.print_button.get_sensitive())

        # After clicking the button, the print dialog should be sensitive
        self.click(dialog.search_button)
        self.assertTrue(dialog.print_button.get_sensitive())

        self.click(dialog.print_button)

        date = dialog.get_daterange()
        print_report.assert_called_once_with(TillDailyMovementReport,
                                             api.get_current_branch(self.store),
                                             date, dialog)
Esempio n. 2
0
    def test_till_daily_movement(self):
        branch = get_current_branch(self.store)
        branch2 = self.store.find(Branch, Branch.id != branch.id).any()

        # Data used to create the examples
        device = self.create_card_device(description=u'MAQ1')
        provider = self.create_credit_provider(u'PRO1')
        date = datetime.date(2013, 1, 1)

        # First, create one sale
        sale = self.create_sale(branch=branch)
        sellable = self.create_sellable()
        sale.add_sellable(sellable, price=100)
        sale.identifier = 1000
        sale.order()

        # With two card payments
        card_data1 = self.create_credit_card_data(
            device=device,
            provider=provider,
            payment_type=Payment.TYPE_IN,
            payment_value=sale.get_sale_subtotal())
        card_data1.auth = 1234
        card_data1.card_type = CreditCardData.TYPE_CREDIT
        card_data1.payment.group = sale.group
        card_data1.payment.branch = sale.branch
        card_data1.payment.identifier = 1010

        card_data2 = self.create_credit_card_data(
            device=device,
            provider=provider,
            payment_type=Payment.TYPE_IN,
            payment_value=sale.get_sale_subtotal())
        card_data2.auth = 1234
        card_data2.card_type = CreditCardData.TYPE_DEBIT

        card_data2.payment.group = sale.group
        card_data2.payment.branch = sale.branch
        card_data2.payment.identifier = 1011

        # Confirm the sale and pay the payments
        sale.confirm()
        sale.group.pay()

        sale.confirm_date = date

        # After calling sale.group.pay(), we need to fix the paid_date
        card_data1.payment.paid_date = date
        card_data2.payment.paid_date = date

        # create lonely input payment
        payer = self.create_client()
        address = self.create_address()
        address.person = payer.person

        method = PaymentMethod.get_by_name(self.store, u'money')
        group = self.create_payment_group()
        payment_lonely_input = method.create_payment(Payment.TYPE_IN, group, branch, Decimal(100))
        payment_lonely_input.description = u"Test receivable account"
        payment_lonely_input.group.payer = payer.person
        payment_lonely_input.set_pending()
        payment_lonely_input.pay()
        payment_lonely_input.identifier = 1001
        payment_lonely_input.paid_date = date

        # create purchase payment
        drawee = self.create_supplier()
        address = self.create_address()
        address.person = drawee.person

        method = PaymentMethod.get_by_name(self.store, u'money')
        purchase = self.create_purchase_order(branch=branch)
        purchase.identifier = 12345
        payment = method.create_payment(Payment.TYPE_OUT,
                                        purchase.group, branch, Decimal(100))
        payment.description = u"Test payable account"
        payment.group.recipient = drawee.person
        payment.set_pending()
        payment.pay()
        payment.identifier = 1002
        payment.paid_date = date

        # Create a returned sale
        sale = self.create_sale(branch=branch)
        self.add_product(sale)
        self.add_product(sale)
        payment = self.add_payments(sale, date=date)[0]
        sale.order()
        sale.confirm()
        sale.identifier = 23456
        returned_sale = sale.create_sale_return_adapter()
        returned_sale.return_()
        sale.return_date = date
        payment.paid_date = date

        payment = returned_sale.group.get_items()[1]
        payment.branch = branch
        payment.identifier = 1003
        payment.pay()
        payment.paid_date = date

        # create lonely output payment
        group = self.create_payment_group()
        method = PaymentMethod.get_by_name(self.store, u'money')
        payment = method.create_payment(Payment.TYPE_OUT, group, branch, Decimal(100))
        payment.branch = branch
        payment.identifier = 1004
        payment.paid_date = date
        payment.status = Payment.STATUS_PAID

        # create lonely input payment on a second branch
        payer = self.create_client()
        address = self.create_address()
        address.person = payer.person

        method = PaymentMethod.get_by_name(self.store, u'money')
        group = self.create_payment_group()
        payment_lonely_input = method.create_payment(Payment.TYPE_IN, group,
                                                     branch2, Decimal(100))
        payment_lonely_input.description = u"Other branch lonely payment"
        payment_lonely_input.group.payer = payer.person
        payment_lonely_input.set_pending()
        payment_lonely_input.pay()
        payment_lonely_input.identifier = 1005
        payment_lonely_input.paid_date = date

        # Run the dialog the precedes the report
        data = TillDailyMovementDialog(self.store)
        data.model.branch = branch
        data.set_daterange(date, date)
        data.search_button.clicked()

        daterange = (date, None)
        self._diff_expected(TillDailyMovementReport,
                            'till-daily-movement-report', self.store, branch,
                            daterange, data)

        end_date = datetime.date(2013, 6, 1)
        data.set_daterange(date, end_date)
        data.search_button.clicked()
        daterange = (date, end_date)
        self._diff_expected(TillDailyMovementReport,
                            'till-daily-movement-report-end', self.store,
                            branch, daterange, data)

        # Generate report for all branches
        data.model.branch = None
        data.search_button.clicked()
        self._diff_expected(TillDailyMovementReport,
                            'till-daily-movement-all-branches-report-end',
                            self.store, None, daterange, data)