def create_model(self, store): tax_constant = SellableTaxConstant.get_by_type(TaxType.SERVICE, self.store) sellable = Sellable(description=u'', price=currency(0), store=store) sellable.tax_constant = tax_constant sellable.unit_id = sysparam.get_object_id('SUGGESTED_UNIT') model = Service(sellable=sellable, store=store) return model
def _set_delivery_default(self, store): if self.has_object("DELIVERY_SERVICE"): return from stoqlib.domain.sellable import (Sellable, SellableTaxConstant) from stoqlib.domain.service import Service tax_constant = SellableTaxConstant.get_by_type(TaxType.SERVICE, store) sellable = Sellable(store=store, description=_(u'Delivery')) sellable.tax_constant = tax_constant service = Service(sellable=sellable, store=store) self.set_object(store, "DELIVERY_SERVICE", service)
def create_service(self, description=u'Description', price=10): from stoqlib.domain.sellable import Sellable, SellableTaxConstant from stoqlib.domain.service import Service tax_constant = SellableTaxConstant.get_by_type(TaxType.SERVICE, self.store) sellable = Sellable(price=price, description=description, store=self.store) sellable.tax_constant = tax_constant service = Service(sellable=sellable, store=self.store) return service
def process_one(self, data, fields, store): tax = store.fetch(self.tax_constant) sellable = Sellable(store=store, description=data.description, price=int(data.price), cost=int(data.cost)) sellable.tax_constant = tax sellable.code = data.barcode sellable.barcode = data.barcode Service(sellable=sellable, store=store)
def create_delivery_service(self): from stoqlib.domain.sellable import (Sellable, SellableTaxConstant) from stoqlib.domain.service import Service key = u"DELIVERY_SERVICE" store = new_store() tax_constant = SellableTaxConstant.get_by_type(TaxType.SERVICE, store) sellable = Sellable(description=_(u'Delivery'), store=store) sellable.tax_constant = tax_constant service = Service(sellable=sellable, store=store) self._set_schema(key, service.id) store.commit(close=True)
def create_sellable(self, price=None, product=True, description=u'Description'): from stoqlib.domain.product import Product from stoqlib.domain.service import Service from stoqlib.domain.sellable import Sellable tax_constant = sysparam(self.store).DEFAULT_PRODUCT_TAX_CONSTANT if price is None: price = 10 sellable = Sellable(cost=125, price=price, description=description, store=self.store) sellable.tax_constant = tax_constant if product: Product(sellable=sellable, store=self.store) else: Service(sellable=sellable, store=self.store) return sellable
def _add_service(self, pos, sellable): service = Service(sellable=sellable, store=self.store) self._add_product(pos, sellable) return service
def test_events(self): store_list = [] p_data = _ServiceEventData() ServiceCreateEvent.connect(p_data.on_create) ServiceEditEvent.connect(p_data.on_edit) ServiceRemoveEvent.connect(p_data.on_delete) try: # Test service being created store = new_store() store_list.append(store) sellable = Sellable( store=store, description=u'Test 1234', price=decimal.Decimal(2), ) service = Service( store=store, sellable=sellable, ) store.commit() self.assertTrue(p_data.was_created) self.assertFalse(p_data.was_edited) self.assertFalse(p_data.was_deleted) self.assertEqual(p_data.service, service) p_data.reset() # Test service being edited and emmiting the event just once store = new_store() store_list.append(store) sellable = store.fetch(sellable) service = store.fetch(service) sellable.notes = u'Notes' sellable.description = u'Test 666' service.weight = decimal.Decimal(10) store.commit() self.assertTrue(p_data.was_edited) self.assertFalse(p_data.was_created) self.assertFalse(p_data.was_deleted) self.assertEqual(p_data.service, service) self.assertEqual(p_data.emit_count, 1) p_data.reset() # Test service being edited, editing Sellable store = new_store() store_list.append(store) sellable = store.fetch(sellable) service = store.fetch(service) sellable.notes = u'Notes for test' store.commit() self.assertTrue(p_data.was_edited) self.assertFalse(p_data.was_created) self.assertFalse(p_data.was_deleted) self.assertEqual(p_data.service, service) self.assertEqual(p_data.emit_count, 1) p_data.reset() finally: # Test service being removed store = new_store() store_list.append(store) sellable = store.fetch(sellable) service = store.fetch(service) sellable.remove() store.commit() self.assertTrue(p_data.was_deleted) self.assertFalse(p_data.was_created) self.assertFalse(p_data.was_edited) self.assertEqual(p_data.service, service) self.assertEqual(p_data.emit_count, 1) p_data.reset() for store in store_list: store.close()
def get_editor_model(self, model): return Service.get(model.service_id, store=self.store)