[FIX] models, fields: add model dependencies for models backed up by sql views
This commit is contained in:
parent
e9fae40faf
commit
a6b025d6d9
|
@ -532,6 +532,11 @@ class hr_timesheet_sheet_sheet_day(osv.osv):
|
|||
'total_attendance': fields.float('Attendance', readonly=True),
|
||||
'total_difference': fields.float('Difference', readonly=True),
|
||||
}
|
||||
_depends = {
|
||||
'hr.analytic.timesheet': ['line_id', 'sheet_id'],
|
||||
'account.analytic.line': ['date', 'unit_amount'],
|
||||
'hr.attendance': ['name', 'action', 'sheet_id'],
|
||||
}
|
||||
|
||||
def init(self, cr):
|
||||
cr.execute("""create or replace view hr_timesheet_sheet_sheet_day as
|
||||
|
|
|
@ -366,9 +366,17 @@ class Field(object):
|
|||
else:
|
||||
self._setup_regular(env)
|
||||
|
||||
# put invalidation/recomputation triggers on dependencies
|
||||
# put invalidation/recomputation triggers on field dependencies
|
||||
model = env[self.model_name]
|
||||
for path in self.depends:
|
||||
self._setup_dependency([], env[self.model_name], path.split('.'))
|
||||
self._setup_dependency([], model, path.split('.'))
|
||||
|
||||
# put invalidation triggers on model dependencies
|
||||
for dep_model_name, field_names in model._depends.iteritems():
|
||||
dep_model = env[dep_model_name]
|
||||
for field_name in field_names:
|
||||
field = dep_model._fields[field_name]
|
||||
field._triggers.add((self, None))
|
||||
|
||||
#
|
||||
# Setup of related fields
|
||||
|
@ -800,7 +808,7 @@ class Field(object):
|
|||
# invalidate the fields that depend on self, and prepare recomputation
|
||||
spec = [(self, records._ids)]
|
||||
for field, path in self._triggers:
|
||||
if field.store:
|
||||
if path and field.store:
|
||||
# don't move this line to function top, see log
|
||||
env = records.env(user=SUPERUSER_ID, context={'active_test': False})
|
||||
target = env[field.model_name].search([(path, 'in', records.ids)])
|
||||
|
|
|
@ -326,6 +326,10 @@ class BaseModel(object):
|
|||
_log_create = False
|
||||
_sql_constraints = []
|
||||
|
||||
# model dependencies, for models backed up by sql views:
|
||||
# {model_name: field_names, ...}
|
||||
_depends = {}
|
||||
|
||||
CONCURRENCY_CHECK_FIELD = '__last_update'
|
||||
|
||||
def log(self, cr, uid, id, message, secondary=False, context=None):
|
||||
|
|
Loading…
Reference in New Issue