def test_credit_limit_update(self): sysparam.set_decimal(self.store, "CREDIT_LIMIT_SALARY_PERCENT", Decimal(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.set_decimal(self.store, "CREDIT_LIMIT_SALARY_PERCENT", Decimal(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)
def test_credit_limit_update(self): sysparam.set_decimal(self.store, "CREDIT_LIMIT_SALARY_PERCENT", Decimal(10)) client = self.create_client() client.salary = 50 slave = ClientCreditSlave(self.store, client) slave.salary.emit('changed') self.assertEqual(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.assertEqual(slave.credit_limit.read(), 10) sysparam.set_decimal(self.store, "CREDIT_LIMIT_SALARY_PERCENT", Decimal(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.assertEqual(slave.credit_limit.read(), credit_limit)
def test_show(self): # this is necessary so previous tests will not interfere in here sysparam.set_decimal(self.store, "CREDIT_LIMIT_SALARY_PERCENT", Decimal(0)) client = self.create_client() client.salary = 100 slave = ClientStatusSlave(self.store, client) self.check_slave(slave, 'slave-clientstatus-show')
def test_credit_limit_active(self): sysparam.set_decimal(self.store, "CREDIT_LIMIT_SALARY_PERCENT", Decimal(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.set_decimal(self.store, "CREDIT_LIMIT_SALARY_PERCENT", Decimal(0)) slave = ClientCreditSlave(self.store, client) self.assertSensitive(slave, ['credit_limit'])
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 _update_system_parameters(self, person): icms = self.tax_proxy.model.icms sysparam.set_decimal(self.store, 'ICMS_TAX', icms) iss = self.tax_proxy.model.iss sysparam.set_decimal(self.store, 'ISS_TAX', iss) substitution = self.tax_proxy.model.substitution_icms sysparam.set_decimal(self.store, 'SUBSTITUTION_TAX', substitution) address = person.get_main_address() if not address: raise StoqlibError("You should have an address defined at " "this point") city = address.city_location.city sysparam.set_string(self.store, 'CITY_SUGGESTED', city) country = address.city_location.country sysparam.set_string(self.store, 'COUNTRY_SUGGESTED', country) state = address.city_location.state sysparam.set_string(self.store, 'STATE_SUGGESTED', state) # Update the fancy name self.company_proxy.model.fancy_name = self.person_proxy.model.name