~openerp-commiter/openobject-addons/extra-6.0

« back to all changes in this revision

Viewing changes to label/report_label.py

  • Committer: Jordi Esteve
  • Date: 2008-11-24 15:19:02 UTC
  • mto: (3356.3.2 trunk-extra-addons)
  • mto: This revision was merged to the branch mainline in revision 3357.
  • Revision ID: jesteve@alba-20081124151902-wrn3dbba91of8tod
Module partner_spam divide in 2 modules: partner_spam and label. Added security rules and Spanish and Catalan translations (new security and i18n directories) to both

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- encoding: utf-8 -*-
 
2
##############################################################################
 
3
#
 
4
# Copyright (c) 2008 Zikzakmedia S.L. (http://zikzakmedia.com) All Rights Reserved.
 
5
#                    Jordi Esteve <jesteve@zikzakmedia.com>
 
6
#
 
7
# WARNING: This program as such is intended to be used by professional
 
8
# programmers who take the whole responsability of assessing all potential
 
9
# consequences resulting from its eventual inadequacies and bugs
 
10
# End users who are looking for a ready-to-use solution with commercial
 
11
# garantees and support are strongly adviced to contract a Free Software
 
12
# Service Company
 
13
#
 
14
# This program is Free Software; you can redistribute it and/or
 
15
# modify it under the terms of the GNU General Public License
 
16
# as published by the Free Software Foundation; either version 2
 
17
# of the License, or (at your option) any later version.
 
18
#
 
19
# This program is distributed in the hope that it will be useful,
 
20
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
21
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
22
# GNU General Public License for more details.
 
23
#
 
24
# You should have received a copy of the GNU General Public License
 
25
# along with this program; if not, write to the Free Software
 
26
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
27
#
 
28
##############################################################################
 
29
 
 
30
from osv import osv, fields
 
31
 
 
32
 
 
33
class report_pagesize(osv.osv):
 
34
    _name = 'report.pagesize'
 
35
    _columns = {
 
36
        'name': fields.char('Name', size=20, required=True),
 
37
        'width': fields.char('Width', size=20, required=True, help="Numeric width of the page ended with the unit (cm or in). For example, A4 is 21cm and letter is 8.5in"),
 
38
        'height': fields.char('Height', size=20, required=True, help="Numeric height of the page ended with the unit (cm or in). For example, A4 is 29.7cm and letter is 11in"),
 
39
    }
 
40
    _order = 'name'
 
41
 
 
42
    def _check_unit(self, cr, uid, ids):
 
43
        for page in self.browse(cr, uid, ids):
 
44
            if page.width[-2:] not in ['cm', 'in']:
 
45
                return False
 
46
            if page.height[-2:] not in ['cm', 'in']:
 
47
                return False
 
48
        return True
 
49
 
 
50
    _constraints = [
 
51
        (_check_unit, 'Error! The page sizes do not have the unit (cm or in) at the end.', [])
 
52
    ]
 
53
 
 
54
report_pagesize()
 
55
 
 
56
 
 
57
class report_label_manufacturer(osv.osv):
 
58
    _name = 'report.label.manufacturer'
 
59
    _columns = {
 
60
        'name': fields.char('Name', size=50, required=True),
 
61
    }
 
62
    _order = 'name'
 
63
 
 
64
report_label_manufacturer()
 
65
 
 
66
 
 
67
class report_label(osv.osv):
 
68
    def name_get(self, cr, uid, ids, context=None):
 
69
        if not len(ids):
 
70
            return []
 
71
        res = []
 
72
        for r in self.browse(cr, uid, ids):
 
73
            name = str(r.manufacturer_id.name or '') + ". " + str(r.name)
 
74
            res.append((r.id, name))
 
75
        return res
 
76
 
 
77
    _name = 'report.label'
 
78
    _columns = {
 
79
        'name': fields.char('Name', size=200, required=True),
 
80
        'manufacturer_id': fields.many2one('report.label.manufacturer', 'Manufacturer'),
 
81
        'description': fields.text('Description'),
 
82
        'pagesize_id': fields.many2one('report.pagesize', 'Page Size', required=True),
 
83
        'landscape': fields.boolean('Landscape', help="No check -> Portrait. Check -> Landscape"),
 
84
        'rows': fields.integer('Number of Rows', size=2, required=True),
 
85
        'cols': fields.integer('Number of Columns', size=2, required=True),
 
86
        'label_width': fields.char('Label Width', size=20, required=True, help="Numeric value ended with the unit (cm or in). For example 29.7cm or 11in"),
 
87
        'label_height': fields.char('Label Height', size=20, required=True, help="Numeric value ended with the unit (cm or in). For example 29.7cm or 11in"),
 
88
        'width_incr': fields.char('Width Increment', size=20, required=True, help="Width between start positions of 2 labels. Numeric value ended with the unit (cm or in). For example 29.7cm or 11in"),
 
89
        'height_incr': fields.char('Height Increment', size=20, required=True, help="Height between start positions of 2 labels. Numeric value ended with the unit (cm or in). For example 29.7cm or 11in"),
 
90
        'margin_top': fields.char('Top Margin', size=20, required=True, help="Numeric value ended with the unit (cm or in). For example 29.7cm or 11in"),
 
91
        'margin_left': fields.char('Left Margin', size=20, required=True, help="Numeric value ended with the unit (cm or in). For example 29.7cm or 11in"),
 
92
        #'margin_bottom': fields.char('Bottom Margin', size=20, required=True, help="Numeric value ended with the unit (cm or in). For example 29.7cm or 11in"),
 
93
        #'margin_right': fields.char('Right Margin', size=20, required=True, help="Numeric value ended with the unit (cm or in). For example 29.7cm or 11in"),
 
94
    }
 
95
    _defaults = {
 
96
    }
 
97
    _order = 'name'
 
98
 
 
99
    def _check_unit(self, cr, uid, ids):
 
100
        for label in self.browse(cr, uid, ids):
 
101
            if label.label_width[-2:] not in ['cm', 'in']:
 
102
                return False
 
103
            if label.label_height[-2:] not in ['cm', 'in']:
 
104
                return False
 
105
            if label.width_incr[-2:] not in ['cm', 'in']:
 
106
                return False
 
107
            if label.height_incr[-2:] not in ['cm', 'in']:
 
108
                return False
 
109
            if label.margin_top[-2:] not in ['cm', 'in']:
 
110
                return False
 
111
            if label.margin_left[-2:] not in ['cm', 'in']:
 
112
                return False
 
113
        return True
 
114
 
 
115
    _constraints = [
 
116
        (_check_unit, 'Error! Some sizes do not have the unit (cm or in) at the end.', [])
 
117
    ]
 
118
 
 
119
report_label()
 
120
 
 
121