1 # -*- coding: utf-8 -*-
2 ##############################################################################
4 # OpenERP, Open Source Management Solution
5 # Copyright (C) 2004-2009 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
25 class notify_message(osv.osv):
26 _name = 'notify.message'
27 _description = 'Notify By Messages'
29 'name' : fields.char('Title',size=64,required=True),
30 'msg' : fields.text('Special Message',size=125,required=True,help='This notification will appear at the bottom of the Invoices when printed.',translate=True)
35 class account_invoice_line(osv.osv):
37 def move_line_get_item(self, cr, uid, line, context={}):
38 if line.state != 'article':
40 return super(account_invoice_line, self).move_line_get_item(cr, uid, line, context)
42 def fields_get(self, cr, uid, fields=None, context=None):
44 'article': [('readonly', False), ('invisible', False)],
45 'text': [('readonly', True), ('invisible', True), ('required', False)],
46 'subtotal': [('readonly', True), ('invisible', True), ('required', False)],
47 'title': [('readonly', True), ('invisible', True), ('required', False)],
48 'break': [('readonly', True), ('invisible', True), ('required', False)],
49 'line': [('readonly', True), ('invisible', True), ('required', False)],
53 'break': [('readonly', True),('required', False),('invisible', True)],
54 'line': [('readonly', True),('required', False),('invisible', True)],
56 'product_id': article,
57 'account_id': article,
60 'price_unit': article,
62 'invoice_line_tax_id': article,
63 'account_analytic_id': article,
65 res = super(account_invoice_line, self).fields_get(cr, uid, fields, context)
67 if states.has_key(field):
68 for key,value in states[field].items():
69 res[field].setdefault('states',{})
70 res[field]['states'][key] = value
73 def _onchange_invoice_line_view(self, cr, uid, id, type, context={}, *args):
83 'price_subtotal': False,
86 'invoice_line_tax_id': False,
87 'account_analytic_id': False,
91 temp['value']['name'] = ' '
93 temp['value']['name'] = ' '
94 if type == 'subtotal':
95 temp['value']['name'] = 'Sub Total'
99 def create(self, cr, user, vals, context=None):
100 if vals.has_key('state'):
101 if vals['state'] == 'line':
103 if vals['state'] == 'break':
105 if vals['state'] != 'article':
107 vals['account_id']= self._default_account(cr, user, None)
108 return super(account_invoice_line, self).create(cr, user, vals, context)
110 def write(self, cr, user, ids, vals, context=None):
111 if vals.has_key('state'):
112 if vals['state'] != 'article':
113 vals['product_id']= False
114 vals['uos_id']= False
115 vals['account_id']= self._default_account(cr, user, None)
116 vals['price_unit']= False
117 vals['price_subtotal']= False
119 vals['discount']= False
120 vals['invoice_line_tax_id']= False
121 vals['account_analytic_id']= False
122 if vals['state'] == 'line':
124 if vals['state'] == 'break':
126 return super(account_invoice_line, self).write(cr, user, ids, vals, context)
128 def copy_data(self, cr, uid, id, default=None, context=None):
131 default['state'] = self.browse(cr, uid, id).state
132 return super(account_invoice_line, self).copy_data(cr, uid, id, default, context)
134 def _fnct(self, cr, uid, id, name, args, context):
136 for m in self.browse(cr, uid, id):
137 if m.state != 'article':
138 if m.state == 'line':
139 res[m.id] = '-----------------------------------------'
140 elif m.state == 'break':
141 res[m.id] = 'PAGE BREAK'
145 [(temp)] = self.pool.get('account.account').name_get(cr, uid, [m.account_id.id], context=context)
149 _name = "account.invoice.line"
150 _order = "invoice_id, sequence asc"
151 _description = "Invoice Line"
152 _inherit = "account.invoice.line"
154 'state': fields.selection([
155 ('article','Product'),
158 ('subtotal','Sub Total'),
159 ('line','Separator Line'),
160 ('break','Page Break'),]
161 ,'Type', select=True, required=True),
162 'sequence': fields.integer('Sequence Number', help="Gives the sequence order when displaying a list of invoice lines."),
163 'functional_field': fields.function(_fnct, arg=None, fnct_inv=None, fnct_inv_arg=None, type='char', fnct_search=None, obj=None, method=True, store=False, string="Source Account"),
166 def _default_account(self, cr, uid, context=None):
167 cr.execute("select id from account_account where parent_id IS NULL LIMIT 1")
172 'state': lambda *a: 'article',
173 # 'account_id': _default_account
175 account_invoice_line()
178 class one2many_mod2(fields.one2many):
179 def get(self, cr, obj, ids, name, user=None, offset=0, context=None, values=None):
187 ids2 = obj.pool.get(self._obj).search(cr, user, [(self._fields_id,'in',ids),('state','=','article')], limit=self._limit)
188 for r in obj.pool.get(self._obj)._read_flat(cr, user, ids2, [self._fields_id], context=context, load='_classic_write'):
189 res[r[self._fields_id]].append( r['id'] )
192 # def copy(self, cr, uid, id, default=None, context=None):
193 # if default is None:
195 # default['line_ids'] = False
196 # return super(account_invoice, self).copy(cr, uid, id, default, context)
199 class account_invoice(osv.osv):
201 def copy(self, cr, uid, id, default=None, context=None):
204 default['invoice_line'] = False
205 return super(account_invoice, self).copy(cr, uid, id, default, context)
207 _inherit = "account.invoice"
209 'abstract_line_ids': fields.one2many('account.invoice.line', 'invoice_id', 'Invoice Lines',readonly=True, states={'draft':[('readonly',False)]}),
210 'invoice_line': one2many_mod2('account.invoice.line', 'invoice_id', 'Invoice Lines',readonly=True, states={'draft':[('readonly',False)]}),
213 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: