Avoid not safe assignment on self passing computed_lines as argument
This commit is contained in:
parent
25ff52d497
commit
565135f77f
@ -21,6 +21,7 @@
|
|||||||
##############################################################################
|
##############################################################################
|
||||||
|
|
||||||
from openerp import models, fields, api, exceptions, _
|
from openerp import models, fields, api, exceptions, _
|
||||||
|
from functools import partial
|
||||||
import re
|
import re
|
||||||
|
|
||||||
|
|
||||||
@ -51,23 +52,26 @@ class AccountDocumentTemplate(models.Model):
|
|||||||
lines[line.sequence] = None
|
lines[line.sequence] = None
|
||||||
return lines
|
return lines
|
||||||
|
|
||||||
@api.model
|
@api.multi
|
||||||
def lines(self, line_number):
|
def lines(self, line_number, computed_lines=None):
|
||||||
if self._computed_lines[line_number] is not None:
|
if computed_lines is None:
|
||||||
return self._computed_lines[line_number]
|
computed_lines = {}
|
||||||
|
if computed_lines[line_number] is not None:
|
||||||
|
return computed_lines[line_number]
|
||||||
line = self._get_template_line(line_number)
|
line = self._get_template_line(line_number)
|
||||||
if re.match(r'L\( *' + str(line_number) + r' *\)', line.python_code):
|
if re.match(r'L\( *' + str(line_number) + r' *\)', line.python_code):
|
||||||
raise exceptions.Warning(
|
raise exceptions.Warning(
|
||||||
_('Line %s can\'t refer to itself') % str(line_number)
|
_('Line %s can\'t refer to itself') % str(line_number)
|
||||||
)
|
)
|
||||||
try:
|
try:
|
||||||
self._computed_lines[line_number] = eval(
|
recurse_lines = partial(self.lines, computed_lines=computed_lines)
|
||||||
line.python_code.replace('L', 'self.lines')
|
computed_lines[line_number] = eval(
|
||||||
|
line.python_code.replace('L', 'recurse_lines')
|
||||||
)
|
)
|
||||||
except KeyError:
|
except KeyError:
|
||||||
raise exceptions.Warning(
|
raise exceptions.Warning(
|
||||||
_('Code "%s" refers to non existing line') % line.python_code)
|
_('Code "%s" refers to non existing line') % line.python_code)
|
||||||
return self._computed_lines[line_number]
|
return computed_lines[line_number]
|
||||||
|
|
||||||
@api.multi
|
@api.multi
|
||||||
def compute_lines(self, input_lines):
|
def compute_lines(self, input_lines):
|
||||||
@ -79,11 +83,12 @@ class AccountDocumentTemplate(models.Model):
|
|||||||
_('Inconsistency between input lines and '
|
_('Inconsistency between input lines and '
|
||||||
'filled lines for template %s') % self.name
|
'filled lines for template %s') % self.name
|
||||||
)
|
)
|
||||||
self._computed_lines = self._generate_empty_lines()
|
computed_lines = self._generate_empty_lines()
|
||||||
self._computed_lines.update(input_lines)
|
computed_lines.update(input_lines)
|
||||||
for line_number in self._computed_lines:
|
for line_number in computed_lines:
|
||||||
self.lines(line_number)
|
computed_lines[line_number] = self.lines(
|
||||||
return self._computed_lines
|
line_number, computed_lines)
|
||||||
|
return computed_lines
|
||||||
|
|
||||||
|
|
||||||
class AccountDocumentTemplateLine(models.Model):
|
class AccountDocumentTemplateLine(models.Model):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user