class WorkOrderCategory(Domain): """A |workorder|'s category Used to categorize a |workorder|. It can be differentiate mainly by the :attr:`.name`, but one can use :obj:`color` in a gui to make the differentiation better. See also: `schema <http://doc.stoq.com.br/schema/tables/work_order_category.html>`__ """ __storm_table__ = 'work_order_category' implements(IDescribable) #: category's name name = UnicodeCol() #: category's color (e.g. #ff0000 for red) color = UnicodeCol() # # IDescribable # def get_description(self): return self.name
class InvoiceField(Domain): """Represents a field in an InvoiceLayout. """ __storm_table__ = 'invoice_field' #: x position of the upper left corner of the field x = IntCol() #: y position of the upper left corner of the field y = IntCol() #: the width of the field, must be larger than 0 width = IntCol() #: the height of the field, must be larger than 0 height = IntCol() #: the name of the field, this is used to identify #: and fetch the data when printing the invoice field_name = UnicodeCol() #: the free text of the field content = UnicodeCol(default=u'') #: the layout this field belongs to layout_id = IdCol() layout = Reference(layout_id, 'InvoiceLayout.id')
class UIForm(Domain): """This describes a form which has a number of fields""" __storm_table__ = 'ui_form' form_name = UnicodeCol() description = UnicodeCol() _field_cache = {} def _build_field_cache(self): # Instead of making one query for each field, let's build a cache for # all fields at once. If there's no cache built yet, builds it. if self._field_cache: return default_store = get_default_store() for field in default_store.find(UIField): self._field_cache[(field.ui_form_id, field.field_name)] = field def get_field(self, field_name): """Returns a |uifield| from |uiform| :param field_name: name of a UIField :returns: the |uifield| of that field_name """ self._build_field_cache() return self._field_cache.get((self.id, field_name))
class CityLocation(ORMObject): __storm_table__ = 'city_location' id = IntCol(primary=True) country = UnicodeCol(default=u"") city = UnicodeCol(default=u"") state = UnicodeCol(default=u"")
class BankAccount(Domain): """Information specific to a bank See also: `schema <http://doc.stoq.com.br/schema/tables/bank_account.html>`__ """ __storm_table__ = 'bank_account' account_id = IdCol() #: the |account| for this bank account account = Reference(account_id, 'Account.id') # FIXME: This is brazil specific, should probably be replaced by a # bank reference to a separate class with name in addition to # the bank number #: an identify for the bank type of this account, bank_number = IntCol(default=0) #: an identifier for the bank branch/agency which is responsible #: for this bank_branch = UnicodeCol(default=None) #: an identifier for this bank account bank_account = UnicodeCol(default=None) @property def options(self): """Get the bill options for this bank account :returns: a list of :class:`BillOption` """ return self.store.find(BillOption, bank_account=self)
class ProductBranchOverride(Domain): __storm_table__ = 'product_branch_override' location = UnicodeCol() icms_template_id = IdCol() icms_template = Reference(icms_template_id, 'ProductIcmsTemplate.id') ipi_template_id = IdCol() ipi_template = Reference(ipi_template_id, 'ProductIpiTemplate.id') pis_template_id = IdCol() pis_template = Reference(pis_template_id, 'ProductPisTemplate.id') cofins_template_id = IdCol() cofins_template = Reference(cofins_template_id, 'ProductCofinsTemplate.id') branch_id = IdCol() branch = Reference(branch_id, 'Branch.id') product_id = IdCol() product = Reference(product_id, 'Product.id') #: Brazil specific. NFE. Código Benefício Fiscal c_benef = UnicodeCol(default=None) @classmethod def find_product(cls, branch: Branch, product): return product.store.find(cls, product=product, branch=branch).one()
class ParameterData(Domain): """ Class to store system parameters. See also: `schema <http://doc.stoq.com.br/schema/tables/parameter_data.html>`__ """ __storm_table__ = 'parameter_data' #: name of the parameter we want to query on field_name = UnicodeCol() #: current result(or value) of this parameter field_value = UnicodeCol() #: the item can't be edited through an editor. is_editable = BoolCol() def get_group(self): from stoqlib.lib.parameters import sysparam return sysparam.get_detail_by_name(self.field_name).group def get_short_description(self): from stoqlib.lib.parameters import sysparam return sysparam.get_detail_by_name(self.field_name).short_desc def get_field_value(self): # FIXME: This is a workaround to handle some parameters which are # locale specific. if self.field_value: return _(self.field_value) return self.field_value
class PluginEgg(Domain): """A cache for plugins eggs""" __storm_table__ = 'plugin_egg' plugin_name = UnicodeCol() egg_content = BLOBCol(default=None) egg_md5sum = UnicodeCol(default=None)
class CreditProvider(Domain): """A credit provider This is the institution that provides the credit to the client, for instance: American Express, Visanet, Redecard, etc... """ __storm_table__ = 'credit_provider' #: A short description of this provider short_name = UnicodeCol() #: An identification for this provider provider_id = UnicodeCol(default=u'') #: the maximum number of installments for a |sale| using this credit provider. max_installments = IntCol(default=1) default_device_id = IdCol() #: The default device for this credit provider. This will be suggested to #: the user when he selects this provider in the checkout dialog default_device = Reference(default_device_id, 'CardPaymentDevice.id') #: The date when we start working with this provider open_contract_date = DateTimeCol() # # IDescribable # def get_description(self): return self.short_name # # Public API # @classmethod def get_provider_by_provider_id(cls, provider_id, store): """Get a provider given a provider id string :param provider_id: a string representing the provider :param store: a database store """ return store.find(cls, provider_id=provider_id) @classmethod def get_card_providers(cls, store): """Get a list of all credit card providers. :param store: a database store """ return store.find(cls) @classmethod def has_card_provider(cls, store): """Find out if there is a card provider :param store: a database store :returns: if there is a card provider """ return bool(store.find(cls).count())
class UIField(Domain): __storm_table__ = 'ui_field' ui_form_id = IntCol() ui_form = Reference(ui_form_id, UIForm.id) field_name = UnicodeCol() description = UnicodeCol() visible = BoolCol() mandatory = BoolCol()
class UIForm(Domain): __storm_table__ = 'ui_form' form_name = UnicodeCol() description = UnicodeCol() def get_field(self, field_name): store = self.store return store.find(UIField, field_name=field_name, ui_form=self).one()
class NFeSupplier(Domain): __storm_table__ = 'nfe_supplier' #: The CNPJ of the supplier cnpj = UnicodeCol(default=u"") #: The real name of the supplier name = UnicodeCol(default=u"") #: The fancy name of the supplier fancy_name = UnicodeCol(default=u"") #: Postal code postal_code = UnicodeCol(default=u"") #: Address commplement (ex: ap 22) complement = UnicodeCol(default=u"") #: The supplier district district = UnicodeCol(default=u"") #: The street/avenue name street = UnicodeCol(default=u"") #: Primary phone phone_number = UnicodeCol(default=u"") #: Street number street_number = IntCol() #: Municipal registry if have both product and service in the same invoice municipal_registry = UnicodeCol(default=u"") #: IBGE's State Code is national 2 digit registry (ex: 29 = Bahia) state_registry = UnicodeCol(default=u"") #: IBGE's City Code is national 7 digit registry (ex: 2927408 = Salvador) city_code = IntCol() #: Stoq supplier id supplier_id = IdCol() #: Stoq supplier reference supplier = Reference(supplier_id, "Supplier.id") @property def state(self): city_location = self.store.find(CityLocation, city_code=self.city_code).one() return city_location.state @property def country(self): city_location = self.store.find(CityLocation, city_code=self.city_code).one() return city_location.country
class OpticalPatientVisualAcuity(Domain): __storm_table__ = 'optical_patient_visual_acuity' create_date = DateTimeCol(default_factory=StatementTimestamp) client_id = IdCol(allow_none=False) #: The related client client = Reference(client_id, 'Client.id') responsible_id = IdCol(allow_none=False) #: The user that registred this information responsible = Reference(responsible_id, 'LoginUser.id') be_distance_glasses = UnicodeCol() le_distance_glasses = UnicodeCol() re_distance_glasses = UnicodeCol() be_distance_lenses = UnicodeCol() le_distance_lenses = UnicodeCol() re_distance_lenses = UnicodeCol() be_near_glasses = UnicodeCol() be_near_lenses = UnicodeCol() #: Free notes notes = UnicodeCol() @property def responsible_name(self): return self.responsible.get_description()
class UIForm(Domain): """This describes a form which has a number of fields""" __storm_table__ = 'ui_form' form_name = UnicodeCol() description = UnicodeCol() fields = Reference('id', 'UIField.ui_form_id', on_remote=True) def get_field(self, field_name): store = self.store return store.find(UIField, field_name=field_name, ui_form=self).one()
class PaymentMethod(Domain): __storm_table__ = 'payment_method' method_name = UnicodeCol() is_active = BoolCol(default=True) description = UnicodeCol() daily_penalty = PercentCol(default=0) interest = PercentCol(default=0) payment_day = IntCol(default=None) closing_day = IntCol(default=None) max_installments = IntCol(default=1) destination_account_id = IntCol()
class UIField(Domain): """This describes a field in form a. Can be used makae fields mandatory or hide them completely. """ __storm_table__ = 'ui_field' ui_form_id = IdCol() ui_form = Reference(ui_form_id, 'UIForm.id') field_name = UnicodeCol() description = UnicodeCol() visible = BoolCol() mandatory = BoolCol()
class ServiceBranchOverride(Domain): __storm_table__ = 'service_branch_override' city_taxation_code = UnicodeCol() service_list_item_code = UnicodeCol() p_iss = PercentCol() branch_id = IdCol() branch = Reference(branch_id, 'Branch.id') service_id = IdCol() service = Reference(service_id, 'Service.id')
class CreditProvider(Domain): """A credit provider This is the institution that provides the credit to the client, for instance: American Express, Visanet, Redecard, etc... """ __storm_table__ = 'credit_provider' implements(IDescribable) #: A short description of this provider short_name = UnicodeCol() #: An identification for this provider provider_id = UnicodeCol(default=u'') #: The date when we start working with this provider open_contract_date = DateTimeCol() # # IDescribable # def get_description(self): return self.short_name # # Public API # @classmethod def get_provider_by_provider_id(cls, provider_id, store): """Get a provider given a provider id string :param provider_id: a string representing the provider :param store: a database store """ return store.find(cls, provider_id=provider_id) @classmethod def get_card_providers(cls, store): """Get a list of all credit card providers. :param store: a database store """ return store.find(cls) @classmethod def has_card_provider(cls, store): """Find out if there is a card provider :param store: a database store :returns: if there is a card provider """ return bool(store.find(cls).count())
class Address(Domain): __storm_table__ = 'address' street = UnicodeCol(default=u'') streetnumber = IntCol(default=None) district = UnicodeCol(default=u'') postal_code = UnicodeCol(default=u'') complement = UnicodeCol(default=u'') is_main_address = BoolCol(default=False) person_id = IntCol() person = Reference(person_id, Person.id) city_location_id = IntCol() city_location = Reference(city_location_id, CityLocation.id)
class StorableBatch(Domain): """Batch information for storables. A batch is a colection of products (storable) that were produced at the same time and thus they have some common information, such as expiration date. This information is useful since sometimes its necessary to make decisions based on the batch like a special promotion for older batches (if it is close to the expiration date, for instance) or if a batch is somehow defective and we need to contact the clients that purchased items from this batch. """ __storm_table__ = 'storable_batch' #: The sequence number for this batch. Should be unique for a given #: storable batch_number = UnicodeCol(allow_none=False) #: The date this batch was created create_date = DateTimeCol(default_factory=localnow) #: An expiration date, specially for perishable products, like milk and food in #: general expire_date = DateTimeCol() #: Some space for the users to add notes to this batch. notes = UnicodeCol() storable_id = IdCol(allow_none=False) #: The storable that is in this batch storable = Reference(storable_id, 'Storable.id') def get_balance_for_branch(self, branch): """Return the stock balance for this |batch| in a |branch|. :param branch: the |branch| to get the stock balance for :returns: the amount of stock available in the |branch| """ store = self.store stock_items = store.find(ProductStockItem, storable=self.storable, batch=self, branch=branch) return stock_items.sum(ProductStockItem.quantity) or Decimal(0) # # IDescribable # def get_description(self): return self.batch_number
class BaseIPI(BaseTax): (CALC_ALIQUOTA, CALC_UNIDADE) = range(2) cl_enq = UnicodeCol(default=u'') cnpj_prod = UnicodeCol(default=u'') c_selo = UnicodeCol(default=u'') q_selo = IntCol(default=None) c_enq = UnicodeCol(default=u'') cst = IntCol(default=None) p_ipi = PercentCol(default=None) q_unid = QuantityCol(default=None) calculo = IntCol(default=CALC_ALIQUOTA)
class SellableTaxConstant(Domain): """A tax constant tied to a sellable """ implements(IDescribable) __storm_table__ = 'sellable_tax_constant' description = UnicodeCol() tax_type = IntCol() tax_value = PercentCol(default=None) _mapping = { int(TaxType.NONE): u'TAX_NONE', # Não tributado - ICMS int(TaxType.EXEMPTION): u'TAX_EXEMPTION', # Isento - ICMS int(TaxType.SUBSTITUTION): u'TAX_SUBSTITUTION', # Substituição tributária - ICMS int(TaxType.SERVICE): u'TAX_SERVICE', # ISS } def get_value(self): return SellableTaxConstant._mapping.get(self.tax_type, self.tax_value) @classmethod def get_by_type(cls, tax_type, store): """Fetch the tax constant for tax_type :param tax_type: the tax constant to fetch :param store: a store :returns: a |sellabletaxconstant| or ``None`` if none is found """ return store.find(SellableTaxConstant, tax_type=int(tax_type)).one() # IDescribable def get_description(self): return self.description
class _TestModel(Domain): __storm_table__ = '_test_model' unicode_var = UnicodeCol() def get_description(self): return self.unicode_var
class ProductTaxTemplate(Domain): TYPE_ICMS = u'icms' TYPE_IPI = u'ipi' TYPE_PIS = u'pis' TYPE_COFINS = u'cofins' __storm_table__ = 'product_tax_template' types = collections.OrderedDict([ (TYPE_ICMS, u"ICMS"), (TYPE_IPI, u"IPI"), (TYPE_PIS, u"PIS"), (TYPE_COFINS, u"COFINS"), ]) type_map = {TYPE_ICMS: ProductIcmsTemplate, TYPE_IPI: ProductIpiTemplate, TYPE_PIS: ProductPisTemplate, TYPE_COFINS: ProductCofinsTemplate} name = UnicodeCol(default=u'') tax_type = EnumCol(default=TYPE_ICMS, allow_none=False) def get_tax_model(self): klass = self.type_map[self.tax_type] store = self.store return store.find(klass, product_tax_template=self).one() def get_tax_type_str(self): return self.types[self.tax_type]
class BaseIPI(BaseTax): CALC_ALIQUOTA = u'aliquot' CALC_UNIDADE = u'unit' cl_enq = UnicodeCol(default=u'') cnpj_prod = UnicodeCol(default=u'') c_selo = UnicodeCol(default=u'') q_selo = IntCol(default=None) c_enq = UnicodeCol(default=u'') cst = IntCol(default=None) p_ipi = PercentCol(default=None) q_unid = QuantityCol(default=None) calculo = EnumCol(default=CALC_ALIQUOTA, allow_none=False)
class ProductManufacturer(Domain): """Product manufacturer. See also: `schema <http://doc.stoq.com.br/schema/tables/product_manufacturer.html>`__ """ __storm_table__ = 'product_manufacturer' #: manufacturer's name name = UnicodeCol() # # IDescribable # def get_description(self): return self.name def can_remove(self): """ Check if the manufacturer is used in some product.""" return not self.store.find(Product, manufacturer=self).count() def remove(self): """Remove this registry from the database.""" self.store.remove(self)
class PaymentChangeHistory(Domain): """ A class to hold information about changes to a payment. Only one tuple (last_due_date, new_due_date) or (last_status, new_status) should be non-null at a time. See also: `schema <http://doc.stoq.com.br/schema/tables/payment_change_history.html>`__ """ __storm_table__ = 'payment_change_history' payment_id = IdCol() #: the changed |payment| payment = Reference(payment_id, 'Payment.id') #: the reason of the change change_reason = UnicodeCol(default=None) #: when the changed happened change_date = DateTimeCol(default_factory=localnow) #: the due date that was set before the changed last_due_date = DateTimeCol(default=None) #: the due date that was set after changed new_due_date = DateTimeCol(default=None) #: status before the change last_status = EnumCol(allow_none=False, default=Payment.STATUS_PREVIEW) #: status after change new_status = EnumCol(allow_none=False, default=Payment.STATUS_PREVIEW)
class ProductBranchOverride(Domain): __storm_table__ = 'product_branch_override' location = UnicodeCol() icms_template_id = IdCol() icms_template = Reference(icms_template_id, 'ProductIcmsTemplate.id') ipi_template_id = IdCol() ipi_template = Reference(ipi_template_id, 'ProductIpiTemplate.id') pis_template_id = IdCol() pis_template = Reference(pis_template_id, 'ProductPisTemplate.id') cofins_template_id = IdCol() cofins_template = Reference(cofins_template_id, 'ProductCofinsTemplate.id') branch_id = IdCol() branch = Reference(branch_id, 'Branch.id') product_id = IdCol() product = Reference(product_id, 'Product.id') @classmethod def find_product(cls, product): branch = get_current_branch(product.store) return product.store.find(cls, product=product, branch=branch).one()
class SaleComment(Domain): __storm_table__ = 'sale_comment' date = DateTimeCol(default_factory=localnow) comment = UnicodeCol() author_id = IdCol() sale_id = IdCol()
class ParameterData(Domain): """ Class to store system parameters. See also: `schema <http://doc.stoq.com.br/schema/tables/parameter_data.html>`__ """ __storm_table__ = 'parameter_data' #: name of the parameter we want to query on field_name = UnicodeCol() #: current result(or value) of this parameter field_value = UnicodeCol() #: the item can't be edited through an editor. is_editable = BoolCol()