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 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 test_settable(): obj = Settable(foo=1, bar=2) assert obj.foo == 1 assert obj.bar == 2 obj.foo = 10 obj.bar = 20 obj.baz = 30 assert obj.foo == 10 assert obj.bar == 20 assert obj.baz == 30
def test_settable(): obj = Settable(foo=1, bar=2) assert "foo=1" in repr(obj) assert "bar=2" in repr(obj) assert obj.foo == 1 assert obj.bar == 2 obj.foo = 10 obj.bar = 20 obj.baz = 30 assert obj.foo == 10 assert obj.bar == 20 assert obj.baz == 30
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 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 # This was already removed from stock, so we need to ignore it. if hasattr(i, 'quantity_decreased'): quantities[sellable] -= i.quantity_decreased 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_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.assertEqual(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.assertEqual(self.store.find(ProductionOrder).count(), 1) production = self.store.find(ProductionOrder).any() self.assertEqual(production.get_items().count(), 1) self.assertEqual(production.get_items()[0].product, product) self.assertEqual(production.get_items()[0].quantity, 15)
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 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, True, True, 0) 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(), True, True, 0) # FIXME: redesign BasicDialog self.main.remove(self.main_label) self.main.add(hbox) hbox.show_all()
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 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 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_validate_confirm(self): editor = BackupSettingsEditor(self.store, Settable(key='123456')) with mock.patch('stoq.lib.gui.editors.backupsettings.yesno') as yesno: self.assertTrue(editor.validate_confirm()) self.assertNotCalled(yesno) with mock.patch('stoq.lib.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('stoq.lib.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 _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.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 _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 _create_model(self, purchase): paid_value = currency(purchase.payments.sum(Payment.paid_value) or 0) received_value = purchase.received_total return Settable(received_value=received_value, paid_value=paid_value, missing_value=currency(received_value - paid_value), purchase=purchase)
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): 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 _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 _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 create_model(self, store): item = None # If there is only one item, select it. if len(self.items) == 1: item = self.items[0][1] return Settable(supplier=None, supplier_order="", item=item, is_freebie=False)
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 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'), sellable=sellable)
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 insert_initial(self, store, edited_account=None): """ Insert accounts and parent accounts in a ObjectTree. :param store: a store :param edited_account: If not None, this is the account being edited. In this case, this acount (and its decendents) will not be shown in the account tree. """ till_id = sysparam.get_object_id('TILLS_ACCOUNT') if self.create_mode and edited_account: accounts = list( store.find(AccountView, AccountView.id != edited_account.id)) else: accounts = list(store.find(AccountView)) accounts = self._orderaccounts(accounts) for account in accounts: account.total = self._calculate_total(accounts, account) if self.create_mode and account.matches(till_id): account.selectable = False self.add_account(account.parent_id, account) selectable = not self.create_mode # Tabs cache requires unique ids self.append( None, Settable(description=_("Accounts Payable"), id=-1, parent=None, kind='payable', selectable=selectable, total=None)) self.append( None, Settable(description=_("Accounts Receivable"), id=-2, parent=None, kind='receivable', selectable=selectable, total=None)) self.flush()
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)
def create_model(self, store): till = Till.get_current(self.store, api.get_current_station(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 setup_proxies(self): self.authentication_type.prefill([(_("Needs Password"), PASSWORD_AUTHENTICATION), (_("Trust"), TRUST_AUTHENTICATION)]) self.add_proxy(self.model, DatabaseSettingsStep.proxy_widgets) # Show localhost instead of empty for unix socket, not strictly # correct but better than showing nothing. if not self.model.address: self.address.set_text("localhost") self.model.stoq_user_data = Settable(password='') self.add_proxy(self.model.stoq_user_data)
def __init__(self, wizard, previous, store, model): super(LoanItemSelectionStep, self).__init__(wizard, previous, store, model) for loan in model: for item in loan.loaned_items: self.wizard.original_items[item] = Settable( quantity=item.quantity, sale_quantity=item.sale_quantity, return_quantity=item.return_quantity, remaining_quantity=item.get_remaining_quantity(), ) LoanItemSelectionStepEvent.emit(self)