def test_cost_precision_digits(self): # Set a number of digts greated than 2 sysparam.set_int(self.store, 'COST_PRECISION_DIGITS', 5) product = self.create_product(storable=True) 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')
def sysparam(self, **kwargs): """ Updates a set of system parameters within a context. The values will be reverted when leaving the scope. kwargs contains a dictionary of parameter name->value """ from stoqlib.lib.parameters import sysparam old_values = {} for param, value in kwargs.items(): if isinstance(value, bool): old_values[param] = sysparam.get_bool(param) sysparam.set_bool(self.store, param, value) elif isinstance(value, int): old_values[param] = sysparam.get_int(param) sysparam.set_int(self.store, param, value) elif isinstance(value, Domain) or value is None: old_values[param] = sysparam.get_object(self.store, param) sysparam.set_object(self.store, param, value) elif isinstance(value, str): old_values[param] = sysparam.get_string(param) sysparam.set_string(self.store, param, value) elif isinstance(value, Decimal): old_values[param] = sysparam.get_decimal(param) sysparam.set_decimal(self.store, param, value) else: raise NotImplementedError(type(value)) try: yield finally: for param, value in old_values.items(): if isinstance(value, bool): sysparam.set_bool(self.store, param, value) elif isinstance(value, int): sysparam.set_int(self.store, param, value) elif isinstance(value, Domain) or value is None: sysparam.set_object(self.store, param, value) elif isinstance(value, str): sysparam.set_string(self.store, param, value) elif isinstance(value, Decimal): sysparam.set_decimal(self.store, param, value) else: raise NotImplementedError(type(value))
def tearDown(self): sysparam.set_int(self.store, 'COST_PRECISION_DIGITS', 2) GUITest.tearDown(self)
def test_sale_to_client_with_late_payments(self, run_dialog): #: this parameter allows a client to buy even if he has late payments sysparam.set_int(self.store, 'LATE_PAYMENTS_POLICY', int(LatePaymentPolicy.ALLOW_SALES)) sale = self.create_sale() sale.identifier = 12345 self.add_product(sale) sale.client = self.create_client() self._create_wizard(sale=sale) wizard = self.wizard step = self.step money_method = PaymentMethod.get_by_name(self.store, u'money') today = localtoday().date() sale.client.credit_limit = currency('90000000000') step.client.emit('changed') self._select_method(u'money') # checks if a client can buy normally self.assertTrue(wizard.next_button.props.sensitive) # checks if a client with late payments can buy 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 = sale.client.person self._select_method('bill') self.assertTrue(wizard.next_button.props.sensitive) self._select_method(u'store_credit') self.assertTrue(wizard.next_button.props.sensitive) #: this parameter disallows a client with late payments to buy with #: store credit sysparam.set_int(self.store, 'LATE_PAYMENTS_POLICY', int(LatePaymentPolicy.DISALLOW_STORE_CREDIT)) # checks if a client can buy normally payment.due_date = today self.assertEquals(step.client.emit('validate', sale.client), None) self.assertTrue(wizard.next_button.props.sensitive) # checks if a client with late payments can buy with money method self._select_method(u'money') payment.due_date = today - relativedelta(days=3) self.assertEquals(step.client.emit('validate', sale.client), None) self.assertTrue(wizard.next_button.props.sensitive) # checks if a client with late payments can buy with store credit self._select_method(u'store_credit') self.assertEquals( unicode(step.client.emit('validate', sale.client)), u'It is not possible to sell with store credit for clients with ' 'late payments.') # self.assertFalse(wizard.next_button.props.sensitive) step.client.validate(force=True) # FIXME: This is not updating correcly # self.assertNotSensitive(wizard, ['next_button']) #: this parameter disallows a client with late payments to buy sysparam.set_int(self.store, 'LATE_PAYMENTS_POLICY', int(LatePaymentPolicy.DISALLOW_SALES)) # checks if a client can buy normally payment.due_date = today self.assertEquals(step.client.emit('validate', sale.client), None) # checks if a client with late payments can buy payment.due_date = today - relativedelta(days=3) self._select_method(u'store_credit') self.assertEquals( unicode(step.client.emit('validate', sale.client)), u'It is not possible to sell for clients with late payments.') self.assertEquals(run_dialog.call_count, 0) self._select_method('check') self.assertEquals( unicode(step.client.emit('validate', sale.client)), u'It is not possible to sell for clients with late payments.') self._select_method(u'store_credit') sysparam.set_int(self.store, 'LATE_PAYMENTS_POLICY', int(LatePaymentPolicy.ALLOW_SALES)) sale.client.credit_limit = currency("9000") # Force validation since we changed the credit limit. step.force_validation() self.click(wizard.next_button) # finish wizard with mock.patch.object(self.store, 'commit'): self.click(wizard.next_button) self.assertEquals(sale.payments[0].method.method_name, u'store_credit')
def test_sale_to_client_with_late_payments(self, run_dialog): #: this parameter allows a client to buy even if he has late payments sysparam.set_int(self.store, 'LATE_PAYMENTS_POLICY', int(LatePaymentPolicy.ALLOW_SALES)) sale = self.create_sale() sale.identifier = 12345 self.add_product(sale) sale.client = self.create_client() self._create_wizard(sale=sale) wizard = self.wizard step = self.step money_method = PaymentMethod.get_by_name(self.store, u'money') today = localtoday().date() sale.client.credit_limit = currency('90000000000') step.client.emit('changed') self._select_method(u'money') # checks if a client can buy normally self.assertTrue(wizard.next_button.props.sensitive) # checks if a client with late payments can buy 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 = sale.client.person self._select_method('bill') self.assertTrue(wizard.next_button.props.sensitive) self._select_method(u'store_credit') self.assertTrue(wizard.next_button.props.sensitive) #: this parameter disallows a client with late payments to buy with #: store credit sysparam.set_int(self.store, 'LATE_PAYMENTS_POLICY', int(LatePaymentPolicy.DISALLOW_STORE_CREDIT)) # checks if a client can buy normally payment.due_date = today self.assertEqual(step.client.emit('validate', sale.client), None) self.assertTrue(wizard.next_button.props.sensitive) # checks if a client with late payments can buy with money method self._select_method(u'money') payment.due_date = today - relativedelta(days=3) self.assertEqual(step.client.emit('validate', sale.client), None) self.assertTrue(wizard.next_button.props.sensitive) # checks if a client with late payments can buy with store credit self._select_method(u'store_credit') self.assertEqual( str(step.client.emit('validate', sale.client)), u'It is not possible to sell with store credit for clients with ' 'late payments.') # self.assertFalse(wizard.next_button.props.sensitive) step.client.validate(force=True) # FIXME: This is not updating correcly # self.assertNotSensitive(wizard, ['next_button']) #: this parameter disallows a client with late payments to buy sysparam.set_int(self.store, 'LATE_PAYMENTS_POLICY', int(LatePaymentPolicy.DISALLOW_SALES)) # checks if a client can buy normally payment.due_date = today self.assertEqual(step.client.emit('validate', sale.client), None) # checks if a client with late payments can buy payment.due_date = today - relativedelta(days=3) self._select_method(u'store_credit') self.assertEqual( str(step.client.emit('validate', sale.client)), u'It is not possible to sell for clients with late payments.') self.assertEqual(run_dialog.call_count, 0) self._select_method('check') self.assertEqual( str(step.client.emit('validate', sale.client)), u'It is not possible to sell for clients with late payments.') self._select_method(u'store_credit') sysparam.set_int(self.store, 'LATE_PAYMENTS_POLICY', int(LatePaymentPolicy.ALLOW_SALES)) sale.client.credit_limit = currency("9000") # Force validation since we changed the credit limit. step.force_validation() self.click(wizard.next_button) # finish wizard with mock.patch.object(self.store, 'commit'): self.click(wizard.next_button) self.assertEqual(sale.payments[0].method.method_name, u'store_credit')