From cda768d80b80a0e75729947573674dba0408eaf2 Mon Sep 17 00:00:00 2001 From: Alex Comba Date: Tue, 9 Dec 2014 17:50:23 +0100 Subject: [PATCH] Apply changes according to the new API and remove all title from Warning --- .../account_document_template.py | 41 ++++++------------- .../wizard/select_template.py | 27 ++++++------ 2 files changed, 27 insertions(+), 41 deletions(-) diff --git a/account_move_template/account_document_template.py b/account_move_template/account_document_template.py index 52e5c148..a4061b28 100644 --- a/account_move_template/account_document_template.py +++ b/account_move_template/account_document_template.py @@ -29,27 +29,25 @@ class AccountDocumentTemplate(models.Model): name = fields.Char(required=True) - @api.model - def _input_lines(self, template): + @api.multi + def _input_lines(self): count = 0 - for line in template.template_line_ids: + for line in self.template_line_ids: if line.type == 'input': count += 1 return count @api.multi - def _get_template_line(self, template_id, line_number): - template = self.browse(template_id) - for line in template.template_line_ids: + def _get_template_line(self, line_number): + for line in self.template_line_ids: if line.sequence == line_number: return line return False @api.multi - def _generate_empty_lines(self, template_id): + def _generate_empty_lines(self): lines = {} - template = self.browse(template_id) - for line in template.template_line_ids: + for line in self.template_line_ids: lines[line.sequence] = None return lines @@ -57,7 +55,7 @@ class AccountDocumentTemplate(models.Model): def lines(self, line_number): if self._computed_lines[line_number] is not None: 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): raise exceptions.Warning( _('Line %s can\'t refer to itself') % str(line_number) @@ -68,38 +66,25 @@ class AccountDocumentTemplate(models.Model): ) except KeyError: raise exceptions.Warning( - _('Error'), _('Code "%s" refers to non existing line') % line.python_code) return self._computed_lines[line_number] - @api.model - def compute_lines(self, template_id, input_lines): + @api.multi + def compute_lines(self, input_lines): # input_lines: dictionary in the form {line_number: line_amount} # returns all the lines (included input lines) # in the form {line_number: line_amount} - template = self.browse(template_id) - if len(input_lines) != self._input_lines(template): + if len(input_lines) != self._input_lines(): raise exceptions.Warning( - _('Error'), _('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(template_id) + self._computed_lines = self._generate_empty_lines() self._computed_lines.update(input_lines) for line_number in self._computed_lines: self.lines(line_number) 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): _name = 'account.document.template.line' diff --git a/account_move_template/wizard/select_template.py b/account_move_template/wizard/select_template.py index 11d919bd..695d205d 100644 --- a/account_move_template/wizard/select_template.py +++ b/account_move_template/wizard/select_template.py @@ -45,11 +45,19 @@ class WizardSelectMoveTemplate(models.TransientModel): 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 def load_lines(self): self.ensure_one() - template = self.env['account.move.template'].browse( - self.template_id.id) + template = self.template_id for line in template.template_line_ids: if line.type == 'input': self.env['wizard.select.move.template.line'].create({ @@ -62,7 +70,7 @@ class WizardSelectMoveTemplate(models.TransientModel): }) if not self.line_ids: return self.load_template() - self.write({'state': 'template_selected'}) + self.state = 'template_selected' view_rec = self.env['ir.model.data'].get_object_reference( 'account_move_template', 'wizard_select_template') @@ -82,11 +90,9 @@ class WizardSelectMoveTemplate(models.TransientModel): @api.multi def load_template(self): self.ensure_one() - template_model = self.env['account.move.template'] account_period_model = self.env['account.period'] - if not template_model.check_zero_lines(self): + if not self.check_zero_lines(): raise exceptions.Warning( - _('Error !'), _('At least one amount has to be non-zero!') ) input_lines = {} @@ -95,13 +101,9 @@ class WizardSelectMoveTemplate(models.TransientModel): period = account_period_model.find() if not period: - raise exceptions.Warning( - _('No period found !'), - _('Unable to find a valid period !') - ) + raise exceptions.Warning(_('Unable to find a valid period !')) - computed_lines = template_model.compute_lines( - self.template_id.id, input_lines) + computed_lines = self.template_id.compute_lines(input_lines) moves = {} for line in self.template_id.template_line_ids: @@ -159,7 +161,6 @@ class WizardSelectMoveTemplate(models.TransientModel): if line.analytic_account_id: if not line.journal_id.analytic_journal_id: raise exceptions.Warning( - _('No Analytic Journal !'), _("You have to define an analytic " "journal on the '%s' journal!") % (line.journal_id.name,)