def reserve_items(ident, qty, earmark, die_if_not=True): if qty <= 0: raise ValueError if fpiswire_ident(ident) and not isinstance(qty, Length): qty = Length(str(qty) + 'm') for location in inventory_locations: if not location.is_valid: continue lqty = location.get_ident_qty(ident) if lqty is not None: if lqty > qty: location.reserve_ident_qty(ident, qty, earmark) return 0 elif lqty > 0: location.reserve_ident_qty(ident, lqty, earmark) qty -= lqty if qty == 0: return 0 if qty > 0: logger.warning('Partial Reservation of ' + ident + ' for ' + earmark + ' : Short by ' + str(qty)) if die_if_not is True: raise ValueError("Insufficient Qty. " "Call with die_if_not=True if handled downstream") return qty
def avail_qty(self): try: if fpiswire_ident(self._ident): qty = self._qty if not isinstance(qty, Length): qty = Length(str(self._qty) + 'm') return qty - self.reserved_qty else: return self._qty - self.reserved_qty except AttributeError: return self._qty - self.reserved_qty
def render_search_results(): form = SourcingIdentSearch() if form.validate_on_submit(): ident = form.ident.data qty = form.qty.data if not qty: qty = electronics_qty.get_compliant_qty(ident, 1) form.qty.data = qty try: qty = int(qty) except ValueError: qty = Length(qty) vl = [] for vname in form.vendors.data: v = get_vendor_by_name(vname) if not v: raise ValueError vl.append(v) try: vsi = get_sourcing_information(ident, qty, avendors=vl, allvendors=True, get_all=form.get_all.data) except SourcingException: vsi = [] symbol = get_symbol(ident) stage = { 'crumbroot': '/sourcing', 'breadcrumbs': [ Crumb(name="Sourcing", path=""), Crumb(name="Vendors", path="vendors/"), Crumb(name="Search Results", path="vendors/results") ], 'isinfos': vsi, 'ident': ident, 'symbol': symbol, } return render_template('vendors_search_results.html', stage=stage, form=form, pagetitle='Sourcing Search Results') else: return redirect(url_for('.main'))
def reserve_qty(self, value, earmark): try: if fpiswire_ident(self._ident) and not isinstance(value, Length): value = Length(str(value) + 'm') except AttributeError: pass if value > self.avail_qty: raise ValueError logger.debug("Reserving " + self.ident + " in " + self._parent._dname + " for " + earmark + " : " + str(value)) self._reservations.append((value, earmark))
def sourcing_info_qty(self, qty): from tendril.inventory.guidelines import electronics_qty from tendril.sourcing.electronics import get_sourcing_information from tendril.sourcing.electronics import SourcingException if fpiswire(self.device): iqty = Length(qty) else: iqty = qty iqty = electronics_qty.get_compliant_qty(self.ident, iqty) try: vsi = get_sourcing_information(self.ident, iqty, allvendors=True) except SourcingException: vsi = [] return vsi
def sourcing_info_qty(self, qty): # TODO Complete Migration try: from tendril.inventory.guidelines import electronics_qty from tendril.sourcing.electronics import get_sourcing_information from tendril.sourcing.electronics import SourcingException except ImportError: return [] if fpiswire(self.device) and not isinstance(qty, Length): iqty = Length(qty) else: iqty = qty iqty = electronics_qty.get_compliant_qty(self.ident, iqty) try: vsi = get_sourcing_information(self.ident, iqty, allvendors=True) except SourcingException: vsi = [] return vsi
def create_obom_from_listing(component_list, head): obom_descriptor = OutputElnBomDescriptor(head, None, head, None) obom = OutputBom(obom_descriptor) for line in component_list: device, value, footprint = parse_ident(line['ident']) from tendril.boms.electronics import EntityElnComp item = EntityElnComp() item.define('Undef', device, value, footprint) if device and fpiswire(device): length = Length(line['qty']) if length > 0: wireitem = EntityElnComp() wireitem.define( 'Undef', device, value, str(length) ) obom.insert_component(wireitem) else: num = int(line['qty']) if num > 0: for i in range(num): obom.insert_component(item) return obom
def uquantity(self): device, value, footprint = parse_ident(self.ident) if device is None: # TODO # logger.warning("Device not identified : " + self.ident) pass elif fpiswire(device): try: elen = Length(footprint) * Decimal(0.1) if elen < Length('5mm'): elen = Length('5mm') elif elen > Length('1inch'): elen = Length('1inch') return len(self.refdeslist) * (Length(footprint) + elen) except ValueError: logger.error( "Problem parsing length for ident : " + self.ident ) raise return len(self.refdeslist)
def load_cobom_from_file(f, name, tf=None, verbose=True, generic=False): bomlist = [] header = [] reader = csv.reader(f) for line in reader: line = [elem.strip() for elem in line] if line[0] == 'device': header = line break if verbose: logger.info('Inserting External Boms') oboms = [] for head in header[1:-1]: if verbose: logger.info('Creating Bom : ' + head) obom_descriptor = OutputElnBomDescriptor(head, None, head, None) obom = OutputBom(obom_descriptor) oboms.append(obom) for line in reader: line = [elem.strip() for elem in line] if line[0] == '': continue if line[0] == 'END': break if tf and not tf.has_contextual_repr(line[0]): logger.warn('{0} Possibly not recognized'.format(line[0])) if tf: device, value, footprint = parse_ident( tf.get_canonical_repr(line[0]), generic=generic ) else: device, value, footprint = parse_ident(line[0], generic=generic) logger.debug("Trying to insert line : " + line[0]) # print base_tf.get_canonical_repr(line[0]) from tendril.boms.electronics import EntityElnComp item = EntityElnComp() item.define('Undef', device, value, footprint) for idx, col in enumerate(line[1:-1]): if col != '': if device and fpiswire(device): length = Length(col) if length > 0: wireitem = EntityElnComp() wireitem.define( 'Undef', device, value, str(length) ) oboms[idx].insert_component(wireitem) else: num = int(col) if num > 0: for i in range(num): oboms[idx].insert_component(item) for obom in oboms: if verbose: logger.info('Inserting External Bom : ' + obom.descriptor.configname) bomlist.append(obom) cobom = CompositeOutputBom( bomlist, name=name ) return cobom