update translations files
[odoo/odoo.git] / addons / account_invoice_layout / account_invoice_layout.py
1 # -*- encoding: utf-8 -*-
2 from osv import fields,osv
3
4
5 class notify_message(osv.osv):
6     _name = 'notify.message'
7     _description = 'Notify By Messages'
8     _columns = {
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)
11     }
12
13 notify_message()
14
15 class account_invoice_line(osv.osv):
16
17     def move_line_get_item(self, cr, uid, line, context={}):
18         if line.state != 'article':
19             return None
20         return super(account_invoice_line, self).move_line_get_item(cr, uid, line, context)
21
22     def fields_get(self, cr, uid, fields=None, context=None):
23         article = {
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)],
30         }
31         states = {
32             'name': {
33                 'break': [('readonly', True),('required', False),('invisible', True)],
34                 'line': [('readonly', True),('required', False),('invisible', True)],
35                 },
36             'product_id': article,
37             'account_id': article,
38             'quantity': article,
39             'uos_id': article,
40             'price_unit': article,
41             'discount': article,
42             'invoice_line_tax_id': article,
43             'account_analytic_id': article,
44         }
45         res = super(account_invoice_line, self).fields_get(cr, uid, fields, context)
46         for field in res:
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
51         return res
52
53     def _onchange_invoice_line_view(self, cr, uid, id, type, context={}, *args):
54
55         if (not type):
56             return {}
57         if type != 'article':
58             temp = {'value': {
59                     'product_id': False,
60                     'uos_id': False,
61                     'account_id': False,
62                     'price_unit': False,
63                     'price_subtotal': False,
64                     'quantity': 0,
65                     'discount': False,
66                     'invoice_line_tax_id': False,
67                     'account_analytic_id': False,
68                     },
69                 }
70             if type == 'line':
71                 temp['value']['name'] = ' '
72             if type == 'break':
73                 temp['value']['name'] = ' '
74             if type == 'subtotal':
75                 temp['value']['name'] = 'Sub Total'
76             return temp
77         return {}
78
79     def create(self, cr, user, vals, context=None):
80         if vals.has_key('state'):
81             if vals['state'] == 'line':
82                 vals['name'] = ' '
83             if vals['state'] == 'break':
84                 vals['name'] = ' '
85             if vals['state'] != 'article':
86                 vals['quantity']= 0
87                 vals['account_id']= self._default_account(cr, user, None)
88         return super(account_invoice_line, self).create(cr, user, vals, context)
89
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
94                 vals['uos_id']= False
95                 vals['account_id']= self._default_account(cr, user, None)
96                 vals['price_unit']= False
97                 vals['price_subtotal']= False
98                 vals['quantity']= 0
99                 vals['discount']= False
100                 vals['invoice_line_tax_id']= False
101                 vals['account_analytic_id']= False
102             if vals['state'] == 'line':
103                 vals['name'] = ' '
104             if vals['state'] == 'break':
105                 vals['name'] = ' '
106         return super(account_invoice_line, self).write(cr, user, ids, vals, context)
107
108     def copy(self, cr, uid, id, default=None, context=None):
109         if default is None:
110             default = {}
111         default['state'] = self.browse(cr, uid, id).state
112         return super(account_invoice_line, self).copy(cr, uid, id, default, context)
113
114     def _fnct(self, cr, uid, id, name, args, context):
115         res = {}
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'
122                 else:
123                     res[m.id] = ' '
124             else:
125                 [(temp)] = self.pool.get('account.account').name_get(cr, uid, [m.account_id.id], context=context)
126                 res[m.id] = temp[1]
127         return res
128
129     _name = "account.invoice.line"
130     _order = "invoice_id, sequence asc"
131     _description = "Invoice Line"
132     _inherit = "account.invoice.line"
133     _columns = {
134         'state': fields.selection([
135                 ('article','Product'),
136                 ('title','Title'),
137                 ('text','Note'),
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"),
144     }
145     def _default_account(self, cr, uid, context=None):
146         cr.execute("select id from account_account where code = 0 LIMIT 1")
147         res=cr.fetchone()
148         return res[0]
149     _defaults = {
150         'state': lambda *a: 'article',
151 #       'account_id': _default_account
152     }
153 account_invoice_line()
154
155
156 class one2many_mod2(fields.one2many):
157     def get(self, cr, obj, ids, name, user=None, offset=0, context=None, values=None):
158         if not context:
159             context = {}
160         if not values:
161             values = {}
162         res = {}
163         for id in ids:
164             res[id] = []
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'] )
168         return res
169
170 #   def copy(self, cr, uid, id, default=None, context=None):
171 #       if default is None:
172 #           default = {}
173 #       default['line_ids'] = False
174 #       return super(account_invoice, self).copy(cr, uid, id, default, context)
175
176
177 class account_invoice(osv.osv):
178
179     def copy(self, cr, uid, id, default=None, context=None):
180         if default is None:
181             default = {}
182         default['invoice_line'] = False
183         return super(account_invoice, self).copy(cr, uid, id, default, context)
184
185     _inherit = "account.invoice"
186     _columns = {
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)]}),
189     }
190 account_invoice()
191 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
192