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

1 by Jose Patricio
incial
1
# -*- encoding: utf-8 -*-
2
##############################################################################
3
#
4
#    OpenERP, Open Source Management Solution	
5
#    Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>). All Rights Reserved
6
#    $Id$
7
#
8
#    This program is free software: you can redistribute it and/or modify
9
#    it under the terms of the GNU General Public License as published by
10
#    the Free Software Foundation, either version 3 of the License, or
11
#    (at your option) any later version.
12
#
13
#    This program is distributed in the hope that it will be useful,
14
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
15
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
#    GNU General Public License for more details.
17
#
18
#    You should have received a copy of the GNU General Public License
19
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
20
#
21
##############################################################################
22
23
24
from osv import osv
25
from osv import fields
26
import time
27
28
#******************************************************************************************
29
#   Invoice Printing Configuration
30
#******************************************************************************************
31
class invoice_printing(osv.osv):
32
	_name = 'invoice.printing'
33
	_description = 'Invoice Printing'
34
35
	_columns = {
36
        'name': fields.char('Name', size=64, required=True),
37
        'adjustment_x': fields.float('Margin Horizontal', help='Move horizontal all the fields together'),
38
        'adjustment_y': fields.float('Margin Vertical', help='Move vertical all the fields together'),
39
        'line_id': fields.one2many('invoice.printing.line', 'printing_id', 'Lines', readonly=False, ),
40
        'page': fields.selection([
41
            ('letter','Letter'), 
42
            ('a4','A4')], 'Page', size=32),
43
        'help': fields.text('Help', readonly=False),
44
	}
45
	_defaults = {
46
        'page': lambda *a: 'letter',
47
        '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''',
48
        'adjustment_x': lambda *a: 15,
49
        'adjustment_y': lambda *a: 15,
50
	}
51
52
invoice_printing()
53
54
class invoice_printing_line(osv.osv):
55
    _name = 'invoice.printing.line'
56
    _description = 'Invoice Printing Line'
57
58
    def _col_get(self, cr, uid, context={}):
59
        result = []
60
        fields = self.pool.get('ir.model.fields').search(cr, uid, [('model','=','account.invoice')])
61
        for field in self.pool.get('ir.model.fields').browse(cr, uid, fields):
62
            result.append((field.id, field.name))
63
        result = sorted(result, key=lambda x:(x[1], x[0]))
64
        return result
65
66
    _columns = {
67
		'printing_id': fields.many2one('invoice.printing','Invoice Printing'),
68
        'sequence': fields.integer('Sequence'),
69
		'many_one_id': fields.many2one('invoice.printing.line','Invoice Printing'),
70
        'line_id': fields.one2many('invoice.printing.line', 'many_one_id', 'Lines'),
71
        'function_id': fields.one2many('invoice.printing.function', 'line_id', 'Function'),
72
		'field_id': fields.many2one('ir.model.fields', 'Field'),
73
        'field': fields.char('Field', size=128),
74
        'field_name': fields.char('Field Name', size=64),
75
        'domain': fields.char('Domain', size=64),
76
        'ttype': fields.char('Type', size=64),
77
       	'x': fields.float('Horizontal', required=True),
78
       	'y': fields.float('Vertical', required=True),
79
       	'size': fields.float('Size', required=False),
80
       	'angle': fields.float('Angle', required=False),
81
        'method': fields.selection([
82
            ('none','None'), 
83
            ('text.text','Amount to Text'), 
84
            ('text.moneyfmt','Money Format'), 
85
            ('text.formatLang','Mx Date Format'),
86
            ('code','Python Code'), 
87
#            ('function','Function'), 
88
            ], 'Method', readonly=False, size=32),
89
        'font': fields.selection([
90
            ('Courier','Courier'), 
91
            ('Courier-Bold','Courier-Bold'), 
92
            ('Courier-BoldOblique','Courier-BoldOblique'), 
93
            ('Courier-Oblique','Courier-Oblique'), 
94
            ('Helvetica','Helvetica'), 
95
            ('Helvetica-Bold','Helvetica-Bold'), 
96
            ('Helvetica-BoldOblique','Helvetica-BoldOblique'), 
97
            ('Helvetica-Oblique','Helvetica-Oblique'), 
98
            ('Symbol','Symbol'), 
99
            ('Times-Bold','Times-Bold'), 
100
            ('Times-BoldItalic','Times-BoldItalic'), 
101
            ('Times-Italic','Times-Italic'), 
102
            ('Times-Roman','Times-Roman'), 
103
            ('ZapfDingbats','ZapfDingbats'), 
104
            ], 'Font', size=32),
105
        'python_compute':fields.text('Python Code'),
106
    }
107
    _defaults = {
108
        'sequence': lambda *a: 1,
109
        'x': lambda *a: 10,
110
        'y': lambda *a: 750,
111
        'size': lambda *a: 10,
112
        'angle': lambda *a: 0,
113
        'domain': lambda *a: 'account.invoice',
114
        'font': lambda *a: 'Helvetica',
115
        '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''',
116
    }
117
118
    _order = 'sequence'
119
120
    def create(self, cr, uid, vals, context={}):
121
#        if vals['domain'] not in ('NULL', 'one2many'):
122
#            raise osv.except_osv(_('Warning'), _('There are non printable fild in selection, all Domain values must contain NULL value !'))
123
        return super(invoice_printing_line, self).create(cr, uid, vals, context)
124
125
    def onchange_field_id(self, cr, uid, ids, text_field, field_id):
126
        text_field = text_field or ''
127
        if not field_id:
128
            raise osv.except_osv(_('Warning'), _('Field value can not be NULL, select a new value or delete the line !'))
129
        field = self.pool.get('ir.model.fields').browse(cr,uid,field_id)
130
        ttype = field.ttype
131
        relation = field.relation
132
        if ttype == 'one2many':
133
            text_field =  text_field + (text_field and '.') + field.name
134
        else:
135
            text_field =  text_field + (text_field and '.') + field.name
136
        return {'value': {'ttype': ttype,'domain': relation, 'field': text_field, 'field_name': field.name}}  
137
138
    def default_get(self, cr, uid, fields, context={}):
139
        data = super(invoice_printing_line, self).default_get(cr, uid, fields, context)
140
        if context.has_key('domain'):
141
            data['domain'] = context['domain']
142
        if context.has_key('y'):
143
            data['y'] = context['y']
144
#        for f in data.keys():
145
#            if f not in fields:
146
#                del data[f]
147
        return data
148
149
invoice_printing_line()
150
151
class invoice_printing_function(osv.osv):
152
    _name = 'invoice.printing.function'
153
    _description = 'Invoice Printing Function'
154
155
    _columns = {
156
		'line_id': fields.many2one('invoice.printing.line','Invoice Printing Line'),
157
		'field_id': fields.many2one('ir.model.fields', 'Field'),
158
        'field': fields.char('Field', size=128),
159
        'field_name': fields.char('Field Name', size=64),
160
        'domain': fields.char('Domain', size=64),
161
        'ttype': fields.char('Type', size=64),
162
        'function': fields.selection([
163
            ('and','AND'), 
164
            ('or','OR'), 
165
            ('in','IN'), 
166
            ('not in','NOT IN'), 
167
            ('get','GET'), 
168
            ], 'Function', size=32),
169
    }
170
    _defaults = {
171
        'domain': lambda *a: 'account.invoice',
172
    }
173
174
    def onchange_field_id(self, cr, uid, ids, text_field, field_id):
175
        res = self.pool.get('invoice.printing.line').onchange_field_id(cr, uid, ids, text_field, field_id)
176
        return res
177
178
invoice_printing_function()
179
#----------------------------------------------------------
180
# Account Journal
181
#----------------------------------------------------------
182
class account_journal(osv.osv):
183
    _inherit="account.journal"
184
185
    _columns = {
186
        'invoice_printing_id': fields.many2one('invoice.printing', 'Invoice Printing'),
187
    }
188
account_journal()
189
190
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
191