Skip to content

Commit

Permalink
Add new background configuration option
Browse files Browse the repository at this point in the history
  • Loading branch information
nbessi committed Apr 22, 2015
1 parent a075150 commit 56242db
Show file tree
Hide file tree
Showing 6 changed files with 101 additions and 3 deletions.
5 changes: 3 additions & 2 deletions l10n_ch_payment_slip/payment_slip.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,10 @@ def validate(self):
"Hook function to validate parameters"""
pass

def __init__(self, **kwargs):
def __init__(self, report_name, **kwargs):
for param, value in kwargs.iteritems():
setattr(self, param, value)
self.report_name = report_name
self.validate()


Expand Down Expand Up @@ -727,7 +728,7 @@ def _get_settings(self, report_name):
col: getattr(company, col) for col in company._fields if
col.startswith('bvr_')
}
return PaymentSlipSettings(**company_settings)
return PaymentSlipSettings(report_name, **company_settings)

def _draw_payment_slip(self, a4=False, out_format='PDF', scale=None,
b64=False, report_name=None):
Expand Down
2 changes: 2 additions & 0 deletions l10n_ch_payment_slip_layouts/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,5 @@
#
##############################################################################
from . import report
from . import payment_slip
from . import company
3 changes: 2 additions & 1 deletion l10n_ch_payment_slip_layouts/__openerp__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
'complexity': 'normal',
'depends': ['base', 'account', 'l10n_ch_payment_slip'],
'website': 'http://www.camptocamp.com',
'data': ['report/report.xml'],
'data': ['report/report.xml',
'view/company_view.xml'],
'demo': [],
'test': [],
'installable': True,
Expand Down
30 changes: 30 additions & 0 deletions l10n_ch_payment_slip_layouts/company.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# Author: Nicolas Bessi
# Copyright 2015 Camptocamp SA
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
from openerp import models, fields


class ResCompany(models.Model):

_inherit = 'res.company'

bvr_background_on_merge = fields.Boolean(
'Insert BVR Background with invoice ?'
)
49 changes: 49 additions & 0 deletions l10n_ch_payment_slip_layouts/payment_slip.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# Author: Nicolas Bessi
# Copyright 2015 Camptocamp SA
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
from reportlab.lib.units import inch
from openerp import models, api


class PaymentSlip(models.Model):

_inherit = 'l10n_ch.payment_slip'

@api.model
def _draw_background(self, canvas, print_settings):
"""Draw payment slip background based on company setting
:param canvas: payment slip reportlab component to be drawn
:type canvas: :py:class:`reportlab.pdfgen.canvas.Canvas`
:param print_settings: layouts print setting
:type print_settings: :py:class:`PaymentSlipSettings` or subclass
"""
def _draw_on_canvas():
canvas.drawImage(self.image_absolute_path('bvr.png'),
0, 0, 8.271 * inch, 4.174 * inch)
report_name = print_settings.report_name
if report_name == 'invoice_and_one_slip_per_page_from_invoice':
if print_settings.bvr_background_on_merge:
_draw_on_canvas()
else:
if print_settings.bvr_background:
_draw_on_canvas()
15 changes: 15 additions & 0 deletions l10n_ch_payment_slip_layouts/view/company_view.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0"?>
<openerp>
<data>
<record model="ir.ui.view" id="company_form_view">
<field name="name">res.company.form.inherit.bvr</field>
<field name="model">res.company</field>
<field name="inherit_id" ref="l10n_ch_payment_slip.company_form_view"/>
<field name="arch" type="xml">
<field name="bvr_background" position="after">
<field name="bvr_background_on_merge"/>
</field>
</field>
</record>
</data>
</openerp>

0 comments on commit 56242db

Please sign in to comment.