def gen_mapfile(vendor, idents, maxage=-1): pb = TendrilProgressBar(max=len(idents)) vendor_obj = controller.get_vendor(name=vendor.cname) for ident in idents: pb.next(note=ident) vpnos, strategy = vendor.search_vpnos(ident) if vpnos is not None: # pb.writeln("Found: {0}\n".format(ident)) avpnos = vpnos else: if strategy not in ['NODEVICE', 'NOVALUE', 'NOT_IMPL']: pb.writeln("Not Found: {0:40}::{1}\n".format(ident, strategy)) avpnos = [] with get_session() as session: # pb.writeln("{0:25} {1}\n".format(ident, avpnos)) controller.set_strategy(vendor=vendor_obj, ident=ident, strategy=strategy, session=session) controller.set_amap_vpnos(vendor=vendor_obj, ident=ident, vpnos=avpnos, session=session) pb.finish() vendor.map._dump_mapfile()
def export_vendor_map_audit(vendor_obj, max_age=-1): if isinstance(vendor_obj, int): vendor_obj = vendor_list[vendor_obj] mapobj = vendor_obj.map outp = os.path.join(VENDOR_MAP_AUDIT_FOLDER, vendor_obj.name + '-electronics-audit.csv') outf = fsutils.VersionedOutputFile(outp) outw = csv.writer(outf) total = mapobj.length() pb = TendrilProgressBar(max=total) for ident in mapobj.get_idents(): for vpno in mapobj.get_all_partnos(ident): try: vp = vendor_obj.get_vpart(vpno, ident, max_age) except VendorPartRetrievalError: logger.error( "Permanent Retrieval Error while getting part {0} from " "{1}. Removing from Map.".format(vpno, vendor_obj.name)) mapobj.remove_apartno(vpno, ident) continue except: logger.error("Unhandled Error while getting part {0} from {1}" "".format(vpno, vendor_obj.name)) raise if isinstance(vp, VendorElnPartBase): row = [ vp.ident, vp.vpno, vp.mpartno, vp.package, vp.vpartdesc, vp.manufacturer, vp.vqtyavail, vp.abs_moq ] else: row = [ vp.ident, vp.vpno, vp.mpartno, None, vp.vpartdesc, vp.manufacturer, vp.vqtyavail, vp.abs_moq ] outw.writerow([six.text_type(s).encode("utf-8") for s in row]) pb.next(note=':'.join([ident, vpno])) # "\n%f%% %s;%s\nGenerating Vendor Map Audit" % ( # percentage, ident, vpno pb.finish() outf.close() logger.info("Written Vendor Map Audit to File : " + vendor_obj.name)
def export_vendor_map_audit(vendor_obj, max_age=600000): if isinstance(vendor_obj, int): vendor_obj = vendor_list[vendor_obj] mapobj = vendor_obj.map outp = os.path.join(config.VENDOR_MAP_AUDIT_FOLDER, vendor_obj.name + '-electronics-audit.csv') outf = fsutils.VersionedOutputFile(outp) outw = csv.writer(outf) total = mapobj.length() pb = TendrilProgressBar(max=total) for ident in mapobj.get_idents(): for vpno in mapobj.get_all_partnos(ident): try: vp = vendor_obj.get_vpart(vpno, ident, max_age) except vendors.VendorPartRetrievalError: logger.error( "Permanent Retrieval Error while getting part {0} from " "{1}. Removing from Map.".format(vpno, vendor_obj.name) ) mapobj.remove_apartno(vpno, ident) continue except: logger.error("Unhandled Error while getting part {0} from {1}" "".format(vpno, vendor_obj.name)) raise try: assert isinstance(vp, vendors.VendorElnPartBase) outw.writerow([vp.ident, vp.vpno, vp.mpartno, vp.package, vp.vpartdesc, vp.manufacturer, vp.vqtyavail, vp.abs_moq]) except AssertionError: outw.writerow([vp.ident, vp.vpno, vp.mpartno, None, vp.vpartdesc, vp.manufacturer, vp.vqtyavail, vp.abs_moq]) pb.next(note=':'.join([ident, vpno])) # "\n%f%% %s;%s\nGenerating Vendor Map Audit" % ( # percentage, ident, vpno pb.finish() outf.close() logger.info("Written Vendor Map Audit to File : " + vendor_obj.name)
def gen_mapfile(vendor, idents): pb = TendrilProgressBar(max=len(idents)) vendor_obj = controller.get_vendor(name=vendor._name) for ident in idents: pb.next(note=ident) vpnos, strategy = vendor.search_vpnos(ident) if vpnos is not None: # pb.writeln("Found: {0}\n".format(ident)) avpnos = vpnos else: if strategy not in ['NODEVICE', 'NOVALUE', 'NOT_IMPL']: pb.writeln("Not Found: {0:40}::{1}\n".format(ident, strategy)) avpnos = [] with get_session() as session: # pb.writeln("{0:25} {1}\n".format(ident, avpnos)) controller.set_strategy(vendor=vendor_obj, ident=ident, strategy=strategy, session=session) controller.set_amap_vpnos(vendor=vendor_obj, ident=ident, vpnos=avpnos, session=session) pb.finish() vendor.map._dump_mapfile()
def gen_verification_checklist(invoice, target_folder, serialno): """ Generates the Customs Duties / Checklist Verification document. :param invoice: The invoice object with customs information :type invoice: :class:`tendril.sourcing.customs.CustomsInvoice` :param target_folder: The folder in which the generated files should be written to :param serialno: The serial number of the Customs documentation set :type serialno: str :return: The output file tuple (path, type) .. rubric:: Template Used ``tendril/dox/templates/customs/verification-duties.tex`` (:download:`Included version <../../tendril/dox/templates/customs/verification-duties.tex>`) .. rubric:: Stage Keys Provided .. list-table:: * - ``date`` - The date the documents were generated at, from :func:`datetime.date.today`. * - ``signatory`` - The name of the person who 'signs' the document, from :data:`tendril.config.legacy.COMPANY_GOVT_POINT`. * - ``inv_no`` - The vendor's invoice number. * - ``inv_date`` - The date of the vendor's invoice. * - ``given_data`` - A dict containing various facts about the invoice. See :attr:`tendril.sourcing.customs.CustomsInvoice.given_data`. * - ``lines`` - A list of :class:`tendril.sourcing.customs.CustomsInvoiceLine` instances. * - ``invoice`` - The :class:`tendril.sourcing.customs.CustomsInvoice` instance. * - ``sno`` - The serial number of the document. * - ``summary`` - A list of dicts containing the summary of the customs duties applicable against a particular section, as described below .. list-table:: Summary keys * - ``section`` - The HS section, a :class:`tendril.sourcing.customs.CustomsSection`` instance. * - ``code`` - The HS section code. * - ``name`` - The HS section name. * - ``idxs`` - Line numbers classified into this line. * - ``qty`` - Total quantity of all lines classified into this line. * - ``assessablevalue`` - Total assessable value of all lines classified into this line. * - ``bcd`` - Total Basic Customs Duty applicable against this section. * - ``cvd`` - Total Countervailing Duty applicable against this section. * - ``acvd`` - Total Additional Countervailing Duty applicable against this section. * - ``cec`` - Total Education Cess on Customs Duty applicable against this section. * - ``cshec`` - Total Secondary and Higher Education Cess on Customs Duty applicable against this section. * - ``cvdec`` - Total Education Cess on Countervailing Duty applicable against this section. * - ``cvdshec`` - Total Secondary and Higher Education Cess on Countervailing Duty applicable against this section. """ print("Generating Customs Duty Verification Checklist") outpath = os.path.join( target_folder, "customs-verification-duties-" + str(invoice.inv_no) + ".pdf") summary = [] pb = TendrilProgressBar(max=len(invoice.hssections)) print("Collating Section Summaries...") for section in invoice.hssections: secsum = { 'section': section, 'code': section.code, 'name': section.name, 'idxs': invoice.getsection_idxs(hssection=section), 'assessablevalue': invoice.getsection_assessabletotal(hssection=section), 'qty': invoice.getsection_qty(hssection=section), 'bcd': sum([ x.bcd.value for x in invoice.getsection_lines(hssection=section) ]), 'cvd': sum([ x.cvd.value for x in invoice.getsection_lines(hssection=section) ]), 'acvd': sum([ x.acvd.value for x in invoice.getsection_lines(hssection=section) ]), 'cec': sum([ x.cec.value for x in invoice.getsection_lines(hssection=section) ]), 'cshec': sum([ x.cshec.value for x in invoice.getsection_lines(hssection=section) ]), 'cvdec': sum([ x.cvdec.value for x in invoice.getsection_lines(hssection=section) ]), 'cvdshec': sum([ x.cvdshec.value for x in invoice.getsection_lines(hssection=section) ]), } summary.append(secsum) pb.next(note=section.code + ' ' + section.name) pb.finish() pb = TendrilProgressBar(max=len(invoice.lines)) pb_summary = TendrilProgressBar(max=len(summary)) stage = { 'date': datetime.date.today().isoformat(), 'signatory': COMPANY_GOVT_POINT, 'inv_no': invoice.inv_no, 'inv_date': invoice.inv_date, 'given_data': invoice.given_data, 'lines': invoice.lines, 'summary': summary, 'invoice': invoice, 'sno': serialno + '.7', 'pb': pb, 'pb_summary': pb_summary } print("Rendering...") outpath = render.render_pdf(stage, 'customs/verification-duties.tex', outpath) return outpath, 'CUST-VERIF-BOE'
def gen_verification_checklist(invoice, target_folder, serialno): """ Generates the Customs Duties / Checklist Verification document. :param invoice: The invoice object with customs information :type invoice: :class:`tendril.sourcing.customs.CustomsInvoice` :param target_folder: The folder in which the generated files should be written to :param serialno: The serial number of the Customs documentation set :type serialno: str :return: The output file tuple (path, type) .. rubric:: Template Used ``tendril/dox/templates/customs/verification-duties.tex`` (:download:`Included version <../../tendril/dox/templates/customs/verification-duties.tex>`) .. rubric:: Stage Keys Provided .. list-table:: * - ``date`` - The date the documents were generated at, from :func:`datetime.date.today`. * - ``signatory`` - The name of the person who 'signs' the document, from :data:`tendril.utils.config.COMPANY_GOVT_POINT`. * - ``inv_no`` - The vendor's invoice number. * - ``inv_date`` - The date of the vendor's invoice. * - ``given_data`` - A dict containing various facts about the invoice. See :attr:`tendril.sourcing.customs.CustomsInvoice.given_data`. * - ``lines`` - A list of :class:`tendril.sourcing.customs.CustomsInvoiceLine` instances. * - ``invoice`` - The :class:`tendril.sourcing.customs.CustomsInvoice` instance. * - ``sno`` - The serial number of the document. * - ``summary`` - A list of dicts containing the summary of the customs duties applicable against a particular section, as described below .. list-table:: Summary keys * - ``section`` - The HS section, a :class:`tendril.sourcing.customs.CustomsSection`` instance. * - ``code`` - The HS section code. * - ``name`` - The HS section name. * - ``idxs`` - Line numbers classified into this line. * - ``qty`` - Total quantity of all lines classified into this line. * - ``assessablevalue`` - Total assessable value of all lines classified into this line. * - ``bcd`` - Total Basic Customs Duty applicable against this section. * - ``cvd`` - Total Countervailing Duty applicable against this section. * - ``acvd`` - Total Additional Countervailing Duty applicable against this section. * - ``cec`` - Total Education Cess on Customs Duty applicable against this section. * - ``cshec`` - Total Secondary and Higher Education Cess on Customs Duty applicable against this section. * - ``cvdec`` - Total Education Cess on Countervailing Duty applicable against this section. * - ``cvdshec`` - Total Secondary and Higher Education Cess on Countervailing Duty applicable against this section. """ print("Generating Customs Duty Verification Checklist") outpath = os.path.join( target_folder, "customs-verification-duties-" + str(invoice.inv_no) + ".pdf" ) summary = [] pb = TendrilProgressBar(max=len(invoice.hssections)) print("Collating Section Summaries...") for section in invoice.hssections: secsum = {'section': section, 'code': section.code, 'name': section.name, 'idxs': invoice.getsection_idxs(hssection=section), 'assessablevalue': invoice.getsection_assessabletotal(hssection=section), 'qty': invoice.getsection_qty(hssection=section), 'bcd': sum([x.bcd.value for x in invoice.getsection_lines(hssection=section)]), 'cvd': sum([x.cvd.value for x in invoice.getsection_lines(hssection=section)]), 'acvd': sum([x.acvd.value for x in invoice.getsection_lines(hssection=section)]), 'cec': sum([x.cec.value for x in invoice.getsection_lines(hssection=section)]), 'cshec': sum([x.cshec.value for x in invoice.getsection_lines(hssection=section)]), 'cvdec': sum([x.cvdec.value for x in invoice.getsection_lines(hssection=section)]), 'cvdshec': sum([x.cvdshec.value for x in invoice.getsection_lines(hssection=section)]), } summary.append(secsum) pb.next(note=section.code + ' ' + section.name) pb.finish() pb = TendrilProgressBar(max=len(invoice.lines)) pb_summary = TendrilProgressBar(max=len(summary)) stage = {'date': datetime.date.today().isoformat(), 'signatory': COMPANY_GOVT_POINT, 'inv_no': invoice.inv_no, 'inv_date': invoice.inv_date, 'given_data': invoice.given_data, 'lines': invoice.lines, 'summary': summary, 'invoice': invoice, 'sno': serialno + '.7', 'pb': pb, 'pb_summary': pb_summary} print("Rendering...") outpath = render.render_pdf( stage, 'customs/verification-duties.tex', outpath ) return outpath, 'CUST-VERIF-BOE'