25
25
from osv import fields
27
27
import decimal_precision as dp
28
from time import strftime
30
from tools.translate import _
29
32
class account_move_line(osv.osv):
30
33
_inherit = 'account.move.line'
64
67
return super(account_move_line, self)._get_move_lines(cr, uid, ids, context=context)
69
def _get_reference(self, cr, uid, ids, field_names, args, context=None):
71
Give reference field content from account_move_line first. Then search move_id.reference field, otherwise display ''.
74
for line in self.browse(cr, uid, ids):
77
res[line.id] = line.reference
79
elif line.move_id and line.move_id.ref:
80
res[line.id] = line.move_id.ref
84
def _set_fake_reference(self, cr, uid, id, name=None, value=None, fnct_inv_arg=None, context=None):
86
Just used to not break default OpenERP behaviour
89
sql = "UPDATE %s SET %s = %s WHERE id = %s" % (self._table, 'ref', value, id)
93
def _search_reference(self, cr, uid, obj, name, args, context):
95
Account MCDB (Selector) seems to be the only one that search on this field.
96
It use 'ilike' operator
103
return [('move_id.reference', '=', args[0][2])]
67
107
'source_date': fields.date('Source date', help="Date used for FX rate re-evaluation"),
68
108
'move_state': fields.related('move_id', 'state', string="Move state", type="selection", selection=[('draft', 'Draft'), ('posted', 'Posted')],
75
115
'debit': fields.float('Func. Debit', digits_compute=dp.get_precision('Account')),
76
116
'credit': fields.float('Func. Credit', digits_compute=dp.get_precision('Account')),
77
117
'currency_id': fields.many2one('res.currency', 'Book. Currency', help="The optional other currency if it is a multi-currency entry."),
78
'document_date': fields.date('Document Date', size=255, readonly=True),
118
'document_date': fields.date('Document Date', size=255, readonly=True, required=True),
79
119
'date': fields.related('move_id','date', string='Posting date', type='date', required=True, select=True,
81
121
'account.move': (_get_move_lines, ['date'], 20)
83
123
'is_write_off': fields.boolean('Is a write-off line?', readonly=True,
84
124
help="This inform that no correction is possible for a line that come from a write-off!"),
125
'reference': fields.char(string='Reference', size=64),
126
'ref': fields.function(_get_reference, fnct_inv=_set_fake_reference, fnct_search=_search_reference, string='Reference', method=True, type='char', size=64, store=True),
89
131
'is_write_off': lambda *a: False,
134
_order = 'move_id DESC'
92
136
def _accounting_balance(self, cr, uid, ids, context=None):
94
138
Get the accounting balance of given lines
104
148
FROM account_move_line
107
cr.execute(sql, [tuple(ids)])
151
cr.execute(sql, (tuple(ids),))
108
152
res = cr.fetchall()
109
153
if isinstance(ids, list):
157
def _check_document_date(self, cr, uid, ids):
159
Check that document's date is done BEFORE posting date
161
for aml in self.browse(cr, uid, ids):
162
if aml.document_date and aml.date and aml.date < aml.document_date:
163
raise osv.except_osv(_('Error'), _('Posting date should be later than Document Date.'))
166
def create(self, cr, uid, vals, context=None, check=True):
168
Filled in 'document_date' if we come from tests
172
if not vals.get('document_date') and vals.get('date'):
173
vals.update({'document_date': vals.get('date')})
174
if vals.get('document_date', False) and vals.get('date', False) and vals.get('date') < vals.get('document_date'):
175
raise osv.except_osv(_('Error'), _('Posting date should be later than Document Date.'))
176
return super(account_move_line, self).create(cr, uid, vals, context=context, check=check)
178
def write(self, cr, uid, ids, vals, context=None, check=True, update_check=True):
180
Check document_date and date validity
184
res = super(account_move_line, self).write(cr, uid, ids, vals, context=context, check=check, update_check=update_check)
185
self._check_document_date(cr, uid, ids)
113
188
account_move_line()
114
189
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: