Example #1
0
    def test_show(self, run_dialog):
        optical = self.create_optical_work_order()
        optical.medic = self.create_optical_medic()

        sale = self.create_sale()
        sale.identifier = 99413

        workorder = optical.work_order
        workorder.sale = sale

        sellable = self.create_sellable()
        sale_item = sale.add_sellable(sellable)
        wo_item = self.create_work_order_item(order=workorder)
        wo_item.sale_item = sale_item
        self.add_payments(sale)
        sale.order()
        sale.confirm()
        sale.open_date = localtoday()
        sale.confirm_date = localtoday()

        search = MedicSalesSearch(self.store)
        search._date_filter.select(data=Any)
        search.search.refresh()
        self.check_search(search, 'optical-medic-sales-search')

        search.results.select(search.results[0])
        self.click(search.sale_details_button)

        self.assertEqual(run_dialog.call_count, 1)
        self.assertEqual(run_dialog.call_args[0][0], SaleDetailsDialog)
        self.assertEqual(run_dialog.call_args[0][1], search)
        self.assertEqual(run_dialog.call_args[0][2], self.store)
        self.assertEqual(run_dialog.call_args[0][3].id, sale.id)
Example #2
0
    def test_price(self):
        branch = self.create_branch()
        p1 = self.create_product(branch=branch, stock=1, price=Decimal('10.15'))
        results = SellableFullStockView.find_by_branch(self.store, branch).find(
            SellableFullStockView.product_id == p1.id)
        self.failUnless(list(results))

        self.assertEquals(results[0].price, Decimal('10.15'))

        # Set a sale price
        sellable = p1.sellable
        sellable.on_sale_price = Decimal('5.55')

        # And a interval that includes today
        yesterday = localtoday() - datetime.timedelta(days=1)
        tomorrow = localtoday() + datetime.timedelta(days=1)
        sellable.on_sale_start_date = yesterday
        sellable.on_sale_end_date = tomorrow

        results = SellableFullStockView.find_by_branch(self.store, branch).find(
            SellableFullStockView.product_id == p1.id)
        self.assertEquals(results[0].price, Decimal('5.55'))

        # Testing with a sale price set, but in the past
        date1 = localtoday() - datetime.timedelta(days=10)
        date2 = localtoday() - datetime.timedelta(days=5)
        sellable.on_sale_start_date = date1
        sellable.on_sale_end_date = date2

        results = SellableFullStockView.find_by_branch(self.store, branch).find(
            SellableFullStockView.product_id == p1.id)
        self.assertEquals(results[0].price, Decimal('10.15'))
Example #3
0
    def test_price(self):
        p1 = self.create_product()
        results = ProductFullStockView.find_by_branch(self.store, None).find(ProductFullStockView.product_id == p1.id)
        self.failUnless(list(results))
        pv = results[0]
        self.assertEquals(pv.price, 10)

        # Set a sale price
        sellable = p1.sellable
        sellable.on_sale_price = Decimal("5.55")

        # And a interval that includes today
        yesterday = localtoday() - datetime.timedelta(days=1)
        tomorrow = localtoday() + datetime.timedelta(days=1)
        sellable.on_sale_start_date = yesterday
        sellable.on_sale_end_date = tomorrow

        results = ProductFullStockView.find_by_branch(self.store, None).find(ProductFullStockView.product_id == p1.id)
        self.assertEquals(results[0].price, Decimal("5.55"))

        # Testing with a sale price set, but in the past
        date1 = localtoday() - datetime.timedelta(days=10)
        date2 = localtoday() - datetime.timedelta(days=5)
        sellable.on_sale_start_date = date1
        sellable.on_sale_end_date = date2

        results = ProductFullStockView.find_by_branch(self.store, None).find(ProductFullStockView.product_id == p1.id)
        self.assertEquals(results[0].price, 10)
Example #4
0
    def test_show(self):
        stock_transaction = self.create_stock_transaction_history()
        entry = self.create_cost_center_entry(stock_transaction=stock_transaction)
        cost_center = entry.cost_center
        sale_item = self.create_sale_item()
        sale = sale_item.sale
        stock_decrease = self.create_stock_decrease()
        # The decrease needs an item to be shown in the dialog
        self.create_stock_decrease_item(stock_decrease=stock_decrease)

        stock_transaction.type = StockTransactionHistory.TYPE_SELL
        stock_transaction.object_id = sale_item.id
        stock_transaction.date = localtoday().date()
        stock_transaction.quantity = 5
        stock_transaction.stock_cost = currency('10.50')

        entry.stock_transaction = stock_transaction

        sale.cost_center = cost_center
        sale.identifier = 1234
        sale.open_date = localtoday().date()
        sale.total_amount = sale.get_total_sale_amount()

        stock_decrease.cost_center = cost_center
        stock_decrease.identifier = 5678
        stock_decrease.confirm_date = localtoday().date()

        dialog = CostCenterDialog(self.store, cost_center)
        self.check_dialog(dialog, 'dialog-cost-center-details')
Example #5
0
    def test_price(self):
        p1 = self.create_product()
        results = ProductFullStockView.find_by_branch(
            self.store, None).find(ProductFullStockView.product_id == p1.id)
        self.assertTrue(list(results))
        pv = results[0]
        self.assertEqual(pv.price, 10)

        # Set a sale price
        sellable = p1.sellable
        sellable.on_sale_price = Decimal('5.55')

        # And a interval that includes today
        yesterday = localtoday() - datetime.timedelta(days=1)
        tomorrow = localtoday() + datetime.timedelta(days=1)
        sellable.on_sale_start_date = yesterday
        sellable.on_sale_end_date = tomorrow

        results = ProductFullStockView.find_by_branch(
            self.store, None).find(ProductFullStockView.product_id == p1.id)
        self.assertEqual(results[0].price, Decimal('5.55'))

        # Testing with a sale price set, but in the past
        date1 = localtoday() - datetime.timedelta(days=10)
        date2 = localtoday() - datetime.timedelta(days=5)
        sellable.on_sale_start_date = date1
        sellable.on_sale_end_date = date2

        results = ProductFullStockView.find_by_branch(
            self.store, None).find(ProductFullStockView.product_id == p1.id)
        self.assertEqual(results[0].price, 10)
Example #6
0
    def testPrice(self):
        branch = self.create_branch()
        p1 = self.create_product(branch=branch, stock=1, price=Decimal('10.15'))
        results = SellableFullStockView.find_by_branch(self.store, branch).find(
            SellableFullStockView.product_id == p1.id)
        self.failUnless(list(results))

        self.assertEquals(results[0].price, Decimal('10.15'))

        # Set a sale price
        sellable = p1.sellable
        sellable.on_sale_price = Decimal('5.55')

        # And a interval that includes today
        yesterday = localtoday().date() - datetime.timedelta(days=1)
        tomorrow = localtoday().date() + datetime.timedelta(days=1)
        sellable.on_sale_start_date = yesterday
        sellable.on_sale_end_date = tomorrow

        results = SellableFullStockView.find_by_branch(self.store, branch).find(
            SellableFullStockView.product_id == p1.id)
        self.assertEquals(results[0].price, Decimal('5.55'))

        # Testing with a sale price set, but in the past
        date1 = localtoday().date() - datetime.timedelta(days=10)
        date2 = localtoday().date() - datetime.timedelta(days=5)
        sellable.on_sale_start_date = date1
        sellable.on_sale_end_date = date2

        results = SellableFullStockView.find_by_branch(self.store, branch).find(
            SellableFullStockView.product_id == p1.id)
        self.assertEquals(results[0].price, Decimal('10.15'))
Example #7
0
    def test_show(self, run_dialog):
        optical = self.create_optical_work_order()
        optical.medic = self.create_optical_medic()

        sale = self.create_sale()
        sale.identifier = 99413

        workorder = optical.work_order
        workorder.sale = sale

        sellable = self.create_sellable()
        sale_item = sale.add_sellable(sellable)
        wo_item = self.create_work_order_item(order=workorder)
        wo_item.sale_item = sale_item
        self.add_payments(sale)
        sale.order()
        sale.confirm()
        sale.open_date = localtoday()
        sale.confirm_date = localtoday()

        search = MedicSalesSearch(self.store)
        search._date_filter.select(data=Any)
        search.search.refresh()
        self.check_search(search, 'optical-medic-sales-search')

        search.results.select(search.results[0])
        self.click(search.sale_details_button)

        self.assertEquals(run_dialog.call_count, 1)
        self.assertEquals(run_dialog.call_args[0][0], SaleDetailsDialog)
        self.assertEquals(run_dialog.call_args[0][1], search)
        self.assertEquals(run_dialog.call_args[0][2], self.store)
        self.assertEquals(run_dialog.call_args[0][3].id, sale.id)
Example #8
0
    def _create_payment(self):
        group = PaymentGroup()
        group.payer = self.client.person

        method = PaymentMethod.get_by_name(self.store, u'credit')
        branch = api.get_current_branch(self.store)

        if self.model.value < 0:
            payment_type = Payment.TYPE_IN
        else:
            payment_type = Payment.TYPE_OUT

        # Set status to PENDING now, to avoid calling set_pending on
        # on_confirm for payments that shoud not have its status changed.
        payment = Payment(open_date=localtoday(),
                          branch=branch,
                          status=Payment.STATUS_PENDING,
                          description=self.model.description,
                          value=abs(self.model.value),
                          base_value=abs(self.model.value),
                          due_date=localtoday(),
                          method=method,
                          group=group,
                          category=None,
                          payment_type=payment_type,
                          bill_received=False)
        payment.pay()

        return payment
Example #9
0
    def _create_payment(self):
        group = PaymentGroup()
        group.payer = self.client.person

        method = PaymentMethod.get_by_name(self.store, u'credit')
        branch = api.get_current_branch(self.store)

        if self.model.value < 0:
            payment_type = Payment.TYPE_IN
        else:
            payment_type = Payment.TYPE_OUT

        # Set status to PENDING now, to avoid calling set_pending on
        # on_confirm for payments that shoud not have its status changed.
        payment = Payment(open_date=localtoday(),
                          branch=branch,
                          status=Payment.STATUS_PENDING,
                          description=self.model.description,
                          value=abs(self.model.value),
                          base_value=abs(self.model.value),
                          due_date=localtoday(),
                          method=method,
                          group=group,
                          till=None,
                          category=None,
                          payment_type=payment_type,
                          bill_received=False)
        payment.pay()

        return payment
Example #10
0
 def __init__(self):
     self.items = []
     self.open_date = localtoday().date()
     self.receival_date = localtoday().date()
     self.source_branch = None
     self.destination_branch = None
     self.source_responsible = None
     self.destination_responsible = None
 def __init__(self, source_branch):
     self.items = []
     self.open_date = localtoday().date()
     self.receival_date = localtoday().date()
     self.source_branch = source_branch
     self.destination_branch = None
     self.source_responsible = None
     self.destination_responsible = None
Example #12
0
    def test_get_days_late(self):
        payment = self.create_payment(payment_type=Payment.TYPE_IN)
        view = self.store.find(InPaymentView, id=payment.id).one()
        self.assertFalse(view.get_days_late())

        payment.due_date = localtoday() + datetime.timedelta(-4)
        view = self.store.find(InPaymentView, id=payment.id).one()
        self.assertEquals(view.get_days_late(), 4)

        payment.due_date = localtoday() + datetime.timedelta(+4)
        view = self.store.find(InPaymentView, id=payment.id).one()
        self.assertFalse(view.get_days_late())
Example #13
0
    def test_get_days_late(self):
        payment = self.create_payment(payment_type=Payment.TYPE_IN)
        view = self.store.find(InPaymentView, id=payment.id).one()
        self.assertFalse(view.get_days_late())

        payment.due_date = localtoday() + datetime.timedelta(-4)
        view = self.store.find(InPaymentView, id=payment.id).one()
        self.assertEquals(view.get_days_late(), 4)

        payment.due_date = localtoday() + datetime.timedelta(+4)
        view = self.store.find(InPaymentView, id=payment.id).one()
        self.assertFalse(view.get_days_late())
Example #14
0
 def create_model(self, store):
     return Calls(date=localtoday().date(),
                  description=u'',
                  message=u'',
                  person=self.person,
                  attendant=api.get_current_user(self.store),
                  store=store)
Example #15
0
    def testCreate(self):
        person = self.create_person()
        editor = CallsEditor(self.store, None, person, None)
        self.assertTrue(isinstance(editor.model, Calls))
        editor.date.update(localtoday().date())

        self.check_editor(editor, 'editor-calls-create')
Example #16
0
    def test_can_remove(self):
        product = self.create_product()
        test = ProductQualityTest(store=self.store, product=product)

        # Test has never been used
        self.assertTrue(test.can_remove())

        order = self.create_production_order()
        user = self.create_user()
        item = ProductionProducedItem(product=product,
                                      order=order,
                                      produced_by=user,
                                      produced_date=localtoday().date(),
                                      serial_number=1,
                                      store=self.store)
        self.assertTrue(test.can_remove())

        # Test has been used in a production
        ProductionItemQualityResult(produced_item=item,
                                    quality_test=test,
                                    tested_by=user,
                                    result_value=u'True',
                                    test_passed=True,
                                    store=self.store)
        self.assertFalse(test.can_remove())
Example #17
0
    def try_finalize_production(self, ignore_completion=False):
        """When all items are completely produced, change the status of the
        production to CLOSED.
        """
        assert self.can_finalize(), self.status

        if ignore_completion:
            is_produced = True
        else:
            is_produced = self.is_completely_produced()
        is_tested = self.is_completely_tested()

        if is_produced and not is_tested:
            # Fully produced but not fully tested. Keep status as QA
            self.status = ProductionOrder.ORDER_QA
        elif is_produced and is_tested:
            # All items must be completely produced and tested
            self.close_date = localtoday()
            self.status = ProductionOrder.ORDER_CLOSED

        # If the order is closed, return the the remaining allocated material to
        # the stock
        if self.status == ProductionOrder.ORDER_CLOSED:
            # Return remaining allocated material to the stock
            for m in self.get_material_items():
                m.return_remaining()

            # Increase the stock for the produced items
            for p in self.produced_items:
                p.send_to_stock()
Example #18
0
    def test_show(self):
        today = localtoday().date()
        client = self.create_client()
        # Nova venda
        sale = self.create_sale()
        sale.identifier = 123
        sale.client = client
        sale.open_date = today

        # Product
        sellable = self.create_sellable(description=u'Normal',
                                        storable=True, price=100)
        sale.add_sellable(sellable)
        # Service
        sellable2 = self.create_sellable(description=u'Service', product=False,
                                         price=100)
        item = sale.add_sellable(sellable2)
        item.estimated_fix_date = today
        # Payments
        payment = self.add_payments(sale, date=today)[0]
        payment.identifier = 999
        payment.group.payer = client.person
        # Call
        self.create_call(client.person)

        dialog = ClientDetailsDialog(self.store, client)
        self.check_editor(dialog, 'dialog-client-details')
Example #19
0
    def __init__(self,
                 price=None,
                 notes=None,
                 recipient=None,
                 transporter_id=None,
                 address=None,
                 estimated_fix_date=None,
                 description=None,
                 freight_type=None,
                 volumes_kind=None,
                 volumes_quantity=1,
                 volumes_gross_weight=decimal.Decimal(),
                 vehicle_state=None,
                 vehicle_license_plate=None,
                 vehicle_registration=None,
                 volumes_net_weight=decimal.Decimal(),
                 original_delivery=None):
        self.price = price
        self.notes = notes
        self.address = address or (recipient and recipient.address)
        self.recipient = recipient or (address and address.person)
        self.transporter_id = transporter_id
        self.estimated_fix_date = estimated_fix_date or localtoday().date()
        self.description = description or _(u'Delivery')
        self.freight_type = freight_type or Delivery.FREIGHT_TYPE_CIF
        self.volumes_kind = volumes_kind or _(u'Volumes')
        self.volumes_quantity = volumes_quantity
        self.volumes_gross_weight = volumes_gross_weight
        self.volumes_net_weight = volumes_net_weight
        self.vehicle_license_plate = vehicle_license_plate
        self.vehicle_state = vehicle_state
        self.vehicle_registration = vehicle_registration
        self.original_delivery = original_delivery

        self._savepoint = {}
Example #20
0
    def testChangeDueDateSale(self, warning):
        sale = self.create_sale()
        sale.client = self.create_client()
        sale.identifier = 9123
        payment = self.add_payments(sale, date=localdate(2001, 1, 1).date())[0]
        editor = PaymentDueDateChangeDialog(self.store, payment, sale)
        self.check_editor(editor, 'editor-payment-change-due-date-sale')

        today = localtoday().date()
        yesterday = today - relativedelta(days=1)

        # By default, we cannot set a due date to the past
        editor.due_date.update(yesterday)
        self.assertNotSensitive(editor.main_dialog, ['ok_button'])

        # Now we should be able to confirm the dialog
        editor.due_date.update(today)
        self.assertSensitive(editor.main_dialog, ['ok_button'])

        # Ok button is enabled, but should show a warning
        self.click(editor.main_dialog.ok_button)
        warning.assert_called_once_with('You can not change the due date '
                                        'without a reason!')
        warning.reset_mock()

        editor.change_reason.update('Just because')
        self.click(editor.main_dialog.ok_button)
        self.assertEquals(warning.call_count, 0)

        self.assertEquals(payment.due_date.date(), today)
Example #21
0
    def __init__(self,
                 wizard,
                 previous,
                 store,
                 model,
                 outstanding_value=currency(0)):
        self.parent = model
        self.slave = None
        self.discount_surcharge_slave = None
        self.outstanding_value = outstanding_value

        if not model.payments.count():
            # Default values
            self._installments_number = None
            self._first_duedate = None
            self._method = 'bill'
        else:
            self._installments_number = model.payments.count()
            self._method = model.payments[0].method.method_name

            # due_date is datetime.datetime. Converting it to datetime.date
            due_date = model.payments[0].due_date.date()
            self._first_duedate = (due_date >= localtoday().date() and due_date
                                   or None)

        WizardEditorStep.__init__(self, store, wizard, model.group, previous)
Example #22
0
    def _create_domain(self):
        self.clean_domain([SaleItem])

        branch = get_current_branch(self.store)
        self.today = localtoday()

        product = self.create_product()
        storable = Storable(store=self.store, product=product)
        ProductStockItem(storable=storable, branch=branch, quantity=5,
                         store=self.store)
        product.sellable.code = u'1'
        product.sellable.description = u'Luvas'

        product2 = self.create_product()
        storable2 = Storable(store=self.store, product=product2)
        ProductStockItem(storable=storable2, branch=branch, quantity=5,
                         store=self.store)
        product2.sellable.code = u'2'
        product2.sellable.description = u'Botas'

        # Sale
        sale = self.create_sale(branch=branch)
        sale.identifier = 123
        sale.open_date = self.today
        sale.add_sellable(product.sellable, 3)
        sale.add_sellable(product2.sellable, 5)
        sale.order()
        self.add_payments(sale, date=self.today)
        sale.confirm()
Example #23
0
    def test_select_by_branch_data(self):
        branch = get_current_branch(self.store)
        sale = self.create_sale()
        sale.branch = branch
        sellable = self.add_product(sale)
        sale.order()
        self.add_payments(sale, method_type=u"money")
        sale.confirm()

        results = SoldItemView.find_by_branch_date(self.store, None, None)
        self.assertFalse(results.is_empty())

        results = SoldItemView.find_by_branch_date(self.store, branch, None)
        self.assertFalse(results.is_empty())

        results = SoldItemView.find_by_branch_date(self.store, branch, None).find(SoldItemView.id == sellable.id)
        # FIXME: Storm does not support count() with group_by
        # self.assertEquals(results.count(), 1)
        self.assertEquals(len(list(results)), 1)

        today = localtoday()
        results = SoldItemView.find_by_branch_date(self.store, None, today).find(SoldItemView.id == sellable.id)
        self.assertEquals(len(list(results)), 1)

        yesterday = today - datetime.timedelta(days=1)
        results = SoldItemView.find_by_branch_date(self.store, None, (yesterday, today))
        results = results.find(SoldItemView.id == sellable.id)
        self.assertEquals(len(list(results)), 1)

        yesterday = today - datetime.timedelta(days=1)
        results = SoldItemView.find_by_branch_date(self.store, None, (yesterday, today))

        self.assertFalse(results.is_empty())
Example #24
0
    def test_can_purchase_allow_all(self):
        #: This parameter always allows the client to purchase, no matter if he
        #: has late payments
        sysparam(self.store).update_parameter(u'LATE_PAYMENTS_POLICY',
                                              unicode(int(LatePaymentPolicy.ALLOW_SALES)))

        client = self.create_client()
        bill_method = PaymentMethod.get_by_name(self.store, u'bill')
        check_method = PaymentMethod.get_by_name(self.store, u'check')
        money_method = PaymentMethod.get_by_name(self.store, u'money')
        store_credit_method = PaymentMethod.get_by_name(self.store,
                                                        u'store_credit')
        today = localtoday()

        # client can pay if he doesn't have any payments
        client.credit_limit = Decimal("1000")
        self.assertTrue(client.can_purchase(money_method, currency("200")))

        # client can pay if he has payments that are not overdue
        payment = self.create_payment(Payment.TYPE_IN, today, method=bill_method)
        payment.group = self.create_payment_group()
        payment.group.payer = client.person
        self.assertTrue(client.can_purchase(check_method, currency("200")))

        # client can pay even if he does have overdue payments
        payment = self.create_payment(Payment.TYPE_IN,
                                      today - relativedelta(days=1), method=check_method)
        payment.group = self.create_payment_group()
        payment.group.payer = client.person
        self.assertTrue(client.can_purchase(store_credit_method, currency("200")))

        # But he cannot pay if its above the credit limit
        self.assertRaises(SellError, client.can_purchase, store_credit_method, currency("1001"))
Example #25
0
    def test_has_late_payments(self):
        client = self.create_client()
        today = localtoday().date()
        method = PaymentMethod.get_by_name(self.store, u'bill')

        # client does not have any payments
        self.assertFalse(
            InPaymentView.has_late_payments(self.store, client.person))

        # client has payments that are not overdue
        payment = self.create_payment(Payment.TYPE_IN,
                                      today + relativedelta(days=1),
                                      method=method)
        payment.group = self.create_payment_group()
        payment.group.payer = client.person
        self.assertFalse(
            InPaymentView.has_late_payments(self.store, client.person))

        # client has overdue payments
        payment = self.create_payment(Payment.TYPE_IN,
                                      today - relativedelta(days=2),
                                      method=method)
        payment.status = Payment.STATUS_PENDING
        payment.group = self.create_payment_group()
        payment.group.payer = client.person
        self.assertTrue(
            InPaymentView.has_late_payments(self.store, client.person))
Example #26
0
    def on_close_date__validate(self, widget, date):
        if sysparam.get_bool('ALLOW_OUTDATED_OPERATIONS'):
            return

        if date > localtoday().date() or date < self.model.open_date:
            return ValidationError(_("Paid date must be between "
                                     "%s and today") % (self.model.open_date, ))
Example #27
0
    def test_can_remove(self):
        product = self.create_product()
        test = ProductQualityTest(store=self.store, product=product)

        # Test has never been used
        self.assertTrue(test.can_remove())

        order = self.create_production_order()
        user = self.create_user()
        item = ProductionProducedItem(product=product,
                                      order=order,
                                      produced_by=user,
                                      produced_date=localtoday().date(),
                                      serial_number=1,
                                      store=self.store)
        self.assertTrue(test.can_remove())

        # Test has been used in a production
        ProductionItemQualityResult(produced_item=item,
                                    quality_test=test,
                                    tested_by=user,
                                    result_value=u'True',
                                    test_passed=True,
                                    store=self.store)
        self.assertFalse(test.can_remove())
Example #28
0
    def _populate_date_filter(self, date_filter):
        # The options we want to show to the users are the following:
        #   'May 2007'
        #   'June 2007'
        #   ...
        #   'September 2008'

        initial_date = self.store.find(SystemTable).min(
            SystemTable.updated).date()

        # Start is the first day of the month
        # End is the last day of the month
        start = initial_date + relativedelta(day=1)
        end = localtoday().date() + relativedelta(day=31)
        intervals = []
        while start < end:
            intervals.append((start, start + relativedelta(day=31)))
            start = start + relativedelta(months=1)

        # When we have the list of intervals, add them to the list and
        # make sure that they are translated
        month_names = get_month_names()
        for start, end in intervals:
            # Translators: Do not translate 'month' and 'year'. You can
            #              change it's positions. In the way it is,
            #              it will product for example 'December 2012'
            name = _('{month} {year}').format(
                month=month_names[start.month - 1],
                year=start.year)
            date_filter.add_option_fixed_interval(
                name, start, end, position=0)
Example #29
0
    def test_has_late_payments(self):
        client = self.create_client()
        today = localtoday().date()
        method = PaymentMethod.get_by_name(self.store, u'bill')

        # client does not have any payments
        self.assertFalse(InPaymentView.has_late_payments(self.store,
                                                         client.person))

        # client has payments that are not overdue
        payment = self.create_payment(Payment.TYPE_IN,
                                      today + relativedelta(days=1),
                                      method=method)
        payment.group = self.create_payment_group()
        payment.group.payer = client.person
        self.assertFalse(InPaymentView.has_late_payments(self.store,
                                                         client.person))

        # client has overdue payments
        payment = self.create_payment(Payment.TYPE_IN,
                                      today - relativedelta(days=2),
                                      method=method)
        payment.status = Payment.STATUS_PENDING
        payment.group = self.create_payment_group()
        payment.group.payer = client.person
        self.assertTrue(InPaymentView.has_late_payments(self.store,
                                                        client.person))
Example #30
0
    def on_close_date__validate(self, widget, date):
        if sysparam(self.store).ALLOW_OUTDATED_OPERATIONS:
            return

        if date > localtoday().date() or date < self.model.open_date:
            return ValidationError(_("Paid date must be between "
                                     "%s and today") % (self.model.open_date, ))
Example #31
0
    def test_confirm(self, yesno, print_report):
        client = self.create_client()
        branch = api.get_current_branch(self.store)
        storable = self.create_storable(branch=branch, stock=1)
        sellable = storable.product.sellable
        wizard = NewLoanWizard(self.store)

        step = wizard.get_current_step()
        step.client.update(client)
        step.expire_date.update(localtoday().date())
        self.check_wizard(wizard, 'new-loan-wizard-start-step')
        self.click(wizard.next_button)

        step = wizard.get_current_step()
        step.barcode.set_text(sellable.barcode)
        step.sellable_selected(sellable)
        step.quantity.update(1)
        self.click(step.add_sellable_button)
        loan_item = self.store.find(LoanItem, sellable=sellable).one()
        module = 'stoqlib.gui.events.NewLoanWizardFinishEvent.emit'
        with mock.patch(module) as emit:
            self.click(wizard.next_button)
            self.assertEquals(emit.call_count, 1)
            args, kwargs = emit.call_args
            self.assertTrue(isinstance(args[0], Loan))
        self.check_wizard(wizard, 'new-loan-wizard-item-step',
                          [wizard.retval, loan_item])

        yesno.assert_called_once_with(
            _('Would you like to print the receipt now?'), gtk.RESPONSE_YES,
            'Print receipt', "Don't print")
        self.assertEquals(print_report.call_count, 1)

        # verifies if stock was decreased correctly
        self.assertEquals(storable.get_balance_for_branch(branch), 0)
Example #32
0
    def on_estimated_start__validate(self, widget, value):
        sysparam_ = api.sysparam(self.store)
        if (value < localtoday().date()
                and not sysparam_.ALLOW_OUTDATED_OPERATIONS):
            return ValidationError(u"The start date cannot be on the past")

        self.estimated_finish.validate(force=True)
Example #33
0
    def test_can_purchase_disallow_store_credit(self):
        #: This parameter disallows the client to purchase with store credit
        #: when he has late payments
        sysparam(self.store).update_parameter(u'LATE_PAYMENTS_POLICY',
                                              unicode(int(LatePaymentPolicy.DISALLOW_STORE_CREDIT)))

        client = self.create_client()
        bill_method = PaymentMethod.get_by_name(self.store, u'bill')
        check_method = PaymentMethod.get_by_name(self.store, u'check')
        money_method = PaymentMethod.get_by_name(self.store, u'money')
        store_credit_method = PaymentMethod.get_by_name(self.store,
                                                        u'store_credit')
        today = localtoday()

        # client can pay if he doesn't have any payments
        self.assertTrue(client.can_purchase(money_method, currency("0")))

        # client can pay if he has payments that are not overdue
        payment = self.create_payment(Payment.TYPE_IN, today, method=bill_method)
        payment.group = self.create_payment_group()
        payment.group.payer = client.person
        self.assertTrue(client.can_purchase(money_method, currency("0")))

        # for a client with overdue payments
        payment = self.create_payment(Payment.TYPE_IN,
                                      today - relativedelta(days=1),
                                      method=money_method)
        payment.status = Payment.STATUS_PENDING
        payment.group = self.create_payment_group()
        payment.group.payer = client.person
        # client can pay if payment method is not store credit
        self.assertTrue(client.can_purchase(check_method, currency("0")))
        self.assertTrue(client.can_purchase(money_method, currency("0")))
        # client can not pay if payment method is store credit
        self.assertRaises(SellError, client.can_purchase, store_credit_method, currency("0"))
Example #34
0
    def test_confirm(self, yesno, print_report):
        client = self.create_client()
        branch = api.get_current_branch(self.store)
        storable = self.create_storable(branch=branch, stock=1)
        sellable = storable.product.sellable
        wizard = NewLoanWizard(self.store)

        step = wizard.get_current_step()
        step.client.update(client)
        step.expire_date.update(localtoday().date())
        self.check_wizard(wizard, 'new-loan-wizard-start-step')
        self.click(wizard.next_button)

        step = wizard.get_current_step()
        step.barcode.set_text(sellable.barcode)
        step.sellable_selected(sellable)
        step.quantity.update(1)
        self.click(step.add_sellable_button)
        loan_item = self.store.find(LoanItem, sellable=sellable).one()
        module = 'stoqlib.gui.events.NewLoanWizardFinishEvent.emit'
        with mock.patch(module) as emit:
            self.click(wizard.next_button)
            self.assertEquals(emit.call_count, 1)
            args, kwargs = emit.call_args
            self.assertTrue(isinstance(args[0], Loan))
        self.check_wizard(wizard, 'new-loan-wizard-item-step',
                          [wizard.retval, loan_item])

        yesno.assert_called_once_with(_('Would you like to print the receipt now?'),
                                      gtk.RESPONSE_YES, 'Print receipt', "Don't print")
        self.assertEquals(print_report.call_count, 1)

        # verifies if stock was decreased correctly
        self.assertEquals(storable.get_balance_for_branch(branch), 0)
Example #35
0
    def test_penalty_and_interest(self):
        payment = self.create_payment(payment_type=Payment.TYPE_OUT,
                                      value=100,
                                      date=localtoday().date() -
                                      datetime.timedelta(5))

        payment.method.daily_interest = 1
        payment.method.penalty = 1

        slave = PurchasePaymentConfirmSlave(self.store, [payment])

        # Penalty and interest enabled
        self.assertEqual(slave.penalty.read(), currency('1'))
        self.assertEqual(slave.interest.read(), currency('5.05'))

        # Penalty disabled and interest enabled
        self.click(slave.pay_penalty)
        self.assertEqual(slave.penalty.read(), currency('0'))
        self.assertEqual(slave.interest.read(), currency('5'))

        # Penalty enabled and interest disabled
        self.click(slave.pay_penalty)
        self.click(slave.pay_interest)
        self.assertEqual(slave.penalty.read(), currency('1'))
        self.assertEqual(slave.interest.read(), currency('0'))

        # Penalty and interest disabled
        self.click(slave.pay_penalty)
        self.assertEqual(slave.penalty.read(), currency('0'))
        self.assertEqual(slave.interest.read(), currency('0'))
Example #36
0
    def open_till(self):
        """Open the till.

        It can only be done once per day.
        The final cash amount of the previous till will be used
        as the initial value in this one after opening it.
        """
        if self.status == Till.STATUS_OPEN:
            raise TillError(_('Till is already open'))

        # Make sure that the till has not been opened today
        today = localtoday().date()
        if not self.store.find(
                Till,
                And(
                    Date(Till.opening_date) >= today, Till.station_id
                    == self.station.id)).is_empty():
            raise TillError(_("A till has already been opened today"))

        last_till = self._get_last_closed_till()
        if last_till:
            if not last_till.closing_date:
                raise TillError(_("Previous till was not closed"))

            initial_cash_amount = last_till.final_cash_amount
        else:
            initial_cash_amount = 0

        self.initial_cash_amount = initial_cash_amount

        self.opening_date = TransactionTimestamp()
        self.status = Till.STATUS_OPEN
Example #37
0
    def on_estimated_start__validate(self, widget, value):
        sysparam_ = api.sysparam(self.store)
        if (value < localtoday().date() and
                not sysparam_.ALLOW_OUTDATED_OPERATIONS):
            return ValidationError(u"The start date cannot be on the past")

        self.estimated_finish.validate(force=True)
Example #38
0
File: till.py Project: rosalin/stoq
    def open_till(self):
        """Open the till.

        It can only be done once per day.
        The final cash amount of the previous till will be used
        as the initial value in this one after opening it.
        """
        if self.status == Till.STATUS_OPEN:
            raise TillError(_('Till is already open'))

        # Make sure that the till has not been opened today
        today = localtoday().date()
        if not self.store.find(Till,
                               And(Date(Till.opening_date) >= today,
                                   Till.station_id == self.station.id)).is_empty():
            raise TillError(_("A till has already been opened today"))

        last_till = self._get_last_closed_till()
        if last_till:
            if not last_till.closing_date:
                raise TillError(_("Previous till was not closed"))

            initial_cash_amount = last_till.final_cash_amount
        else:
            initial_cash_amount = 0

        self.initial_cash_amount = initial_cash_amount

        self.opening_date = TransactionTimestamp()
        self.status = Till.STATUS_OPEN
Example #39
0
 def _update_p_cred_sn_valid_until(self):
     if (self.p_cred_sn.get_value()
             and not self.p_cred_sn_valid_until.get_date()):
         # Set the default expire date to the last day of current month.
         default_expire_date = (localtoday().date() +
                                relativedelta(day=1, months=+1, days=-1))
         self.p_cred_sn_valid_until.set_date(default_expire_date)
Example #40
0
    def on_expected_receival_date__validate(self, widget, date):
        if sysparam.get_bool('ALLOW_OUTDATED_OPERATIONS'):
            return

        if date < localtoday().date():
            return ValidationError(
                _("Expected receival date must be set to a future date"))
Example #41
0
    def __init__(self,
                 price=None,
                 notes=None,
                 client=None,
                 transporter=None,
                 address=None,
                 estimated_fix_date=None,
                 description=None,
                 freight_type=None,
                 volumes_kind=None,
                 volumes_quantity=1,
                 original_delivery=None):
        self.price = price
        self.notes = notes
        self.address = address or (client and client.person.address)
        self.client = client or (address and address.person.client)
        self.transporter = transporter
        self.estimated_fix_date = estimated_fix_date or localtoday().date()
        self.description = description or _(u'Delivery')
        self.freight_type = freight_type or Delivery.FREIGHT_TYPE_CIF
        self.volumes_kind = volumes_kind or _(u'Volumes')
        self.volumes_quantity = volumes_quantity
        self.original_delivery = original_delivery

        self._savepoint = {}
    def test_penalty_and_interest(self):
        payment = self.create_payment(
            payment_type=Payment.TYPE_OUT, value=100, date=localtoday().date() - datetime.timedelta(5)
        )

        payment.method.daily_interest = 1
        payment.method.penalty = 1

        slave = PurchasePaymentConfirmSlave(self.store, [payment])

        # Penalty and interest enabled
        self.assertEquals(slave.penalty.read(), currency("1"))
        self.assertEquals(slave.interest.read(), currency("5.05"))

        # Penalty disabled and interest enabled
        self.click(slave.pay_penalty)
        self.assertEquals(slave.penalty.read(), currency("0"))
        self.assertEquals(slave.interest.read(), currency("5"))

        # Penalty enabled and interest disabled
        self.click(slave.pay_penalty)
        self.click(slave.pay_interest)
        self.assertEquals(slave.penalty.read(), currency("1"))
        self.assertEquals(slave.interest.read(), currency("0"))

        # Penalty and interest disabled
        self.click(slave.pay_penalty)
        self.assertEquals(slave.penalty.read(), currency("0"))
        self.assertEquals(slave.interest.read(), currency("0"))
Example #43
0
    def _create_domain(self):
        self.clean_domain([SaleItem])

        branch = get_current_branch(self.store)
        self.today = localtoday()

        product = self.create_product()
        storable = Storable(store=self.store, product=product)
        self.create_product_stock_item(storable=storable,
                                       branch=branch,
                                       quantity=5)
        product.sellable.code = u'1'
        product.sellable.description = u'Luvas'

        product2 = self.create_product()
        storable2 = Storable(store=self.store, product=product2)
        self.create_product_stock_item(storable=storable2,
                                       branch=branch,
                                       quantity=5)
        product2.sellable.code = u'2'
        product2.sellable.description = u'Botas'

        # Sale
        sale = self.create_sale(branch=branch)
        sale.identifier = 123
        sale.open_date = self.today
        sale.add_sellable(product.sellable, 3)
        sale.add_sellable(product2.sellable, 5)
        sale.order(self.current_user)
        self.add_payments(sale, date=self.today)
        sale.confirm(self.current_user)
Example #44
0
    def try_finalize_production(self):
        """When all items are completely produced, change the status of the
        production to CLOSED.
        """
        assert (self.status == ProductionOrder.ORDER_PRODUCING or
                self.status == ProductionOrder.ORDER_QA), self.status

        is_produced = self.is_completely_produced()
        is_tested = self.is_completely_tested()

        if is_produced and not is_tested:
            # Fully produced but not fully tested. Keep status as QA
            self.status = ProductionOrder.ORDER_QA
        elif is_produced and is_tested:
            # All items must be completely produced and tested
            self.close_date = localtoday()
            self.status = ProductionOrder.ORDER_CLOSED

        # If the order is closed, return the the remaining allocated material to
        # the stock
        if self.status == ProductionOrder.ORDER_CLOSED:
            # Return remaining allocated material to the stock
            for m in self.get_material_items():
                m.return_remaining()

            # Increase the stock for the produced items
            for p in self.produced_items:
                p.send_to_stock()
Example #45
0
 def _update_p_cred_sn_valid_until(self):
     if (self.p_cred_sn.get_value()
         and not self.p_cred_sn_valid_until.get_date()):
             # Set the default expire date to the last day of current month.
         default_expire_date = (localtoday().date() +
                                relativedelta(day=1, months=+1, days=-1))
         self.p_cred_sn_valid_until.set_date(default_expire_date)
Example #46
0
 def test_initial_with_open_till_and_token(self):
     till = self.create_till()
     till.opening_date = localtoday()
     till.status = Till.STATUS_OPEN
     with self.sysparam(USE_SALE_TOKEN=True):
         app = self.create_app(TillApp, u'till')
         self.check_app(app, u'till-opened-till-with-token')
Example #47
0
 def test_initial_with_open_till_and_token(self):
     till = self.create_till()
     till.opening_date = localtoday()
     till.status = Till.STATUS_OPEN
     with self.sysparam(USE_SALE_TOKEN=True):
         app = self.create_app(TillApp, u'till')
         self.check_app(app, u'till-opened-till-with-token')
Example #48
0
    def _populate_date_filter(self, date_filter):
        # The options we want to show to the users are the following:
        #   'May 2007'
        #   'June 2007'
        #   ...
        #   'September 2008'

        initial_date = self.store.find(SystemTable).min(
            SystemTable.updated).date()

        # Start is the first day of the month
        # End is the last day of the month
        start = initial_date + relativedelta(day=1)
        end = localtoday().date() + relativedelta(day=31)
        intervals = []
        while start < end:
            intervals.append((start, start + relativedelta(day=31)))
            start = start + relativedelta(months=1)

        # When we have the list of intervals, add them to the list and
        # make sure that they are translated
        month_names = get_month_names()
        for start, end in intervals:
            # Translators: Do not translate 'month' and 'year'. You can
            #              change it's positions. In the way it is,
            #              it will product for example 'December 2012'
            name = _('{month} {year}').format(month=month_names[start.month -
                                                                1],
                                              year=start.year)
            date_filter.add_option_fixed_interval(name, start, end, position=0)
Example #49
0
 def on_open_date__validate(self, widget, date):
     if sysparam.get_bool('ALLOW_OUTDATED_OPERATIONS'):
         return
     if date < localtoday().date():
         return ValidationError(
             _("Open date must be set to today or "
               "a future date"))
Example #50
0
 def test_change_due_date(self):
     payment = self.create_payment()
     self.assertEqual(payment.due_date, localtoday())
     payment.change_due_date(new_due_date=self._get_relative_day(-2))
     self.assertEqual(payment.due_date, self._get_relative_day(-2))
     payment.status = Payment.STATUS_PAID
     with self.assertRaises(StoqlibError):
         payment.change_due_date(new_due_date=self._get_relative_day(-1))
    def _populate_date_filter(self, date_filter):
        transaction = self.store.find(AccountTransaction).order_by(AccountTransaction.date).first()
        if transaction is None:
            return

        for i in range(transaction.date.year, localtoday().year + 1):
            year = datetime.datetime(i, 1, 1)
            date_filter.add_option_fixed_interval(_("Year %d") % (i,), year, year.replace(month=12, day=31), position=0)
 def on_open_date__validate(self, widget, date):
     if date < localtoday().date():
         return ValidationError(_(u"The date must be set to today "
                                  "or a future date"))
     receival_date = self.receival_date.get_date()
     if receival_date is not None and date > receival_date:
         return ValidationError(_(u"The open date must be set to "
                                  "before the receival date"))
 def create_model(self, store):
     return CreditCheckHistory(check_date=localtoday().date(),
                               identifier=u'',
                               status=CreditCheckHistory.STATUS_NOT_INCLUDED,
                               client=self._client,
                               notes=u'',
                               user=api.get_current_user(self.store),
                               store=store)
Example #54
0
 def test_change_due_date(self):
     payment = self.create_payment()
     self.assertEquals(payment.due_date, localtoday())
     payment.change_due_date(new_due_date=self._get_relative_day(-2))
     self.assertEquals(payment.due_date, self._get_relative_day(-2))
     payment.status = Payment.STATUS_PAID
     with self.assertRaises(StoqlibError):
         payment.change_due_date(new_due_date=self._get_relative_day(-1))
Example #55
0
 def on_PrintReceipt__activate(self, action):
     payment_views = self.results.get_selected_rows()
     payments = [v.payment for v in payment_views]
     date = localtoday().date()
     print_report(OutPaymentReceipt,
                  payment=payments[0],
                  order=payment_views[0].purchase,
                  date=date)