def receive_item(self, item, quantity_to_receive): if not item in self.get_pending_items(): raise StoqlibError(_(u'This item is not pending, hence ' u'cannot be received')) quantity = item.quantity - item.quantity_received if quantity < quantity_to_receive: raise StoqlibError(_(u'The quantity that you want to receive ' u'is greater than the total quantity of ' u'this item %r') % item) self.increase_quantity_received(item, quantity_to_receive)
def cancel(self, change_entry=None): """Cancel the payment, set it's status to :obj:`.STATUS_CANCELLED` """ # TODO Check for till entries here and call cancel_till_entry if # it's possible. Bug 2598 if not self.can_cancel(): raise StoqlibError( _(u"Invalid status for cancel operation, " u"got %s") % self.status_str) if self.transaction: self.transaction.create_reverse() old_status = self.status self.status = self.STATUS_CANCELLED self.cancel_date = TransactionTimestamp() if change_entry is not None: change_entry.last_status = old_status change_entry.new_status = self.status msg = _( u"{method} payment with value {value:.2f} was cancelled").format( method=self.method.method_name, value=self.value) Event.log(self.store, Event.TYPE_PAYMENT, msg.capitalize())
def _update_system_parameters(self, person): icms = self.tax_proxy.model.icms self.param.update_parameter(u'ICMS_TAX', unicode(icms)) iss = self.tax_proxy.model.iss self.param.update_parameter(u'ISS_TAX', unicode(iss)) substitution = self.tax_proxy.model.substitution_icms self.param.update_parameter(u'SUBSTITUTION_TAX', unicode(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 self.param.update_parameter(u'CITY_SUGGESTED', city) country = address.city_location.country self.param.update_parameter(u'COUNTRY_SUGGESTED', country) state = address.city_location.state self.param.update_parameter(u'STATE_SUGGESTED', state) # Update the fancy name self.company_proxy.model.fancy_name = self.person_proxy.model.name
def _get_sellable(self): barcode = self.barcode.get_text() if not barcode: raise StoqlibError("_get_sellable needs a barcode") barcode = unicode(barcode) fmt = api.sysparam(self.store).SCALE_BARCODE_FORMAT # Check if this barcode is from a scale info = parse_barcode(barcode, fmt) if info: barcode = info.code weight = info.weight sellable = self.store.find(Sellable, barcode=barcode, status=Sellable.STATUS_AVAILABLE).one() # If the barcode didnt match, maybe the user typed the product code if not sellable: sellable = self.store.find(Sellable, code=barcode, status=Sellable.STATUS_AVAILABLE).one() # If the barcode has the price information, we need to calculate the # corresponding weight. if info and sellable and info.mode == BarcodeInfo.MODE_PRICE: weight = info.price / sellable.price if info and sellable: self.quantity.set_value(weight) return sellable
def change_due_date(self, new_due_date): """Changes the payment due date. :param new_due_date: The new due date for the payment. :rtype: datetime.date """ if self.status in [Payment.STATUS_PAID, Payment.STATUS_CANCELLED]: raise StoqlibError(_(u"Invalid status for change_due_date operation, " u"got %s") % self.status_str) self.due_date = new_due_date
def __init__(self, store, columns=None, editor_class=None, klist_objects=None, visual_mode=False, restore_name=None, tree=False): """ Creates a new AdditionListSlave object :param store: a store :param columns: column definitions :type columns: sequence of :class:`kiwi.ui.objectlist.Columns` :param editor_class: the window that is going to be open when user clicks on add_button or edit_button. :type: editor_class: a :class:`stoqlib.gui.editors.BaseEditor` subclass :param klist_objects: initial objects to insert into the list :param visual_mode: if we are working on visual mode, that means, not possible to edit the model on this object type visual_mode: bool :param restore_name: the name used to save and restore the columns on a cache system (e.g. pickle) :type restore_name: basestring :param tree: Indication of which kind of list we are adding. If `True` ObjectTree otherwise ObjectList will be added """ columns = columns or self.get_columns() SearchSlave.__init__(self, columns=columns, restore_name=restore_name, store=store) self.tree = tree self.klist = ObjectTree() if tree else ObjectList() self.list_vbox.add(self.klist) self.list_vbox.show_all() if not self.columns: raise StoqlibError("columns must be specified") self.visual_mode = visual_mode self.store = store self.set_editor(editor_class) self._can_edit = True self._callback_id = None if self.visual_mode: self.hide_add_button() self.hide_edit_button() self.hide_del_button() items = klist_objects or self.get_items() self._setup_klist(items) self._update_sensitivity()
def create(cls, store, branch, name): """Create a new station id for the current machine. Optionally a branch can be specified which will be set as the branch for created station. :param store: a store :param branch: the branch :param name: name of the station :returns: a BranchStation instance """ if cls.get_station(store, branch, name): raise StoqlibError( _(u"There is already a station registered as `%s'.") % name) return cls(name=name, is_active=True, branch=branch, store=store)
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
def _create_procedural_languages(): "Creates procedural SQL languages we're going to use in scripts" store = new_store() log.info('Creating procedural SQL languages') results = store.execute('SELECT lanname FROM pg_language').get_all() languages = [item[0] for item in results] if 'plpgsql' in languages: return if not user_has_usesuper(store): raise StoqlibError( _("The current database user does not have super user rights")) # Create the plpgsql language store.execute('CREATE LANGUAGE plpgsql') store.commit() store.close()
def on_details_button__clicked(self, button): if not self.model.client_id: raise StoqlibError("You should never call ClientDetailsDialog " "for sales which clients were not specified") client = self.store.get(Client, self.model.client_id) run_dialog(ClientDetailsDialog, self, self.store, client)
def _check_selected(self): sale_view = self.results.get_selected() if not sale_view: raise StoqlibError("You should have a selected item at " "this point") return sale_view
def _check_payment_group(self, model, store): if not isinstance(model, Sale): raise StoqlibError("Invalid datatype for model, it should be " "of type Sale, got %s instead" % model) self.payment_group = model.group
def on_edit_item_button__clicked(self, button): item = self.sale_items.get_selected() if item is None: raise StoqlibError("You should have a item selected " "at this point") self._edit_sale_item(item)