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
def _update_system_parameters(self, person): 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