Browse Source

update

pull/6/head
Mathias Markl 6 years ago
parent
commit
ae5c824649
  1. 2
      muk_autovacuum/__manifest__.py
  2. 13
      muk_autovacuum/models/ir_autovacuum.py
  3. 17
      muk_autovacuum/models/rules.py

2
muk_autovacuum/__manifest__.py

@ -20,7 +20,7 @@
{
"name": "MuK Autovacuum",
"summary": """Configure automatic garbage collection""",
"version": "11.0.2.1.1",
"version": "11.0.2.1.2",
"category": "Extra Tools",
"license": "AGPL-3",
"website": "https://www.mukit.at",

13
muk_autovacuum/models/ir_autovacuum.py

@ -42,15 +42,6 @@ class AutoVacuum(models.AbstractModel):
_inherit = 'ir.autovacuum'
@api.model
def _eval_context(self):
return {
'datetime': datetime,
'dateutil': dateutil,
'time': time,
'uid': self.env.uid,
'user': self.env.user}
@api.model
def power_on(self, *args, **kwargs):
res = super(AutoVacuum, self).power_on(*args, **kwargs)
@ -79,7 +70,7 @@ class AutoVacuum(models.AbstractModel):
records = model.with_context({'active_test': False}).search([], order=rule.size_order, limit=limit)
elif rule.state == 'domain':
_logger.info(_("GC domain: %s"), rule.domain)
domain = safe_eval(rule.domain, self._eval_context())
domain = safe_eval(rule.domain, rules._get_eval_domain_context())
records = model.with_context({'active_test': False}).search(domain)
if rule.only_attachments:
attachments = self.env['ir.attachment'].sudo().search([
@ -93,5 +84,5 @@ class AutoVacuum(models.AbstractModel):
records.unlink()
_logger.info(_("GC'd %s %s records"), count, rule.model.model)
elif rule.state == 'code':
safe_eval(rule.code.strip(), rule._get_eval_context(), mode="exec")
safe_eval(rule.code.strip(), rules._get_eval_code_context(rule), mode="exec")
return res

17
muk_autovacuum/models/rules.py

@ -236,10 +236,21 @@ class AutoVacuumRules(models.Model):
# Functions
#----------------------------------------------------------
def _get_eval_context(self):
@api.model
def _get_eval_domain_context(self):
return {
'datetime': datetime,
'dateutil': dateutil,
'time': time,
'uid': self.env.uid,
'user': self.env.user
}
@api.model
def _get_eval_code_context(self, rule):
return {
'env': self.env,
'model': self.env[self.model_name],
'model': self.env[rule.model_name],
'uid': self.env.user.id,
'user': self.env.user,
'time': time,
@ -249,7 +260,7 @@ class AutoVacuumRules(models.Model):
'date_format': DEFAULT_SERVER_DATE_FORMAT,
'datetime_format': DEFAULT_SERVER_DATETIME_FORMAT,
'Warning': Warning,
'logger': logging.getLogger("%s (%s)" % (__name__, self.name)),
'logger': logging.getLogger("%s (%s)" % (__name__, rule.name)),
}
#----------------------------------------------------------

Loading…
Cancel
Save