1 # -*- encoding: utf-8 -*-
2 from osv import fields,osv
5 class notify_message(osv.osv):
6 _name = 'notify.message'
7 _description = 'Notify By Messages'
9 'name' : fields.char('Title',size=64,required=True),
10 'msg' : fields.text('Special Message',size=125,required=True,help='This notification will appear at the bottom of the Invoices when printed.',translate=True)
15 class account_invoice_line(osv.osv):
17 def move_line_get_item(self, cr, uid, line, context={}):
18 if line.state != 'article':
20 return super(account_invoice_line, self).move_line_get_item(cr, uid, line, context)
22 def fields_get(self, cr, uid, fields=None, context=None):
24 'article': [('readonly', False), ('invisible', False)],
25 'text': [('readonly', True), ('invisible', True), ('required', False)],
26 'subtotal': [('readonly', True), ('invisible', True), ('required', False)],
27 'title': [('readonly', True), ('invisible', True), ('required', False)],
28 'break': [('readonly', True), ('invisible', True), ('required', False)],
29 'line': [('readonly', True), ('invisible', True), ('required', False)],
33 'break': [('readonly', True),('required', False),('invisible', True)],
34 'line': [('readonly', True),('required', False),('invisible', True)],
36 'product_id': article,
37 'account_id': article,
40 'price_unit': article,
42 'invoice_line_tax_id': article,
43 'account_analytic_id': article,
45 res = super(account_invoice_line, self).fields_get(cr, uid, fields, context)
47 if states.has_key(field):
48 for key,value in states[field].items():
49 res[field].setdefault('states',{})
50 res[field]['states'][key] = value
53 def _onchange_invoice_line_view(self, cr, uid, id, type, context={}, *args):
63 'price_subtotal': False,
66 'invoice_line_tax_id': False,
67 'account_analytic_id': False,
71 temp['value']['name'] = ' '
73 temp['value']['name'] = ' '
74 if type == 'subtotal':
75 temp['value']['name'] = 'Sub Total'
79 def create(self, cr, user, vals, context=None):
80 if vals.has_key('state'):
81 if vals['state'] == 'line':
83 if vals['state'] == 'break':
85 if vals['state'] != 'article':
87 vals['account_id']= self._default_account(cr, user, None)
88 return super(account_invoice_line, self).create(cr, user, vals, context)
90 def write(self, cr, user, ids, vals, context=None):
91 if vals.has_key('state'):
92 if vals['state'] != 'article':
93 vals['product_id']= False
95 vals['account_id']= self._default_account(cr, user, None)
96 vals['price_unit']= False
97 vals['price_subtotal']= False
99 vals['discount']= False
100 vals['invoice_line_tax_id']= False
101 vals['account_analytic_id']= False
102 if vals['state'] == 'line':
104 if vals['state'] == 'break':
106 return super(account_invoice_line, self).write(cr, user, ids, vals, context)
108 def copy(self, cr, uid, id, default=None, context=None):
111 default['state'] = self.browse(cr, uid, id).state
112 return super(account_invoice_line, self).copy(cr, uid, id, default, context)
114 def _fnct(self, cr, uid, id, name, args, context):
116 for m in self.browse(cr, uid, id):
117 if m.state != 'article':
118 if m.state == 'line':
119 res[m.id] = '-----------------------------------------'
120 elif m.state == 'break':
121 res[m.id] = 'PAGE BREAK'
125 [(temp)] = self.pool.get('account.account').name_get(cr, uid, [m.account_id.id], context=context)
129 _name = "account.invoice.line"
130 _order = "invoice_id, sequence asc"
131 _description = "Invoice Line"
132 _inherit = "account.invoice.line"
134 'state': fields.selection([
135 ('article','Product'),
138 ('subtotal','Sub Total'),
139 ('line','Separator Line'),
140 ('break','Page Break'),]
141 ,'Type', select=True, required=True),
142 'sequence': fields.integer('Sequence Number'),
143 '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"),
145 def _default_account(self, cr, uid, context=None):
146 cr.execute("select id from account_account where code = 0 LIMIT 1")
150 'state': lambda *a: 'article',
151 # 'account_id': _default_account
153 account_invoice_line()
156 class one2many_mod2(fields.one2many):
157 def get(self, cr, obj, ids, name, user=None, offset=0, context=None, values=None):
165 ids2 = obj.pool.get(self._obj).search(cr, user, [(self._fields_id,'in',ids),('state','=','article')], limit=self._limit)
166 for r in obj.pool.get(self._obj)._read_flat(cr, user, ids2, [self._fields_id], context=context, load='_classic_write'):
167 res[r[self._fields_id]].append( r['id'] )
170 # def copy(self, cr, uid, id, default=None, context=None):
171 # if default is None:
173 # default['line_ids'] = False
174 # return super(account_invoice, self).copy(cr, uid, id, default, context)
177 class account_invoice(osv.osv):
179 def copy(self, cr, uid, id, default=None, context=None):
182 default['invoice_line'] = False
183 return super(account_invoice, self).copy(cr, uid, id, default, context)
185 _inherit = "account.invoice"
187 'abstract_line_ids': fields.one2many('account.invoice.line', 'invoice_id', 'Invoice Lines',readonly=True, states={'draft':[('readonly',False)]}),
188 'invoice_line': one2many_mod2('account.invoice.line', 'invoice_id', 'Invoice Lines',readonly=True, states={'draft':[('readonly',False)]}),
191 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: