def apply_patch(store): store.execute(""" CREATE TABLE sale_comment ( id uuid PRIMARY KEY DEFAULT uuid_generate_v1(), te_id bigint UNIQUE REFERENCES transaction_entry(id), date timestamp, comment text, sale_id uuid NOT NULL REFERENCES sale(id) ON UPDATE CASCADE, author_id uuid NOT NULL REFERENCES login_user(id) ON UPDATE CASCADE ); """) tables = [ Sale, Join(SalesPerson, Sale.salesperson_id == SalesPerson.id), Join(Person, SalesPerson.person_id == Person.id), Join(LoginUser, LoginUser.person_id == Person.id) ] for sale, user in store.using(*tables).find((Sale, LoginUser), Ne(Sale.notes, None)): SaleComment(store=store, sale_id=sale.id, author_id=user.id, date=sale.open_date, comment=sale.notes) # Just a precaution: Flush to make sure we do the migration before # dropping the column store.flush() store.execute("ALTER TABLE sale DROP COLUMN notes;")
def executer_query(self, store): results = super(SaleSellableSearch, self).executer_query(store) # if we select a quantity which is not an integer, filter out # sellables without a unit set if self._quantity is not None and (self._quantity % 1) != 0: results = results.find(Ne(Sellable.unit_id, None)) return results
def get_plugin_names(cls, store): """Fetchs a list of installed plugin names :param store: a store :returns: list of strings """ return [ p.plugin_name for p in store.find(cls, Ne(cls.plugin_version, None)) ]
def has_adjusted_items(self): """Returns if we already have an item adjusted or not. :returns: ``True`` if there is one or more items adjusted, False otherwise. """ query = And(InventoryItem.inventory_id == self.id, Ne(InventoryItem.cfop_data_id, None), InventoryItem.reason != u"") return not self.store.find(InventoryItem, query).is_empty()
def executer_query(self, store): queries = [] if self._delivery_sellable: queries.append( And(SellableFullStockView.status == Sellable.STATUS_AVAILABLE, SellableFullStockView.id != self._delivery_sellable.id)) # If we select a quantity which is not an integer, filter out # sellables without a unit set if self.quantity is not None and (self.quantity % 1) != 0: queries.append(Ne(Sellable.unit_id, None)) branch = api.get_current_branch(store) results = SellableFullStockView.find_by_branch(store, branch) if queries: return results.find(And(*queries)) return results
def fill_features(store): conn = uutils.get_feature_db() @uutils.memo def tag_fct(tag): return uutils.tag_features(tag, conn=conn, normalize=True) for track in store.find(Track, Ne(Track.tags, None) & Eq(Track.features, None)): print "Processing %s - %s ..." % (track.artist, track.title) if isinstance(track.tags, basestring): continue features = uutils.track_features(track.tags, conn=conn, tag_fct=tag_fct) if features is None: # The track probably didn't have any tags. print "-- Feature vector is null." continue # Serialize and save the feature vector. track.features = uutils.encode_features(features) store.commit()
def get_saved_items(self): return self.model.returned_items.find(Ne(ReturnedSaleItem.quantity, 0))
def get_stock_trasaction_entries(self): return self.store.find( CostCenterEntry, And(CostCenterEntry.cost_center == self, Ne(CostCenterEntry.stock_transaction_id, None)))
def get_payment_entries(self): return self.store.find( CostCenterEntry, And(CostCenterEntry.cost_center == self, Ne(CostCenterEntry.payment_id, None)))
def _get_query(self, states): return Ne(ServiceView.service_id, None)
def _get_orders(self): branch = api.get_current_branch(self.store) query = And(Ne(WorkOrderView.sale_id, None), Eq(WorkOrderView.branch_id, branch.id)) result = WorkOrderView.find_pending(self.store).find(query) return result.order_by(WorkOrder.estimated_finish, WorkOrder.status)
def _get_categories(cls, store): categories_root = [] aux = {} branch = api.get_current_branch(store) # SellableCategory and Sellable/Product data # FIXME: Remove categories that have no products inside them for c in store.find(SellableCategory): if c.category_id is None: parent_list = categories_root else: parent_list = aux.setdefault( c.category_id, {}).setdefault('children', []) c_dict = aux.setdefault(c.id, {}) parent_list.append(c_dict) # Set/Update the data c_dict.update({ 'id': c.id, 'description': c.description, }) c_dict.setdefault('children', []) products_list = c_dict.setdefault('products', []) tables = [Sellable, LeftJoin(Product, Product.id == Sellable.id)] if branch.person.company.cnpj.startswith('11.950.487'): # For now, only display products that have a fiscal configuration for the # current branch. We should find a better way to ensure this in the future tables.append( Join(ProductBranchOverride, And(ProductBranchOverride.product_id == Product.id, ProductBranchOverride.branch_id == branch.id, Ne(ProductBranchOverride.icms_template_id, None)))) sellables = store.using(*tables).find( Sellable, category=c, status='available').order_by('height', 'description') for s in sellables: ccp = store.find(ClientCategoryPrice, sellable_id=s.id) ccp_dict = {} for item in ccp: ccp_dict[item.category_id] = str(item.price) products_list.append({ 'id': s.id, 'description': s.description, 'price': str(s.price), 'order': str(s.product.height), 'category_prices': ccp_dict, 'color': s.product.part_number, 'availability': ( s.product and s.product.storable and { si.branch.id: str(si.quantity) for si in s.product.storable.get_stock_items() } ) }) aux[c.id] = c_dict return categories_root
def get(self, store): data = request.args request_available = data.get('ativo') request_branches = data.get('lojas') branch_ids = _parse_request_list(request_branches) database_branches = store.find(Branch) database_branch_ids = [branch.id for branch in database_branches] not_found_ids = [ branch_id for branch_id in branch_ids if branch_id not in database_branch_ids ] if not_found_ids: message = 'Branch(es) %s not found' % not_found_ids log.error(message) abort(404, message) delivery = sysparam.get_object(store, 'DELIVERY_SERVICE') if request_available == '1': sellables = Sellable.get_available_sellables(store) elif request_available == '0': # We want to exclude not available sellables and the ones # that are not products, example "Entrega" sellables = store.find( Sellable, And(Ne(Sellable.id, delivery.sellable.id), Ne(Sellable.description, 'Entrega'), Ne(Sellable.status, Sellable.STATUS_AVAILABLE))) else: sellables = store.find( Sellable, And(Ne(Sellable.id, delivery.sellable.id), Ne(Sellable.description, 'Entrega'))) self.network = _get_network_info() response = [] if not branch_ids: for sellable in sellables: res_item = self._get_response_item(sellable, branch_id=None) response.append(res_item) return response query = ProductBranchOverride.branch_id.is_in(branch_ids) pbos = store.find(ProductBranchOverride, query) branch_sellable_ids = {} for pbo in pbos: branch_sellable_ids.setdefault(pbo.branch_id, []) branch_sellable_ids[pbo.branch_id].append(pbo.product_id) for branch_id in branch_ids: if not branch_sellable_ids.get(branch_id): branch_sellables = sellables else: sellable_ids = branch_sellable_ids[branch_id] branch_sellables = [ sellable for sellable in sellables if sellable.id in sellable_ids ] for sellable in branch_sellables: res_item = self._get_response_item(sellable, branch_id=branch_id) response.append(res_item) return response
def _setup_widgets(self): if self._is_batch: self._add_batches_tab() self.receiving_list.set_columns(self._get_receiving_columns()) self.sales_list.set_columns(self._get_sale_columns()) self.transfer_list.set_columns(self._get_transfer_columns()) self.loan_list.set_columns(self._get_loan_columns()) self.decrease_list.set_columns(self._get_decrease_columns()) self.inventory_list.set_columns(self._get_inventory_columns()) self.returned_list.set_columns(self._get_returned_columns()) current_branch = api.get_current_branch(self.store) items = self.store.find(ReceivingItemView, sellable_id=self.model.id) if api.sysparam.get_bool('SYNCHRONIZED_MODE'): items = items.find(Branch.id == current_branch.id) self.receiving_list.add_list(list(items)) items = SaleItemsView.find_confirmed(self.store, sellable=self.model) if api.sysparam.get_bool('SYNCHRONIZED_MODE'): items = items.find(Branch.id == current_branch.id) self.sales_list.add_list(list(items)) items = self.store.find( TransferOrderItem, And(Ne(TransferOrderItem.transfer_order_id, None), TransferOrderItem.sellable_id == self.model.id)) self.transfer_list.add_list(list(items)) items = self.store.find(LoanItemView, sellable_id=self.model.id) if api.sysparam.get_bool('SYNCHRONIZED_MODE'): items = items.find(Branch.id == current_branch.id) self.loan_list.add_list(list(items)) items = self.store.find(StockDecreaseItemsView, sellable=self.model.id) if api.sysparam.get_bool('SYNCHRONIZED_MODE'): items = items.find(Branch.id == current_branch.id) self.decrease_list.add_list(list(items)) items = InventoryItemsView.find_by_product(self.store, self.model.product) if api.sysparam.get_bool('SYNCHRONIZED_MODE'): items = items.find(Branch.id == current_branch.id) self.inventory_list.add_list(items) items = self.store.find(ReturnedSaleItemsView, sellable_id=self.model.id) if api.sysparam.get_bool('SYNCHRONIZED_MODE'): items = items.find(Branch.id == current_branch.id) self.returned_list.add_list(items) value_format = '<b>%s</b>' total_label = "<b>%s</b>" % api.escape(_("Total:")) receiving_summary_label = SummaryLabel(klist=self.receiving_list, column='quantity', label=total_label, value_format=value_format) receiving_summary_label.show() self.receiving_vbox.pack_start(receiving_summary_label, False) sales_summary_label = SummaryLabel(klist=self.sales_list, column='quantity', label=total_label, value_format=value_format) sales_summary_label.show() self.sales_vbox.pack_start(sales_summary_label, False) transfer_summary_label = SummaryLabel(klist=self.transfer_list, column='quantity', label=total_label, value_format=value_format) transfer_summary_label.show() self.transfer_vbox.pack_start(transfer_summary_label, False) loan_summary_label = SummaryLabel(klist=self.loan_list, column='quantity', label=total_label, value_format=value_format) self.loan_vbox.pack_start(loan_summary_label, False) decrease_summary_label = SummaryLabel(klist=self.decrease_list, column='quantity', label=total_label, value_format=value_format) decrease_summary_label.show() self.decrease_vbox.pack_start(decrease_summary_label, False)