示例#1
0
文件: account.py 项目: esosaja/stoq
    def create_from_payment(cls, payment, account=None):
        """Create a new transaction based on a |payment|.
        It's normally used when creating a transaction which represents
        a payment, for instance when you receive a bill or a check from
        a |client| which will enter a |bankaccount|.

        :param payment: the |payment| to create the transaction for.
        :param account: if an outgoing payment, the |account| will be the source of
          transaction. Otherwise will be the destination account.
        :returns: the transaction
        """
        if not payment.is_paid():
            raise PaymentError(_("Payment needs to be paid"))
        store = payment.store
        value = payment.paid_value
        if payment.is_outpayment():
            operation_type = cls.TYPE_OUT
            source = account or payment.method.destination_account
            destination = sysparam.get_object(store, 'IMBALANCE_ACCOUNT')
        else:
            operation_type = cls.TYPE_IN
            source = sysparam.get_object(store, 'IMBALANCE_ACCOUNT')
            destination = account or payment.method.destination_account
        return cls(source_account=source,
                   account=destination,
                   value=value,
                   description=payment.description,
                   code=unicode(payment.identifier),
                   date=payment.paid_date,
                   store=store,
                   payment=payment,
                   operation_type=operation_type)
示例#2
0
    def test_account_can_remove(self):
        account = self.create_account()
        self.assertTrue(account.can_remove())

        self.assertFalse(
            sysparam.get_object(self.store, 'TILLS_ACCOUNT').can_remove())
        self.assertFalse(
            sysparam.get_object(self.store, 'IMBALANCE_ACCOUNT').can_remove())
        self.assertFalse(
            sysparam.get_object(self.store, 'BANKS_ACCOUNT').can_remove())

        station = self.create_station()
        account.station = station

        self.assertFalse(account.can_remove())

        account.station = None

        self.assertTrue(account.can_remove())

        a2 = self.create_account()

        self.assertTrue(account.can_remove())

        a2.parent = account

        self.assertFalse(account.can_remove())
示例#3
0
    def _update_accounts(self):
        if len(self._payments) != 1:
            return

        payment = self._payments[0]
        create_transaction = payment.method.operation.create_transaction()
        for combo in [self.destination_account, self.source_account]:
            combo.set_sensitive(create_transaction)

        if not create_transaction:
            return

        destination_combo = self.get_account_destination_combo()
        for combo in [self.destination_account, self.source_account]:
            combo.prefill(api.for_combo(
                self.store.find(Account),
                attr='long_description'))

            if combo is destination_combo:
                combo.select(payment.method.destination_account)
            else:
                combo.select(
                    sysparam.get_object(self.store, 'IMBALANCE_ACCOUNT'))

        category_account = payment.category and payment.category.account
        if category_account:
            if payment.payment_type == payment.TYPE_IN:
                self.source_account.select(category_account)
            else:
                self.destination_account.select(category_account)
示例#4
0
    def _create_or_update_delivery(self):
        delivery_service = sysparam.get_object(self.store, 'DELIVERY_SERVICE')
        delivery_sellable = delivery_service.sellable

        items = [item for item in self.slave.klist
                 if item.sellable.product is not None]

        if self._delivery is not None:
            model = self._delivery

        else:
            model = CreateDeliveryModel(
                price=delivery_sellable.price, recipient=self.model.person)

        rv = run_dialog(
            CreateDeliveryEditor, self.get_toplevel().get_toplevel(),
            self.store, model=model, items=items, person_type=Person)

        if not rv:
            return

        self._delivery = rv
        if self._delivery_item:
            self.slave.klist.update(self._delivery_item)
        else:
            self._delivery_item = self.get_order_item(
                delivery_sellable, self._delivery.price, 1)
            self.slave.klist.append(None, self._delivery_item)
示例#5
0
    def _update_accounts(self):
        if len(self._payments) != 1:
            return

        payment = self._payments[0]
        create_transaction = payment.method.operation.create_transaction()
        for combo in [self.destination_account, self.source_account]:
            combo.set_sensitive(create_transaction)

        if not create_transaction:
            return

        destination_combo = self.get_account_destination_combo()
        for combo in [self.destination_account, self.source_account]:
            combo.prefill(
                api.for_combo(self.store.find(Account),
                              attr='long_description'))

            if combo is destination_combo:
                combo.select(payment.method.destination_account)
            else:
                combo.select(
                    sysparam.get_object(self.store, 'IMBALANCE_ACCOUNT'))

        category_account = payment.category and payment.category.account
        if category_account:
            if payment.payment_type == payment.TYPE_IN:
                self.source_account.select(category_account)
            else:
                self.destination_account.select(category_account)
示例#6
0
    def __init__(self, store, product, visual_mode=False):
        self._product = product
        BaseRelationshipEditorSlave.__init__(self, store, visual_mode=visual_mode)

        suggested = sysparam.get_object(store, 'SUGGESTED_SUPPLIER')
        if suggested is not None:
            self.target_combo.select(suggested)
示例#7
0
    def _load_tax_values(self, item):
        assert item
        sellable = item.sellable
        product = sellable.product
        service = sellable.service
        delivery = sysparam.get_object(item.store, 'DELIVERY_SERVICE').sellable
        if product:
            code = product.ncm or ''
            ex_tipi = self._format_ex(product.ex_tipi)
        else:
            if not self.include_services or sellable == delivery:
                return

            code = '%04d' % int(service.service_list_item_code.replace(
                '.', ''))
            ex_tipi = ''

        options = taxes_data[self.state].get(code, {})
        n_options = len(options)
        if n_options == 0:
            tax_values = TaxInfo('0', '0', '0', '', '0')
        elif n_options == 1:
            tax_values = options['']
        else:
            tax_values = options.get(ex_tipi) or options['']
        return tax_values
示例#8
0
    def test_account_remove(self):
        a1 = self.create_account()
        a2 = self.create_account()

        imbalance_account = sysparam.get_object(self.store, 'IMBALANCE_ACCOUNT')

        t1 = self.create_account_transaction(a1)
        t1.source_account = a2
        self.store.flush()

        t2 = self.create_account_transaction(a2)
        t2.source_account = a1
        self.store.flush()

        a2.parent = a1
        with self.assertRaises(TypeError):
            a1.remove(self.store)
        a2.parent = None

        a1.station = self.create_station()
        self.assertRaises(TypeError, a1.remove)
        a1.station = None

        a1.remove(self.store)

        self.assertEqual(t1.account, imbalance_account)
        self.assertEqual(t2.source_account, imbalance_account)
示例#9
0
 def cfop_code(self):
     # Transfers between distinct companies are fiscally considered a sale
     if not self.transfer_order.is_between_same_company:
         sale_cfop_data = sysparam.get_object(self.store,
                                              'DEFAULT_SALES_CFOP')
         return sale_cfop_data.code.replace(u'.', u'')
     return u'5152'
示例#10
0
    def test_wizard_remove_delivery(self, yesno):
        yesno.return_value = True
        branch = api.get_current_branch(self.store)
        storable = self.create_storable(branch=branch, stock=1)
        sellable = storable.product.sellable
        # Run the wizard
        wizard = StockDecreaseWizard(self.store)
        step = wizard.get_current_step()
        step.reason.update('test')
        self.click(wizard.next_button)
        step = wizard.get_current_step()
        self.assertNotSensitive(step, ['delivery_button'])
        step.sellable_selected(sellable)
        step.quantity.update(1)
        self.click(step.add_sellable_button)
        self.assertSensitive(step, ['delivery_button'])

        delivery_sellable = sysparam.get_object(self.store, 'DELIVERY_SERVICE').sellable
        delivery = CreateDeliveryModel(price=delivery_sellable.price,
                                       recipient=wizard.model.person)

        module = 'stoqlib.gui.wizards.stockdecreasewizard.run_dialog'
        with mock.patch(module) as run_dialog:
            # Delivery set
            run_dialog.return_value = delivery
            self.click(step.delivery_button)
            self.assertEqual(step._delivery, delivery)
            self.assertTrue(isinstance(step._delivery_item, StockDecreaseItem))

            # Remove the delivery item
            run_dialog.return_value = delivery
            step.slave.klist.select(step.slave.klist[1])
            self.click(step.slave.delete_button)
            self.assertIsNone(step._delivery)
            self.assertIsNone(step._delivery_item)
示例#11
0
    def test_can_remove(self):
        sellable = Sellable(store=self.store)
        self.assertTrue(sellable.can_remove())

        sellable = self.create_sellable()
        storable = Storable(product=sellable.product, store=self.store)
        self.assertTrue(sellable.can_remove())

        branch = get_current_branch(self.store)
        storable.increase_stock(1, branch,
                                StockTransactionHistory.TYPE_INITIAL, None)
        sale = self.create_sale()
        sale.status = Sale.STATUS_QUOTE
        sale.branch = branch
        sale.add_sellable(sellable)
        self.assertFalse(sellable.can_remove())

        # Can't remove the sellable if it's in a purchase.
        from stoqlib.domain.purchase import PurchaseItem
        sellable = self.create_sellable()
        Storable(product=sellable.product, store=self.store)
        self.assertTrue(sellable.can_remove())
        PurchaseItem(store=self.store,
                     quantity=8,
                     quantity_received=0,
                     cost=125,
                     base_cost=125,
                     sellable=sellable,
                     order=self.create_purchase_order())
        self.assertFalse(sellable.can_remove())

        # The delivery service cannot be removed.
        sellable = sysparam.get_object(self.store, 'DELIVERY_SERVICE').sellable
        self.assertFalse(sellable.can_remove())
示例#12
0
 def __init__(self, store=None, **kw):
     super(ReceivingOrder, self).__init__(store=store, **kw)
     # These miss default parameters and needs to be set before
     # cfop, which triggers an implicit flush.
     self.branch = kw.pop('branch', None)
     if not 'cfop' in kw:
         self.cfop = sysparam.get_object(store, 'DEFAULT_RECEIVING_CFOP')
示例#13
0
    def _create_or_update_delivery(self):
        delivery_service = sysparam.get_object(self.store, 'DELIVERY_SERVICE')
        delivery_sellable = delivery_service.sellable

        items = [
            item for item in self.slave.klist
            if item.sellable.product is not None
        ]
        if self._delivery is not None:
            model = self._delivery
        else:
            model = CreateDeliveryModel(price=delivery_sellable.price,
                                        client=self.model.client)

        rv = run_dialog(CreateDeliveryEditor,
                        self.get_toplevel().get_toplevel(),
                        self.store,
                        model,
                        sale_items=items)
        if not rv:
            return

        self._delivery = rv
        if self._delivery_item:
            self._delivery_item.price = self._delivery.price
            self._delivery_item.notes = self._delivery.notes
            self._delivery_item.estimated_fix_date = self._delivery.estimated_fix_date
            self.slave.klist.update(self._delivery_item)
        else:
            self._delivery_item = self.get_order_item(delivery_sellable,
                                                      self._delivery.price, 1)
            self.slave.klist.append(None, self._delivery_item)
示例#14
0
    def get_sellable_view_query(self):
        delivery_sellable = sysparam.get_object(
            self.store, 'DELIVERY_SERVICE').sellable

        query = And(ServiceView.status == Sellable.STATUS_AVAILABLE,
                    ServiceView.id != delivery_sellable.id)
        return self.sellable_view, query
示例#15
0
    def _create_or_update_delivery(self):
        delivery_service = sysparam.get_object(self.store, 'DELIVERY_SERVICE')
        delivery_sellable = delivery_service.sellable

        items = [item for item in self.slave.klist
                 if item.sellable.product is not None]
        if self._delivery is not None:
            model = self._delivery
        else:
            model = CreateDeliveryModel(
                price=delivery_sellable.price, client=self.model.client)

        rv = run_dialog(
            CreateDeliveryEditor, self.get_toplevel().get_toplevel(),
            self.store, model, sale_items=items)
        if not rv:
            return

        self._delivery = rv
        if self._delivery_item:
            self._delivery_item.price = self._delivery.price
            self._delivery_item.notes = self._delivery.notes
            self._delivery_item.estimated_fix_date = self._delivery.estimated_fix_date
            self.slave.klist.update(self._delivery_item)
        else:
            self._delivery_item = self.get_order_item(
                delivery_sellable, self._delivery.price, 1)
            self.slave.klist.append(None, self._delivery_item)
示例#16
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)
示例#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 type(value) is bool:
             old_values[param] = sysparam.get_bool(param)
             sysparam.set_bool(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)
         else:
             raise NotImplementedError(type(value))
     try:
         yield
     finally:
         for param, value in old_values.items():
             if type(value) is bool:
                 sysparam.set_bool(self.store, param, value)
             elif isinstance(value, Domain) or value is None:
                 sysparam.set_object(self.store, param, value)
             else:
                 raise NotImplementedError(type(value))
示例#18
0
    def test_get_available_sellables_query(self):
        # Sellable and query without supplier
        sellable = self.create_sellable()
        self.create_storable(product=sellable.product,
                             branch=self.create_branch())

        self.assertIn(
            sellable,
            self.store.find(Sellable,
                            Sellable.get_available_sellables_query(self.store)))

        sellable.close()
        self.assertNotIn(
            sellable,
            self.store.find(Sellable,
                            Sellable.get_available_sellables_query(self.store)))

        delivery_sellable = sysparam.get_object(self.store, 'DELIVERY_SERVICE').sellable
        delivery_sellable.status = Sellable.STATUS_AVAILABLE
        # Deliveries are treated differently, that's why they should
        # not be present here
        self.assertNotIn(
            sellable,
            self.store.find(Sellable,
                            Sellable.get_available_sellables_query(self.store)))
示例#19
0
    def test_can_remove(self):
        sellable = Sellable(store=self.store)
        self.assertTrue(sellable.can_remove())

        sellable = self.create_sellable()
        storable = Storable(product=sellable.product, store=self.store)
        self.assertTrue(sellable.can_remove())

        branch = get_current_branch(self.store)
        storable.increase_stock(1, branch,
                                StockTransactionHistory.TYPE_INITIAL, None)
        sale = self.create_sale()
        sale.status = Sale.STATUS_QUOTE
        sale.branch = branch
        sale.add_sellable(sellable)
        self.assertFalse(sellable.can_remove())

        # Can't remove the sellable if it's in a purchase.
        from stoqlib.domain.purchase import PurchaseItem
        sellable = self.create_sellable()
        Storable(product=sellable.product, store=self.store)
        self.assertTrue(sellable.can_remove())
        PurchaseItem(store=self.store,
                     quantity=8, quantity_received=0,
                     cost=125, base_cost=125,
                     sellable=sellable,
                     order=self.create_purchase_order())
        self.assertFalse(sellable.can_remove())

        # The delivery service cannot be removed.
        sellable = sysparam.get_object(self.store, 'DELIVERY_SERVICE').sellable
        self.assertFalse(sellable.can_remove())
示例#20
0
    def test_get_available_sellables_query(self):
        # Sellable and query without supplier
        sellable = self.create_sellable()
        self.create_storable(product=sellable.product,
                             branch=self.create_branch())

        self.assertIn(
            sellable,
            self.store.find(Sellable,
                            Sellable.get_available_sellables_query(
                                self.store)))

        sellable.close()
        self.assertNotIn(
            sellable,
            self.store.find(Sellable,
                            Sellable.get_available_sellables_query(
                                self.store)))

        delivery_sellable = sysparam.get_object(self.store,
                                                'DELIVERY_SERVICE').sellable
        delivery_sellable.status = Sellable.STATUS_AVAILABLE
        # Deliveries are treated differently, that's why they should
        # not be present here
        self.assertNotIn(
            sellable,
            self.store.find(Sellable,
                            Sellable.get_available_sellables_query(
                                self.store)))
示例#21
0
    def _load_tax_values(self, item):
        assert item
        sellable = item.sellable
        product = sellable.product
        service = sellable.service
        delivery = sysparam.get_object(item.store, 'DELIVERY_SERVICE').sellable
        if product:
            code = product.ncm or ''
            ex_tipi = self._format_ex(product.ex_tipi)
        else:
            if not self.include_services or sellable == delivery:
                return

            code = '%04d' % int(service.service_list_item_code.replace('.', ''))
            ex_tipi = ''

        options = taxes_data.get(code, {})
        n_options = len(options)
        if n_options == 0:
            tax_values = TaxInfo('0', '0', '0', '', '0')
        elif n_options == 1:
            tax_values = options['']
        else:
            tax_values = options.get(ex_tipi) or options['']
        return tax_values
示例#22
0
    def _create_or_update_delivery(self):
        delivery_service = sysparam.get_object(self.store, 'DELIVERY_SERVICE')
        delivery_sellable = delivery_service.sellable

        items = [
            item for item in self.slave.klist
            if item.sellable.product is not None
        ]

        if self._delivery is not None:
            model = self._delivery

        else:
            model = CreateDeliveryModel(price=delivery_sellable.price,
                                        recipient=self.model.person)

        rv = run_dialog(CreateDeliveryEditor,
                        self.get_toplevel().get_toplevel(),
                        self.store,
                        model=model,
                        items=items,
                        person_type=Person)

        if not rv:
            return

        self._delivery = rv
        if self._delivery_item:
            self.slave.klist.update(self._delivery_item)
        else:
            self._delivery_item = self.get_order_item(delivery_sellable,
                                                      self._delivery.price, 1)
            self.slave.klist.append(None, self._delivery_item)
示例#23
0
    def create_receiving_order(self, station):
        notes = u"Created automatically with Stoq-Link"
        # TODO Eventually get this from the invoice data.
        cfop = sysparam.get_object(self.store, 'DEFAULT_RECEIVING_CFOP')
        receiving_invoice = ReceivingInvoice(
            store=self.store,
            freight_total=self.freight_cost,
            invoice_number=self.invoice_number,
            invoice_total=self.total_cost,
            supplier=self.purchase_order.supplier,
            branch=self.branch,
            responsible=self.user,
            station=station)

        receiving_order = ReceivingOrder(store=self.store,
                                         branch=self.branch,
                                         station=station,
                                         notes=notes,
                                         cfop=cfop,
                                         confirm_date=datetime.datetime.now(),
                                         status=u'closed',
                                         receiving_invoice=receiving_invoice)

        receiving_order.add_purchase(self.purchase_order)
        for item in self.purchase_order.get_items():
            receiving_order.add_purchase_item(item=item)

        if self.freight_type == PurchaseOrder.FREIGHT_CIF:
            receiving_order.update_payments(create_freight_payment=True)

        receiving_invoice.freight_type = receiving_invoice.guess_freight_type()
        receiving_order.confirm(self.user)

        return receiving_order
示例#24
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)
示例#25
0
文件: taxes.py 项目: metrorede/stak
    def get_tax_template(cls, invoice_item):
        default_cofins = sysparam.get_object(invoice_item.store, 'DEFAULT_PRODUCT_COFINS_TEMPLATE')
        # FIXME: Allow use COFINS templates in services
        if invoice_item.sellable.service:
            return default_cofins

        return invoice_item.sellable.product.cofins_template or default_cofins
示例#26
0
    def test_account_remove(self):
        a1 = self.create_account()
        a2 = self.create_account()

        imbalance_account = sysparam.get_object(self.store,
                                                'IMBALANCE_ACCOUNT')

        t1 = self.create_account_transaction(a1)
        t1.source_account = a2
        self.store.flush()

        t2 = self.create_account_transaction(a2)
        t2.source_account = a1
        self.store.flush()

        a2.parent = a1
        with self.assertRaises(TypeError):
            a1.remove(self.store)
        a2.parent = None

        a1.station = self.create_station()
        self.assertRaises(TypeError, a1.remove)
        a1.station = None

        a1.remove(self.store)

        self.assertEqual(t1.account, imbalance_account)
        self.assertEqual(t2.source_account, imbalance_account)
示例#27
0
文件: runtime.py 项目: relsi/stoq
def _register_branch_station(caller_store, station_name):
    import gtk
    from stoqlib.lib.parameters import sysparam

    if not sysparam.get_bool('DEMO_MODE'):
        fmt = _(u"The computer '%s' is not registered to the Stoq "
                u"server at %s.\n\n"
                u"Do you want to register it "
                u"(requires administrator access) ?")
        if not yesno(fmt % (station_name,
                            db_settings.address),
                     gtk.RESPONSE_YES, _(u"Register computer"), _(u"Quit")):
            raise SystemExit

        from stoqlib.gui.utils.login import LoginHelper
        h = LoginHelper(username="******")
        try:
            user = h.validate_user()
        except LoginError as e:
            error(str(e))

        if not user:
            error(_("Must login as 'admin'"))

    from stoqlib.domain.station import BranchStation
    with new_store() as store:
        branch = sysparam.get_object(store, 'MAIN_COMPANY')
        station = BranchStation.create(store, branch=branch, name=station_name)
    return caller_store.fetch(station)
示例#28
0
文件: runtime.py 项目: metrorede/stak
def _register_branch_station(caller_store, station_name, confirm=True):
    from gi.repository import Gtk
    from stoqlib.lib.parameters import sysparam

    if not sysparam.get_bool('DEMO_MODE'):
        fmt = _(u"The computer '%s' is not registered to the Stoq "
                u"server at %s.\n\n"
                u"Do you want to register it "
                u"(requires administrator access) ?")
        if confirm and not yesno(fmt % (station_name, db_settings.address),
                                 Gtk.ResponseType.YES, _(u"Register computer"),
                                 _(u"Quit")):
            raise SystemExit

        from stoqlib.gui.utils.login import LoginHelper
        h = LoginHelper()
        try:
            user = h.validate_user()
        except LoginError as e:
            error(str(e))

        if not user:
            error(_("Must login as 'admin'"))

    from stoqlib.domain.station import BranchStation
    with new_store() as store:
        branch = sysparam.get_object(store, 'MAIN_COMPANY')
        station = BranchStation.create(store, branch=branch, name=station_name)
    return caller_store.fetch(station)
示例#29
0
    def get_sellable_view_query(self):
        delivery_sellable = sysparam.get_object(self.store,
                                                'DELIVERY_SERVICE').sellable

        query = And(ServiceView.status == Sellable.STATUS_AVAILABLE,
                    ServiceView.id != delivery_sellable.id)
        return self.sellable_view, query
示例#30
0
    def __init__(self, store, hide_footer=False, hide_toolbar=True,
                 selection_mode=None, search_str=None, search_spec=None,
                 search_query=None, double_click_confirm=True, info_message=None):
        """
        :param store: a store
        :param hide_footer: do I have to hide the dialog footer?
        :param hide_toolbar: do I have to hide the dialog toolbar?
        :param selection_mode: the kiwi list selection mode
        :param search_str: If this search should already filter for some string
        :param double_click_confirm: If double click a item in the list should
            automatically confirm
        """
        if selection_mode is None:
            selection_mode = gtk.SELECTION_BROWSE

        self._image_viewer = None
        self._first_search = True
        self._first_search_string = search_str
        self._search_query = search_query
        self._delivery_sellable = sysparam.get_object(
            store, 'DELIVERY_SERVICE').sellable

        SearchEditor.__init__(self, store, search_spec=search_spec,
                              editor_class=self.editor_class,
                              hide_footer=hide_footer,
                              hide_toolbar=hide_toolbar,
                              selection_mode=selection_mode,
                              double_click_confirm=double_click_confirm)

        if info_message:
            self.set_message(info_message)

        if search_str:
            self.set_searchbar_search_string(search_str)
            self.search.refresh()
示例#31
0
 def __init__(self, store=None, **kw):
     super(ReceivingOrder, self).__init__(store=store, **kw)
     # These miss default parameters and needs to be set before
     # cfop, which triggers an implicit flush.
     self.branch = kw.pop('branch', None)
     if not 'cfop' in kw:
         self.cfop = sysparam.get_object(store, 'DEFAULT_RECEIVING_CFOP')
示例#32
0
def get_logo_data(store):
    logo_domain = sysparam.get_object(store, 'CUSTOM_LOGO_FOR_REPORTS')
    if logo_domain and logo_domain.image:
        data = logo_domain.image
    else:
        data = environ.get_resource_string('stoq', 'pixmaps', 'stoq_logo_bgwhite.png')

    return 'data:image/png;base64,' + base64.b64encode(data)
示例#33
0
def get_logo_data(store):
    logo_domain = sysparam.get_object(store, 'CUSTOM_LOGO_FOR_REPORTS')
    if logo_domain and logo_domain.image:
        data = logo_domain.image
    else:
        data = environ.get_resource_string('stoq', 'pixmaps', 'stoq_logo_bgwhite.png')

    return 'data:image/png;base64,' + base64.b64encode(data)
示例#34
0
文件: taxes.py 项目: Felipebros/stoq
    def get_tax_template(cls, invoice_item):
        default_pis = sysparam.get_object(invoice_item.store, 'DEFAULT_PRODUCT_PIS_TEMPLATE')
        # FIXME: Allow use PIS templates in services
        if invoice_item.sellable.service:
            return default_pis

        return (invoice_item.sellable.product.get_pis_template(invoice_item.parent.branch) or
                default_pis)
示例#35
0
 def __init__(self, store=None, **kw):
     Domain.__init__(self, store=store, **kw)
     # These miss default parameters and needs to be set before
     # cfop, which triggers an implicit flush.
     self.branch = kw.pop("branch", None)
     self.supplier = kw.pop("supplier", None)
     if not "cfop" in kw:
         self.cfop = sysparam.get_object(store, "DEFAULT_RECEIVING_CFOP")
示例#36
0
 def create_model(self, store):
     price = sysparam.get_object(store, 'DELIVERY_SERVICE').sellable.price
     volumes_weight = decimal.Decimal()
     for item in self.items:
         product = item.sellable.product
         if product:
             volumes_weight += product.weight * item.quantity
     return CreateDeliveryModel(price=price, volumes_net_weight=volumes_weight,
                                volumes_gross_weight=volumes_weight)
示例#37
0
 def _set_receiving_order_data(self):
     order = self.wizard.receiving_order
     self.branch.update(order.branch)
     cfop = sysparam.get_object(self.store, 'DEFAULT_PURCHASE_RETURN_CFOP')
     self.cfop.update(cfop)
     self.person.update(order.supplier.person.id)
     for widget in (self.branch, self.person):
         if widget.is_valid():
             widget.set_sensitive(False)
示例#38
0
    def validate_confirm(self):
        if not sysparam.get_bool('BLOCK_PAYMENT_FOR_IMBALANCE_ACCOUNT'):
            return True

        accounts = [self.source_account.get_selected(), self.destination_account.get_selected()]
        if sysparam.get_object(self.store, 'IMBALANCE_ACCOUNT') in accounts:
            warning(_('You must inform the source and destination accounts'))
            return False
        return True
示例#39
0
 def test_delivery_adaptor(self):
     decrease = self.create_stock_decrease()
     sellable = sysparam.get_object(self.store, 'DELIVERY_SERVICE').sellable
     decrease_item = self.create_stock_decrease_item(stock_decrease=decrease)
     delivery = self.create_delivery()
     delivery.invoice_id = decrease.invoice_id
     self.assertIsNone(decrease_item.delivery_adaptor)
     decrease_item.sellable = sellable
     self.assertEqual(decrease_item.delivery_adaptor, delivery)
示例#40
0
def _set_person_utilities():
    store = new_store()
    branch = sysparam.get_object(store, 'MAIN_COMPANY')
    provide_utility(ICurrentBranch, branch)

    station = BranchStation(name=u"Stoqlib station", branch=branch,
                            store=store, is_active=True)
    provide_utility(ICurrentBranchStation, station)
    store.commit(close=True)
示例#41
0
 def create_model(self, store):
     price = sysparam.get_object(store, 'DELIVERY_SERVICE').sellable.price
     volumes_weight = decimal.Decimal()
     for item in self.items:
         product = item.sellable.product
         if product:
             volumes_weight += product.weight * item.quantity
     return CreateDeliveryModel(price=price, volumes_net_weight=volumes_weight,
                                volumes_gross_weight=volumes_weight)
示例#42
0
def _set_person_utilities():
    store = new_store()
    branch = sysparam.get_object(store, 'MAIN_COMPANY')
    provide_utility(ICurrentBranch, branch)

    station = BranchStation(name=u"Stoqlib station", branch=branch,
                            store=store, is_active=True)
    provide_utility(ICurrentBranchStation, station)
    store.commit(close=True)
示例#43
0
文件: pos.py 项目: pkaislan/stoq
    def _create_delivery(self):
        delivery_param = sysparam.get_object(self.store, 'DELIVERY_SERVICE')
        if delivery_param.sellable in self.sale_items:
            self._delivery = delivery_param.sellable

        delivery = self._edit_delivery()
        if delivery:
            self._add_delivery_item(delivery, delivery_param.sellable)
            self._delivery = delivery
示例#44
0
    def __init__(self, store, product, visual_mode=False):
        self._product = product
        BaseRelationshipEditorSlave.__init__(self, store, visual_mode=visual_mode)

        suggested = sysparam.get_object(store, 'SUGGESTED_SUPPLIER')
        if suggested is not None:
            self.target_combo.select(suggested)

        if self._product.parent is not None:
            self._disable_child_widgets()
示例#45
0
    def test_can_close(self):
        service = self.create_service()
        self.assertTrue(service.can_close())

        old = sysparam.get_object(self.store, 'DELIVERY_SERVICE')
        try:
            sysparam.set_object(self.store, 'DELIVERY_SERVICE', service)
            self.assertFalse(service.can_close())
        finally:
            sysparam.set_object(self.store, 'DELIVERY_SERVICE', old)
示例#46
0
 def price(self):
     if self.is_on_sale():
         return self.on_sale_price
     else:
         category = sysparam.get_object(self.store, 'DEFAULT_TABLE_PRICE')
         if category:
             info = self.get_category_price_info(category)
             if info:
                 return info.price
         return self.base_price
示例#47
0
    def create_from_payment(cls,
                            payment,
                            code=None,
                            source_account=None,
                            destination_account=None):
        """Create a new transaction based on a |payment|.
        It's normally used when creating a transaction which represents
        a payment, for instance when you receive a bill or a check from
        a |client| which will enter a |bankaccount|.

        :param payment: the |payment| to create the transaction for.
        :param code: the code for the transaction. If not provided,
            the payment identifier will be used by default
        :param source_account: the source |account| for the transaction.
        :param destination_account: the destination |account| for the transaction.
        :returns: the transaction
        """
        if not payment.is_paid():
            raise PaymentError(_("Payment needs to be paid"))
        store = payment.store
        value = payment.paid_value
        if payment.is_outpayment():
            operation_type = cls.TYPE_OUT
            source = source_account or payment.method.destination_account
            destination = (destination_account
                           or sysparam.get_object(store, 'IMBALANCE_ACCOUNT'))
        else:
            operation_type = cls.TYPE_IN
            source = (source_account
                      or sysparam.get_object(store, 'IMBALANCE_ACCOUNT'))
            destination = (destination_account
                           or payment.method.destination_account)

        code = code if code is not None else str(payment.identifier)
        return cls(source_account=source,
                   account=destination,
                   value=value,
                   description=payment.description,
                   code=code,
                   date=payment.paid_date,
                   store=store,
                   payment=payment,
                   operation_type=operation_type)
示例#48
0
    def test_can_close(self):
        service = self.create_service()
        self.assertTrue(service.can_close())

        old = sysparam.get_object(self.store, 'DELIVERY_SERVICE')
        try:
            sysparam.set_object(self.store, 'DELIVERY_SERVICE', service)
            self.assertFalse(service.can_close())
        finally:
            sysparam.set_object(self.store, 'DELIVERY_SERVICE', old)
示例#49
0
 def _set_receiving_order_data(self):
     order = self.wizard.receiving_order
     self.branch.update(order.branch)
     cfop = sysparam.get_object(self.store, 'DEFAULT_PURCHASE_RETURN_CFOP')
     self.cfop.update(cfop)
     if order.receiving_invoice:
         self.person.update(order.receiving_invoice.supplier.person.id)
     for widget in (self.branch, self.person):
         if widget.is_valid():
             widget.set_sensitive(False)
示例#50
0
 def create_model(self, store):
     return AccountTransaction(code=u"",
                               description=u"",
                               value=currency(0),
                               payment=None,
                               date=datetime.datetime.today(),
                               account=sysparam.get_object(store, 'IMBALANCE_ACCOUNT'),
                               source_account=self.parent_account,
                               operation_type=AccountTransaction.TYPE_OUT,
                               store=store)
示例#51
0
 def price(self):
     if self.is_on_sale():
         return self.on_sale_price
     else:
         category = sysparam.get_object(self.store, 'DEFAULT_TABLE_PRICE')
         if category:
             info = self.get_category_price_info(category)
             if info:
                 return info.price
         return self.base_price
示例#52
0
 def create_model(self, store):
     return AccountTransaction(code=u"",
                               description=u"",
                               value=currency(0),
                               payment=None,
                               date=datetime.datetime.today(),
                               account=sysparam.get_object(store, 'IMBALANCE_ACCOUNT'),
                               source_account=self.parent_account,
                               operation_type=AccountTransaction.TYPE_OUT,
                               store=store)
示例#53
0
    def __init__(self, store, hide_footer=False, hide_toolbar=True,
                 selection_mode=None, search_str=None,
                 sale_items=None, quantity=None, double_click_confirm=False,
                 info_message=None):
        """
        Create a new SellableSearch object.
        :param store: a store
        :param hide_footer: do I have to hide the dialog footer?
        :param hide_toolbar: do I have to hide the dialog toolbar?
        :param selection_mode: the kiwi list selection mode
        :param search_str: FIXME
        :param sale_items: optionally, a list of sellables which will be
            used to deduct stock values
        :param quantity: the quantity of stock to add to the order,
            is necessary to supply if you supply an order.
        :param double_click_confirm: If double click a item in the list should
            automatically confirm
        """
        if selection_mode is None:
            selection_mode = gtk.SELECTION_BROWSE
        self._first_search = True
        self._first_search_string = search_str
        self.quantity = quantity
        self._delivery_sellable = sysparam.get_object(store, 'DELIVERY_SERVICE').sellable

        # FIXME: This dictionary should be used to deduct from the
        #        current stock (in the current branch) and not others
        self.current_sale_stock = {}
        if sale_items:
            if selection_mode == gtk.SELECTION_MULTIPLE:
                raise TypeError("gtk.SELECTION_MULTIPLE is not supported "
                                "when supplying an order")
            if self.quantity is None:
                raise TypeError("You need to specify a quantity "
                                "when supplying an order")
            for item in sale_items:
                if item.sellable.product_storable:
                    quantity = self.current_sale_stock.get(item.sellable.id, 0)
                    quantity += item.quantity
                    self.current_sale_stock[item.sellable.id] = quantity

        SearchEditor.__init__(self, store, search_spec=self.search_spec,
                              editor_class=self.editor_class,
                              hide_footer=hide_footer,
                              hide_toolbar=hide_toolbar,
                              selection_mode=selection_mode,
                              double_click_confirm=double_click_confirm)
        self.set_ok_label(self.footer_ok_label)

        if info_message:
            self.set_message(info_message)

        if search_str:
            self.set_searchbar_search_string(search_str)
            self.search.refresh()
示例#54
0
    def create_model(self, store):
        self._model_created = True
        sellable = Sellable(store=store)
        model = Product(store=store, sellable=sellable)
        no_storable = [Product.TYPE_WITHOUT_STOCK, Product.TYPE_PACKAGE]
        if not self._product_type in no_storable:
            storable = Storable(product=model, store=store)

        if self._product_type == Product.TYPE_BATCH:
            storable.is_batch = True
        elif self._product_type == Product.TYPE_WITHOUT_STOCK:
            model.manage_stock = False
        elif self._product_type == Product.TYPE_CONSIGNED:
            model.consignment = True
        elif self._product_type == Product.TYPE_GRID:
            model.is_grid = True
            # Configurable products should not manage stock
            model.manage_stock = False
        elif self._product_type == Product.TYPE_PACKAGE:
            model.is_package = True
            # Package products should not manage stock
            model.manage_stock = False

        if self._template is not None:
            sellable.tax_constant = self._template.sellable.tax_constant
            sellable.unit = self._template.sellable.unit
            sellable.category = self._template.sellable.category
            sellable.base_price = self._template.sellable.base_price
            sellable.cost = self._template.sellable.cost
            sellable.default_sale_cfop = self._template.sellable.default_sale_cfop

            model.manufacturer = self._template.manufacturer
            model.brand = self._template.brand
            model.model = self._template.model
            model.family = self._template.family
            model.ncm = self._template.ncm
            model.set_icms_template(self._template._icms_template)
            model.set_ipi_template(self._template._ipi_template)
            model.set_pis_template(self._template._pis_template)
            model.set_cofins_template(self._template._cofins_template)

            for product_attr in self._template.attributes:
                ProductAttribute(store=self.store,
                                 product_id=model.id,
                                 attribute_id=product_attr.attribute.id)
            for supplier_info in self._template.suppliers:
                ProductSupplierInfo(store=self.store,
                                    product=model,
                                    supplier=supplier_info.supplier)
        else:
            sellable.tax_constant = sysparam.get_object(
                self.store, 'DEFAULT_PRODUCT_TAX_CONSTANT')
            sellable.unit_id = sysparam.get_object_id('SUGGESTED_UNIT')

        return model
示例#55
0
    def test_transporter(self):
        decrease = self.create_stock_decrease()
        self.assertIsNone(decrease.transporter)

        sellable = sysparam.get_object(self.store, 'DELIVERY_SERVICE').sellable
        self.create_stock_decrease_item(sellable=sellable,
                                        stock_decrease=decrease)
        transporter = self.create_transporter()
        delivery = self.create_delivery(transporter=transporter)
        delivery.invoice = decrease.invoice
        self.assertEqual(decrease.transporter, transporter)