Exemple #1
0
    def test_create(self):
        # Allow creating purchases in the past.
        sysparam(self.store).update_parameter(u"ALLOW_OUTDATED_OPERATIONS",
                                              u"1")

        self.wizard = PurchaseWizard(self.store)
        purchase_branch = self.create_branch()
        purchase_order = PurchaseOrder(branch=purchase_branch)
        sellable = self.create_sellable()
        purchase_order.add_item(sellable=sellable)
        self.wizard.model.identifier = 12345
        self.wizard.model.open_date = localdate(2010, 1, 3).date()
        self._check_start_step('wizard-purchase-start-step')
        self._check_item_step('wizard-purchase-item-step')
        self._check_payment_step('wizard-purchase-payment-step')

        purchase = self.wizard.model
        models = [purchase]
        models.extend(purchase.get_items())
        models.extend(purchase.payments)
        models.append(purchase.group)

        self.check_wizard(self.wizard,
                          'wizard-purchase-finish-step',
                          models=models)

        self.click(self.wizard.next_button)
Exemple #2
0
    def test_credit_limit_update(self):
        sysparam(self.store).update_parameter(u"CREDIT_LIMIT_SALARY_PERCENT",
                                              u"10")

        client = self.create_client()
        client.salary = 50
        slave = ClientCreditSlave(self.store, client)
        slave.salary.emit('changed')
        self.assertEquals(slave.credit_limit.read(), 5)

        # checks if credit limit updated correctly when salary changes
        # and parameter salary percent is not 0
        slave.salary.update(100)
        slave.salary.emit('changed')
        self.assertEquals(slave.credit_limit.read(), 10)

        sysparam(self.store).update_parameter(u"CREDIT_LIMIT_SALARY_PERCENT",
                                              u"0")

        # checks if credit limit does not update (correct behavior)
        # when salary percent is 0 and salary changes
        credit_limit = 0
        client.credit_limit = credit_limit
        slave.credit_limit.update(credit_limit)
        slave.credit_limit.emit('changed')

        slave.salary.update(200)
        slave.salary.emit('changed')

        self.assertEquals(slave.credit_limit.read(), credit_limit)
Exemple #3
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"))
Exemple #4
0
    def _check_branch(self):
        from stoqlib.database.runtime import (get_default_store, new_store,
                                              get_current_station,
                                              set_current_branch_station)
        from stoqlib.domain.person import Company
        from stoqlib.lib.parameters import sysparam
        from stoqlib.lib.message import info

        default_store = get_default_store()
        set_current_branch_station(default_store, station_name=None)

        compaines = default_store.find(Company)
        if (compaines.count() == 0 or
            not sysparam(default_store).MAIN_COMPANY):
            from stoqlib.gui.base.dialogs import run_dialog
            from stoqlib.gui.dialogs.branchdialog import BranchDialog
            if self._ran_wizard:
                info(_("You need to register a company before start using Stoq"))
            else:
                info(_("Could not find a company. You'll need to register one "
                       "before start using Stoq"))
            store = new_store()
            person = run_dialog(BranchDialog, None, store)
            if not person:
                raise SystemExit
            branch = person.branch
            sysparam(store).MAIN_COMPANY = branch.id
            get_current_station(store).branch = branch
            store.commit()
            store.close()
Exemple #5
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"))
Exemple #6
0
    def test_wizard_create_payment(self, yesno):
        yesno.return_value = False

        sysparam(self.store).update_parameter(
            u'CREATE_PAYMENTS_ON_STOCK_DECREASE',
            u'True')

        till = self.create_till()
        till.open_till()

        branch = api.get_current_branch(self.store)
        storable = self.create_storable(branch=branch, stock=1)
        sellable = storable.product.sellable
        wizard = StockDecreaseWizard(self.store)

        step = wizard.get_current_step()
        self.assertTrue(step.create_payments.get_visible())
        step.create_payments.update(True)
        step.reason.update('reason')
        self.check_wizard(wizard, 'start-stock-decrease-step-create-payments')
        self.assertSensitive(wizard, ['next_button'])
        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)
        self.click(wizard.next_button)

        step = wizard.get_current_step()
        self.assertTrue(isinstance(step, PaymentMethodStep))
Exemple #7
0
    def _setup_widgets(self):
        # Hide total and subtotal
        self.table1.hide()
        self.hbox4.hide()
        # Hide invoice number details
        self.invoice_number_label.hide()
        self.invoice_number.hide()

        # Hide cost center combobox
        self.cost_center_lbl.hide()
        self.cost_center.hide()

        # Salesperson combo
        salespersons = self.store.find(SalesPerson)
        self.salesperson.prefill(api.for_person_combo(salespersons))
        if not sysparam(self.store).ACCEPT_CHANGE_SALESPERSON:
            self.salesperson.set_sensitive(False)
        else:
            self.salesperson.grab_focus()

        # CFOP combo
        if sysparam(self.store).ASK_SALES_CFOP:
            cfops = self.store.find(CfopData)
            self.cfop.prefill(api.for_combo(cfops))
        else:
            self.cfop_lbl.hide()
            self.cfop.hide()
            self.create_cfop.hide()

        self.transporter_lbl.hide()
        self.transporter.hide()
        self.create_transporter.hide()

        self._fill_clients_combo()
        self._fill_clients_category_combo()
Exemple #8
0
    def _check_param_online_services(self):
        from stoqlib.database.runtime import get_default_store, new_store
        from stoqlib.lib.parameters import sysparam
        import gtk

        sparam = sysparam(get_default_store())
        if sparam.ONLINE_SERVICES is None:
            from kiwi.ui.dialogs import HIGAlertDialog
            # FIXME: All of this is to avoid having to set markup as the default
            #        in kiwi/ui/dialogs:HIGAlertDialog.set_details, after 1.0
            #        this can be simplified when we fix so that all descriptions
            #        sent to these dialogs are properly escaped
            dialog = HIGAlertDialog(
                parent=None,
                flags=gtk.DIALOG_MODAL,
                type=gtk.MESSAGE_WARNING)
            dialog.add_button(_("Not right now"), gtk.RESPONSE_NO)
            dialog.add_button(_("Enable online services"), gtk.RESPONSE_YES)

            dialog.set_primary(_('Do you want to enable Stoq online services?'))
            dialog.set_details(PRIVACY_STRING, use_markup=True)
            dialog.set_default_response(gtk.RESPONSE_YES)
            response = dialog.run()
            dialog.destroy()
            store = new_store()
            sysparam(store).ONLINE_SERVICES = int(bool(response == gtk.RESPONSE_YES))
            store.commit()
            store.close()
    def test_create(self):
        # Allow creating purchases in the past.
        sysparam(self.store).update_parameter(
            u"ALLOW_OUTDATED_OPERATIONS", u"1")

        self.wizard = PurchaseWizard(self.store)
        purchase_branch = self.create_branch()
        purchase_order = PurchaseOrder(branch=purchase_branch)
        sellable = self.create_sellable()
        purchase_order.add_item(sellable=sellable)
        self.wizard.model.identifier = 12345
        self.wizard.model.open_date = localdate(2010, 1, 3).date()
        self._check_start_step('wizard-purchase-start-step')
        self._check_item_step('wizard-purchase-item-step')
        self._check_payment_step('wizard-purchase-payment-step')

        purchase = self.wizard.model
        models = [purchase]
        models.extend(purchase.get_items())
        models.extend(purchase.payments)
        models.append(purchase.group)

        self.check_wizard(self.wizard, 'wizard-purchase-finish-step',
                          models=models)

        self.click(self.wizard.next_button)
Exemple #10
0
    def test_credit_limit_update(self):
        sysparam(self.store).update_parameter(
            u"CREDIT_LIMIT_SALARY_PERCENT",
            u"10")

        client = self.create_client()
        client.salary = 50
        slave = ClientCreditSlave(self.store, client)
        slave.salary.emit('changed')
        self.assertEquals(slave.credit_limit.read(), 5)

        # checks if credit limit updated correctly when salary changes
        # and parameter salary percent is not 0
        slave.salary.update(100)
        slave.salary.emit('changed')
        self.assertEquals(slave.credit_limit.read(), 10)

        sysparam(self.store).update_parameter(
            u"CREDIT_LIMIT_SALARY_PERCENT",
            u"0")

        # checks if credit limit does not update (correct behavior)
        # when salary percent is 0 and salary changes
        credit_limit = 0
        client.credit_limit = credit_limit
        slave.credit_limit.update(credit_limit)
        slave.credit_limit.emit('changed')

        slave.salary.update(200)
        slave.salary.emit('changed')

        self.assertEquals(slave.credit_limit.read(), credit_limit)
Exemple #11
0
    def _setup_widgets(self):
        # Hide total and subtotal
        self.table1.hide()
        self.hbox4.hide()
        # Hide invoice number details
        self.invoice_number_label.hide()
        self.invoice_number.hide()

        # Hide cost center combobox
        self.cost_center_lbl.hide()
        self.cost_center.hide()

        # Salesperson combo
        salespersons = self.store.find(SalesPerson)
        self.salesperson.prefill(api.for_person_combo(salespersons))
        if not sysparam(self.store).ACCEPT_CHANGE_SALESPERSON:
            self.salesperson.set_sensitive(False)
        else:
            self.salesperson.grab_focus()

        # CFOP combo
        if sysparam(self.store).ASK_SALES_CFOP:
            cfops = self.store.find(CfopData)
            self.cfop.prefill(api.for_combo(cfops))
        else:
            self.cfop_lbl.hide()
            self.cfop.hide()
            self.create_cfop.hide()

        self.transporter_lbl.hide()
        self.transporter.hide()
        self.create_transporter.hide()

        self._fill_clients_combo()
        self._fill_clients_category_combo()
Exemple #12
0
    def _check_param_online_services(self):
        from stoqlib.database.runtime import get_default_store, new_store
        from stoqlib.lib.parameters import sysparam
        import gtk

        sparam = sysparam(get_default_store())
        if sparam.ONLINE_SERVICES is None:
            from kiwi.ui.dialogs import HIGAlertDialog
            # FIXME: All of this is to avoid having to set markup as the default
            #        in kiwi/ui/dialogs:HIGAlertDialog.set_details, after 1.0
            #        this can be simplified when we fix so that all descriptions
            #        sent to these dialogs are properly escaped
            dialog = HIGAlertDialog(
                parent=None,
                flags=gtk.DIALOG_MODAL,
                type=gtk.MESSAGE_WARNING)
            dialog.add_button(_("Not right now"), gtk.RESPONSE_NO)
            dialog.add_button(_("Enable online services"), gtk.RESPONSE_YES)

            dialog.set_primary(_('Do you want to enable Stoq online services?'))
            dialog.set_details(PRIVACY_STRING, use_markup=True)
            dialog.set_default_response(gtk.RESPONSE_YES)
            response = dialog.run()
            dialog.destroy()
            store = new_store()
            sysparam(store).ONLINE_SERVICES = int(bool(response == gtk.RESPONSE_YES))
            store.commit()
            store.close()
Exemple #13
0
    def _check_branch(self):
        from stoqlib.database.runtime import (get_default_store, new_store,
                                              get_current_station,
                                              set_current_branch_station)
        from stoqlib.domain.person import Company
        from stoqlib.lib.parameters import sysparam
        from stoqlib.lib.message import info

        default_store = get_default_store()
        set_current_branch_station(default_store, station_name=None)

        compaines = default_store.find(Company)
        if (compaines.count() == 0 or
            not sysparam(default_store).MAIN_COMPANY):
            from stoqlib.gui.base.dialogs import run_dialog
            from stoqlib.gui.dialogs.branchdialog import BranchDialog
            if self._ran_wizard:
                info(_("You need to register a company before start using Stoq"))
            else:
                info(_("Could not find a company. You'll need to register one "
                       "before start using Stoq"))
            store = new_store()
            person = run_dialog(BranchDialog, None, store)
            if not person:
                raise SystemExit
            branch = person.branch
            sysparam(store).MAIN_COMPANY = branch.id
            get_current_station(store).branch = branch
            store.commit()
            store.close()
Exemple #14
0
 def testGetDefault(self):
     location = CityLocation.get_default(self.store)
     self.failUnless(isinstance(location, CityLocation))
     self.assertEquals(location.city, sysparam(self.store).CITY_SUGGESTED)
     self.assertEquals(location.state, sysparam(self.store).STATE_SUGGESTED)
     self.assertEquals(location.country,
                       sysparam(self.store).COUNTRY_SUGGESTED)
Exemple #15
0
    def testShow(self):
        # this is necessary so previous tests will not interfere in here
        sysparam(self.store).update_parameter(u"CREDIT_LIMIT_SALARY_PERCENT", u"0")

        client = self.create_client()
        client.salary = 100
        slave = ClientStatusSlave(self.store, client)
        self.check_slave(slave, "slave-clientstatus-show")
Exemple #16
0
 def test_get_logo_data(self):
     image = self.create_image()
     image.image = 'foobar'
     sysparam(self.store).update_parameter(
         u'CUSTOM_LOGO_FOR_REPORTS',
         image.id)
     data = get_logo_data(self.store)
     self.assertEquals(data, 'data:image/png;base64,Zm9vYmFy')
Exemple #17
0
 def _edit_item(self, item):
     store = api.new_store()
     parameter = store.fetch(item)
     retval = run_dialog(SystemParameterEditor, self, store, parameter)
     if store.confirm(retval):
         sysparam(store).rebuild_cache_for(item.field_name)
         self.results.update(item)
     store.close()
Exemple #18
0
def _create_transaction(store, till_entry):
    AccountTransaction(description=till_entry.description,
                       source_account=sysparam(store).IMBALANCE_ACCOUNT,
                       account=sysparam(store).TILLS_ACCOUNT,
                       value=till_entry.value,
                       code=unicode(till_entry.id),
                       date=TransactionTimestamp(),
                       store=store,
                       payment=till_entry.payment)
Exemple #19
0
 def create_model(self, store):
     self._model_created = True
     tax_constant = sysparam(store).DEFAULT_PRODUCT_TAX_CONSTANT
     sellable = Sellable(store=store)
     sellable.tax_constant = tax_constant
     sellable.unit = sysparam(self.store).SUGGESTED_UNIT
     model = Product(store=store, sellable=sellable)
     Storable(product=model, store=store)
     return model
Exemple #20
0
 def create_model(self, store):
     self._model_created = True
     tax_constant = sysparam(store).DEFAULT_PRODUCT_TAX_CONSTANT
     sellable = Sellable(store=store)
     sellable.tax_constant = tax_constant
     sellable.unit = sysparam(self.store).SUGGESTED_UNIT
     model = Product(store=store, sellable=sellable)
     Storable(product=model, store=store)
     return model
Exemple #21
0
    def setup_widgets(self):
        marker('Setting up widgets')
        # Only quotes have expire date.
        self.expire_date.hide()
        self.expire_label.hide()

        # Hide operation nature widgets
        self.operation_nature.hide()
        self.nature_lbl.hide()

        # Hide client category widgets
        self.client_category_lbl.hide()
        self.client_category.hide()

        # if the NF-e plugin is active, the client is mandantory in this
        # wizard (in this situation, we have only quote sales).
        if self.model.status == Sale.STATUS_QUOTE:
            manager = get_plugin_manager()
            mandatory_client = manager.is_active('nfe')
            self.client.set_property('mandatory', mandatory_client)

        marker('Filling sales persons')
        salespersons = self.store.find(SalesPerson)
        self.salesperson.prefill(api.for_person_combo(salespersons))
        marker('Finished filling sales persons')

        marker('Read parameter')
        if not sysparam(self.store).ACCEPT_CHANGE_SALESPERSON:
            self.salesperson.set_sensitive(False)
        else:
            self.salesperson.grab_focus()
        marker('Finished reading parameter')
        self._fill_clients_combo()
        self._fill_transporter_combo()
        self._fill_cost_center_combo()

        if sysparam(self.store).ASK_SALES_CFOP:
            self._fill_cfop_combo()
        else:
            self.cfop_lbl.hide()
            self.cfop.hide()
            self.create_cfop.hide()

        # the maximum number allowed for an invoice is 999999999.
        self.invoice_number.set_adjustment(
            gtk.Adjustment(lower=1, upper=999999999, step_incr=1))

        if not self.model.invoice_number:
            new_invoice_number = Sale.get_last_invoice_number(self.store) + 1
            self.invoice_model.invoice_number = new_invoice_number
        else:
            new_invoice_number = self.model.invoice_number
            self.invoice_model.invoice_number = new_invoice_number
            self.invoice_number.set_sensitive(False)

        self.invoice_model.original_invoice = new_invoice_number
        marker('Finished setting up widgets')
Exemple #22
0
 def testGetDefault(self):
     location = CityLocation.get_default(self.store)
     self.failUnless(isinstance(location, CityLocation))
     self.assertEquals(location.city,
                       sysparam(self.store).CITY_SUGGESTED)
     self.assertEquals(location.state,
                       sysparam(self.store).STATE_SUGGESTED)
     self.assertEquals(location.country,
                       sysparam(self.store).COUNTRY_SUGGESTED)
Exemple #23
0
    def test_show(self):
        # this is necessary so previous tests will not interfere in here
        sysparam(self.store).update_parameter(u"CREDIT_LIMIT_SALARY_PERCENT",
                                              u"0")

        client = self.create_client()
        client.salary = 100
        slave = ClientStatusSlave(self.store, client)
        self.check_slave(slave, 'slave-clientstatus-show')
Exemple #24
0
    def setup_widgets(self):
        marker('Setting up widgets')
        # Only quotes have expire date.
        self.expire_date.hide()
        self.expire_label.hide()

        # Hide operation nature widgets
        self.operation_nature.hide()
        self.nature_lbl.hide()

        # Hide client category widgets
        self.client_category_lbl.hide()
        self.client_category.hide()

        # if the NF-e plugin is active, the client is mandantory in this
        # wizard (in this situation, we have only quote sales).
        if self.model.status == Sale.STATUS_QUOTE:
            manager = get_plugin_manager()
            mandatory_client = manager.is_active('nfe')
            self.client.set_property('mandatory', mandatory_client)

        marker('Filling sales persons')
        salespersons = self.store.find(SalesPerson)
        self.salesperson.prefill(api.for_person_combo(salespersons))
        marker('Finished filling sales persons')

        marker('Read parameter')
        if not sysparam(self.store).ACCEPT_CHANGE_SALESPERSON:
            self.salesperson.set_sensitive(False)
        else:
            self.salesperson.grab_focus()
        marker('Finished reading parameter')
        self._fill_clients_combo()
        self._fill_transporter_combo()
        self._fill_cost_center_combo()

        if sysparam(self.store).ASK_SALES_CFOP:
            self._fill_cfop_combo()
        else:
            self.cfop_lbl.hide()
            self.cfop.hide()
            self.create_cfop.hide()

        # the maximum number allowed for an invoice is 999999999.
        self.invoice_number.set_adjustment(
            gtk.Adjustment(lower=1, upper=999999999, step_incr=1))

        if not self.model.invoice_number:
            new_invoice_number = Sale.get_last_invoice_number(self.store) + 1
            self.invoice_model.invoice_number = new_invoice_number
        else:
            new_invoice_number = self.model.invoice_number
            self.invoice_model.invoice_number = new_invoice_number
            self.invoice_number.set_sensitive(False)

        self.invoice_model.original_invoice = new_invoice_number
        marker('Finished setting up widgets')
    def test_check_payment_mandatory_check_number(self):
        sysparam(self.store).update_parameter(u'MANDATORY_CHECK_NUMBER', u'True')

        wizard = PurchaseWizard(self.store)

        method = PaymentMethod.get_by_name(self.store, u'check')
        order = self.create_purchase_order()
        order.identifier = 123456
        CheckMethodSlave(wizard, None, self.store, order, method, Decimal(200))

        self.assertNotSensitive(wizard, ['next_button'])
Exemple #26
0
    def get_default(cls, store):
        """Get the default city location according to the database parameters.
        The is usually the same city as main branch.

        :returns: the default city location
        """
        city = sysparam(store).CITY_SUGGESTED
        state = sysparam(store).STATE_SUGGESTED
        country = sysparam(store).COUNTRY_SUGGESTED

        return cls.get_or_create(store, city, state, country)
Exemple #27
0
    def testCostPrecisionDigits(self):
        # Set a number of digts greated than 2
        sysparam(self.store).update_parameter(
            u'COST_PRECISION_DIGITS', u'5')

        product = self.create_product()
        product.sellable.cost = Decimal('1.23456')
        editor = ProductEditor(self.store, product)
        editor.code.update("12345")
        # We expect the editor to show the correct value
        self.check_editor(editor, 'editor-product-cost-precision-digits')
Exemple #28
0
 def before_start(self, store):
     account = store.find(Account, code=unicode(self.tp.account_id)).one()
     if account is None:
         account = Account(description=self.get_account_id(),
                           code=unicode(self.tp.account_id),
                           account_type=Account.TYPE_BANK,
                           parent=sysparam(store).BANKS_ACCOUNT,
                           store=store)
     self.account_id = account.id
     self.source_account_id = sysparam(store).IMBALANCE_ACCOUNT.id
     self.skipped = 0
Exemple #29
0
    def setup_proxies(self):
        self._setup_widgets()
        self.proxy = self.add_proxy(self.model,
                                    StartSaleQuoteStep.proxy_widgets)
        if sysparam(self.store).ASK_SALES_CFOP:
            self.add_proxy(self.model, StartSaleQuoteStep.cfop_widgets)

        expire_delta = sysparam(self.store).EXPIRATION_SALE_QUOTE_DATE
        if expire_delta > 0:
            self.expire_date.update(localtoday() +
                                    relativedelta(days=expire_delta))
Exemple #30
0
    def setup_proxies(self):
        self._setup_widgets()
        self.proxy = self.add_proxy(self.model,
                                    StartSaleQuoteStep.proxy_widgets)
        if sysparam(self.store).ASK_SALES_CFOP:
            self.add_proxy(self.model, StartSaleQuoteStep.cfop_widgets)

        expire_delta = sysparam(self.store).EXPIRATION_SALE_QUOTE_DATE
        if expire_delta > 0:
            self.expire_date.update(localtoday() +
                                    relativedelta(days=expire_delta))
Exemple #31
0
    def get_default(cls, store):
        """Get the default city location according to the database parameters.
        The is usually the same city as main branch.

        :returns: the default city location
        """
        city = sysparam(store).CITY_SUGGESTED
        state = sysparam(store).STATE_SUGGESTED
        country = sysparam(store).COUNTRY_SUGGESTED

        return cls.get_or_create(store, city, state, country)
Exemple #32
0
    def _create_model(self, store):
        user = api.get_current_user(store)
        salesperson = user.person.salesperson

        return Sale(coupon_id=None,
                    status=Sale.STATUS_QUOTE,
                    salesperson=salesperson,
                    branch=api.get_current_branch(store),
                    group=PaymentGroup(store=store),
                    cfop=sysparam(store).DEFAULT_SALES_CFOP,
                    operation_nature=sysparam(store).DEFAULT_OPERATION_NATURE,
                    store=store)
Exemple #33
0
    def _create_model(self, store):
        user = api.get_current_user(store)
        salesperson = user.person.salesperson

        return Sale(coupon_id=None,
                    status=Sale.STATUS_QUOTE,
                    salesperson=salesperson,
                    branch=api.get_current_branch(store),
                    group=PaymentGroup(store=store),
                    cfop=sysparam(store).DEFAULT_SALES_CFOP,
                    operation_nature=sysparam(store).DEFAULT_OPERATION_NATURE,
                    store=store)
Exemple #34
0
 def before_start(self, store):
     account = store.find(Account,
                          code=unicode(self.tp.account_id)).one()
     if account is None:
         account = Account(description=self.get_account_id(),
                           code=unicode(self.tp.account_id),
                           account_type=Account.TYPE_BANK,
                           parent=sysparam(store).BANKS_ACCOUNT,
                           store=store)
     self.account_id = account.id
     self.source_account_id = sysparam(store).IMBALANCE_ACCOUNT.id
     self.skipped = 0
Exemple #35
0
 def create_model(self, store):
     self._model_created = True
     tax_constant = sysparam(store).DEFAULT_PRODUCT_TAX_CONSTANT
     sellable = Sellable(store=store)
     sellable.tax_constant = tax_constant
     sellable.unit = sysparam(self.store).SUGGESTED_UNIT
     model = Product(store=store, sellable=sellable)
     # FIXME: Instead of creating and then removing, we should only create
     # the Storable if the user chooses to do so, but due to the way the
     # editor is implemented, it is not that easy. Change this once we write
     # the new product editor.
     Storable(product=model, store=store)
     return model
Exemple #36
0
    def test_installments(self):
        sysparam(self.store).update_parameter(u"ALLOW_OUTDATED_OPERATIONS", u"1")
        wizard = PurchaseWizard(self.store)

        method = PaymentMethod.get_by_name(self.store, u"bill")
        order = self.create_purchase_order()
        order.identifier = 12345

        slave = BillMethodSlave(wizard, None, self.store, order, method, Decimal(200), localdate(2012, 01, 01).date())
        self.check_slave(slave, "slave-bill-method-1-installments")

        slave.installments_number.update(2)
        self.check_slave(slave, "slave-bill-method-2-installments")
Exemple #37
0
 def create_model(self, store):
     self._model_created = True
     tax_constant = sysparam(store).DEFAULT_PRODUCT_TAX_CONSTANT
     sellable = Sellable(store=store)
     sellable.tax_constant = tax_constant
     sellable.unit = sysparam(self.store).SUGGESTED_UNIT
     model = Product(store=store, sellable=sellable)
     # FIXME: Instead of creating and then removing, we should only create
     # the Storable if the user chooses to do so, but due to the way the
     # editor is implemented, it is not that easy. Change this once we write
     # the new product editor.
     Storable(product=model, store=store)
     return model
Exemple #38
0
    def test_outdated(self):
        sysparam(self.store).update_parameter(u"ALLOW_OUTDATED_OPERATIONS", u"0")
        wizard = PurchaseWizard(self.store)

        method = PaymentMethod.get_by_name(self.store, u"bill")
        order = self.create_purchase_order()

        today = localtoday().date()
        slave = BillMethodSlave(wizard, None, self.store, order, method, Decimal(200), today)
        self.assertValid(slave, ["first_duedate"])

        slave.first_duedate.update(datetime.date(2012, 01, 01))
        self.assertInvalid(slave, ["first_duedate"])
    def testCreate(self, delete, commit):
        # Allow creating purchases in the past.
        sysparam(self.store).update_parameter(u"ALLOW_OUTDATED_OPERATIONS",
                                              u"1")

        self.wizard = QuotePurchaseWizard(self.store)
        self.wizard.model.branch = self.create_branch()
        self.wizard.model.identifier = 12345
        self.wizard.model.open_date = localdate(2010, 1, 3).date()
        self._check_start_step('wizard-purchasequote-start-step')
        self._check_item_step('wizard-purchasequote-item-step')

        supplier_step = self.wizard.get_current_step()
        supplier_step.quoting_list.select(supplier_step.quoting_list[0])
        patch = 'stoqlib.gui.wizards.purchasequotewizard.run_dialog'
        with mock.patch(patch) as run_dialog:
            self.click(supplier_step.missing_products_button)
            run_dialog.assert_called_once_with(SimpleListDialog,
                                               self.wizard,
                                               supplier_step.product_columns,
                                               set([]),
                                               title='Missing Products')

        sellable = supplier_step.model.get_items()[0].sellable
        with mock.patch(patch) as run_dialog:
            self.click(supplier_step.view_products_button)
            run_dialog.assert_called_once_with(
                SimpleListDialog,
                self.wizard,
                supplier_step.product_columns, [sellable],
                title='Products supplied by Supplier')

        patch = 'stoqlib.gui.wizards.purchasequotewizard.print_report'
        with mock.patch(patch) as print_report:
            self.click(supplier_step.print_button)
            print_report.assert_called_once_with(PurchaseQuoteReport,
                                                 self.wizard.model)

        self._check_supplier_step('wizard-purchasequote-supplier-step')

        # FIXME: How many times?
        self.assertEquals(commit.call_count, 1)

        purchase = self.wizard.model
        models = [purchase]
        models.extend(purchase.get_items())

        self.check_wizard(self.wizard,
                          'wizard-purchasequote-finish-step',
                          models=models)
Exemple #40
0
    def test_credit_limit_active(self):
        sysparam(self.store).update_parameter(u"CREDIT_LIMIT_SALARY_PERCENT", u"10")

        client = self.create_client()
        slave = ClientStatusSlave(self.store, client)

        # if CREDIT_LIMIT_SALARY_PERCENT is higher than 0, credit limit
        # should not be editable
        self.assertNotSensitive(slave, ["credit_limit"])

        # if salary percent is 0 credit limit should be editable
        sysparam(self.store).update_parameter(u"CREDIT_LIMIT_SALARY_PERCENT", u"0")
        slave = ClientStatusSlave(self.store, client)
        self.assertSensitive(slave, ["credit_limit"])
Exemple #41
0
    def testOutdated(self):
        sysparam(self.store).update_parameter(u'ALLOW_OUTDATED_OPERATIONS', u'0')
        wizard = PurchaseWizard(self.store)

        method = PaymentMethod.get_by_name(self.store, u'bill')
        order = self.create_purchase_order()

        today = datetime.date.today()
        slave = BillMethodSlave(wizard, None, self.store, order, method,
                                Decimal(200), today)
        self.assertValid(slave, ['first_duedate'])

        slave.first_duedate.update(datetime.date(2012, 01, 01))
        self.assertInvalid(slave, ['first_duedate'])
Exemple #42
0
    def testInstallments(self):
        sysparam(self.store).update_parameter(u'ALLOW_OUTDATED_OPERATIONS', u'1')
        wizard = PurchaseWizard(self.store)

        method = PaymentMethod.get_by_name(self.store, u'bill')
        order = self.create_purchase_order()
        order.identifier = 12345

        slave = BillMethodSlave(wizard, None, self.store, order, method,
                                Decimal(200), datetime.date(2012, 01, 01))
        self.check_slave(slave, 'slave-bill-method-1-installments')

        slave.installments_number.update(2)
        self.check_slave(slave, 'slave-bill-method-2-installments')
Exemple #43
0
    def testOutdated(self):
        sysparam(self.store).update_parameter(u'ALLOW_OUTDATED_OPERATIONS',
                                              u'0')
        wizard = PurchaseWizard(self.store)

        method = PaymentMethod.get_by_name(self.store, u'bill')
        order = self.create_purchase_order()

        today = localtoday().date()
        slave = BillMethodSlave(wizard, None, self.store, order, method,
                                Decimal(200), today)
        self.assertValid(slave, ['first_duedate'])

        slave.first_duedate.update(datetime.date(2012, 01, 01))
        self.assertInvalid(slave, ['first_duedate'])
    def test_param_accept_change_salesperson(self):
        sysparam(self.store).update_parameter(
            u'ACCEPT_CHANGE_SALESPERSON',
            u'True')
        wizard = OpticalSaleQuoteWizard(self.store)
        step = wizard.get_current_step()
        self.assertTrue(step.salesperson.get_sensitive())

        sysparam(self.store).update_parameter(
            u'ACCEPT_CHANGE_SALESPERSON',
            u'False')

        wizard = OpticalSaleQuoteWizard(self.store)
        step = wizard.get_current_step()
        self.assertFalse(step.salesperson.get_sensitive())
Exemple #45
0
 def on_open_date__validate(self, widget, date):
     if sysparam(self.store).ALLOW_OUTDATED_OPERATIONS:
         return
     if date < localtoday().date():
         return ValidationError(
             _("Open date must be set to today or "
               "a future date"))
Exemple #46
0
    def __init__(self, store, model, subtotal, total_paid=0):
        """Creates a new SaleWizard that confirms a sale.
        To avoid excessive querying of the database we pass
        some data already queried/calculated before hand.

        :param store: a store
        :param model: a |sale|
        :param subtotal: subtotal of the sale
        :param total_paid: totaly value already paid
        """
        marker('ConfirmSaleWizard')
        self._check_payment_group(model, store)
        self._subtotal = subtotal
        self._total_paid = total_paid
        self.model = model

        # invoice_model is a Settable so avoid bug 4218, where more
        # than one checkout may try to use the same invoice number.
        self.invoice_model = Settable(invoice_number=None,
                                      original_invoice=None)
        marker('running SalesPersonStep')
        first_step = self.first_step(self, store, model, self.payment_group,
                                     self.invoice_model)
        marker('finished creating SalesPersonStep')
        BaseWizard.__init__(self, store, first_step, model)

        if not sysparam(self.store).CONFIRM_SALES_ON_TILL:
            # This was added to allow us to work even if an error
            # happened while adding a payment, where we already order
            # but cannot confirm and are thrown back to the main
            # POS interface
            if self.model.can_order():
                self.model.order()

        marker('leaving ConfirmSaleWizard.__init__')
Exemple #47
0
    def test_get_available_sellables_query(self):
        # Sellable and query without supplier
        sellable = self.create_sellable()
        self.create_storable(product=sellable.product,
                             branch=self.create_branch())

        self.assertIn(
            sellable,
            self.store.find(Sellable,
                            Sellable.get_available_sellables_query(self.store)))

        sellable.close()
        self.assertNotIn(
            sellable,
            self.store.find(Sellable,
                            Sellable.get_available_sellables_query(self.store)))

        delivery_sellable = sysparam(self.store).DELIVERY_SERVICE.sellable
        delivery_sellable.status = Sellable.STATUS_AVAILABLE
        # Deliveries are treated differently, that's why they should
        # not be present here
        self.assertNotIn(
            sellable,
            self.store.find(Sellable,
                            Sellable.get_available_sellables_query(self.store)))
Exemple #48
0
    def test_credit_limit_active(self):
        sysparam(self.store).update_parameter(u"CREDIT_LIMIT_SALARY_PERCENT",
                                              u"10")

        client = self.create_client()
        slave = ClientCreditSlave(self.store, client)

        # if CREDIT_LIMIT_SALARY_PERCENT is higher than 0, credit limit
        # should not be editable
        self.assertNotSensitive(slave, ['credit_limit'])

        # if salary percent is 0 credit limit should be editable
        sysparam(self.store).update_parameter(u"CREDIT_LIMIT_SALARY_PERCENT",
                                              u"0")
        slave = ClientCreditSlave(self.store, client)
        self.assertSensitive(slave, ['credit_limit'])
Exemple #49
0
    def test_sales_person_report(self):
        sysparam(self.store).SALE_PAY_COMMISSION_WHEN_CONFIRMED = 1
        salesperson = self.create_sales_person()
        product = self.create_product(price=100)
        sellable = product.sellable

        sale = self.create_sale()
        sale.salesperson = salesperson
        sale.add_sellable(sellable, quantity=1)

        self.create_storable(product, get_current_branch(self.store), stock=100)

        CommissionSource(sellable=sellable,
                         direct_value=Decimal(10),
                         installments_value=1,
                         store=self.store)

        sale.order()

        method = PaymentMethod.get_by_name(self.store, u'money')
        till = Till.get_last_opened(self.store)
        method.create_payment(Payment.TYPE_IN, sale.group, sale.branch,
                              sale.get_sale_subtotal(),
                              till=till)
        sale.confirm()
        sale.group.pay()

        salesperson_name = salesperson.person.name
        commissions = list(self.store.find(CommissionView))
        commissions[0].identifier = 1
        commissions[1].identifier = 139

        self._diff_expected(SalesPersonReport, 'sales-person-report', commissions,
                            salesperson_name)
Exemple #50
0
    def test_get_available_sellables_query(self):
        # Sellable and query without supplier
        sellable = self.create_sellable()
        self.create_storable(product=sellable.product,
                             branch=self.create_branch())

        self.assertIn(
            sellable,
            self.store.find(Sellable,
                            Sellable.get_available_sellables_query(self.store)))

        sellable.close()
        self.assertNotIn(
            sellable,
            self.store.find(Sellable,
                            Sellable.get_available_sellables_query(self.store)))

        delivery_sellable = sysparam(self.store).DELIVERY_SERVICE.sellable
        delivery_sellable.status = Sellable.STATUS_AVAILABLE
        # Deliveries are treated differently, that's why they should
        # not be present here
        self.assertNotIn(
            sellable,
            self.store.find(Sellable,
                            Sellable.get_available_sellables_query(self.store)))
Exemple #51
0
    def test_can_remove(self):
        branch = get_current_branch(self.store)
        sellable = self.create_sellable()
        storable = Storable(product=sellable.product, store=self.store)
        self.failUnless(sellable.can_remove())

        storable.increase_stock(1, branch, 0, None)
        sale = self.create_sale()
        sale.status = Sale.STATUS_QUOTE
        sale.branch = branch
        sale.add_sellable(sellable)
        self.failIf(sellable.can_remove())

        # Can't remove the sellable if it's in a purchase.
        from stoqlib.domain.purchase import PurchaseItem
        sellable = self.create_sellable()
        Storable(product=sellable.product, store=self.store)
        self.assertTrue(sellable.can_remove())
        PurchaseItem(store=self.store,
                     quantity=8, quantity_received=0,
                     cost=125, base_cost=125,
                     sellable=sellable,
                     order=self.create_purchase_order())
        self.assertFalse(sellable.can_remove())

        # The delivery service cannot be removed.
        sellable = sysparam(self.store).DELIVERY_SERVICE.sellable
        self.failIf(sellable.can_remove())
Exemple #52
0
    def _add_pos_menus(self, uimanager):
        if sysparam(self.default_store).POS_SEPARATE_CASHIER:
            return

        ui_string = """<ui>
          <menubar name="menubar">
            <placeholder name="ExtraMenubarPH">
              <menu action="ECFMenu">
                <menuitem action="CancelLastDocument"/>
                <menuitem action="Summary"/>
                <menuitem action="ReadMemory"/>
              </menu>
            </placeholder>
          </menubar>
        </ui>"""

        group = get_accels('plugin.ecf')

        ag = gtk.ActionGroup('ECFMenuActions')
        ag.add_actions([
            ('ECFMenu', None, _('ECF')),
            ('ReadMemory', None, _('Read Memory'), group.get('read_memory'),
             None, self._on_ReadMemory__activate),
            ('CancelLastDocument', None, _('Cancel Last Document'), None, None,
             self._on_CancelLastDocument__activate),
        ])
        ag.add_action_with_accel(self._till_summarize_action,
                                 group.get('summarize'))

        uimanager.insert_action_group(ag, 0)
        self._ui = uimanager.add_ui_from_string(ui_string)
Exemple #53
0
    def __init__(self, store, product, visual_mode=False):
        self._product = product
        BaseRelationshipEditorSlave.__init__(self, store, visual_mode=visual_mode)

        suggested = sysparam(store).SUGGESTED_SUPPLIER
        if suggested is not None:
            self.target_combo.select(suggested)
Exemple #54
0
def register_accounts(store):
    # FIXME: If you need to run this in a patch, you need to
    #        make sure that .find().one() is fixed bellow, as accounts
    #        with the same names are allowed.
    #        It's for now okay to run this when creating a new
    #        database.

    from stoqlib.domain.account import Account
    log.info("Creating Accounts")
    for name, atype in [
        (_(u"Assets"), Account.TYPE_ASSET),
        (_(u"Banks"), Account.TYPE_BANK),
        (_(u"Equity"), Account.TYPE_EQUITY),
        (_(u"Expenses"), Account.TYPE_EXPENSE),
        (_(u"Imbalance"), Account.TYPE_BANK),
        (_(u"Income"), Account.TYPE_INCOME),
        (_(u"Tills"), Account.TYPE_CASH),
    ]:
        # FIXME: This needs to rewritten to not use .find().one(),
        #        see comment above.
        account = store.find(Account, description=name).one()
        if not account:
            account = Account(store=store, description=name)
        account.account_type = atype

    sparam = sysparam(store)
    sparam.BANKS_ACCOUNT = store.find(Account,
                                      description=_(u"Banks")).one().id
    sparam.TILLS_ACCOUNT = store.find(Account,
                                      description=_(u"Tills")).one().id
    sparam.IMBALANCE_ACCOUNT = store.find(Account,
                                          description=_(u"Imbalance")).one().id
Exemple #55
0
    def test_can_remove(self):
        branch = get_current_branch(self.store)
        sellable = self.create_sellable()
        storable = Storable(product=sellable.product, store=self.store)
        self.failUnless(sellable.can_remove())

        storable.increase_stock(1, branch, 0, None)
        sale = self.create_sale()
        sale.status = Sale.STATUS_QUOTE
        sale.branch = branch
        sale.add_sellable(sellable)
        self.failIf(sellable.can_remove())

        # Can't remove the sellable if it's in a purchase.
        from stoqlib.domain.purchase import PurchaseItem
        sellable = self.create_sellable()
        Storable(product=sellable.product, store=self.store)
        self.assertTrue(sellable.can_remove())
        PurchaseItem(store=self.store,
                     quantity=8, quantity_received=0,
                     cost=125, base_cost=125,
                     sellable=sellable,
                     order=self.create_purchase_order())
        self.assertFalse(sellable.can_remove())

        # The delivery service cannot be removed.
        sellable = sysparam(self.store).DELIVERY_SERVICE.sellable
        self.failIf(sellable.can_remove())
Exemple #56
0
    def on_expected_receival_date__validate(self, widget, date):
        if sysparam(self.store).ALLOW_OUTDATED_OPERATIONS:
            return

        if date < localtoday().date():
            return ValidationError(
                _("Expected receival date must be set to a future date"))