def _setup_widgets(self):
        self.tax_constant.prefill(
            stoq_api.for_combo(self.store.find(SellableTaxConstant)))

        categories = set(self.store.find(SellableCategory,
                                         SellableCategory.id != self.model.id))
        # Remove all children recursively to avoid creating
        # a circular hierarchy
        categories -= self.model.get_children_recursively()

        self.category.prefill(
            stoq_api.for_combo(categories, attr='full_description'))
        self.suggested_markup.set_adjustment(
            Gtk.Adjustment(lower=0, upper=MAX_INT, step_increment=1))
Exemple #2
0
 def test_for_combo_attr(self):
     individual = self.create_individual()
     individual.father_name = u'Daddy'
     individual.mother_name = u'Mommy'
     results = self.store.find(Individual, father_name=u'Daddy')
     items = stoq_api.for_combo(results, attr=u'mother_name')
     self.assertEqual(items, [('Mommy', individual)])
    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(
                stoq_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)
 def create_filters(self):
     # Category
     categories = self.store.find(SellableCategory)
     items = stoq_api.for_combo(categories, attr='full_description')
     items.insert(0, (_('Any'), None))
     category_filter = ComboSearchFilter(_('Category'), items)
     self.add_filter(category_filter, columns=[Sellable.category])
    def _setup_widgets(self):
        self.total.set_bold(True)
        idents = sorted(p.identifier for p in self.purchases)
        identifier = ', '.join(str(i) for i in idents)
        self.identifier.set_text(identifier)

        # TODO: Testar isso quando compras > 1
        if len(self.purchases) == 1 and self.purchases[0].is_paid():
            # This widgets would make the value of the installments change.
            for widget in (self.ipi, self.discount_value, self.icms_total,
                           self.icms_st_total, self.secure_value,
                           self.expense_value):
                widget.set_sensitive(False)

        # Only allow to edit the cfop if there is only one receiving for this invoice
        self.cfop.set_sensitive(
            bool(not self.visual_mode and self._receiving_order))

        self._setup_transporter_entry()
        self._setup_freight_combo()

        cfops = CfopData.get_for_receival(self.store)
        self.cfop.prefill(stoq_api.for_combo(cfops))
        self.table.set_focus_chain([
            self.invoice_hbox, self.invoice_key, self.cfop, self.transporter,
            self.freight_combo, self.notes_box, self.freight, self.ipi,
            self.icms_total, self.icms_st_total, self.discount_value,
            self.secure_value, self.expense_value
        ])
Exemple #6
0
    def populate(self, gridgroup):
        from stoqlib.domain.product import GridGroup
        store = get_store_for_field(self)
        self.prefill(stoq_api.for_combo(store.find(GridGroup)), gridgroup)

        self.add_button.set_tooltip_text(_("Add a new grid group"))
        self.edit_button.set_tooltip_text(_("Edit the grid group"))
Exemple #7
0
    def _setup_widgets(self):
        # Salesperson combo
        salespersons = SalesPerson.get_active_salespersons(
            self.store, api.get_current_branch(self.store))
        self.salesperson.prefill(salespersons)

        change_salesperson = sysparam.get_int('ACCEPT_CHANGE_SALESPERSON')
        if change_salesperson == ChangeSalespersonPolicy.ALLOW:
            self.salesperson.grab_focus()
        elif change_salesperson == ChangeSalespersonPolicy.DISALLOW:
            self.salesperson.set_sensitive(False)
        elif change_salesperson == ChangeSalespersonPolicy.FORCE_CHOOSE:
            self.model.salesperson = None
            self.salesperson.grab_focus()
        else:
            raise AssertionError

        # CFOP combo
        if sysparam.get_bool('ASK_SALES_CFOP'):
            cfops = CfopData.get_for_sale(self.store)
            self.cfop.prefill(stoq_api.for_combo(cfops))
        else:
            self.cfop_lbl.hide()
            self.cfop.hide()
            self.create_cfop.hide()

        self._fill_clients_category_combo()
        self._setup_clients_widget()

        self._client_credit_set_visible(bool(self.client.read()))
    def fields(self):
        device_values = stoq_api.for_combo(
            CardPaymentDevice.get_devices(self.store))
        provider_values = stoq_api.for_combo(
            CreditProvider.get_card_providers(self.store))

        return collections.OrderedDict(
            device=ChoiceField(_('Device'),
                               proxy=True,
                               mandatory=True,
                               values=device_values),
            provider=ChoiceField(_('Provider'),
                                 proxy=True,
                                 mandatory=True,
                                 values=provider_values),
            auth=TextField(_('Authorization'), proxy=True, mandatory=True))
Exemple #9
0
    def _fill_clients_category_combo(self):
        categories = self.store.find(ClientCategory).order_by(
            ClientCategory.name)
        self.client_category.prefill(stoq_api.for_combo(categories, empty=''))

        if categories.is_empty():
            self.client_category.hide()
            self.client_category_lbl.hide()
Exemple #10
0
    def setup_sellable_combos(self):
        self._fill_categories()
        self.edit_category.set_sensitive(False)

        cfops = CfopData.get_for_sale(self.store)
        self.default_sale_cfop.prefill(stoq_api.for_combo(cfops, empty=''))

        self.setup_unit_combo()
 def _setup_widgets(self):
     """Populate device widgets and set some properties"""
     # Let the user edit provider_id when creating a new one
     self.provider_id.set_property('sensitive', not self.edit_mode)
     self.provider_id.set_property('editable', not self.edit_mode)
     devices = CardPaymentDevice.get_devices(self.store)
     self.default_device.prefill(
         stoq_api.for_combo(devices, empty=_(u"No device")))
Exemple #12
0
    def populate(self, cfop):
        from stoqlib.domain.fiscal import CfopData
        store = get_store_for_field(self)
        cfops = store.find(CfopData)
        self.prefill(stoq_api.for_combo(cfops), cfop)

        self.add_button.set_tooltip_text(_("Add a new C.F.O.P"))
        self.edit_button.set_tooltip_text(_("View C.F.O.P details"))
Exemple #13
0
 def setup_entry(self, entry):
     entry.set_mode(ENTRY_MODE_DATA)
     entry.set_exact_completion()
     completion = entry.get_completion()
     completion.set_minimum_key_length = 1
     items = self.model.get_available_batches(
         api.get_current_branch(self.store))
     entry.prefill(stoq_api.for_combo(items))
Exemple #14
0
 def test_for_combo_all(self):
     client = self.create_client()
     client.credit_limit = 99
     clients = self.store.find(
         Client,
         credit_limit=99,
     )
     items = stoq_api.for_combo(clients)
     self.assertEqual(items, [('Client', client)])
Exemple #15
0
 def setup_proxies(self):
     categories = self.store.find(ClientCategory)
     self.category_combo.prefill(stoq_api.for_combo(categories, empty=''))
     table = self.model_type
     items = [(value, constant)
              for constant, value in table.statuses.items()]
     self.statuses_combo.prefill(items)
     self.proxy = self.add_proxy(self.model,
                                 ClientStatusSlave.proxy_widgets)
Exemple #16
0
    def setup_proxies(self):
        groups = list(GridGroup.get_active_groups(self.store))
        # If the current group is no longer active, we must add it to the list
        # of groups:
        if not self.model.group.is_active:
            groups.append(self.model.group)

        self.fields['group'].prefill(
            stoq_api.for_combo(groups, attr='description'), self.model.group)
        self.proxy = self.add_proxy(self.model, self.proxy_widgets)
 def _fill_categories_combo(self):
     if self.categories_for_combo is not None:
         categories = self.store.find(
             WorkOrderCategory,
             In(WorkOrderCategory.name, self.categories_for_combo))
     else:
         categories = self.store.find(WorkOrderCategory)
     self.category.color_attribute = 'color'
     self.category.prefill(
         stoq_api.for_combo(categories, empty=_(u"No category")))
    def setup_proxies(self):
        if api.sysparam.get_bool('SYNCHRONIZED_MODE'):
            current = api.get_current_branch(self.store)
            branches = [(current.get_description(), current)]
        else:
            branches = stoq_api.for_combo(
                Branch.get_active_branches(self.store))

        self.branch.prefill(branches)
        self.add_proxy(self.model, self.proxy_widgets)
Exemple #19
0
 def _fill_person_combo(self):
     if self.model.person:
         self.person_combo.prefill([(self.model.person.name,
                                     self.model.person)])
         self.person_combo.set_sensitive(False)
     else:
         # Get only persons of person_type by joining with the table
         query = (self.person_type.person_id == Person.id)
         persons = self.store.find(Person, query)
         self.person_combo.prefill(stoq_api.for_combo(persons, attr='name'))
Exemple #20
0
    def create_filters(self):
        self.search.set_query(self.executer_query)

        # Category
        categories = self.store.find(SellableCategory)
        items = stoq_api.for_combo(categories, attr='full_description')
        items.insert(0, (_('Any'), None))
        category_filter = ComboSearchFilter(_('Category'), items)
        self.add_filter(category_filter, position=SearchFilterPosition.TOP)
        self.category_filter = category_filter
 def fields(self):
     user = stoq_api.for_combo(self.store.find(Employee), empty='')
     return collections.OrderedDict(
         responsible=ChoiceField(_("Responsible"),
                                 mandatory=True,
                                 use_entry=True,
                                 proxy=True,
                                 values=user),
         notes=TextField(_('Notes'), proxy=True),
     )
Exemple #22
0
    def populate(self, address):
        from stoqlib.domain.address import Address
        self.person = address.person if address else None
        store = get_store_for_field(self)
        addresses = store.find(Address,
                               person=self.person).order_by(Address.street)

        self.prefill(stoq_api.for_combo(addresses), address)

        self.add_button.set_tooltip_text(_("Add a new address"))
        self.edit_button.set_tooltip_text(_("Edit the selected address"))
Exemple #23
0
 def create_filters(self):
     self.search.set_query(self._query)
     self.set_text_field_columns([
         'description', 'code', 'barcode', 'category_description',
         'manufacturer'
     ])
     branches = Branch.get_active_branches(self.store)
     self.branch_filter = ComboSearchFilter(
         _('Show by:'), stoq_api.for_combo(branches,
                                           empty=_("All branches")))
     self.branch_filter.select(api.get_current_branch(self.store))
     self.add_filter(self.branch_filter, position=SearchFilterPosition.TOP)
Exemple #24
0
 def populate(self, value):
     from stoqlib.domain.payment.category import PaymentCategory
     store = get_store_for_field(self)
     categories = PaymentCategory.get_by_type(store, self.category_type)
     values = stoq_api.for_combo(categories,
                                 empty=_('No category'),
                                 attr='name')
     self.prefill(values, value)
     # FIXME: Move to noun
     self.add_button.set_tooltip_text(_("Add a new payment category"))
     self.edit_button.set_tooltip_text(
         _("Edit the selected payment category"))
    def _fill_wo_categories_combo(self):
        wo_categories = list(self.store.find(WorkOrderCategory))
        self.wo_categories.color_attribute = 'color'

        self.wo_categories.prefill(
            stoq_api.for_combo(wo_categories, empty=_("No category")))
        self.wo_categories.set_sensitive(len(wo_categories))

        # We can use any work order, since all workorders in the same sale are
        # sharing the same category.
        workorder = WorkOrder.find_by_sale(self.store, self.model).any()
        if workorder and workorder.category:
            self.wo_categories.select(workorder.category)
Exemple #26
0
 def populate(self, value):
     from stoqlib.domain.payment.method import PaymentMethod
     assert self.payment_type is not None
     store = get_store_for_field(self)
     methods = set(
         PaymentMethod.get_creatable_methods(store,
                                             self.payment_type,
                                             separate=self.separate))
     # Add the current value, just in case the payment method is not
     # currently creatable
     methods.add(value)
     self.widget.prefill(stoq_api.for_combo(methods))
     if value is not None:
         self.widget.select(value)
Exemple #27
0
    def _fill_cost_center_combo(self):
        cost_centers = CostCenter.get_active(self.store)

        # we keep this value because each call to is_empty() is a new sql query
        # to the database
        cost_centers_exists = not cost_centers.is_empty()

        if cost_centers_exists:
            self.cost_center.prefill(
                stoq_api.for_combo(cost_centers,
                                   attr='name',
                                   empty=_('No cost center.')))
        self.cost_center.set_visible(cost_centers_exists)
        self.cost_center_lbl.set_visible(cost_centers_exists)
    def _setup_widgets(self):
        # Set a default provider, otherwise, if the user does not change the
        # combo, the provider may not be set (bug in kiwi)
        providers = CreditProvider.get_card_providers(self.store).order_by(
            CreditProvider.short_name)
        self.provider.prefill(stoq_api.for_combo(providers))

        types = [(value, key) for key, value in CreditCardData.types.items()]
        self.card_type.prefill(types)

        # Set values to the ones of the model
        self.installment_start.set_value(self.model.installment_start)
        self.installment_end.set_value(self.model.installment_end)

        self.set_installment_limits()
Exemple #29
0
    def fields(self):
        suppliers = stoq_api.for_combo(self.store.find(Supplier), empty='')

        return collections.OrderedDict(
            item=ChoiceField(_('Item'),
                             mandatory=True,
                             use_entry=True,
                             proxy=True,
                             values=self.items),
            # FIXME change to an appropiate name
            supplier=ChoiceField(_('Supplier'),
                                 mandatory=True,
                                 use_entry=True,
                                 proxy=True,
                                 values=suppliers),
            supplier_order=TextField(_('Supplier Order'),
                                     mandatory=True,
                                     proxy=True),
            is_freebie=BoolField(_('Freebie'), proxy=True),
        )
Exemple #30
0
 def setup_proxies(self):
     repeat_types = get_interval_type_items(with_multiples=True,
                                            adverb=True)
     repeat_types.insert(0, (_('Once'), _ONCE))
     self.repeat.prefill(repeat_types)
     is_paid = self.model.is_paid()
     # Show account information only after the payment is paid
     if is_paid:
         accounts = Account.get_accounts(self.store)
         self.account.prefill(
             stoq_api.for_combo(accounts, attr='long_description'))
         if self.payment_type == Payment.TYPE_OUT:
             account = self.model.transaction.source_account
         else:
             account = self.model.transaction.account
         self.account.select(account)
         self.account.set_property('sensitive', False)
     else:
         self.account.hide()
         self.account_lbl.hide()
     self.add_proxy(self.model, _PaymentEditor.proxy_widgets)