Exemplo n.º 1
0
class BaseICMS(BaseTax):
    """NfeProductIcms stores the default values that will be used when
    creating NfeItemIcms objects
    """

    # FIXME: this is only used by pylint
    __storm_table__ = 'invalid'

    orig = IntCol(default=None)
    cst = IntCol(default=None)

    mod_bc = IntCol(default=None)
    p_icms = PercentCol(default=None)

    mod_bc_st = IntCol(default=None)
    p_mva_st = PercentCol(default=None)
    p_red_bc_st = PercentCol(default=None)
    p_icms_st = PercentCol(default=None)
    p_red_bc = PercentCol(default=None)

    bc_include_ipi = BoolCol(default=True)
    bc_st_include_ipi = BoolCol(default=True)

    # Simples Nacional
    csosn = IntCol(default=None)
    p_cred_sn = PercentCol(default=None)
Exemplo n.º 2
0
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 layout this field belongs to
    layout_id = IntCol()
    layout = Reference(layout_id, 'InvoiceLayout.id')
Exemplo n.º 3
0
class CommissionSource(Domain):
    """Commission Source object implementation

    A CommissionSource is tied to a |sellablecategory| or |sellable|,
    it's used to determine the value of a commission for a certain
    item which is sold.
    There are two different commission values defined here, one
    which is used when the item is sold directly, eg one installment
    and another one which is used when the item is sold in installments.

    The category and the sellable should not exist when sellable exists
    and the opposite is true.

    See also:
    `schema <http://doc.stoq.com.br/schema/tables/commission_source.html>`__,
    """

    __storm_table__ = 'commission_source'

    #: the commission value to be used in a |sale| with one installment
    direct_value = PercentCol()

    #: the commission value to be used in a |sale| with multiple installments
    installments_value = PercentCol()

    category_id = IntCol(default=None)

    #: the |sellablecategory|
    category = Reference(category_id, 'SellableCategory.id')

    sellable_id = IntCol(default=None)

    #: the |sellable|
    sellable = Reference(sellable_id, 'Sellable.id')
Exemplo n.º 4
0
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 = IntCol(default=None)

    #: status after change
    new_status = IntCol(default=None)
Exemplo n.º 5
0
class TransferOrderItem(Domain):
    """Transfer order item

    """

    __storm_table__ = 'transfer_order_item'

    sellable_id = IntCol()

    # FIXME: This should be a product, since it does not make sense to transfer
    # serviçes
    #: The |sellable| to transfer
    sellable = Reference(sellable_id, 'Sellable.id')

    batch_id = IntCol()

    #: If the sellable is a storable, the |batch| that was transfered
    batch = Reference(batch_id, 'StorableBatch.id')

    transfer_order_id = IntCol()

    #: The |transfer| this item belongs to
    transfer_order = Reference(transfer_order_id, 'TransferOrder.id')

    #: The quantity to transfer
    quantity = QuantityCol()

    #
    # Public API
    #

    def get_total(self):
        """Returns the total cost of a transfer item eg quantity * cost"""
        return self.quantity * self.sellable.cost

    def send(self):
        """Sends this item to it's destination |branch|"""
        assert self.transfer_order.can_close()

        storable = self.sellable.product_storable
        storable.decrease_stock(self.quantity,
                                self.transfer_order.source_branch,
                                StockTransactionHistory.TYPE_TRANSFER_TO,
                                self.id)
        ProductHistory.add_transfered_item(self.store,
                                           self.transfer_order.source_branch,
                                           self)

    def receive(self):
        """Receives this item, increasing the quantity in the stock
        """
        storable = self.sellable.product_storable
        from_stock = storable.get_stock_item(self.transfer_order.source_branch,
                                             self.batch)
        storable.increase_stock(self.quantity,
                                self.transfer_order.destination_branch,
                                StockTransactionHistory.TYPE_TRANSFER_FROM,
                                self.id,
                                unit_cost=from_stock.stock_cost,
                                batch=self.batch)
Exemplo n.º 6
0
class ProductionService(Domain):
    """Production Service object implementation.

    :attribute order: The :class:`ProductionOrder` of this service.
    :attribute service: The service that will be used by the production.
    :attribute quantity: The service's quantity.
    """
    implements(IDescribable)

    __storm_table__ = 'production_service'

    service_id = IntCol()
    service = Reference(service_id, 'Service.id')
    order_id = IntCol()
    order = Reference(order_id, 'ProductionOrder.id')
    quantity = QuantityCol(default=1)

    #
    # IDescribable Implementation
    #

    def get_description(self):
        return self.service.sellable.get_description()

    # Accessors

    def get_unit_description(self):
        return self.service.sellable.get_unit_description()
Exemplo n.º 7
0
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 = IntCol()

    #: 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)
Exemplo n.º 8
0
class TransactionEntry(ORMObject):
    """
    A TransactionEntry keeps track of state associated with a database
    transaction. It's main use case is to know information about the system when
    a domain object is created or modified.

    Such information will be used by stoq when syncing databases
    """
    __storm_table__ = 'transaction_entry'

    id = IntCol(primary=True, default=AutoReload)

    #: last time this object was modified
    te_time = DateTimeCol(allow_none=False)

    #: id of the last |loginuser| that modified this object
    user_id = IntCol(default=None)

    #: id of the last |branchstation| this object was modified on
    station_id = IntCol(default=None)

    #: It this object was modified since the last time it was synced
    #: After the object is synced, this property will be set to ``False``, so
    #: that when the next sync begins, only the objects that are **dirty** will be
    #: processed
    dirty = BoolCol(default=True)
Exemplo n.º 9
0
class SaleItem(Domain):
    __storm_table__ = 'sale_item'

    sale_id = IntCol()
    sale = Reference(sale_id, Sale.id)
    sellable_id = IntCol()
    sellable = Reference(sellable_id, Sellable.id)
Exemplo n.º 10
0
class Domain(ORMObject):
    __storm_table__ = 'invalid'

    id = IntCol(primary=True, default=AutoReload)

    te_id = IntCol(default=None)
    te = Reference(te_id, 'TransactionEntry.id')

    def __init__(self, *args, **kwargs):
        self._listen_to_events()
        self._creating = True
        ORMObject.__init__(self, *args, **kwargs)
        self._creating = False

    def __repr__(self):
        return '<%s %r>' % (self.__class__.__name__, self.id)

    def __storm_loaded__(self):
        self._listen_to_events()
        self._creating = False

    # Private

    def _listen_to_events(self):
        event = get_obj_info(self).event
        event.hook('added', self._on_object_added)
        event.hook('changed', self._on_object_changed)
        event.hook('removed', self._on_object_removed)

    def _on_object_changed(self, obj_info, variable, old_value, new_value,
                           fromdb):
        if new_value is not AutoReload and not fromdb:
            if self._creating:
                return
            store = obj_info.get("store")
            store.add_modified_object(self)

    def _on_object_added(self, obj_info):
        store = obj_info.get("store")

        self.te = TransactionEntry(store=store,
                                   te_time=StatementTimestamp(),
                                   user_id=None,
                                   station_id=None)

        store.add_created_object(self)

    def _on_object_removed(self, obj_info):
        store = obj_info.get("store")
        store.add_deleted_object(self)

    def on_create(self):
        pass

    def on_update(self):
        pass

    def on_delete(self):
        pass
Exemplo n.º 11
0
class CityLocation(ORMObject):
    __storm_table__ = 'city_location'
    id = IntCol(primary=True)
    country = UnicodeCol(default=u"")
    city = UnicodeCol(default=u"")
    state = UnicodeCol(default=u"")
    city_code = IntCol(default=None)
    state_code = IntCol(default=None)
Exemplo n.º 12
0
class ReturnedSaleItem(Domain):
    __storm_table__ = 'returned_sale_item'
    quantity = QuantityCol(default=0)
    price = PriceCol()
    sale_item_id = IntCol()
    sale_item = Reference(sale_item_id, SaleItem.id)
    sellable_id = IntCol()
    returned_sale_id = IntCol()
Exemplo n.º 13
0
class StockDecreaseItem(Domain):
    """An item in a stock decrease object.

    Note that objects of this type should not be created manually, only by
    calling :meth:`StockDecrease.add_sellable`
    """

    __storm_table__ = 'stock_decrease_item'

    stock_decrease_id = IntCol(default=None)

    #: The stock decrease this item belongs to
    stock_decrease = Reference(stock_decrease_id, 'StockDecrease.id')

    sellable_id = IntCol()

    #: the |sellable| for this decrease
    sellable = Reference(sellable_id, 'Sellable.id')

    batch_id = IntCol()

    #: If the sellable is a storable, the |batch| that it was removed from
    batch = Reference(batch_id, 'StorableBatch.id')

    #: the cost of the |sellable| on the moment this decrease was created
    cost = PriceCol(default=0)

    #: the quantity decreased for this item
    quantity = QuantityCol()

    def __init__(self, store=None, **kw):
        if not 'kw' in kw:
            if not 'sellable' in kw:
                raise TypeError('You must provide a sellable argument')
        Domain.__init__(self, store=store, **kw)

    def decrease(self, branch):
        assert branch

        storable = self.sellable.product_storable
        if storable:
            storable.decrease_stock(self.quantity, branch,
                                    StockTransactionHistory.TYPE_STOCK_DECREASE,
                                    self.id,
                                    cost_center=self.stock_decrease.cost_center)

    #
    # Accessors
    #

    def get_total(self):
        return currency(self.cost * self.quantity)

    def get_quantity_unit_string(self):
        return u"%s %s" % (self.quantity, self.sellable.get_unit_description())

    def get_description(self):
        return self.sellable.get_description()
Exemplo n.º 14
0
class TransactionEntry(ORMObject):
    __storm_table__ = 'transaction_entry'

    id = IntCol(primary=True, default=AutoReload)

    te_time = DateTimeCol(allow_none=False)
    user_id = IntCol(default=None)
    station_id = IntCol(default=None)
    dirty = BoolCol(default=True)
Exemplo n.º 15
0
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
Exemplo n.º 16
0
class TransactionEntry(ORMObject):
    __storm_table__ = 'transaction_entry'

    (CREATED, MODIFIED) = range(2)

    id = IntCol(primary=True)
    te_time = DateTimeCol(allow_none=False)
    user_id = IntCol(default=None)
    station_id = IntCol(default=None)
    type = IntCol()
Exemplo n.º 17
0
class PaymentMethod(Domain):
    __storm_table__ = 'payment_method'
    method_name = UnicodeCol()
    is_active = BoolCol(default=True)
    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()
Exemplo n.º 18
0
class StockTransactionHistory(Domain):
    __storm_table__ = 'stock_transaction_history'

    TYPE_IMPORTED = 15
    product_stock_item_id = IntCol()
    stock_cost = PriceCol()
    quantity = QuantityCol()
    responsible_id = IntCol()
    date = DateTimeCol()
    object_id = IntCol()
    type = IntCol()
Exemplo n.º 19
0
class FiscalSaleHistory(Domain):
    """Holds fiscal information about the sales.
    """
    (TYPE_CPF, TYPE_CNPJ) = range(2)

    __storm_table__ = 'fiscal_sale_history'

    document_type = IntCol(default=TYPE_CPF)
    document = UnicodeCol(default=None)
    sale_id = IdCol()
    sale = Reference(sale_id, 'Sale.id')
    coo = IntCol(default=0)
    document_counter = IntCol(default=0)
Exemplo n.º 20
0
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)
Exemplo n.º 21
0
class Sale(Domain):
    __storm_table__ = 'sale'

    close_date = DateTimeCol()
    confirm_date = DateTimeCol()

    client_id = IntCol()
    client = Reference(client_id, Client.id)
    transporter_id = IntCol()
    transporter = Reference(transporter_id, Transporter.id)

    def get_items(self):
        return self.store.find(SaleItem, sale=self).order_by(SaleItem.id)
Exemplo n.º 22
0
class ProductionItemQualityResult(Domain):
    """This table stores the test results for every produced item.
    """

    implements(IDescribable)

    __storm_table__ = 'production_item_quality_result'

    produced_item_id = IntCol()
    produced_item = Reference(produced_item_id, 'ProductionProducedItem.id')
    quality_test_id = IntCol()
    quality_test = Reference(quality_test_id, 'ProductQualityTest.id')
    tested_by_id = IntCol()
    tested_by = Reference(tested_by_id, 'LoginUser.id')
    tested_date = DateTimeCol(default=None)
    result_value = UnicodeCol()
    test_passed = BoolCol(default=False)

    def get_description(self):
        return self.quality_test.description

    @property
    def result_value_str(self):
        return _(self.result_value)

    def get_boolean_value(self):
        if self.result_value == u'True':
            return True
        elif self.result_value == u'False':
            return False
        else:
            raise ValueError

    def get_decimal_value(self):
        return Decimal(self.result_value)

    def set_value(self, value):
        if isinstance(value, bool):
            self.set_boolean_value(value)
        else:
            self.set_decimal_value(value)

    def set_boolean_value(self, value):
        self.test_passed = self.quality_test.result_value_passes(value)
        self.result_value = unicode(value)
        self.produced_item.check_tests()

    def set_decimal_value(self, value):
        self.test_passed = self.quality_test.result_value_passes(value)
        self.result_value = u'%s' % (value, )
        self.produced_item.check_tests()
Exemplo n.º 23
0
class FiscalSaleHistory(Domain):
    """Holds fiscal information about the sales.
    """
    TYPE_CPF = u'cpf'
    TYPE_CNPJ = u'cnpj'

    __storm_table__ = 'fiscal_sale_history'

    document_type = EnumCol(allow_none=False, default=TYPE_CPF)
    document = UnicodeCol(default=None)
    sale_id = IdCol()
    sale = Reference(sale_id, 'Sale.id')
    coo = IntCol(default=0)
    document_counter = IntCol(default=0)
Exemplo n.º 24
0
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)
Exemplo n.º 25
0
class ProductComponent(Domain):
    """A |product| and it's related |component| eg other product

    See also:
    `schema <http://doc.stoq.com.br/schema/tables/product_component.html>`__
    """

    __storm_table__ = 'product_component'

    quantity = QuantityCol(default=Decimal(1))
    product_id = IntCol()
    product = Reference(product_id, 'Product.id')
    component_id = IntCol()
    component = Reference(component_id, 'Product.id')
    design_reference = UnicodeCol(default=u'')
Exemplo n.º 26
0
class ECFDocumentHistory(Domain):
    """Documents emitted by the fiscal printer.

    This does not include fiscal coupons
    """
    (TYPE_MEMORY_READ, TYPE_Z_REDUCTION, TYPE_SUMMARY) = range(3)

    __storm_table__ = 'ecf_document_history'

    printer_id = IdCol()
    printer = Reference(printer_id, 'ECFPrinter.id')
    type = IntCol()
    coo = IntCol(default=0)
    gnf = IntCol(default=0)
    crz = IntCol(default=None)
    emission_date = DateTimeCol(default_factory=datetime.datetime.now)
Exemplo n.º 27
0
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)
Exemplo n.º 28
0
class ProductIcmsTemplate(BaseICMS):
    __storm_table__ = 'product_icms_template'

    REASON_LIVESTOCK = 3
    REASON_OTHERS = 9
    REASON_AGRICULTURAL_AGENCY = 12

    product_tax_template_id = IdCol()
    product_tax_template = Reference(product_tax_template_id,
                                     'ProductTaxTemplate.id')

    # Simples Nacional
    p_cred_sn_valid_until = DateTimeCol(default=None)

    # Motivo de Desoneração do ICMS
    mot_des_icms = IntCol(default=None)

    def is_p_cred_sn_valid(self):
        """Returns if p_cred_sn has expired."""
        if not self.p_cred_sn_valid_until:
            # If we don't have a valid_until, means p_cred_sn will never
            # expire. Therefore, p_cred_sn is valid.
            return True
        elif self.p_cred_sn_valid_until.date() < localtoday().date():
            return False

        return True
Exemplo n.º 29
0
class TransactionEntry(ORMObject):
    """
    A TransactionEntry keeps track of state associated with a database
    transaction. It's main use case is to know information about the system when
    a domain object is created or modified.

    Such information will be used by stoq when syncing databases
    """
    __storm_table__ = 'transaction_entry'

    id = IntCol(primary=True, default=AutoReload)

    #: last time this object was modified
    te_time = DateTimeCol(allow_none=False)

    metadata = JsonCol()

    #: A bit string that stores information about this object syncronization status.
    #: a bit with value '0' means the object was changed and need to be sent to the server/client.
    #: a bit with value '1' means this object is already synced with the server/client.
    #: Note that on the client this column will have a size of 1. On the server it may vary
    sync_status = BitStringCol(default=AutoReload)

    #: For use of the sync conector
    te_server = DateTimeCol()
Exemplo n.º 30
0
class CheckData(Domain):
    """Stores check informations and also a history of possible
    devolutions.
    """

    __storm_table__ = 'check_data'

    payment_id = IntCol()

    #: the :class:`payment <stoqlib.domain.payment.Payment>`
    payment = Reference(payment_id, 'Payment.id')

    bank_account_id = IntCol()

    #: the :class:`bank account <stoqlib.domain.account.BankAccount>`
    bank_account = Reference(bank_account_id, 'BankAccount.id')