def test_show(self, get_serial_devices, get_usb): get_serial_devices.return_value = [ _Device('/dev/ttyS0'), _Device('/dev/ttyS1') ] get_usb.return_value = [ # Without manufacturer and product Settable(idProduct=1234, idVendor=9999), # Without manufacturer Settable(idProduct=0x1234, idVendor=0x9876, manufacturer=None, product='Printer'), # Complete Settable(idProduct=0x1234, idVendor=0x9876, manufacturer='USB', product='Printer') ] station = self.create_station() settings = DeviceSettings(store=self.store, type=DeviceSettings.SCALE_DEVICE) editor = DeviceSettingsEditor(self.store, model=settings, station=station) self.check_editor(editor, 'editor-devicesetting-show')
def main(): win = Gtk.Window() win.set_size_request(600, 300) win.connect('destroy', Gtk.main_quit) kanban = KanbanView() for title in ['Opened', 'Approved', 'Executing', 'Finished']: kanban.add_column(KanbanViewColumn(title)) kanban.connect('item-dragged', lambda *x: True) kanban.enable_editing() items = [ Settable(name='Ronaldo', phone='1972-2878'), Settable(name='Gabriel', phone='1234-5678'), Settable(name='João Paulo', phone='2982-8278'), Settable(name='Bellini', phone='2982-2909'), Settable(name='Johan', phone='2929-0202') ] column = kanban.get_column_by_title('Opened') for item in items: column.append_item(item) win.add(kanban) win.show_all() Gtk.main()
def create_model(self, store): if self._stock_item: return Settable(quantity=self._stock_item.quantity, cost=self._stock_item.stock_cost, reason=u'') else: return Settable(quantity=Decimal(0), cost=self._product.sellable.cost)
def testGetNextAndPrevious(self): self.klist.append(Settable(name='second')) self.klist.append(Settable(name='third')) item1, item2, item3 = self.klist self.assertEqual(self.klist.get_next(item1), item2) self.assertEqual(self.klist.get_next(item2), item3) self.assertEqual(self.klist.get_next(item3), item1) self.assertRaises(ValueError, self.klist.get_next, None) self.assertEqual(self.klist.get_previous(item1), item3) self.assertEqual(self.klist.get_previous(item2), item1) self.assertEqual(self.klist.get_previous(item3), item2) self.assertRaises(ValueError, self.klist.get_previous, None)
def testInsert(self): self.klist = ObjectList([Column('name')]) self.assertEqual(list(self.klist), []) self.klist.insert(0, Settable(name='one')) self.assertEqual(self.klist[0].name, 'one') self.klist.insert(0, Settable(name='two')) self.assertEqual(self.klist[0].name, 'two') self.assertEqual(self.klist[1].name, 'one') self.klist.insert(1, Settable(name='three')) self.assertEqual(self.klist[0].name, 'two') self.assertEqual(self.klist[1].name, 'three') self.assertEqual(self.klist[2].name, 'one')
def _build_data(self, purchases): self.payments = [] product_dict = {} for purchase_view in purchases: purchase = purchase_view.purchase self.payments.extend(purchase.group.payments) for purchase_item in purchase.get_items(): qty = purchase_item.quantity cost = purchase_item.cost total_value = cost * qty unit = purchase_item.sellable.get_unit_description() qty_str = '%s %s' % (qty, unit) product_codes = [item.code for item in product_dict.values()] sellable = purchase_item.sellable if not sellable.code in product_codes: desc = sellable.description obj = Settable(code=sellable.code, description=desc, _total_qty=qty, total_value=total_value, qty_str=qty_str, unit=unit, cost=cost) product_dict[sellable] = obj else: product_dict[sellable]._total_qty += qty table = product_dict[sellable] table.qty_str = '%s %s' % (table._total_qty, table.unit) table.total_value = table._total_qty * table.cost self.products = list(product_dict.values())
def setup_proxies(self): self.discount.set_tooltip_text( _("Use absolute or percentage (%) value")) # We need to put discount on a proxy or else it won't be validated # on it's validate callback self.add_proxy(Settable(discount=u''), ['discount'])
def test_validate_confirm(self): editor = BackupSettingsEditor(self.store, Settable(key='123456')) with mock.patch('stoqlib.gui.editors.backupsettings.yesno') as yesno: self.assertTrue(editor.validate_confirm()) self.assertNotCalled(yesno) with mock.patch('stoqlib.gui.editors.backupsettings.yesno') as yesno: editor.model.key = '321' yesno.return_value = False self.assertFalse(editor.validate_confirm()) self.assertCalledOnceWith( yesno, ("Changing the backup key will make any backup done with " "the previous key unrecoverable. Are you sure?"), Gtk.ResponseType.NO, "Change", "Keep old key") with mock.patch('stoqlib.gui.editors.backupsettings.yesno') as yesno: editor.model.key = '321' yesno.return_value = True self.assertTrue(editor.validate_confirm()) self.assertCalledOnceWith( yesno, ("Changing the backup key will make any backup done with " "the previous key unrecoverable. Are you sure?"), Gtk.ResponseType.NO, "Change", "Keep old key")
def setup_proxies(self): unit = self.model.sellable.unit digits = QUANTITY_PRECISION if unit and unit.allow_fraction else 0 for widget in [self.quantity, self.quantity_reserved]: widget.set_digits(digits) self.quantity.set_range(1, MAX_INT) # If there's a sale, we can't change it's quantity, but we can # reserve/return_to_stock them. On the other hand, if there's no sale, # the quantity_reserved must be in sync with quantity # *Only products with stock control can be reserved storable = self.model.sellable.product_storable if self.model.order.sale_id is not None and storable: self.price.set_sensitive(False) self.quantity.set_sensitive(False) self.quantity_reserved.set_range(0, self.model.quantity) else: self.quantity_reserved.set_range(0, MAX_INT) self.quantity_reserved.set_visible(False) self.fields['quantity_reserved'].label_widget.set_visible(False) # We need to add quantity_reserved to a proxy or else it's validate # method won't do anything self.add_proxy( Settable(quantity_reserved=self.model.quantity_decreased), ['quantity_reserved'])
def _get_day_history(self): if not self.till: assert self._close_ecf and not self._close_db return day_history = {} day_history[_(u'Initial Amount')] = self.till.initial_cash_amount for entry in self.till.get_entries(): payment = entry.payment if payment is not None: desc = payment.method.get_description() else: if entry.value > 0: desc = _(u'Cash In') else: desc = _(u'Cash Out') day_history.setdefault(desc, 0) day_history[desc] += entry.value for description, value in day_history.items(): yield Settable(description=description, system_value=value, user_value=0)
def _update_total(self): SellableItemStep._update_total(self) quantities = {} missing = {} lead_time = 0 for i in self.slave.klist: sellable = i.sellable if sellable.service or not sellable.product.manage_stock: continue quantities.setdefault(sellable, 0) quantities[sellable] += i.quantity if quantities[sellable] > i._stock_quantity: _lead_time = sellable.product.get_max_lead_time( quantities[sellable], self.model.branch) max_lead_time = max(lead_time, _lead_time) missing[sellable] = Settable( description=sellable.get_description(), stock=i._stock_quantity, ordered=quantities[sellable], lead_time=_lead_time, ) self.missing = missing if missing: msg = _('Not enough stock. ' 'Estimated time to obtain missing items: %d days.' ) % max_lead_time self.slave.set_message('<b>%s</b>' % (api.escape(msg)), self._show_missing_details) else: self.slave.clear_message()
def test_get_description(self): sale = self.create_sale() purchase = self.create_purchase_order() renegotiation = self.create_payment_renegotiation() group = self.create_payment_group() decrease = self.create_stock_decrease(group=group) group = self.create_payment_group() receiving_invoice = self.create_receiving_invoice(group=group) sale.identifier = 77777 purchase.identifier = 88888 renegotiation.identifier = 99999 decrease.identifier = 12345 receiving_invoice.identifier = 12223 self.assertEqual(sale.group.get_description(), u'sale 77777') self.assertEqual(purchase.group.get_description(), u'order 88888') self.assertEqual(renegotiation.group.get_description(), u'renegotiation 99999') self.assertEqual(decrease.group.get_description(), u'stock decrease 12345') self.assertEqual(receiving_invoice.group.get_description(), u'receiving 12223') callback = lambda g, s: Settable(payment_description='foobar') PaymentGroupGetOrderEvent.connect(callback) try: self.assertEqual(self.create_payment_group().get_description(), 'foobar') finally: PaymentGroupGetOrderEvent.disconnect(callback)
def test_confirm(self, new_store): # We need to use the current transaction in the test, since the test # object is only in this transaction new_store.return_value = self.store sale = self.create_sale() sale_item = self.create_sale_item(sale=sale) product = sale_item.sellable.product self.create_storable(product=product) missing_item = Settable(description='desc', ordered=Decimal('1'), stock=Decimal('0'), storable=sale_item.sellable.product.storable) sale.status = Sale.STATUS_QUOTE dialog = MissingItemsDialog(sale, [missing_item]) # Dont commit the transaction with mock.patch.object(self.store, 'commit'): # Also dont close it, since tearDown will do it. with mock.patch.object(self.store, 'close'): self.click(dialog.ok_button) storable = dialog.retval[0].storable self.check_dialog(dialog, 'test-confirm-sale-missing-dialog-confirm', [storable, sale, sale_item, product, sale.invoice])
def _create_ui(self): hbox = gtk.HBox() self.klist = ObjectList([Column('name')]) self.klist.set_size_request(150, -1) self.klist.get_treeview().set_headers_visible(False) self.klist.connect('selection-changed', self._on_klist__selection_changed) hbox.pack_start(self.klist) hbox.show() for name, ctype in [(_(u'Units'), DeviceConstant.TYPE_UNIT), (_(u'Tax'), DeviceConstant.TYPE_TAX), (_(u'Payments'), DeviceConstant.TYPE_PAYMENT)]: self.klist.append(Settable(name=name, type=ctype)) self.klist.show() self._constant_slave = _DeviceConstantsList(self.store, self.printer) self._constant_slave.switch(DeviceConstant.TYPE_UNIT) hbox.pack_start(self._constant_slave.get_toplevel()) # FIXME: redesign BasicDialog self.main.remove(self.main_label) self.main.add(hbox) hbox.show_all()
def _populate_quoting_list(self): # populate the quoting list by finding the suppliers based on the # products list quotes = {} total_items = 0 # O(n*n) for item in self.model.get_items(): total_items += 1 sellable = item.sellable product = sellable.product for supplier_info in product.suppliers: supplier = supplier_info.supplier if supplier is None: continue if supplier not in quotes.keys(): quotes[supplier] = [sellable] else: quotes[supplier].append(sellable) for supplier, items in quotes.items(): total_supplier_items = len(items) per_supplier = _(u"%s/%s") % (total_supplier_items, total_items) self.quoting_list.append(Settable(supplier=supplier, items=items, products_per_supplier=per_supplier, selected=True))
def test_handle_action_threaded(self, ProgressDialog): ProgressDialog.return_value = mock.Mock() resource = mock.MagicMock(status=0, name='mock', label='Mock', reason='Reason', reason_long='Long reason') manager = ResourceStatusManager.get_instance() box = ResourceStatusBox(resource, manager) action = ResourceStatusAction(Settable(label='baz'), 'foo', 'bar', lambda: None, threaded=True) btn = box.add_action(action) with mock.patch.object(manager, 'handle_action') as handle_action: t = mock.Mock() t.is_alive.side_effect = [True, False] handle_action.return_value = t self.click(btn) self.assertCalledOnceWith(handle_action, action) self.assertCalledOnceWith( ProgressDialog, 'Executing "bar". This might take a while...', pulse=True)
def __init__(self, store, model, subtotal, total_paid=0): """Creates a new SaleWizard that confirms a sale. To avoid excessive querying of the database we pass some data already queried/calculated before hand. :param store: a store :param model: a |sale| :param subtotal: subtotal of the sale :param total_paid: totaly value already paid """ marker('ConfirmSaleWizard') self._check_payment_group(model, store) self._subtotal = subtotal self._total_paid = total_paid self.model = model # invoice_model is a Settable so avoid bug 4218, where more # than one checkout may try to use the same invoice number. self.invoice_model = Settable(invoice_number=None, original_invoice=None) marker('running SalesPersonStep') first_step = self.first_step(self, store, model, self.payment_group, self.invoice_model) marker('finished creating SalesPersonStep') BaseWizard.__init__(self, store, first_step, model) if not sysparam(self.store).CONFIRM_SALES_ON_TILL: # This was added to allow us to work even if an error # happened while adding a payment, where we already order # but cannot confirm and are thrown back to the main # POS interface if self.model.can_order(): self.model.order() marker('leaving ConfirmSaleWizard.__init__')
def _create_model(self, purchase): paid_value = currency(purchase.payments.sum(Payment.paid_value) or 0) received_value = purchase.get_received_total() return Settable(received_value=received_value, paid_value=paid_value, missing_value=currency(received_value - paid_value), purchase=purchase)
def test_confirm_production(self, new_store, info): # We need to use the current transaction in the test, since the test # object is only in this transaction new_store.return_value = self.store sale = self.create_sale() sale.status = Sale.STATUS_QUOTE product = self.create_product() self.create_storable(product) self.create_product_component(product) sale.add_sellable(product.sellable, quantity=15) missing_item = Settable(description='desc', ordered=Decimal('15'), stock=Decimal('0'), storable=product.storable) dialog = MissingItemsDialog(sale, [missing_item]) self.assertEquals(self.store.find(ProductionOrder).count(), 0) # Dont commit the transaction with mock.patch.object(self.store, 'commit'): # Also dont close it, since tearDown will do it. with mock.patch.object(self.store, 'close'): self.click(dialog.ok_button) info.assert_called_once_with('A new production was created for the ' 'missing composed products') self.assertEquals(self.store.find(ProductionOrder).count(), 1) production = self.store.find(ProductionOrder).any() self.assertEquals(production.get_items().count(), 1) self.assertEquals(production.get_items()[0].product, product) self.assertEquals(production.get_items()[0].quantity, 15)
def get_namespace(self): store = self.loan.store order_identifier = str(self.loan.identifier) print_promissory_note = api.sysparam.get_bool( 'PRINT_PROMISSORY_NOTE_ON_LOAN') branch = api.get_current_branch(store) drawer_person = self.loan.branch.person drawee_person = self.loan.client.person emission_address = branch.person.get_main_address() emission_location = emission_address.city_location promissory_data = Settable( order_identifier=order_identifier, payment_number=None, drawee=drawee_person.name, drawer=branch.get_description(), drawee_document=self._get_person_document(drawee_person), drawer_document=self._get_person_document(drawer_person), drawee_address=self._get_person_address(drawee_person), drawer_address=self._get_person_address(drawer_person), due_date=self.loan.expire_date, value=self.loan.get_total_amount(), emission_city=emission_location.city, emission_date=datetime.date.today(), ) return dict(subtitle=_("Loan number: %s") % order_identifier, loan=self.loan, print_promissory_note=print_promissory_note, promissory_data=promissory_data, notice=api.sysparam.get_string('LOAN_NOTICE'))
def create_model(self, store): return Settable(branch=api.get_current_branch(store), in_total=currency(0), in_credit=currency(0), in_subtotal=currency(0), out_total=currency(0), out_credit=currency(0), out_subtotal=currency(0))
def __init__(self, store, model, parent): self.model = model self.icms_slave = parent.icms_slave self.ipi_slave = parent.ipi_slave self.pis_slave = parent.pis_slave self.cofins_slave = parent.cofins_slave self.quantity_model = Settable(quantity=model.quantity) BaseEditorSlave.__init__(self, store, self.model)
def create_model(self, store): sellable = self.sellable return Settable(barcode=sellable.barcode, code=sellable.code, description=sellable.description, price=sellable.price, quantity=Decimal('1'), skip=Decimal('0'))
def _show_lonely_payments(self, payments, widget): widget.clear() for payment in payments: payment_data = Settable(identifier=payment.identifier, method=payment.method.get_description(), description=payment.description, branch=payment.branch_name, value=payment.value) widget.append(payment_data)
def setUp(self): self.model = Settable(attr=0) proxy = Proxy(FakeView(), self.model) self.combo = disabledeprecationcall(self.type) self.combo.data_type = int self.combo.model_attribute = 'attr' self.combo.prefill([('foo', 0), ('bar', 1)]) proxy.add_widget('attr', self.combo) self.combo.show()
def test_key_validate(self): editor = BackupSettingsEditor(self.store, Settable(key='1234567890')) self.assertValid(editor, ['key']) editor.key.update('123') self.assertInvalid(editor, ['key']) editor.key.update('0987654321') self.assertValid(editor, ['key'])
def _on_configure(self): key = self._server.call('get_backup_key') with api.new_store() as store: rv = run_dialog(BackupSettingsEditor, None, store, Settable(key=key)) if rv: key = self._server.call('set_backup_key', rv.key)
def create_model(self, store): till = Till.get_current(self.store) return Settable(employee=None, payment=None, # FIXME: should send in consts.now() open_date=None, till=till, balance=till.get_balance(), value=currency(0))
def _register_test_plugin(self): # Workaround to register _TestPlugin since it is not really a plugin. # Two plugins are instanced and setup to be used on this class' tests. # _dependend_plugin depends on _independent_plugin. ind_name = self._independent_plugin.name dep_name = self._dependent_plugin.name # Creating independent plugin description ind_desc = Settable(dependencies=[]) # Description that sets the dependency to the independent plugin. dep_desc = Settable(dependencies=[ind_name]) self._manager._plugin_descriptions[ind_name] = ind_desc self._manager._plugin_descriptions[dep_name] = dep_desc register_plugin(_TestPlugin) register_plugin(_TestDependentPlugin)
def get_saved_items(self): # we keep a copy of the important data to calculate values when we # finish this step for item in self.consignment.get_items(): self._original_items[item.id] = Settable(item_id=item.id, sold=item.quantity_sold, returned=item.quantity_returned) # self.store.fetch: used to bring the objet to this store. yield self.store.fetch(item)