Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions InvoiceGenerator/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,8 @@ def getContent(self):
self.pdf.showPage()
self.pdf.save()

f = open(self.pdffile.name)
data = f.read()
f.close()
with open(self.pdffile.name) as f:
data = f.read()

os.unlink(self.pdffile.name)

Expand Down Expand Up @@ -351,6 +350,5 @@ def gen(self, filename, pdf_invoice):
invoice.addItem(item1)
invoice.addItem(item2)

f = open("test.pdf", "w")
f.write(invoice.getContent())
f.close()
with open("test.pdf", "w") as f:
f.write(invoice.getContent())
14 changes: 7 additions & 7 deletions InvoiceGenerator/pdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,10 +227,10 @@ def _drawAddress(self, top, left, width, height, header_string, address):
frame.addFromList([story_inframe], self.pdf)

if address.logo_filename:
im = Image.open(address.logo_filename)
height = 30.0
width = float(im.size[0]) / (float(im.size[1])/height)
self.pdf.drawImage(self.invoice.provider.logo_filename, (left + 84) * mm - width, (top - 4) * mm, width, height, mask="auto")
with Image.open(address.logo_filename) as im:
height = 30.0
width = float(im.size[0]) / (float(im.size[1])/height)
self.pdf.drawImage(self.invoice.provider.logo_filename, (left + 84) * mm - width, (top - 4) * mm, width, height, mask="auto")

def _drawClient(self, TOP, LEFT):
self._drawAddress(TOP, LEFT, 88, 41, _(u'Customer'), self.invoice.client)
Expand Down Expand Up @@ -454,9 +454,9 @@ def _drawItems(self, TOP, LEFT): # noqa
def _drawCreator(self, TOP, LEFT):
height = 20*mm
if self.invoice.creator.stamp_filename:
im = Image.open(self.invoice.creator.stamp_filename)
height = float(im.size[1]) / (float(im.size[0])/200.0)
self.pdf.drawImage(self.invoice.creator.stamp_filename, (LEFT) * mm, (TOP - 2) * mm - height, 200, height, mask="auto")
with Image.open(self.invoice.creator.stamp_filename) as im:
height = float(im.size[1]) / (float(im.size[0])/200.0)
self.pdf.drawImage(self.invoice.creator.stamp_filename, (LEFT) * mm, (TOP - 2) * mm - height, 200, height, mask="auto")

path = self.pdf.beginPath()
path.moveTo((LEFT + 8) * mm, (TOP) * mm - height)
Expand Down
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ def command(cmd):


def read(fname):
return open(os.path.join(os.path.dirname(__file__), fname)).read()
with open(os.path.join(os.path.dirname(__file__), fname)) as f:
return f.read()


description = ""
Expand Down