本文整理汇总了Python中stoqlib.database.runtime.get_current_user函数的典型用法代码示例。如果您正苦于以下问题:Python get_current_user函数的具体用法?Python get_current_user怎么用?Python get_current_user使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_current_user函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_run_dialog
def test_run_dialog(self):
observations = (
u"Mussum ipsum cacilds, vidis litro abertis. "
"Consetis adipiscings elitis. Pra la , depois "
"divoltis porris, paradis. Paisis, filhis, "
"espiritis santis. Me faiz elementum girarzis, "
"nisi eros vermeio, in elementis me pra quem e "
"amistosis quis leo. Manduma pindureta quium dia "
"nois paga. Sapien in monti palavris qui num "
"significa nadis i pareci latim. Interessantiss "
"quisso pudia ce receita de bolis, mais bolis eu num gostis.")
till = self.create_till()
till.open_till()
till.close_till(observations)
model = self.store.find(TillClosedView, id=till.id).one()
self.assertEquals(observations, model.observations)
self.assertEquals(get_current_user(self.store).get_description(),
model.responsible_open_name)
self.assertEquals(get_current_user(self.store).get_description(),
model.responsible_close_name)
self.assertEquals(observations, model.observations)
dialog = TillClosedSearch(self.store)
dialog.search.refresh()
self.assertNotSensitive(dialog._details_slave, ['details_button'])
with mock.patch("stoqlib.gui.search.tillsearch.run_dialog") as r_dialog:
dialog.results.select(model)
self.assertSensitive(dialog._details_slave, ['details_button'])
self.click(dialog._details_slave.details_button)
r_dialog.assert_called_once_with(TillDetailsDialog, dialog,
dialog.store, model)
示例2: test_on_confirm_with_discount
def test_on_confirm_with_discount(self):
events_before = self.store.find(Event).count()
sale_item = self.create_sale_item()
sale_item.sale.identifier = 333123
current_user = get_current_user(self.store)
current_user.profile.max_discount = Decimal('5')
# A manager to authorize the discount
manager = self.create_user()
manager.profile.max_discount = Decimal('10')
editor = SaleQuoteItemEditor(self.store, sale_item)
# Try applying 9% of discount
editor.price.update(currency('9.10'))
# The user is not allowed to give 10% discount
self.assertNotSensitive(editor.main_dialog, ['ok_button'])
# Lets call the manager and ask for permission
with mock.patch('stoqlib.gui.editors.saleeditor.run_dialog') as rd:
rd.return_value = manager
editor.price.emit('icon-press', gtk.ENTRY_ICON_PRIMARY, None)
# Now it should be possible to confirm
self.click(editor.main_dialog.ok_button)
events_after = self.store.find(Event).count()
self.assertEquals(events_after, events_before + 1)
last_event = self.store.find(Event).order_by(Event.id).last()
expected = (u'Sale 333123: User username authorized 9.00 % '
u'of discount changing\n Description value from $10.00 to $9.10.')
self.assertEquals(last_event.description, expected)
示例3: _update_te
def _update_te(self):
user = get_current_user(self.store)
station = get_current_station(self.store)
self.te_modified.te_time = TransactionTimestamp()
self.te_modified.user_id = user and user.id
self.te_modified.station_id = station and station.id
示例4: create_for_receiving_order
def create_for_receiving_order(cls, receiving_order):
store = receiving_order.store
current_user = get_current_user(store)
employee = current_user.person.employee
cfop_id = sysparam.get_object_id('DEFAULT_STOCK_DECREASE_CFOP')
return_stock_decrease = cls(
store=store,
receiving_order=receiving_order,
branch=get_current_branch(store),
responsible=current_user,
removed_by=employee,
cfop_id=cfop_id)
for receiving_item in receiving_order.get_items(with_children=False):
if receiving_item.is_totally_returned():
# Exclude items already totally returned
continue
if receiving_item.children_items.count():
for child in receiving_item.children_items:
StockDecreaseItem.create_for_receiving_item(
return_stock_decrease, child)
else:
StockDecreaseItem.create_for_receiving_item(return_stock_decrease,
receiving_item)
return return_stock_decrease
示例5: confirm
def confirm(self, confirm_date=None):
"""Confirms the purchase order
:param confirm_data: optional, datetime
"""
if confirm_date is None:
confirm_date = TransactionTimestamp()
if self.status not in [PurchaseOrder.ORDER_PENDING,
PurchaseOrder.ORDER_CONSIGNED]:
raise ValueError(
_(u'Invalid order status, it should be '
u'ORDER_PENDING or ORDER_CONSIGNED, got %s') % (
self.get_status_str(), ))
transaction = IPaymentTransaction(self)
transaction.confirm()
if self.supplier:
self.group.recipient = self.supplier.person
self.responsible = get_current_user(self.store)
self.status = PurchaseOrder.ORDER_CONFIRMED
self.confirm_date = confirm_date
Event.log(self.store, Event.TYPE_ORDER,
_(u"Order %s, total value %2.2f, supplier '%s' "
u"is now confirmed") % (self.identifier,
self.get_purchase_total(),
self.supplier.person.name))
示例6: orm_get_unittest_value
def orm_get_unittest_value(klass, test, tables_dict, name, column):
value = None
if isinstance(column, PropertyColumn):
if column.variable_factory.keywords['value'] is not Undef:
value = column.variable_factory.keywords['value']
else:
try:
value = orm_get_random(column)
except ValueError:
raise ORMTestError(u"No default for %r" % (column, ))
elif isinstance(column, Reference):
if name == 'te':
return None
if isinstance(column._remote_key, basestring):
cls = tables_dict[column._remote_key.split('.')[0]]
else:
cls = column._remote_key[0].cls
if cls.__name__ == 'LoginUser':
# Avoid unique problems on domains that defines 2 references
# to LoginUser (e.g. WorkOrder)
from stoqlib.database.runtime import get_current_user
value = get_current_user(test.store)
elif cls.__name__ == 'StorableBatch':
# StorableBatch needs some very specific information, that is
# related to other objects. Thus, it cannot be created with random
# value.
value = None
else:
value = test.create_by_type(cls)
if value is None:
raise ORMTestError(u"No example for %s" % cls)
return value
示例7: open_till
def open_till(self):
"""Open the till.
It can only be done once per day.
The final cash amount of the previous till will be used
as the initial value in this one after opening it.
"""
if self.status == Till.STATUS_OPEN:
raise TillError(_('Till is already open'))
# Make sure that the till has not been opened today
today = localtoday().date()
if not self.store.find(Till,
And(Date(Till.opening_date) >= today,
Till.station_id == self.station.id)).is_empty():
raise TillError(_("A till has already been opened today"))
last_till = self._get_last_closed_till()
if last_till:
if not last_till.closing_date:
raise TillError(_("Previous till was not closed"))
initial_cash_amount = last_till.final_cash_amount
else:
initial_cash_amount = 0
self.initial_cash_amount = initial_cash_amount
self.opening_date = TransactionTimestamp()
self.status = Till.STATUS_OPEN
self.responsible_open = get_current_user(self.store)
示例8: _update_wizard_model
def _update_wizard_model(self):
wizard_model = self.wizard.model
if wizard_model:
# We are replacing the model. Remove old one
for item in wizard_model.returned_items:
item.delete(item.id, store=item.store)
wizard_model.delete(wizard_model.id,
store=wizard_model.store)
sale_view = self.slave.results.get_selected()
# FIXME: Selecting a sale and then clicking on unknown_sale_check
# will not really deselect it, not until the results are sensitive
# again. This should be as simple as 'if sale_view'.
if sale_view and not self.unknown_sale_check.get_active():
sale = self.store.fetch(sale_view.sale)
model = sale.create_sale_return_adapter()
for item in model.returned_items:
_adjust_returned_sale_item(item)
else:
assert self._allow_unknown_sales()
model = ReturnedSale(
store=self.store,
responsible=get_current_user(self.store),
branch=get_current_branch(self.store),
)
self.wizard.model = model
示例9: confirm
def confirm(self, confirm_date=None):
"""Confirms the purchase order
:param confirm_data: optional, datetime
"""
if confirm_date is None:
confirm_date = TransactionTimestamp()
if self.status not in [PurchaseOrder.ORDER_PENDING,
PurchaseOrder.ORDER_CONSIGNED]:
fmt = _(u'Invalid order status, it should be '
u'ORDER_PENDING or ORDER_CONSIGNED, got %s')
raise ValueError(fmt % (self.status_str, ))
# In consigned purchases there is no payments at this point.
if self.status != PurchaseOrder.ORDER_CONSIGNED:
for payment in self.payments:
payment.set_pending()
if self.supplier:
self.group.recipient = self.supplier.person
self.responsible = get_current_user(self.store)
self.status = PurchaseOrder.ORDER_CONFIRMED
self.confirm_date = confirm_date
Event.log(self.store, Event.TYPE_ORDER,
_(u"Order %s, total value %2.2f, supplier '%s' "
u"is now confirmed") % (self.identifier,
self.purchase_total,
self.supplier.person.name))
示例10: test_on_confirm_without_discount
def test_on_confirm_without_discount(self):
events_before = self.store.find(Event).count()
sale_item = self.create_sale_item()
current_user = get_current_user(self.store)
current_user.profile.max_discount = Decimal('5')
# A manager to authorize the discount
manager = self.create_user()
manager.profile.max_discount = Decimal('10')
editor = SaleQuoteItemEditor(self.store, sale_item)
# Try applying 10% of discount
editor.price.update(currency('9.00'))
# The user is not allowed to give 10% discount
self.assertNotSensitive(editor.main_dialog, ['ok_button'])
# Lets call the manager and ask for permission
with mock.patch('stoqlib.gui.editors.saleeditor.run_dialog') as rd:
rd.return_value = manager
editor.price.emit('icon-press', gtk.ENTRY_ICON_PRIMARY, None)
# Forget about the discount
editor.price.update(currency('10'))
# This will not trigger an event
self.click(editor.main_dialog.ok_button)
events_after = self.store.find(Event).count()
# The number of events doesn't changed
self.assertEquals(events_after, events_before)
示例11: _update_te
def _update_te(self):
user = get_current_user(self.store)
station = get_current_station(self.store)
self.te.dirty = True
self.te.te_time = StatementTimestamp()
self.te.user_id = user and user.id
self.te.station_id = station and station.id
示例12: set_consigned
def set_consigned(self):
if self.status != PurchaseOrder.ORDER_PENDING:
raise ValueError(
_(u'Invalid order status, it should be '
u'ORDER_PENDING, got %s') % (self.status_str, ))
self.responsible = get_current_user(self.store)
self.status = PurchaseOrder.ORDER_CONSIGNED
示例13: _logout
def _logout(self):
from stoqlib.database.runtime import (get_current_user,
get_default_store)
log.debug('Logging out the current user')
try:
user = get_current_user(get_default_store())
if user:
user.logout()
except StoqlibError:
pass
示例14: apply
def apply(self):
if self.test_type == ProductQualityTest.TYPE_BOOLEAN:
value = self.model.boolean_value
else:
value = self.model.decimal_value
for item in self._items:
result = item.set_test_result_value(self.model.quality_test, value,
get_current_user(self.store))
self.emit('test-updated', item, self.model.quality_test, result)
示例15: test_set_consigned
def test_set_consigned(self):
order = self.create_purchase_order()
order.status = PurchaseOrder.ORDER_PENDING
order.set_consigned()
current = get_current_user(store=self.store)
self.assertEquals(current, order.responsible)
self.assertEquals(order.status, order.ORDER_CONSIGNED)
order.status = PurchaseOrder.ORDER_CONFIRMED
with self.assertRaises(ValueError):
order.set_consigned()