Apply changes according to the new API and remove all title from Warning
This commit is contained in:
parent
dc32e4dd62
commit
cda768d80b
@ -29,27 +29,25 @@ class AccountDocumentTemplate(models.Model):
|
|||||||
|
|
||||||
name = fields.Char(required=True)
|
name = fields.Char(required=True)
|
||||||
|
|
||||||
@api.model
|
@api.multi
|
||||||
def _input_lines(self, template):
|
def _input_lines(self):
|
||||||
count = 0
|
count = 0
|
||||||
for line in template.template_line_ids:
|
for line in self.template_line_ids:
|
||||||
if line.type == 'input':
|
if line.type == 'input':
|
||||||
count += 1
|
count += 1
|
||||||
return count
|
return count
|
||||||
|
|
||||||
@api.multi
|
@api.multi
|
||||||
def _get_template_line(self, template_id, line_number):
|
def _get_template_line(self, line_number):
|
||||||
template = self.browse(template_id)
|
for line in self.template_line_ids:
|
||||||
for line in template.template_line_ids:
|
|
||||||
if line.sequence == line_number:
|
if line.sequence == line_number:
|
||||||
return line
|
return line
|
||||||
return False
|
return False
|
||||||
|
|
||||||
@api.multi
|
@api.multi
|
||||||
def _generate_empty_lines(self, template_id):
|
def _generate_empty_lines(self):
|
||||||
lines = {}
|
lines = {}
|
||||||
template = self.browse(template_id)
|
for line in self.template_line_ids:
|
||||||
for line in template.template_line_ids:
|
|
||||||
lines[line.sequence] = None
|
lines[line.sequence] = None
|
||||||
return lines
|
return lines
|
||||||
|
|
||||||
@ -57,7 +55,7 @@ class AccountDocumentTemplate(models.Model):
|
|||||||
def lines(self, line_number):
|
def lines(self, line_number):
|
||||||
if self._computed_lines[line_number] is not None:
|
if self._computed_lines[line_number] is not None:
|
||||||
return self._computed_lines[line_number]
|
return self._computed_lines[line_number]
|
||||||
line = self._get_template_line(self._current_template_id, 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)
|
||||||
@ -68,38 +66,25 @@ class AccountDocumentTemplate(models.Model):
|
|||||||
)
|
)
|
||||||
except KeyError:
|
except KeyError:
|
||||||
raise exceptions.Warning(
|
raise exceptions.Warning(
|
||||||
_('Error'),
|
|
||||||
_('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 self._computed_lines[line_number]
|
||||||
|
|
||||||
@api.model
|
@api.multi
|
||||||
def compute_lines(self, template_id, input_lines):
|
def compute_lines(self, input_lines):
|
||||||
# input_lines: dictionary in the form {line_number: line_amount}
|
# input_lines: dictionary in the form {line_number: line_amount}
|
||||||
# returns all the lines (included input lines)
|
# returns all the lines (included input lines)
|
||||||
# in the form {line_number: line_amount}
|
# in the form {line_number: line_amount}
|
||||||
template = self.browse(template_id)
|
if len(input_lines) != self._input_lines():
|
||||||
if len(input_lines) != self._input_lines(template):
|
|
||||||
raise exceptions.Warning(
|
raise exceptions.Warning(
|
||||||
_('Error'),
|
|
||||||
_('Inconsistency between input lines and '
|
_('Inconsistency between input lines and '
|
||||||
'filled lines for template %s') % template.name
|
'filled lines for template %s') % self.name
|
||||||
)
|
)
|
||||||
self._current_template_id = template.id
|
self._computed_lines = self._generate_empty_lines()
|
||||||
self._computed_lines = self._generate_empty_lines(template_id)
|
|
||||||
self._computed_lines.update(input_lines)
|
self._computed_lines.update(input_lines)
|
||||||
for line_number in self._computed_lines:
|
for line_number in self._computed_lines:
|
||||||
self.lines(line_number)
|
self.lines(line_number)
|
||||||
return self._computed_lines
|
return self._computed_lines
|
||||||
|
|
||||||
@api.model
|
|
||||||
def check_zero_lines(self, wizard):
|
|
||||||
if not wizard.line_ids:
|
|
||||||
return True
|
|
||||||
for template_line in wizard.line_ids:
|
|
||||||
if template_line.amount:
|
|
||||||
return True
|
|
||||||
return False
|
|
||||||
|
|
||||||
|
|
||||||
class AccountDocumentTemplateLine(models.Model):
|
class AccountDocumentTemplateLine(models.Model):
|
||||||
_name = 'account.document.template.line'
|
_name = 'account.document.template.line'
|
||||||
|
@ -45,11 +45,19 @@ class WizardSelectMoveTemplate(models.TransientModel):
|
|||||||
string='State'
|
string='State'
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@api.multi
|
||||||
|
def check_zero_lines(self):
|
||||||
|
if not self.line_ids:
|
||||||
|
return True
|
||||||
|
for template_line in self.line_ids:
|
||||||
|
if template_line.amount:
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
@api.multi
|
@api.multi
|
||||||
def load_lines(self):
|
def load_lines(self):
|
||||||
self.ensure_one()
|
self.ensure_one()
|
||||||
template = self.env['account.move.template'].browse(
|
template = self.template_id
|
||||||
self.template_id.id)
|
|
||||||
for line in template.template_line_ids:
|
for line in template.template_line_ids:
|
||||||
if line.type == 'input':
|
if line.type == 'input':
|
||||||
self.env['wizard.select.move.template.line'].create({
|
self.env['wizard.select.move.template.line'].create({
|
||||||
@ -62,7 +70,7 @@ class WizardSelectMoveTemplate(models.TransientModel):
|
|||||||
})
|
})
|
||||||
if not self.line_ids:
|
if not self.line_ids:
|
||||||
return self.load_template()
|
return self.load_template()
|
||||||
self.write({'state': 'template_selected'})
|
self.state = 'template_selected'
|
||||||
|
|
||||||
view_rec = self.env['ir.model.data'].get_object_reference(
|
view_rec = self.env['ir.model.data'].get_object_reference(
|
||||||
'account_move_template', 'wizard_select_template')
|
'account_move_template', 'wizard_select_template')
|
||||||
@ -82,11 +90,9 @@ class WizardSelectMoveTemplate(models.TransientModel):
|
|||||||
@api.multi
|
@api.multi
|
||||||
def load_template(self):
|
def load_template(self):
|
||||||
self.ensure_one()
|
self.ensure_one()
|
||||||
template_model = self.env['account.move.template']
|
|
||||||
account_period_model = self.env['account.period']
|
account_period_model = self.env['account.period']
|
||||||
if not template_model.check_zero_lines(self):
|
if not self.check_zero_lines():
|
||||||
raise exceptions.Warning(
|
raise exceptions.Warning(
|
||||||
_('Error !'),
|
|
||||||
_('At least one amount has to be non-zero!')
|
_('At least one amount has to be non-zero!')
|
||||||
)
|
)
|
||||||
input_lines = {}
|
input_lines = {}
|
||||||
@ -95,13 +101,9 @@ class WizardSelectMoveTemplate(models.TransientModel):
|
|||||||
|
|
||||||
period = account_period_model.find()
|
period = account_period_model.find()
|
||||||
if not period:
|
if not period:
|
||||||
raise exceptions.Warning(
|
raise exceptions.Warning(_('Unable to find a valid period !'))
|
||||||
_('No period found !'),
|
|
||||||
_('Unable to find a valid period !')
|
|
||||||
)
|
|
||||||
|
|
||||||
computed_lines = template_model.compute_lines(
|
computed_lines = self.template_id.compute_lines(input_lines)
|
||||||
self.template_id.id, input_lines)
|
|
||||||
|
|
||||||
moves = {}
|
moves = {}
|
||||||
for line in self.template_id.template_line_ids:
|
for line in self.template_id.template_line_ids:
|
||||||
@ -159,7 +161,6 @@ class WizardSelectMoveTemplate(models.TransientModel):
|
|||||||
if line.analytic_account_id:
|
if line.analytic_account_id:
|
||||||
if not line.journal_id.analytic_journal_id:
|
if not line.journal_id.analytic_journal_id:
|
||||||
raise exceptions.Warning(
|
raise exceptions.Warning(
|
||||||
_('No Analytic Journal !'),
|
|
||||||
_("You have to define an analytic "
|
_("You have to define an analytic "
|
||||||
"journal on the '%s' journal!")
|
"journal on the '%s' journal!")
|
||||||
% (line.journal_id.name,)
|
% (line.journal_id.name,)
|
||||||
|
Loading…
Reference in New Issue
Block a user