Example #1
0
    def _get_instrucoes(self, payment):
        instructions = []

        sale = payment.group.sale
        if sale:
            invoice_number = sale.invoice_number
        else:
            invoice_number = payment.identifier

        penalty = currency(
            (sysparam.get_decimal('BILL_PENALTY') / 100) * payment.value)
        interest = currency(
            (sysparam.get_decimal('BILL_INTEREST') / 100) * payment.value)
        discount = currency(
            (sysparam.get_decimal('BILL_DISCOUNT') / 100) * payment.value)
        data = sysparam.get_string('BILL_INSTRUCTIONS')
        for line in data.split('\n')[:4]:
            line = line.replace('$DATE', payment.due_date.strftime('%d/%m/%Y'))
            line = line.replace('$PENALTY',
                                converter.as_string(currency, penalty))
            line = line.replace('$INTEREST',
                                converter.as_string(currency, interest))
            line = line.replace('$DISCOUNT',
                                converter.as_string(currency, discount))
            line = line.replace('$INVOICE_NUMBER', str(invoice_number))
            instructions.append(line)

        instructions.append('')
        instructions.append('\n' + _('Stoq Retail Management') + ' - www.stoq.com.br')
        return instructions
Example #2
0
    def _get_instrucoes(self, payment):
        instructions = []

        sale = payment.group.sale
        if sale:
            invoice_number = sale.invoice.invoice_number
        else:
            invoice_number = payment.identifier

        penalty = currency(
            (sysparam.get_decimal('BILL_PENALTY') / 100) * payment.value)
        interest = currency(
            (sysparam.get_decimal('BILL_INTEREST') / 100) * payment.value)
        discount = currency(
            (sysparam.get_decimal('BILL_DISCOUNT') / 100) * payment.value)
        data = sysparam.get_string('BILL_INSTRUCTIONS')
        for line in data.split('\n')[:4]:
            line = line.replace('$DATE', payment.due_date.strftime('%d/%m/%Y'))
            line = line.replace('$PENALTY',
                                converter.as_string(currency, penalty))
            line = line.replace('$INTEREST',
                                converter.as_string(currency, interest))
            line = line.replace('$DISCOUNT',
                                converter.as_string(currency, discount))
            line = line.replace('$INVOICE_NUMBER', str(invoice_number))
            instructions.append(line)

        instructions.append('')
        instructions.append('\n' + _('Stoq Retail Management') +
                            ' - www.stoq.com.br')
        return instructions
Example #3
0
    def _get_parameter_value(self, obj):
        """Given a ParameterData object, returns a string representation of
        its current value.
        """
        detail = sysparam.get_detail_by_name(obj.field_name)
        if detail.type == unicode:
            data = sysparam.get_string(obj.field_name)
        elif detail.type == bool:
            data = sysparam.get_bool(obj.field_name)
        elif detail.type == int:
            data = sysparam.get_int(obj.field_name)
        elif detail.type == decimal.Decimal:
            data = sysparam.get_decimal(obj.field_name)
        elif isinstance(detail.type, basestring):
            data = sysparam.get_object(self.store, obj.field_name)
        else:
            raise NotImplementedError(detail.type)

        if isinstance(data, Domain):
            if not (IDescribable in providedBy(data)):
                raise TypeError(u"Parameter `%s' must implement IDescribable "
                                "interface." % obj.field_name)
            return data.get_description()
        elif detail.options:
            return detail.options[int(obj.field_value)]
        elif isinstance(data, bool):
            return [_(u"No"), _(u"Yes")][data]
        elif obj.field_name == u'COUNTRY_SUGGESTED':
            return dgettext("iso_3166", data)
        elif isinstance(data, unicode):
            # FIXME: workaround to handle locale specific data
            return _(data)
        return unicode(data)
Example #4
0
 def __init__(self, store, model, model_type, visual_mode=False):
     self._proxy = None
     self.model = model
     self.model_type = model_type
     self.default_max_discount = sysparam.get_decimal("MAX_SALE_DISCOUNT")
     self.max_discount = self.default_max_discount
     BaseEditorSlave.__init__(self, store, model, visual_mode=visual_mode)
Example #5
0
    def _get_parameter_value(self, obj):
        """Given a ParameterData object, returns a string representation of
        its current value.
        """
        detail = sysparam.get_detail_by_name(obj.field_name)
        if detail.type == unicode:
            data = sysparam.get_string(obj.field_name)
        elif detail.type == bool:
            data = sysparam.get_bool(obj.field_name)
        elif detail.type == int:
            data = sysparam.get_int(obj.field_name)
        elif detail.type == decimal.Decimal:
            data = sysparam.get_decimal(obj.field_name)
        elif isinstance(detail.type, basestring):
            data = sysparam.get_object(self.store, obj.field_name)
        else:
            raise NotImplementedError(detail.type)

        if isinstance(data, Domain):
            if not (IDescribable in providedBy(data)):
                raise TypeError(u"Parameter `%s' must implement IDescribable "
                                "interface." % obj.field_name)
            return data.get_description()
        elif detail.options:
            return detail.options[int(obj.field_value)]
        elif isinstance(data, bool):
            return [_(u"No"), _(u"Yes")][data]
        elif obj.field_name == u'COUNTRY_SUGGESTED':
            return dgettext("iso_3166", data)
        elif isinstance(data, unicode):
            # FIXME: workaround to handle locale specific data
            return _(data)
        return unicode(data)
Example #6
0
 def fetch(self, width, height):
     total = Decimal(0)
     tax_value = sysparam.get_decimal('SUBSTITUTION_TAX')
     for sale_item in self.sale.products:
         tax = sale_item.sellable.get_tax_constant()
         if tax.tax_type == TaxType.SUBSTITUTION:
             total += sale_item.get_total() * (Decimal(tax_value) / 100)
     return total
Example #7
0
 def fetch(self, width, height):
     total = Decimal(0)
     tax_value = sysparam.get_decimal('ISS_TAX')
     for sale_item in self.sale.services:
         tax = sale_item.sellable.get_tax_constant()
         if tax.tax_type == TaxType.SERVICE:
             total += sale_item.get_total() * (Decimal(tax_value) / 100)
     return total
Example #8
0
 def fetch(self, width, height):
     total = Decimal(0)
     tax_value = sysparam.get_decimal('ISS_TAX')
     for sale_item in self.sale.services:
         tax = sale_item.sellable.get_tax_constant()
         if tax.tax_type == TaxType.SERVICE:
             total += sale_item.get_total() * (Decimal(tax_value) / 100)
     return total
Example #9
0
 def fetch(self, width, height):
     total = Decimal(0)
     tax_value = sysparam.get_decimal('SUBSTITUTION_TAX')
     for sale_item in self.sale.products:
         tax = sale_item.sellable.get_tax_constant()
         if tax.tax_type == TaxType.SUBSTITUTION:
             total += sale_item.get_total() * (Decimal(tax_value) / 100)
     return total
Example #10
0
    def setup_proxies(self):
        self._setup_widgets()
        self._setup_slaves()
        widgets = self.person_widgets
        self.person_proxy = self.add_proxy(self.model, widgets)

        widgets = self.tax_widgets
        iss = Decimal(sysparam.get_decimal('ISS_TAX'))
        icms = Decimal(sysparam.get_decimal('ICMS_TAX'))
        substitution = Decimal(sysparam.get_decimal('SUBSTITUTION_TAX'))
        model = Settable(iss=iss, icms=icms,
                         substitution_icms=substitution)
        self.tax_proxy = self.add_proxy(model, widgets)

        widgets = self.company_widgets
        model = self.model.company
        if not model is None:
            self.company_proxy = self.add_proxy(model, widgets)
Example #11
0
    def _add_fiscal_coupon_information(self):
        sales = list(self._get_sales())
        iss_tax = sysparam.get_decimal('ISS_TAX') * 100

        for sale in sales:
            client = sale.client
            history = self.store.find(FiscalSaleHistory, sale=sale)

            # We should have exactly one row with the paulista invoice details
            if len(list(history)) != 1:
                continue

            self.cat.add_fiscal_coupon(sale, client, history[0])

            for i, item in enumerate(sale.get_items()):
                self.cat.add_fiscal_coupon_details(sale, client, history[0],
                                                   item, iss_tax, i + 1)

            # Ignore returned sales here, they will be handled later
            if sale.return_date:
                continue

            for payment in sale.payments:
                # Pagamento de entrada para devoluções. Nós não devemos incluir
                # esse pagamento, pois a empresa deve preencher uma nota de
                # entrada para pedir a devolução do imposto.
                if payment.is_inpayment():
                    continue
                self.cat.add_payment_method(sale, history[0], payment)

        # Essas vendas são as que foram devolvidas *imediatamente após* terem
        # sido emitida. Ou seja, houve o cancelamento da mesma na ECF, então os
        # pagamentos de estorno devem ser adicionados. ao cat
        returned_sales = list(self._get_sales(returned=True))
        for sale in returned_sales:
            history = self.store.find(FiscalSaleHistory, sale=sale)
            # We should have exactly one row with the paulista invoice details
            if len(list(history)) != 1:
                continue

            returned_sales = list(self.store.find(ReturnedSale, sale=sale))
            # We should only handle sales cancelled right after they were made,
            # and they have only one returned_sale object related
            if len(returned_sales) != 1:
                continue

            # Sales cancelled right after being made dont have an invoice number
            if returned_sales[0].invoice.invoice_number is not None:
                continue

            for payment in sale.payments:
                if payment.is_outpayment():
                    continue

                self.cat.add_payment_method(sale, history[0], payment,
                                            returned_sales[0])
Example #12
0
    def _add_fiscal_coupon_information(self):
        sales = list(self._get_sales())
        iss_tax = sysparam.get_decimal('ISS_TAX') * 100

        for sale in sales:
            client = sale.client
            history = self.store.find(FiscalSaleHistory, sale=sale)

            # We should have exactly one row with the paulista invoice details
            if len(list(history)) != 1:
                continue

            self.cat.add_fiscal_coupon(sale, client, history[0])

            for i, item in enumerate(sale.get_items()):
                self.cat.add_fiscal_coupon_details(sale, client, history[0],
                                                   item, iss_tax, i + 1)

            # Ignore returned sales here, they will be handled later
            if sale.return_date:
                continue

            for payment in sale.payments:
                # Pagamento de entrada para devoluções. Nós não devemos incluir
                # esse pagamento, pois a empresa deve preencher uma nota de
                # entrada para pedir a devolução do imposto.
                if payment.is_inpayment():
                    continue
                self.cat.add_payment_method(sale, history[0], payment)

        # Essas vendas são as que foram devolvidas *imediatamente após* terem
        # sido emitida. Ou seja, houve o cancelamento da mesma na ECF, então os
        # pagamentos de estorno devem ser adicionados. ao cat
        returned_sales = list(self._get_sales(returned=True))
        for sale in returned_sales:
            history = self.store.find(FiscalSaleHistory, sale=sale)
            # We should have exactly one row with the paulista invoice details
            if len(list(history)) != 1:
                continue

            returned_sales = list(self.store.find(ReturnedSale, sale=sale))
            # We should only handle sales cancelled right after they were made,
            # and they have only one returned_sale object related
            if len(returned_sales) != 1:
                continue

            # Sales cancelled right after being made dont have an invoice number
            if returned_sales[0].invoice_number is not None:
                continue

            for payment in sale.payments:
                if payment.is_outpayment():
                    continue

                self.cat.add_payment_method(sale, history[0], payment,
                                            returned_sales[0])
Example #13
0
    def _setup_widgets(self):
        salary_percentage = sysparam.get_decimal('CREDIT_LIMIT_SALARY_PERCENT')
        if salary_percentage > 0:
            self.credit_limit.set_sensitive(False)

        # Only management can add credit to clients (in other words, users with
        # access to the Admin app).
        user = api.get_current_user(self.store)
        if not user.profile.check_app_permission(u'admin'):
            self.credit_transactions_button.hide()
Example #14
0
    def _setup_widgets(self):
        salary_percentage = sysparam.get_decimal("CREDIT_LIMIT_SALARY_PERCENT")
        if salary_percentage > 0:
            self.credit_limit.set_sensitive(False)

        # Only management can add credit to clients (in other words, users with
        # access to the Admin app).
        user = api.get_current_user(self.store)
        if not user.profile.check_app_permission(u"admin"):
            self.credit_transactions_button.hide()
Example #15
0
 def __init__(self, store, model, model_type, visual_mode=False):
     self._proxy = None
     self.model = model
     self.model_type = model_type
     self.default_max_discount = sysparam.get_decimal('MAX_SALE_DISCOUNT')
     self.max_discount = self.default_max_discount
     # If there is an original discount, this means the sale was from a trade,
     # and the parameter USE_TRADE_AS_DISCOUNT must be set.
     self.original_discount = self.model.discount_value * 100 / self.model.get_sale_subtotal()
     if self.original_discount:
         assert sysparam.get_bool('USE_TRADE_AS_DISCOUNT')
     self.original_sale_amount = self.model.get_total_sale_amount()
     BaseEditorSlave.__init__(self, store, model, visual_mode=visual_mode)
Example #16
0
 def __init__(self, store, model, model_type, visual_mode=False):
     self._proxy = None
     self.model = model
     self.model_type = model_type
     self.default_max_discount = sysparam.get_decimal('MAX_SALE_DISCOUNT')
     self.max_discount = self.default_max_discount
     # If there is an original discount, this means the sale was from a trade,
     # and the parameter USE_TRADE_AS_DISCOUNT must be set.
     self.original_discount = self.model.discount_value * 100 / self.model.get_sale_subtotal()
     if self.original_discount:
         assert sysparam.get_bool('USE_TRADE_AS_DISCOUNT')
     self.original_sale_amount = self.model.get_total_sale_amount()
     BaseEditorSlave.__init__(self, store, model, visual_mode=visual_mode)
Example #17
0
 def sysparam(self, **kwargs):
     """
     Updates a set of system parameters within a context.
     The values will be reverted when leaving the scope.
     kwargs contains a dictionary of parameter name->value
     """
     from stoqlib.lib.parameters import sysparam
     old_values = {}
     for param, value in kwargs.items():
         if isinstance(value, bool):
             old_values[param] = sysparam.get_bool(param)
             sysparam.set_bool(self.store, param, value)
         elif isinstance(value, int):
             old_values[param] = sysparam.get_int(param)
             sysparam.set_int(self.store, param, value)
         elif isinstance(value, Domain) or value is None:
             old_values[param] = sysparam.get_object(self.store, param)
             sysparam.set_object(self.store, param, value)
         elif isinstance(value, str):
             old_values[param] = sysparam.get_string(param)
             sysparam.set_string(self.store, param, value)
         elif isinstance(value, Decimal):
             old_values[param] = sysparam.get_decimal(param)
             sysparam.set_decimal(self.store, param, value)
         else:
             raise NotImplementedError(type(value))
     try:
         yield
     finally:
         for param, value in old_values.items():
             if isinstance(value, bool):
                 sysparam.set_bool(self.store, param, value)
             elif isinstance(value, int):
                 sysparam.set_int(self.store, param, value)
             elif isinstance(value, Domain) or value is None:
                 sysparam.set_object(self.store, param, value)
             elif isinstance(value, str):
                 sysparam.set_string(self.store, param, value)
             elif isinstance(value, Decimal):
                 sysparam.set_decimal(self.store, param, value)
             else:
                 raise NotImplementedError(type(value))
Example #18
0
 def sysparam(self, **kwargs):
     """
     Updates a set of system parameters within a context.
     The values will be reverted when leaving the scope.
     kwargs contains a dictionary of parameter name->value
     """
     from stoqlib.lib.parameters import sysparam
     old_values = {}
     for param, value in kwargs.items():
         if isinstance(value, bool):
             old_values[param] = sysparam.get_bool(param)
             sysparam.set_bool(self.store, param, value)
         elif isinstance(value, int):
             old_values[param] = sysparam.get_int(param)
             sysparam.set_int(self.store, param, value)
         elif isinstance(value, Domain) or value is None:
             old_values[param] = sysparam.get_object(self.store, param)
             sysparam.set_object(self.store, param, value)
         elif isinstance(value, str):
             old_values[param] = sysparam.get_string(param)
             sysparam.set_string(self.store, param, value)
         elif isinstance(value, Decimal):
             old_values[param] = sysparam.get_decimal(param)
             sysparam.set_decimal(self.store, param, value)
         else:
             raise NotImplementedError(type(value))
     try:
         yield
     finally:
         for param, value in old_values.items():
             if isinstance(value, bool):
                 sysparam.set_bool(self.store, param, value)
             elif isinstance(value, int):
                 sysparam.set_int(self.store, param, value)
             elif isinstance(value, Domain) or value is None:
                 sysparam.set_object(self.store, param, value)
             elif isinstance(value, str):
                 sysparam.set_string(self.store, param, value)
             elif isinstance(value, Decimal):
                 sysparam.set_decimal(self.store, param, value)
             else:
                 raise NotImplementedError(type(value))
Example #19
0
 def penalty_percentage(self):
     return sysparam.get_decimal('BILL_PENALTY')
Example #20
0
 def discount_percentage(self):
     return sysparam.get_decimal('BILL_DISCOUNT')
Example #21
0
 def discount_percentage(self):
     return sysparam.get_decimal('BILL_DISCOUNT')
Example #22
0
 def interest_percentage(self):
     return sysparam.get_decimal('BILL_INTEREST')
Example #23
0
 def penalty_percentage(self):
     return sysparam.get_decimal('BILL_PENALTY')
Example #24
0
 def interest_percentage(self):
     return sysparam.get_decimal('BILL_INTEREST')