本文整理汇总了Python中stoqlib.lib.parameters.sysparam.get_object函数的典型用法代码示例。如果您正苦于以下问题:Python get_object函数的具体用法?Python get_object怎么用?Python get_object使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_object函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create_from_payment
def create_from_payment(cls, payment, account=None):
"""Create a new transaction based on a |payment|.
It's normally used when creating a transaction which represents
a payment, for instance when you receive a bill or a check from
a |client| which will enter a |bankaccount|.
:param payment: the |payment| to create the transaction for.
:param account: if an outgoing payment, the |account| will be the source of
transaction. Otherwise will be the destination account.
:returns: the transaction
"""
if not payment.is_paid():
raise PaymentError(_("Payment needs to be paid"))
store = payment.store
value = payment.paid_value
if payment.is_outpayment():
operation_type = cls.TYPE_OUT
source = account or payment.method.destination_account
destination = sysparam.get_object(store, 'IMBALANCE_ACCOUNT')
else:
operation_type = cls.TYPE_IN
source = sysparam.get_object(store, 'IMBALANCE_ACCOUNT')
destination = account or payment.method.destination_account
return cls(source_account=source,
account=destination,
value=value,
description=payment.description,
code=unicode(payment.identifier),
date=payment.paid_date,
store=store,
payment=payment,
operation_type=operation_type)
示例2: _update_accounts
def _update_accounts(self):
if len(self._payments) != 1:
return
payment = self._payments[0]
create_transaction = payment.method.operation.create_transaction()
for combo in [self.destination_account, self.source_account]:
combo.set_sensitive(create_transaction)
if not create_transaction:
return
destination_combo = self.get_account_destination_combo()
for combo in [self.destination_account, self.source_account]:
combo.prefill(api.for_combo(
self.store.find(Account),
attr='long_description'))
if combo is destination_combo:
combo.select(payment.method.destination_account)
else:
combo.select(
sysparam.get_object(self.store, 'IMBALANCE_ACCOUNT'))
category_account = payment.category and payment.category.account
if category_account:
if payment.payment_type == payment.TYPE_IN:
self.source_account.select(category_account)
else:
self.destination_account.select(category_account)
示例3: test_can_remove
def test_can_remove(self):
sellable = Sellable(store=self.store)
self.assertTrue(sellable.can_remove())
sellable = self.create_sellable()
storable = Storable(product=sellable.product, store=self.store)
self.assertTrue(sellable.can_remove())
branch = get_current_branch(self.store)
storable.increase_stock(1, branch,
StockTransactionHistory.TYPE_INITIAL, None)
sale = self.create_sale()
sale.status = Sale.STATUS_QUOTE
sale.branch = branch
sale.add_sellable(sellable)
self.assertFalse(sellable.can_remove())
# Can't remove the sellable if it's in a purchase.
from stoqlib.domain.purchase import PurchaseItem
sellable = self.create_sellable()
Storable(product=sellable.product, store=self.store)
self.assertTrue(sellable.can_remove())
PurchaseItem(store=self.store,
quantity=8, quantity_received=0,
cost=125, base_cost=125,
sellable=sellable,
order=self.create_purchase_order())
self.assertFalse(sellable.can_remove())
# The delivery service cannot be removed.
sellable = sysparam.get_object(self.store, 'DELIVERY_SERVICE').sellable
self.assertFalse(sellable.can_remove())
示例4: test_account_remove
def test_account_remove(self):
a1 = self.create_account()
a2 = self.create_account()
imbalance_account = sysparam.get_object(self.store, 'IMBALANCE_ACCOUNT')
t1 = self.create_account_transaction(a1)
t1.source_account = a2
self.store.flush()
t2 = self.create_account_transaction(a2)
t2.source_account = a1
self.store.flush()
a2.parent = a1
with self.assertRaises(TypeError):
a1.remove(self.store)
a2.parent = None
a1.station = self.create_station()
self.assertRaises(TypeError, a1.remove)
a1.station = None
a1.remove(self.store)
self.assertEqual(t1.account, imbalance_account)
self.assertEqual(t2.source_account, imbalance_account)
示例5: _create_or_update_delivery
def _create_or_update_delivery(self):
delivery_service = sysparam.get_object(self.store, 'DELIVERY_SERVICE')
delivery_sellable = delivery_service.sellable
items = [item for item in self.slave.klist
if item.sellable.product is not None]
if self._delivery is not None:
model = self._delivery
else:
model = CreateDeliveryModel(
price=delivery_sellable.price, recipient=self.model.person)
rv = run_dialog(
CreateDeliveryEditor, self.get_toplevel().get_toplevel(),
self.store, model=model, items=items, person_type=Person)
if not rv:
return
self._delivery = rv
if self._delivery_item:
self.slave.klist.update(self._delivery_item)
else:
self._delivery_item = self.get_order_item(
delivery_sellable, self._delivery.price, 1)
self.slave.klist.append(None, self._delivery_item)
示例6: _register_branch_station
def _register_branch_station(caller_store, station_name):
import gtk
from stoqlib.lib.parameters import sysparam
if not sysparam.get_bool('DEMO_MODE'):
fmt = _(u"The computer '%s' is not registered to the Stoq "
u"server at %s.\n\n"
u"Do you want to register it "
u"(requires administrator access) ?")
if not yesno(fmt % (station_name,
db_settings.address),
gtk.RESPONSE_YES, _(u"Register computer"), _(u"Quit")):
raise SystemExit
from stoqlib.gui.utils.login import LoginHelper
h = LoginHelper(username="admin")
try:
user = h.validate_user()
except LoginError as e:
error(str(e))
if not user:
error(_("Must login as 'admin'"))
from stoqlib.domain.station import BranchStation
with new_store() as store:
branch = sysparam.get_object(store, 'MAIN_COMPANY')
station = BranchStation.create(store, branch=branch, name=station_name)
return caller_store.fetch(station)
示例7: __init__
def __init__(self, store, hide_footer=False, hide_toolbar=True,
selection_mode=None, search_str=None, search_spec=None,
search_query=None, double_click_confirm=True, info_message=None):
"""
:param store: a store
:param hide_footer: do I have to hide the dialog footer?
:param hide_toolbar: do I have to hide the dialog toolbar?
:param selection_mode: the kiwi list selection mode
:param search_str: If this search should already filter for some string
:param double_click_confirm: If double click a item in the list should
automatically confirm
"""
if selection_mode is None:
selection_mode = gtk.SELECTION_BROWSE
self._image_viewer = None
self._first_search = True
self._first_search_string = search_str
self._search_query = search_query
self._delivery_sellable = sysparam.get_object(
store, 'DELIVERY_SERVICE').sellable
SearchEditor.__init__(self, store, search_spec=search_spec,
editor_class=self.editor_class,
hide_footer=hide_footer,
hide_toolbar=hide_toolbar,
selection_mode=selection_mode,
double_click_confirm=double_click_confirm)
if info_message:
self.set_message(info_message)
if search_str:
self.set_searchbar_search_string(search_str)
self.search.refresh()
示例8: test_get_available_sellables_query
def test_get_available_sellables_query(self):
# Sellable and query without supplier
sellable = self.create_sellable()
self.create_storable(product=sellable.product,
branch=self.create_branch())
self.assertIn(
sellable,
self.store.find(Sellable,
Sellable.get_available_sellables_query(self.store)))
sellable.close()
self.assertNotIn(
sellable,
self.store.find(Sellable,
Sellable.get_available_sellables_query(self.store)))
delivery_sellable = sysparam.get_object(self.store, 'DELIVERY_SERVICE').sellable
delivery_sellable.status = Sellable.STATUS_AVAILABLE
# Deliveries are treated differently, that's why they should
# not be present here
self.assertNotIn(
sellable,
self.store.find(Sellable,
Sellable.get_available_sellables_query(self.store)))
示例9: get_sellable_view_query
def get_sellable_view_query(self):
delivery_sellable = sysparam.get_object(
self.store, 'DELIVERY_SERVICE').sellable
query = And(ServiceView.status == Sellable.STATUS_AVAILABLE,
ServiceView.id != delivery_sellable.id)
return self.sellable_view, query
示例10: __init__
def __init__(self, store, product, visual_mode=False):
self._product = product
BaseRelationshipEditorSlave.__init__(self, store, visual_mode=visual_mode)
suggested = sysparam.get_object(store, 'SUGGESTED_SUPPLIER')
if suggested is not None:
self.target_combo.select(suggested)
示例11: get_tax_template
def get_tax_template(cls, invoice_item):
default_cofins = sysparam.get_object(invoice_item.store, 'DEFAULT_PRODUCT_COFINS_TEMPLATE')
# FIXME: Allow use COFINS templates in services
if invoice_item.sellable.service:
return default_cofins
return invoice_item.sellable.product.cofins_template or default_cofins
示例12: test_wizard_remove_delivery
def test_wizard_remove_delivery(self, yesno):
yesno.return_value = True
branch = api.get_current_branch(self.store)
storable = self.create_storable(branch=branch, stock=1)
sellable = storable.product.sellable
# Run the wizard
wizard = StockDecreaseWizard(self.store)
step = wizard.get_current_step()
step.reason.update('test')
self.click(wizard.next_button)
step = wizard.get_current_step()
self.assertNotSensitive(step, ['delivery_button'])
step.sellable_selected(sellable)
step.quantity.update(1)
self.click(step.add_sellable_button)
self.assertSensitive(step, ['delivery_button'])
delivery_sellable = sysparam.get_object(self.store, 'DELIVERY_SERVICE').sellable
delivery = CreateDeliveryModel(price=delivery_sellable.price,
recipient=wizard.model.person)
module = 'stoqlib.gui.wizards.stockdecreasewizard.run_dialog'
with mock.patch(module) as run_dialog:
# Delivery set
run_dialog.return_value = delivery
self.click(step.delivery_button)
self.assertEqual(step._delivery, delivery)
self.assertTrue(isinstance(step._delivery_item, StockDecreaseItem))
# Remove the delivery item
run_dialog.return_value = delivery
step.slave.klist.select(step.slave.klist[1])
self.click(step.slave.delete_button)
self.assertIsNone(step._delivery)
self.assertIsNone(step._delivery_item)
示例13: _get_parameter_value
def _get_parameter_value(self, obj):
"""Given a ParameterData object, returns a string representation of
its current value.
"""
detail = sysparam.get_detail_by_name(obj.field_name)
if detail.type == unicode:
data = sysparam.get_string(obj.field_name)
elif detail.type == bool:
data = sysparam.get_bool(obj.field_name)
elif detail.type == int:
data = sysparam.get_int(obj.field_name)
elif detail.type == decimal.Decimal:
data = sysparam.get_decimal(obj.field_name)
elif isinstance(detail.type, basestring):
data = sysparam.get_object(self.store, obj.field_name)
else:
raise NotImplementedError(detail.type)
if isinstance(data, Domain):
if not (IDescribable in providedBy(data)):
raise TypeError(u"Parameter `%s' must implement IDescribable "
"interface." % obj.field_name)
return data.get_description()
elif detail.options:
return detail.options[int(obj.field_value)]
elif isinstance(data, bool):
return [_(u"No"), _(u"Yes")][data]
elif obj.field_name == u'COUNTRY_SUGGESTED':
return dgettext("iso_3166", data)
elif isinstance(data, unicode):
# FIXME: workaround to handle locale specific data
return _(data)
return unicode(data)
示例14: sysparam
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 type(value) is bool:
old_values[param] = sysparam.get_bool(param)
sysparam.set_bool(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)
else:
raise NotImplementedError(type(value))
try:
yield
finally:
for param, value in old_values.items():
if type(value) is bool:
sysparam.set_bool(self.store, param, value)
elif isinstance(value, Domain) or value is None:
sysparam.set_object(self.store, param, value)
else:
raise NotImplementedError(type(value))
示例15: _load_tax_values
def _load_tax_values(self, item):
assert item
sellable = item.sellable
product = sellable.product
service = sellable.service
delivery = sysparam.get_object(item.store, 'DELIVERY_SERVICE').sellable
if product:
code = product.ncm or ''
ex_tipi = self._format_ex(product.ex_tipi)
else:
if not self.include_services or sellable == delivery:
return
code = '%04d' % int(service.service_list_item_code.replace('.', ''))
ex_tipi = ''
options = taxes_data.get(code, {})
n_options = len(options)
if n_options == 0:
tax_values = TaxInfo('0', '0', '0', '', '0')
elif n_options == 1:
tax_values = options['']
else:
tax_values = options.get(ex_tipi) or options['']
return tax_values