1 # -*- coding: utf-8 -*-
2 ##############################################################################
4 # OpenERP, Open Source Management Solution
5 # Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
7 # This program is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU Affero General Public License as
9 # published by the Free Software Foundation, either version 3 of the
10 # License, or (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU Affero General Public License for more details.
17 # You should have received a copy of the GNU Affero General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
20 ##############################################################################
22 from osv import fields, osv
24 class notify_message(osv.osv):
25 _name = 'notify.message'
26 _description = 'Notify By Messages'
28 'name': fields.char('Title', size=64, required=True),
29 'msg': fields.text('Special Message', size=128, required=True, help='This notification will appear at the bottom of the Invoices when printed.', translate=True)
34 class account_invoice_line(osv.osv):
36 def move_line_get_item(self, cr, uid, line, context=None):
37 if line.state != 'article':
39 return super(account_invoice_line, self).move_line_get_item(cr, uid, line, context)
41 def fields_get(self, cr, uid, fields=None, context=None):
43 'article': [('readonly', False), ('invisible', False)],
44 'text': [('readonly', True), ('invisible', True), ('required', False)],
45 'subtotal': [('readonly', True), ('invisible', True), ('required', False)],
46 'title': [('readonly', True), ('invisible', True), ('required', False)],
47 'break': [('readonly', True), ('invisible', True), ('required', False)],
48 'line': [('readonly', True), ('invisible', True), ('required', False)],
52 'break': [('readonly', True),('required', False),('invisible', True)],
53 'line': [('readonly', True),('required', False),('invisible', True)],
55 'product_id': article,
56 'account_id': article,
59 'price_unit': article,
61 'invoice_line_tax_id': article,
62 'account_analytic_id': article,
64 res = super(account_invoice_line, self).fields_get(cr, uid, fields, context)
66 if states.has_key(field):
67 for key,value in states[field].items():
68 res[field].setdefault('states',{})
69 res[field]['states'][key] = value
72 def onchange_invoice_line_view(self, cr, uid, id, type, context=None, *args):
82 'price_subtotal': False,
85 'invoice_line_tax_id': False,
86 'account_analytic_id': False,
90 temp['value']['name'] = ' '
92 temp['value']['name'] = ' '
93 if type == 'subtotal':
94 temp['value']['name'] = 'Sub Total'
98 def create(self, cr, user, vals, context=None):
99 if vals.has_key('state'):
100 if vals['state'] == 'line':
102 if vals['state'] == 'break':
104 if vals['state'] != 'article':
106 vals['account_id']= self._default_account(cr, user, None)
107 return super(account_invoice_line, self).create(cr, user, vals, context)
109 def write(self, cr, user, ids, vals, context=None):
110 if vals.has_key('state'):
111 if vals['state'] != 'article':
112 vals['product_id']= False
113 vals['uos_id']= False
114 vals['account_id']= self._default_account(cr, user, None)
115 vals['price_unit']= False
116 vals['price_subtotal']= False
118 vals['discount']= False
119 vals['invoice_line_tax_id']= False
120 vals['account_analytic_id']= False
121 if vals['state'] == 'line':
123 if vals['state'] == 'break':
125 return super(account_invoice_line, self).write(cr, user, ids, vals, context)
127 def copy_data(self, cr, uid, id, default=None, context=None):
130 default['state'] = self.browse(cr, uid, id, context=context).state
131 return super(account_invoice_line, self).copy_data(cr, uid, id, default, context)
133 def _fnct(self, cr, uid, ids, name, args, context=None):
135 lines = self.browse(cr, uid, ids, context=context)
136 account_ids = [line.account_id.id for line in lines]
137 account_names = dict(self.pool.get('account.account').name_get(cr, uid, account_ids, context=context))
139 if line.state != 'article':
140 if line.state == 'line':
141 res[line.id] = '-----------------------------------------'
142 elif line.state == 'break':
143 res[line.id] = 'PAGE BREAK'
147 res[line.id] = account_names.get(line.account_id.id, '')
150 _name = "account.invoice.line"
151 _order = "invoice_id, sequence asc"
152 _description = "Invoice Line"
153 _inherit = "account.invoice.line"
155 'state': fields.selection([
156 ('article','Product'),
159 ('subtotal','Sub Total'),
160 ('line','Separator Line'),
161 ('break','Page Break'),]
162 ,'Type', select=True, required=True),
163 'sequence': fields.integer('Sequence Number', help="Gives the sequence order when displaying a list of invoice lines."),
164 'functional_field': fields.function(_fnct, arg=None, fnct_inv=None, fnct_inv_arg=None, type='char', fnct_search=None, obj=None, store=False, string="Source Account"),
167 def _default_account(self, cr, uid, context=None):
168 cr.execute("select id from account_account where parent_id IS NULL LIMIT 1")
177 account_invoice_line()
179 class one2many_mod2(fields.one2many):
181 def get(self, cr, obj, ids, name, user=None, offset=0, context=None, values=None):
189 ids2 = obj.pool.get(self._obj).search(cr, user, [(self._fields_id,'in',ids),('state','=','article')], limit=self._limit)
190 for r in obj.pool.get(self._obj)._read_flat(cr, user, ids2, [self._fields_id], context=context, load='_classic_write'):
191 res[r[self._fields_id]].append( r['id'] )
194 class account_invoice(osv.osv):
196 def copy(self, cr, uid, id, default=None, context=None):
199 default['invoice_line'] = False
200 return super(account_invoice, self).copy(cr, uid, id, default, context)
202 _inherit = "account.invoice"
204 'abstract_line_ids': fields.one2many('account.invoice.line', 'invoice_id', 'Invoice Lines',readonly=True, states={'draft':[('readonly',False)]}),
205 'invoice_line': one2many_mod2('account.invoice.line', 'invoice_id', 'Invoice Lines',readonly=True, states={'draft':[('readonly',False)]}),
210 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: