bzr revid: fp@tinyerp.com-20081023174549-yooeluxdpfrsizgs
This commit is contained in:
Fabien Pinckaers
2008-10-23 19:45:49 +02:00
parent 08e80733c4
commit 93cbe3d14a
3 changed files with 17 additions and 12 deletions
-3
View File
@@ -204,8 +204,6 @@ class ir_model_fields(osv.osv):
'relation_field': fields.char('Relation Field', size=64),
'model_id': fields.many2one('ir.model', 'Object id', required=True, select=True, ondelete='cascade'),
'field_description': fields.char('Field Label', required=True, size=256),
'relate': fields.boolean('Click and Relate'),
'ttype': fields.selection(_get_fields_type, 'Field Type',size=64, required=True),
'selection': fields.char('Field Selection',size=128),
'required': fields.boolean('Required'),
@@ -221,7 +219,6 @@ class ir_model_fields(osv.osv):
'view_load': fields.boolean('View Auto-Load'),
}
_defaults = {
'relate': lambda *a: 0,
'view_load': lambda *a: 0,
'selection': lambda *a: "[]",
'domain': lambda *a: "[]",
+12 -3
View File
@@ -79,7 +79,7 @@ class res_currency(osv.osv):
def is_zero(self, cr, uid, currency, amount):
return abs(self.round(cr, uid, currency, amount)) < currency.rounding
def compute(self, cr, uid, from_currency_id, to_currency_id, from_amount, round=True, context={}):
def compute(self, cr, uid, from_currency_id, to_currency_id, from_amount, round=True, context={}, account=None):
if not from_currency_id:
from_currency_id = to_currency_id
xc=self.browse(cr, uid, [from_currency_id,to_currency_id], context=context)
@@ -94,6 +94,14 @@ class res_currency(osv.osv):
raise osv.except_osv(_('Error'), _('No rate found \n' \
'for the currency: %s \n' \
'at the date: %s') % (code, date))
rate = to_currency.rate/from_currency.rate
if account and (account.currency_mode=='average') and account.currency_id:
q = self.pool.get('account.move.line')._query_get(cr, uid, context=context)
cr.execute('select sum(debit-credit),sum(amount_currency) from account_move_line l ' \
'where l.currency_id=%d and l.account_id=%d and '+q, (account.currency_id.id,account.id,))
tot1,tot2 = cr.fetchone()
if tot2:
rate = float(tot1)/float(tot2)
if to_currency_id==from_currency_id:
if round:
return self.round(cr, uid, to_currency, from_amount)
@@ -101,9 +109,10 @@ class res_currency(osv.osv):
return from_amount
else:
if round:
return self.round(cr, uid, to_currency, from_amount * to_currency.rate/from_currency.rate)
return self.round(cr, uid, to_currency, from_amount * rate)
else:
return (from_amount * to_currency.rate/from_currency.rate)
return (from_amount * rate)
def name_search(self, cr, uid, name, args=[], operator='ilike', context={}, limit=80):
args2 = args[:]
if name:
+5 -6
View File
@@ -328,7 +328,6 @@ class orm_template(object):
'name': k,
'field_description': f.string.replace("'", " "),
'ttype': f._type,
'relate': (f.relate and 1) or 0,
'relation': f._obj or 'NULL',
'view_load': (f.view_load and 1) or 0,
'select_level': str(f.select or 0),
@@ -341,12 +340,12 @@ class orm_template(object):
vals['id'] = id
cr.execute("""INSERT INTO ir_model_fields (
id, model_id, model, name, field_description, ttype,
relate,relation,view_load,state,select_level
relation,view_load,state,select_level
) VALUES (
%d,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s
%d,%s,%s,%s,%s,%s,%s,%s,%s,%s
)""", (
id, vals['model_id'], vals['model'], vals['name'], vals['field_description'], vals['ttype'],
bool(vals['relate']), vals['relation'], bool(vals['view_load']), 'base',
vals['relation'], bool(vals['view_load']), 'base',
vals['select_level']
))
if 'module' in context:
@@ -359,11 +358,11 @@ class orm_template(object):
cr.execute('update ir_model_fields set field_description=%s where model=%s and name=%s', (vals['field_description'], vals['model'], vals['name']))
cr.commit()
cr.execute("""UPDATE ir_model_fields SET
model_id=%s, field_description=%s, ttype=%s, relate=%s, relation=%s,
model_id=%s, field_description=%s, ttype=%s, relation=%s,
view_load=%s, select_level=%s, readonly=%s ,required=%s
WHERE
model=%s AND name=%s""", (
vals['model_id'], vals['field_description'], vals['ttype'], bool(vals['relate']),
vals['model_id'], vals['field_description'], vals['ttype'],
vals['relation'], bool(vals['view_load']),
vals['select_level'], bool(vals['readonly']),bool(vals['required']), vals['model'], vals['name']
))