~eduardo-bayardo-bias/bias-trunk/bias_trunk

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
# -*- encoding: utf-8 -*-
##############################################################################
#
#    OpenERP, Open Source Management Solution	
#    Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>). All Rights Reserved
#    $Id$
#
#    This program is free software: you can redistribute it and/or modify
#    it under the terms of the GNU 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 General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################


from osv import osv
from osv import fields
import time

#******************************************************************************************
#   Invoice Printing Configuration
#******************************************************************************************
class invoice_printing(osv.osv):
	_name = 'invoice.printing'
	_description = 'Invoice Printing'

	_columns = {
        'name': fields.char('Name', size=64, required=True),
        'adjustment_x': fields.float('Margin Horizontal', help='Move horizontal all the fields together'),
        'adjustment_y': fields.float('Margin Vertical', help='Move vertical all the fields together'),
        'line_id': fields.one2many('invoice.printing.line', 'printing_id', 'Lines', readonly=False, ),
        'page': fields.selection([
            ('letter','Letter'), 
            ('a4','A4')], 'Page', size=32),
        'help': fields.text('Help', readonly=False),
	}
	_defaults = {
        'page': lambda *a: 'letter',
        'help': lambda *a: '''# price_unit\n# address : res.partner.address object or False\n# product : product.product object or None\n# partner : res.partner object or None\n\nresult = price_unit * 0.10''',
        'adjustment_x': lambda *a: 15,
        'adjustment_y': lambda *a: 15,
	}

invoice_printing()

class invoice_printing_line(osv.osv):
    _name = 'invoice.printing.line'
    _description = 'Invoice Printing Line'

    def _col_get(self, cr, uid, context={}):
        result = []
        fields = self.pool.get('ir.model.fields').search(cr, uid, [('model','=','account.invoice')])
        for field in self.pool.get('ir.model.fields').browse(cr, uid, fields):
            result.append((field.id, field.name))
        result = sorted(result, key=lambda x:(x[1], x[0]))
        return result

    _columns = {
		'printing_id': fields.many2one('invoice.printing','Invoice Printing'),
        'sequence': fields.integer('Sequence'),
		'many_one_id': fields.many2one('invoice.printing.line','Invoice Printing'),
        'line_id': fields.one2many('invoice.printing.line', 'many_one_id', 'Lines'),
        'function_id': fields.one2many('invoice.printing.function', 'line_id', 'Function'),
		'field_id': fields.many2one('ir.model.fields', 'Field'),
        'field': fields.char('Field', size=128),
        'field_name': fields.char('Field Name', size=64),
        'domain': fields.char('Domain', size=64),
        'ttype': fields.char('Type', size=64),
       	'x': fields.float('Horizontal', required=True),
       	'y': fields.float('Vertical', required=True),
       	'size': fields.float('Size', required=False),
       	'angle': fields.float('Angle', required=False),
        'method': fields.selection([
            ('none','None'), 
            ('text.text','Amount to Text'), 
            ('text.moneyfmt','Money Format'), 
            ('text.formatLang','Mx Date Format'),
            ('code','Python Code'), 
#            ('function','Function'), 
            ], 'Method', readonly=False, size=32),
        'font': fields.selection([
            ('Courier','Courier'), 
            ('Courier-Bold','Courier-Bold'), 
            ('Courier-BoldOblique','Courier-BoldOblique'), 
            ('Courier-Oblique','Courier-Oblique'), 
            ('Helvetica','Helvetica'), 
            ('Helvetica-Bold','Helvetica-Bold'), 
            ('Helvetica-BoldOblique','Helvetica-BoldOblique'), 
            ('Helvetica-Oblique','Helvetica-Oblique'), 
            ('Symbol','Symbol'), 
            ('Times-Bold','Times-Bold'), 
            ('Times-BoldItalic','Times-BoldItalic'), 
            ('Times-Italic','Times-Italic'), 
            ('Times-Roman','Times-Roman'), 
            ('ZapfDingbats','ZapfDingbats'), 
            ], 'Font', size=32),
        'python_compute':fields.text('Python Code'),
    }
    _defaults = {
        'sequence': lambda *a: 1,
        'x': lambda *a: 10,
        'y': lambda *a: 750,
        'size': lambda *a: 10,
        'angle': lambda *a: 0,
        'domain': lambda *a: 'account.invoice',
        'font': lambda *a: 'Helvetica',
        'python_compute': lambda *a: '''# pool : pool object\n# cr : cursor object\n# uid : user object\n# i : account.invoice.line object or False\n# l : invoice.printing.line object or None\n\nresult = i.name''',
    }

    _order = 'sequence'

    def create(self, cr, uid, vals, context={}):
#        if vals['domain'] not in ('NULL', 'one2many'):
#            raise osv.except_osv(_('Warning'), _('There are non printable fild in selection, all Domain values must contain NULL value !'))
        return super(invoice_printing_line, self).create(cr, uid, vals, context)

    def onchange_field_id(self, cr, uid, ids, text_field, field_id):
        text_field = text_field or ''
        if not field_id:
            raise osv.except_osv(_('Warning'), _('Field value can not be NULL, select a new value or delete the line !'))
        field = self.pool.get('ir.model.fields').browse(cr,uid,field_id)
        ttype = field.ttype
        relation = field.relation
        if ttype == 'one2many':
            text_field =  text_field + (text_field and '.') + field.name
        else:
            text_field =  text_field + (text_field and '.') + field.name
        return {'value': {'ttype': ttype,'domain': relation, 'field': text_field, 'field_name': field.name}}  

    def default_get(self, cr, uid, fields, context={}):
        data = super(invoice_printing_line, self).default_get(cr, uid, fields, context)
        if context.has_key('domain'):
            data['domain'] = context['domain']
        if context.has_key('y'):
            data['y'] = context['y']
#        for f in data.keys():
#            if f not in fields:
#                del data[f]
        return data

invoice_printing_line()

class invoice_printing_function(osv.osv):
    _name = 'invoice.printing.function'
    _description = 'Invoice Printing Function'

    _columns = {
		'line_id': fields.many2one('invoice.printing.line','Invoice Printing Line'),
		'field_id': fields.many2one('ir.model.fields', 'Field'),
        'field': fields.char('Field', size=128),
        'field_name': fields.char('Field Name', size=64),
        'domain': fields.char('Domain', size=64),
        'ttype': fields.char('Type', size=64),
        'function': fields.selection([
            ('and','AND'), 
            ('or','OR'), 
            ('in','IN'), 
            ('not in','NOT IN'), 
            ('get','GET'), 
            ], 'Function', size=32),
    }
    _defaults = {
        'domain': lambda *a: 'account.invoice',
    }

    def onchange_field_id(self, cr, uid, ids, text_field, field_id):
        res = self.pool.get('invoice.printing.line').onchange_field_id(cr, uid, ids, text_field, field_id)
        return res

invoice_printing_function()
#----------------------------------------------------------
# Account Journal
#----------------------------------------------------------
class account_journal(osv.osv):
    _inherit="account.journal"

    _columns = {
        'invoice_printing_id': fields.many2one('invoice.printing', 'Invoice Printing'),
    }
account_journal()

# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: