本文整理汇总了Python中stoqlib.api.api.get_current_user函数的典型用法代码示例。如果您正苦于以下问题:Python get_current_user函数的具体用法?Python get_current_user怎么用?Python get_current_user使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_current_user函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_columns
def get_columns(self):
columns = [SearchColumn('code', title=_(u'Code'), data_type=str),
SearchColumn('barcode', title=_('Barcode'), data_type=str,
sort_func=sort_sellable_code, width=80),
SearchColumn('category_description', title=_('Category'),
data_type=str, width=120),
SearchColumn('description', title=_('Description'),
data_type=str, expand=True, sorted=True),
SearchColumn('location', title=_('Location'),
data_type=str, visible=False),
SearchColumn('manufacturer', title=_('Manufacturer'),
data_type=str, visible=False),
SearchColumn('model', title=_('Model'),
data_type=str, visible=False)]
user = api.get_current_user(self.store)
if user.profile.check_app_permission('purchase'):
columns.append(SearchColumn('cost',
title=_(u'Cost'),
data_type=currency, visible=True))
if hasattr(self.search_spec, 'price'):
columns.append(SearchColumn('price',
title=_(u'Price'),
data_type=currency, visible=True))
if hasattr(self.search_spec, 'minimum_quantity'):
columns.append(SearchColumn('minimum_quantity',
title=_(u'Minimum Qty'),
data_type=Decimal, visible=False))
if hasattr(self.search_spec, 'stock'):
columns.append(QuantityColumn('stock', title=_(u'In Stock')))
return columns
示例2: on_confirm
def on_confirm(self):
till = self.model.till
removed = abs(self.model.value)
if removed:
# We need to do this inside a new transaction, because if the
# till closing fails further on, this still needs to be recorded
# in the database
store = api.new_store()
t_till = store.fetch(till)
TillRemoveCashEvent.emit(till=t_till, value=removed)
reason = _('Amount removed from Till by %s') % (
api.get_current_user(self.store).get_description(), )
till_entry = t_till.add_debit_entry(removed, reason)
# Financial transaction
_create_transaction(store, till_entry)
# DB transaction
store.confirm(True)
store.close()
if self._close_ecf:
try:
retval = TillCloseEvent.emit(till=till,
previous_day=self._previous_day)
except (TillError, DeviceError), e:
warning(str(e))
return None
# If the event was captured and its return value is False, then we
# should not close the till.
if retval is False:
return False
示例3: on_cost__validate
def on_cost__validate(self, widget, value):
sellable = self.proxy.model.sellable
if not sellable:
return
# Dont allow numbers bigger than MAX_INT (see stoqlib.lib.defaults)
if value > MAX_INT:
return ValidationError(_("Price cannot be bigger than %s") % MAX_INT)
if value <= 0:
return ValidationError(_(u"Cost must be greater than zero."))
if self.validate_price:
category = getattr(self.model, "client_category", None)
default_price = sellable.get_price_for_category(category)
if not sysparam.get_bool("ALLOW_HIGHER_SALE_PRICE") and value > default_price:
return ValidationError(_(u"The sell price cannot be greater " "than %s.") % default_price)
manager = self.manager or api.get_current_user(self.store)
client = getattr(self.model, "client", None)
category = client and client.category
extra_discount = self.get_extra_discount(sellable)
valid_data = sellable.is_valid_price(value, category, manager, extra_discount=extra_discount)
if not valid_data["is_valid"]:
return ValidationError((_(u"Max discount for this product is %.2f%%.") % valid_data["max_discount"]))
示例4: _create_receiving_order
def _create_receiving_order(self):
supplier_id = self.purchases[0].supplier_id
branch_id = self.purchases[0].branch_id
# If the receiving is for another branch, we need a temporary identifier
temporary_identifier = None
if (api.sysparam.get_bool('SYNCHRONIZED_MODE') and
api.get_current_branch(self.store).id != branch_id):
temporary_identifier = ReceivingOrder.get_temporary_identifier(self.store)
# We cannot create the model in the wizard since we haven't
# selected a PurchaseOrder yet which ReceivingOrder depends on
# Create the order here since this is the first place where we
# actually have a purchase selected
receiving_invoice = ReceivingInvoice(
supplier=supplier_id, store=self.store, branch=branch_id,
responsible=api.get_current_user(self.store))
self.wizard.model = self.model = ReceivingOrder(
identifier=temporary_identifier,
receiving_invoice=receiving_invoice,
responsible=receiving_invoice.responsible,
invoice_number=None, branch=branch_id, store=self.store)
for row in self.purchases:
self.model.add_purchase(row.purchase)
示例5: on_cost__validate
def on_cost__validate(self, widget, value):
sellable = self.proxy.model.sellable
if not sellable:
return
if value <= 0:
return ValidationError(_(u'Cost must be greater than zero.'))
if self.validate_price:
category = getattr(self.model, 'client_category', None)
default_price = sellable.get_price_for_category(category)
if (not sysparam.get_bool('ALLOW_HIGHER_SALE_PRICE') and
value > default_price):
return ValidationError(_(u'The sell price cannot be greater '
'than %s.') % default_price)
manager = self.manager or api.get_current_user(self.store)
client = getattr(self.model, 'client', None)
category = client and client.category
extra_discount = self.get_extra_discount(sellable)
valid_data = sellable.is_valid_price(value, category, manager,
extra_discount=extra_discount)
if not valid_data['is_valid']:
return ValidationError(
(_(u'Max discount for this product is %.2f%%.') %
valid_data['max_discount']))
示例6: create_model
def create_model(self, store):
return Calls(date=datetime.date.today(),
description=u'',
message=u'',
person=self.person,
attendant=api.get_current_user(self.store),
store=store)
示例7: test_create
def test_create(self, set_message):
sellable = self.create_sellable()
self.create_storable(product=sellable.product)
sale_item = TemporarySaleItem(sellable=sellable, quantity=1)
user = api.get_current_user(self.store)
with mock.patch.object(user.profile, 'check_app_permission') as has_acess:
has_acess.side_effect = [False]
search = SaleSellableSearch(self.store,
sale_items=[sale_item], quantity=1)
self.assertRaises(TypeError, SaleSellableSearch, self.store,
sale_items=[sale_item],
selection_mode=Gtk.SelectionMode.MULTIPLE)
self.assertRaises(TypeError, SaleSellableSearch, self.store,
sale_items=[sale_item], quantity=None)
search = SaleSellableSearch(self.store)
search.search.refresh()
self.check_search(search, 'sale-sellable-no-filter')
search = SaleSellableSearch(self.store, info_message='test')
set_message.assert_called_once_with('test')
search = SaleSellableSearch(self.store, search_str='cal')
self.check_search(search, 'sale-sellable-string-filter')
示例8: test_show
def test_show(self):
workorder = self.create_workorder(description=u'Test equipment')
workorder.client = self.create_client()
workorder.client.category = self.create_client_category()
product = self.create_product(stock=10)
sellable = product.sellable
storable = product.storable
item = workorder.add_sellable(sellable)
editor = _WorkOrderItemEditor(self.store, model=item)
self.check_editor(editor, 'editor-workorderitem-show')
self.assertValid(editor, ['price'])
editor.price.update(0)
self.assertInvalid(editor, ['price'])
editor.price.update(-1)
self.assertInvalid(editor, ['price'])
with mock.patch.object(sellable, 'is_valid_price') as ivp:
ivp.return_value = {
'is_valid': False,
'min_price': decimal.Decimal('10.00'),
'max_discount': decimal.Decimal('0.00'),
}
editor.price.update(1)
ivp.assert_called_once_with(1, workorder.client.category,
api.get_current_user(self.store))
self.assertInvalid(editor, ['price'])
self.assertValid(editor, ['quantity'])
with mock.patch.object(storable, 'get_balance_for_branch') as gbfb:
gbfb.return_value = 0
editor.quantity.update(20)
gbfb.assert_called_once_with(workorder.branch)
self.assertInvalid(editor, ['quantity'])
示例9: on_price__validate
def on_price__validate(self, widget, value):
if value <= 0:
return ValidationError(_(u"The price must be greater than zero."))
if (not sysparam.get_bool('ALLOW_HIGHER_SALE_PRICE') and
value > self.model.base_price):
return ValidationError(_(u'The sell price cannot be greater '
'than %s.') % self.model.base_price)
sellable = self.model.sellable
manager = self.manager or api.get_current_user(self.store)
if api.sysparam.get_bool('REUTILIZE_DISCOUNT'):
extra_discount = self.model.sale.get_available_discount_for_items(
user=manager, exclude_item=self.model)
else:
extra_discount = None
valid_data = sellable.is_valid_price(
value, category=self.model.sale.client_category,
user=manager, extra_discount=extra_discount)
if not valid_data['is_valid']:
return ValidationError(
(_(u'Max discount for this product is %.2f%%.') %
valid_data['max_discount']))
示例10: fields
def fields(self):
# Only users with admin or purchase permission can modify transporters
user = api.get_current_user(self.store)
can_modify_transporter = any((
user.profile.check_app_permission(u'admin'),
user.profile.check_app_permission(u'purchase'),
))
freight_types = [(v, k) for k, v in Delivery.freights.items()]
states = [(v, v) for v in api.get_l10n_field('state').state_list]
return collections.OrderedDict(
recipient=PersonQueryField(_("Recipient"), proxy=True, mandatory=True,
person_type=self.person_type),
transporter_id=PersonField(_("Transporter"), proxy=True,
person_type=Transporter,
can_add=can_modify_transporter,
can_edit=can_modify_transporter),
address=AddressField(_("Address"), proxy=True, mandatory=True),
freight_type=ChoiceField(_("Freight type"), proxy=True,
values=freight_types),
price=PriceField(_("Delivery cost"), proxy=True),
estimated_fix_date=DateField(_("Estimated delivery date"), proxy=True),
volumes_kind=TextField(_("Volumes kind"), proxy=True),
volumes_quantity=IntegerField(_("Volumes quantity"), proxy=True),
volumes_net_weight=NumericField(_("Volumes net weight"), proxy=True,
digits=3),
volumes_gross_weight=NumericField(_("Volumes gross weight"),
proxy=True, digits=3),
vehicle_license_plate=TextField(_("Vehicle license plate"), proxy=True),
vehicle_state=ChoiceField(_("Vehicle state"), proxy=True, use_entry=True,
values=states),
vehicle_registration=TextField(_("Vehicle registration"), proxy=True),
)
示例11: test_price_validation
def test_price_validation(self):
user = api.get_current_user(self.store)
user.profile.max_discount = 2
editor = self._create_editor()
with self.sysparam(ALLOW_HIGHER_SALE_PRICE=True):
editor.price.update(101)
self.assertValid(editor, ['price'])
editor.price.update(98)
self.assertValid(editor, ['price'])
editor.price.update(97)
self.assertInvalid(editor, ['price'])
editor.price.update(-1)
self.assertInvalid(editor, ['price'])
with self.sysparam(ALLOW_HIGHER_SALE_PRICE=False):
editor.price.update(101)
self.assertInvalid(editor, ['price'])
editor.price.update(98)
self.assertValid(editor, ['price'])
editor.price.update(97)
self.assertInvalid(editor, ['price'])
editor.price.update(-1)
self.assertInvalid(editor, ['price'])
with self.sysparam(REUTILIZE_DISCOUNT=True):
editor.price.update(10)
self.assertInvalid(editor, ['price'])
with self.sysparam(REUTILIZE_DISCOUNT=False):
editor.price.update(10)
self.assertInvalid(editor, ['price'])
示例12: _create_receiving_order
def _create_receiving_order(self):
# since we will create a new receiving order, we should confirm the
# purchase first. Note that the purchase may already be confirmed
if self.model.status in [PurchaseOrder.ORDER_PENDING,
PurchaseOrder.ORDER_CONSIGNED]:
self.model.confirm()
temporary_identifier = None
if self.wizard.is_for_another_branch():
temporary_identifier = ReceivingOrder.get_temporary_identifier(self.store)
receiving_invoice = ReceivingInvoice(
store=self.store,
supplier=self.model.supplier,
branch=self.model.branch,
responsible=api.get_current_user(self.store))
receiving_model = ReceivingOrder(
identifier=temporary_identifier,
receiving_invoice=receiving_invoice,
responsible=receiving_invoice.responsible,
branch=self.model.branch,
invoice_number=None,
store=self.store)
receiving_model.add_purchase(self.model)
# Creates ReceivingOrderItem's
for item in self.model.get_pending_items():
receiving_model.add_purchase_item(item)
self.wizard.receiving_model = receiving_model
示例13: search_products
def search_products(self):
with api.new_store() as store:
profile = api.get_current_user(store).profile
can_create = (profile.check_app_permission('admin') or
profile.check_app_permission('purchase'))
run_dialog(ProductSearch, None, store, hide_footer=True, hide_toolbar=not can_create,
hide_cost_column=not can_create)
示例14: on_SalesCancel__activate
def on_SalesCancel__activate(self, action):
sale_view = self.results.get_selected()
can_cancel = api.sysparam.get_bool('ALLOW_CANCEL_LAST_COUPON')
if can_cancel and ECFIsLastSaleEvent.emit(sale_view.sale):
info(_("That is last sale in ECF. Return using the menu "
"ECF - Cancel Last Document"))
return
store = api.new_store()
sale = store.fetch(sale_view.sale)
msg_text = _(u"This will cancel the sale, Are you sure?")
model = SaleComment(store=store, sale=sale,
author=api.get_current_user(store))
retval = self.run_dialog(
NoteEditor, store, model=model, attr_name='comment',
message_text=msg_text, label_text=_(u"Reason"),
mandatory=True, ok_button_label=_(u"Cancel sale"),
cancel_button_label=_(u"Don't cancel"))
if not retval:
store.rollback()
return
sale.cancel()
store.commit(close=True)
self.refresh()
示例15: create_actions
def create_actions(self):
group = get_accels('app.financial')
actions = [
('Import', Gtk.STOCK_ADD, _('Import...'),
group.get('import'), _('Import a GnuCash or OFX file')),
('ConfigurePaymentMethods', None,
_('Payment methods'),
group.get('configure_payment_methods'),
_('Select accounts for the payment methods on the system')),
('Delete', None, _('Delete...')),
("NewAccount", Gtk.STOCK_NEW, _("Account..."),
group.get('new_account'),
_("Add a new account")),
("NewTransaction", Gtk.STOCK_NEW, _("Transaction..."),
group.get('new_store'),
_("Add a new transaction")),
("Edit", Gtk.STOCK_EDIT, _("Edit..."),
group.get('edit')),
]
self.financial_ui = self.add_ui_actions(actions)
self.set_help_section(_("Financial help"), 'app-financial')
user = api.get_current_user(self.store)
if not user.profile.check_app_permission(u'admin'):
self.set_sensitive([self.ConfigurePaymentMethods], False)