Advertisement
Guest User

Part 1: Macros

a guest
Dec 17th, 2014
367
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 11.90 KB | None | 0 0
  1. {%- macro render_field(df, doc) -%}
  2.         {%- if df.fieldtype=="Table" -%}
  3.                 {{ render_table(df, doc) }}
  4.         {%- elif df.fieldtype=="HTML" -%}
  5.                 <div>{{ df.options or "" }}</div>
  6.         {%- elif df.fieldtype in ("Text", "Text Editor", "Code") -%}
  7.                 {{ render_text_field(df, doc) }}
  8.    
  9.         {%- endif -%}
  10. {%- endmacro -%}
  11.  
  12. {%- macro render_table(df, doc, page_num, max_pages) -%}
  13.         {%- set table_meta = frappe.get_meta(df.options) -%}
  14.         {%- set data = doc.get(df.fieldname)[df.start:df.end] -%}
  15.  
  16.                 {%- if data -%}
  17.                 {%- set visible_columns = get_visible_columns(doc.get(df.fieldname),
  18.                         table_meta) -%}
  19.                 <div>
  20.                       {% if doc.doctype == "Sales Invoice" %}
  21.                         <table class="table table-bordered table-condensed">
  22.                                 <thead>
  23.                                         <tr>
  24.                                             <th width="5%">Pos.</b></th>
  25.                                             <th width="10%">Art. Nr.</b></th>
  26.                                             <th width="54%">Beschreibung</b></th>
  27.                                             <th width="7%" class="text-right">Menge</th>
  28.                                             <th width="12%" class="text-right">Preis</th>
  29.                                             <th width="12%" class="text-right">Gesamt</th>
  30.                                         </tr>
  31.                                 </thead>
  32.                                 <tbody>
  33.                                         {% for d in data %}
  34. <tr>
  35.                                                 <td>{{ d.idx }}</td>
  36.                                          
  37.                                                         <td>{{ d.item_code }}</td>
  38.                                                         <td>{{ d.item_name }}
  39.                                                         <br>{{ d.description }}</td>
  40.                                                         <td>{{ d.qty }}</td>
  41.                                                         <td>{{ d.get_formatted("price_list_rate") }}{%- if d.discount_percentage -%}<br>- {{ d.discount_percentage }} %{%- endif -%}</td>
  42.                                                         <td>{{ d.get_formatted("amount") }}</td>
  43.                                                        
  44.                                          
  45.                                         </tr>
  46.                                         {% endfor %}
  47.                                 </tbody>
  48.                         </table>
  49.                         {% elif doc.doctype == "Purchase Order" %}
  50.                         <table class="table table-bordered table-condensed">
  51.                                 <thead>
  52.                                         <tr>
  53.                                             <th width="5%">Pos.</b></th>
  54.                                             <th width="10%">Art. Nr.</b></th>
  55.                                             <th width="54%">Beschreibung</b></th>
  56.                                             <th width="7%" class="text-right">Menge</th>
  57.                                             <th width="12%" class="text-right">Preis</th>
  58.                                             <th width="12%" class="text-right">Gesamt</th>
  59.                                         </tr>
  60.                                 </thead>
  61.                                 <tbody>
  62.                                         {% for d in data %}
  63. <tr>
  64.                                                 <td>{{ d.idx }}</td>
  65.                                          
  66.                                                         <td>{{ d.item_code }}</td>
  67.                                                         <td>{{ d.item_name }}
  68.                                                         <br>{{ d.description }}</td>
  69.                                                         <td>{{ d.qty }}</td>
  70.                                                         <td>{{ d.get_formatted("price_list_rate") }}{%- if d.discount_percentage -%}<br>- {{ d.discount_percentage }} %{%- endif -%}</td>
  71.                                                         <td>{{ d.get_formatted("amount") }}</td>
  72.                                                        
  73.                                          
  74.                                         </tr>
  75.                                         {% endfor %}
  76.                                 </tbody>
  77.                         </table>
  78.                         {% elif doc.doctype == "Delivery Note" %}
  79.                            <table class="table table-bordered table-condensed">
  80.                                 <thead>
  81.                                         <tr>
  82.                                             <th width="7%">Pos.</b></th>
  83.                                             <th width="13%">Art. Nr.</b></th>
  84.                                             <th width="65%">Beschreibung</b></th>
  85.                                             <th width="15%" class="text-right">Menge</th>
  86.                                        
  87.                                         </tr>
  88.                                 </thead>
  89.                                 <tbody>
  90.                                         {% for d in data %}
  91. <tr>
  92.                                                 <td>{{ d.idx }}</td>
  93.                                          
  94.                                                         <td>{{ d.item_code }}</td>
  95.                                                         <td>{{ d.item_name }}
  96.                                                         <br>{{ d.description }}</td>
  97.                                                         <td>{{ d.qty }}</td>
  98.                                                        
  99.                                                        
  100.                                          
  101.                                         </tr>
  102.                                         {% endfor %}
  103.                                 </tbody>
  104.                         </table>
  105.                         {%- else -%}
  106.                         <table class="table table-bordered table-condensed">
  107.                                 <thead>
  108.                                         <tr>
  109.                                             <th width="5%">Pos.</b></th>
  110.                                             <th width="10%">Art. Nr.</b></th>
  111.                                             <th width="54%">Beschreibung</b></th>
  112.                                             <th width="7%" class="text-right">Menge</th>
  113.                                             <th width="12%" class="text-right">Preis</th>
  114.                                             <th width="12%" class="text-right">Gesamt</th>
  115.                                         </tr>
  116.                                 </thead>
  117.                                 <tbody>
  118.                                         {% for d in data %}
  119. <tr>
  120.                                                 <td>{{ d.idx }}</td>
  121.                                          
  122.                                                         <td>{{ d.item_code }}</td>
  123.                                                         <td>{{ d.item_name }}
  124.                                                         <br>{{ d.description }}</td>
  125.                                                         <td>{{ d.qty }}</td>
  126.                                                         <td>{{ d.get_formatted("price_list_rate") }}{%- if d.discount_percentage -%}<br>- {{ d.discount_percentage }} %{%- endif -%}</td>
  127.                                                         <td>{{ d.get_formatted("amount") }}</td>
  128.                                                        
  129.                                          
  130.                                         </tr>
  131.                                         {% endfor %}
  132.                                 </tbody>
  133.                         </table>
  134.                          {%- endif -%}
  135.                 </div>
  136.                 {%- endif -%}
  137.                
  138.                
  139.                 {{ max_pages }}<br>
  140.                 {{ num_page }}
  141.          
  142.                
  143.                
  144.        
  145. {%- endmacro -%}
  146.  
  147.  
  148. {%- macro render_text_field(df, doc) -%}
  149.  
  150. {%- if doc.get(df.fieldname) != None -%}
  151. <div style="padding: 10px 0px">
  152.        
  153.         {% if doc.doctype == "Customer Issue" %}
  154.         <table>
  155.         <tr>
  156.         <td width="40%">Produkt</td>
  157.         <td width="60%">Reklamation</td>
  158.         </tr>
  159.             <tr>
  160.         <td width="40%">{{ doc.item_name }}</td>
  161.         <td width="60%">{{ doc.complaint }}</td>
  162.         </tr>
  163.         </table>
  164.        
  165.         {% endif -%}
  166.        
  167.  
  168.         {%- if df.fieldtype in ("Text", "Code") %}<label>{{ _(df.label) }}</label>{%- endif %}
  169.         {%- if df.fieldtype=="Code" %}
  170.                 <pre>{{ doc.get(df.fieldname) }}</pre>
  171. {% else -%}
  172.                 {{ doc.get_formatted(df.fieldname, parent_doc or doc) }}
  173.         {% endif -%}
  174. </div>
  175. {%- endif -%}
  176.  
  177.  
  178. {%- endmacro -%}
  179.  
  180. {%- macro print_value(df, doc, parent_doc=None) -%}
  181.         {% if df.fieldtype=="Check" %}
  182.                 <i class="{{ 'icon-check' if doc[df.fieldname] else 'icon-check-empty' }}"></i>
  183.         {% elif df.fieldtype=="Image" %}
  184.                 <img src="{{ doc[doc.meta.get_field(df.fieldname).options] }}" class="img-responsive">
  185.         {% else %}
  186.                 {{ doc.get_formatted(df.fieldname, parent_doc or doc) }}
  187.         {% endif %}
  188. {%- endmacro %}
  189.  
  190. {% macro get_width(df) -%}
  191.         {%- if df.print_width -%}{{ (df.print_width|str).replace("px", "") }}
  192.         {%- elif df.fieldtype in ("Int", "Check", "Float", "Currency") -%}{{ 80 }}
  193.         {%- else -%}{{ 150 }}{% endif -%}
  194. {%- endmacro %}
  195.  
  196.  
  197.  
  198. {% macro get_align_class(fieldtype) %}
  199.         {%- if fieldtype in ("Int", "Check", "Float", "Currency") -%}{{ "text-right" }}
  200.         {%- else -%}{{ "" }}
  201.         {%- endif -%}
  202. {% endmacro %}
  203.  
  204. {%- macro add_header(page_num, max_pages, doc, letter_head, no_letterhead) -%}
  205.         {% if letter_head and not no_letterhead %}
  206.         <div class="letter-head">{{ letter_head }}</div>
  207.         {% endif %}
  208.      
  209.         {% if page_num == 1 %}
  210.       <br><br><br>  <table width="100%">
  211. <tr>
  212.     <td width="60%">
  213.          {% if doc.doctype == "Purchase Order" %}
  214.          <p style="line-height:145%;">{{ doc.supplier_name }}<br>{{ doc.supplier_address.address_line1 }}<br>
  215.         <div id="test" style="display:none;"></div>
  216.         </p>
  217.          {% else %}
  218.          <p style="line-height:145%;">{{ doc.customer_name }}<br>{{ doc.address_display }}<br>
  219.         <div id="test" style="display:none;"></div>
  220.         </p>
  221.         {% endif %}
  222.     </td>
  223.     <td width="40%">
  224.         <!-- Rechnungsnummer und so -->
  225.        
  226.         <table style="line-height:145%;" width="100%">
  227.         <tr>
  228.             <td width="50%">Belegnummer</td>
  229.             <td width="50%" style="text-align:right;">{{ doc.name }}</td>
  230.         </tr>
  231.                
  232.         </table>
  233.     </td>
  234. </tr>
  235. </table>
  236.  
  237. <br><br>
  238. <table width="100%">
  239.     <tr>
  240.         <td width="50%">
  241.     <div id="Rechnung">
  242.     </div>
  243.         {% if doc.doctype == "Sales Invoice" %}
  244.             <big><big><big><big>Rechnung </big></big></big></big>
  245.         {% elif doc.doctype == "Purchase Order" %}
  246.             <big><big><big><big>Bestellung </big></big></big></big>    
  247.         {% elif doc.doctype == "Delivery Note" %}
  248.         <big><big><big><big>Lieferschein </big></big></big></big>  
  249.         {% elif doc.doctype == "Sales Order" %}
  250.         <big><big><big><big>Auftragsbestätigung </big></big></big></big>  
  251.         {% elif doc.doctype == "Customer Issue" %}
  252.         <big><big><big><big>Kundenreklamation </big></big></big></big> 
  253.         {% else %}
  254.        
  255.         <big><big><big><big>{{ doc.doctype }} </big></big></big></big>
  256.         {% endif %}
  257.         </td>
  258.         <td width="50%" style="text-align:right; valign:top;">
  259.          {% if doc.doctype == "Purchase Order" %}
  260.          
  261.          {% elif doc.doctype == "Customer Issue" %}
  262.          
  263.          {% else %}
  264.          <b>Datum:</b> {{ doc.get_formatted("posting_date") }}<br>
  265.          {% endif %}
  266.         </td>
  267.     </tr>
  268. </table>
  269.  
  270. <br><br>
  271.         {% endif %}
  272.        
  273.        
  274.         {% if max_pages > 1 %}
  275.        
  276.          {% if page_num ==  max_pages %}
  277.         <table width="100%">
  278. <tr>
  279.     <td width="60%">
  280.         <table style="line-height:145%;" width="100%">
  281.         <tr>
  282.             <td width="50%">Rechnungsnr.</td>
  283.             <td width="50%" style="text-align:right;">{{ doc.name }}</td>
  284.         </tr>
  285.                
  286.         </table>
  287.        
  288.     </td>
  289.     <td width="40%">
  290.         <!-- Rechnungsnummer und so -->
  291.          <p class="text-right">{{ _("Seite {0} von {1}").format(page_num, max_pages) }}</p>
  292.        
  293.     </td>
  294. </tr>
  295. </table>
  296.  
  297.        <br>{% endif %}
  298.         {% endif %}
  299. {%- endmacro -%}
  300.  
  301.  
  302. {%- macro bottom(meta) -%}
  303.  
  304. {{ page }}
  305.          <p class="text-right">{{ _("Seite {0} von {1}").format(page_num, max_pages) }}</p>
  306.  
  307.  
  308. {%- endmacro -%}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement