<s> from __future__ import absolute_import , unicode_literals <EOL> from decimal import Decimal <EOL> from django . core . urlresolvers import get_callable <EOL> from django . utils . text import capfirst <EOL> from django . utils . translation import activate , ugettext as _ <EOL> from pdfdocument . document import cm , mm <EOL> from pdfdocument . elements import create_stationery_fn <EOL> import plata <EOL> class OrderReport ( object ) : <EOL> def __init__ ( self , pdf , order ) : <EOL> self . pdf = pdf <EOL> self . order = order <EOL> if order . language_code : <EOL> activate ( order . language_code ) <EOL> def init_letter ( self ) : <EOL> self . pdf . init_letter ( page_fn = create_stationery_fn ( <EOL> get_callable ( plata . settings . PLATA_REPORTING_STATIONERY ) ( ) ) ) <EOL> def address ( self , address_key ) : <EOL> """<STR_LIT>""" <EOL> if plata . settings . PLATA_REPORTING_ADDRESSLINE : <EOL> self . pdf . address_head ( plata . settings . PLATA_REPORTING_ADDRESSLINE ) <EOL> self . pdf . address ( self . order . addresses ( ) [ address_key ] ) <EOL> self . pdf . next_frame ( ) <EOL> def title ( self , title = None ) : <EOL> self . pdf . p ( u'<STR_LIT>' % ( <EOL> capfirst ( _ ( '<STR_LIT>' ) ) , <EOL> self . order . confirmed . strftime ( '<STR_LIT>' ) <EOL> if self . order . confirmed else _ ( '<STR_LIT>' ) , <EOL> ) ) <EOL> self . pdf . spacer ( <NUM_LIT:3> * mm ) <EOL> if not title : <EOL> title = _ ( '<STR_LIT>' ) <EOL> self . pdf . h1 ( u'<STR_LIT>' % ( title , self . order . order_id ) ) <EOL> self . pdf . hr ( ) <EOL> def items_without_prices ( self ) : <EOL> self . pdf . table ( <EOL> [ <EOL> ( <EOL> _ ( '<STR_LIT>' ) , <EOL> capfirst ( _ ( '<STR_LIT>' ) ) , <EOL> capfirst ( _ ( '<STR_LIT>' ) ) , <EOL> ) <EOL> ] + [ <EOL> ( <EOL> item . sku , <EOL> item . name , <EOL> item . quantity , <EOL> ) for item in self . order . items . all ( ) <EOL> ] , <EOL> ( <NUM_LIT:2> * cm , <NUM_LIT> * cm , <NUM_LIT:1> * cm ) , self . pdf . style . tableHead + ( <EOL> ( '<STR_LIT>' , ( <NUM_LIT:1> , <NUM_LIT:0> ) , ( <NUM_LIT:1> , - <NUM_LIT:1> ) , '<STR_LIT>' ) , <EOL> ) ) <EOL> def items_with_prices ( self ) : <EOL> self . pdf . table ( <EOL> [ <EOL> ( <EOL> _ ( '<STR_LIT>' ) , <EOL> capfirst ( _ ( '<STR_LIT>' ) ) , <EOL> capfirst ( _ ( '<STR_LIT>' ) ) , <EOL> capfirst ( _ ( '<STR_LIT>' ) ) , <EOL> capfirst ( _ ( '<STR_LIT>' ) ) , <EOL> ) <EOL> ] + [ <EOL> ( <EOL> item . sku , <EOL> item . name , <EOL> item . quantity , <EOL> u'<STR_LIT>' % item . unit_price , <EOL> u'<STR_LIT>' % item . discounted_subtotal , <EOL> ) for item in self . order . items . all ( ) <EOL> ] , <EOL> ( <NUM_LIT:2> * cm , <NUM_LIT:6> * cm , <NUM_LIT:1> * cm , <NUM_LIT:3> * cm , <NUM_LIT> * cm ) , <EOL> self . pdf . style . tableHead + ( <EOL> ( '<STR_LIT>' , ( <NUM_LIT:1> , <NUM_LIT:0> ) , ( <NUM_LIT:1> , - <NUM_LIT:1> ) , '<STR_LIT>' ) , <EOL> ) ) <EOL> def summary ( self ) : <EOL> summary_table = [ <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( capfirst ( _ ( '<STR_LIT>' ) ) , u'<STR_LIT>' % self . order . subtotal ) , <EOL> ] <EOL> if self . order . discount : <EOL> summary_table . append ( ( <EOL> capfirst ( _ ( '<STR_LIT>' ) ) , <EOL> u'<STR_LIT>' % self . order . discount ) ) <EOL> if self . order . shipping : <EOL> summary_table . append ( ( <EOL> capfirst ( _ ( '<STR_LIT>' ) ) , <EOL> u'<STR_LIT>' % self . order . shipping ) ) <EOL> self . pdf . table ( <EOL> summary_table , ( <NUM_LIT:12> * cm , <NUM_LIT> * cm ) , self . pdf . style . table ) <EOL> self . pdf . spacer ( <NUM_LIT:1> * mm ) <EOL> total_title = u'<STR_LIT>' % ( capfirst ( _ ( '<STR_LIT>' ) ) , self . order . currency ) <EOL> if self . order . tax : <EOL> if '<STR_LIT>' in self . order . data : <EOL> zero = Decimal ( '<STR_LIT>' ) <EOL> self . pdf . table ( [ ( <EOL> u'<STR_LIT>' , <EOL> u'<STR_LIT>' % ( <EOL> _ ( '<STR_LIT>' ) , <EOL> u'<STR_LIT>' % row [ '<STR_LIT>' ] , <EOL> ) , <EOL> row [ '<STR_LIT>' ] . quantize ( zero ) , <EOL> row [ '<STR_LIT>' ] . quantize ( zero ) , <EOL> u'<STR_LIT>' , <EOL> ) for rate , row in self . order . data [ '<STR_LIT>' ] ] , <EOL> ( <NUM_LIT:2> * cm , <NUM_LIT:4> * cm , <NUM_LIT:3> * cm , <NUM_LIT:3> * cm , <NUM_LIT> * cm ) , <EOL> self . pdf . style . table ) <EOL> self . pdf . table ( [ <EOL> ( total_title , u'<STR_LIT>' % self . order . total ) , <EOL> ] , ( <NUM_LIT:12> * cm , <NUM_LIT> * cm ) , self . pdf . style . tableHead ) <EOL> self . pdf . spacer ( ) <EOL> def payment ( self ) : <EOL> if not self . order . balance_remaining : <EOL> try : <EOL> payment = self . order . payments . authorized ( ) [ <NUM_LIT:0> ] <EOL> except IndexError : <EOL> payment = None <EOL> if payment and payment . payment_method : <EOL> self . pdf . p ( <EOL> _ ( '<STR_LIT>' <EOL> '<STR_LIT>' ) % { <EOL> '<STR_LIT>' : payment . payment_method , <EOL> '<STR_LIT>' : payment . transaction_id , <EOL> } ) <EOL> else : <EOL> self . pdf . p ( _ ( '<STR_LIT>' ) ) <EOL> else : <EOL> self . pdf . p ( _ ( '<STR_LIT>' ) ) <EOL> def notes ( self ) : <EOL> if self . order . notes : <EOL> self . pdf . spacer ( <NUM_LIT:10> * mm ) <EOL> self . pdf . p ( capfirst ( _ ( '<STR_LIT>' ) ) , style = self . pdf . style . bold ) <EOL> self . pdf . spacer ( <NUM_LIT:1> * mm ) <EOL> self . pdf . p ( self . order . notes ) <EOL> def invoice_pdf ( pdf , order ) : <EOL> """<STR_LIT>""" <EOL> report = OrderReport ( pdf , order ) <EOL> report . init_letter ( ) <EOL> report . address ( '<STR_LIT>' ) <EOL> report . title ( ) <EOL> report . items_with_prices ( ) <EOL> report . summary ( ) <EOL> report . payment ( ) <EOL> pdf . generate ( ) <EOL> def packing_slip_pdf ( pdf , order ) : <EOL> """<STR_LIT>""" <EOL> report = OrderReport ( pdf , order ) <EOL> report . init_letter ( ) <EOL> report . address ( '<STR_LIT>' ) <EOL> report . title ( ) <EOL> report . items_without_prices ( ) <EOL> report . notes ( ) <EOL> pdf . generate ( ) </s>
