From aba790be588434993c671d7ab7b07d75c9af6d73 Mon Sep 17 00:00:00 2001 From: Nicolas Bessi Date: Wed, 20 Aug 2014 15:46:23 +0200 Subject: [PATCH] pep8 line length to 80, activate pep8 check in travis, and add noqa on scenario while waiting improvement of quality-tools --- account_move_template/__openerp__.py | 12 +++- .../account_document_template.py | 24 ++++++-- .../account_move_template.py | 60 ++++++++++++++----- .../wizard/select_template.py | 35 ++++++++--- 4 files changed, 98 insertions(+), 33 deletions(-) diff --git a/account_move_template/__openerp__.py b/account_move_template/__openerp__.py index 2400975f..a4119bf0 100644 --- a/account_move_template/__openerp__.py +++ b/account_move_template/__openerp__.py @@ -27,9 +27,15 @@ Templates for Journal Entries User can configure journal entries templates, useful for recurring entries. -The amount of each template line can be computed (through python code) or kept as user input. -If user input, when using the template, user has to fill the amount of every input lines. -The journal entry form allows lo load, through a wizard, the template to use and the amounts to fill. + +The amount of each template line can be computed (through python code) +or kept as user input. + +If user input, when using the template, user has to fill +the amount of every input lines. + +The journal entry form allows lo load, through a wizard, +the template to use and the amounts to fill. """, 'author': 'Agile Business Group', diff --git a/account_move_template/account_document_template.py b/account_move_template/account_document_template.py index 18f03df5..1d740af1 100644 --- a/account_move_template/account_document_template.py +++ b/account_move_template/account_document_template.py @@ -51,21 +51,27 @@ class account_document_template(orm.Model): def _generate_empty_lines(self, cr, uid, template_id): lines = {} - for template_line in self.browse(cr, uid, template_id).template_line_ids: + t_lines = self.browse(cr, uid, template_id).template_line_ids + for template_line in t_lines: lines[template_line.sequence] = None return lines 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._cr, self._uid, self._current_template_id, line_number) + line = self._get_template_line(self._cr, + self._uid, + self._current_template_id, + line_number) if re.match('L\( *' + str(line_number) + ' *\)', line.python_code): raise orm.except_orm( _('Error'), _('Line %s can\'t refer to itself') % str(line_number) ) try: - self._computed_lines[line_number] = eval(line.python_code.replace('L', 'self.lines')) + self._computed_lines[line_number] = eval( + line.python_code.replace('L', 'self.lines') + ) except KeyError: raise orm.except_orm( _('Error'), @@ -74,12 +80,14 @@ class account_document_template(orm.Model): def compute_lines(self, cr, uid, template_id, 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} + # returns all the lines (included input lines) + # in the form {line_number: line_amount} template = self.browse(cr, uid, template_id) if len(input_lines) != self._input_lines(cr, uid, template): raise orm.except_orm( _('Error'), - _('Inconsistency between input lines and filled lines for template %s') % template.name + _('Inconsistency between input lines and ' + 'filled lines for template %s') % template.name ) self._current_template_id = template.id self._cr = cr @@ -106,6 +114,10 @@ class account_document_template_line(orm.Model): _columns = { 'name': fields.char('Name', size=64, required=True), 'sequence': fields.integer('Sequence', required=True), - 'type': fields.selection([('computed', 'Computed'), ('input', 'User input')], 'Type', required=True), + 'type': fields.selection( + [('computed', 'Computed'), ('input', 'User input')], + 'Type', + required=True + ), 'python_code': fields.text('Python Code'), } diff --git a/account_move_template/account_move_template.py b/account_move_template/account_move_template.py index 36c60675..e39864ff 100644 --- a/account_move_template/account_move_template.py +++ b/account_move_template/account_move_template.py @@ -28,23 +28,40 @@ class account_move_template(orm.Model): _name = 'account.move.template' _columns = { - 'company_id': fields.many2one('res.company', 'Company', required=True, change_default=True), - 'template_line_ids': fields.one2many('account.move.template.line', 'template_id', 'Template Lines'), + 'company_id': fields.many2one( + 'res.company', + 'Company', + required=True, + change_default=True + ), + 'template_line_ids': fields.one2many( + 'account.move.template.line', + 'template_id', + 'Template Lines' + ), 'cross_journals': fields.boolean('Cross-Journals'), - 'transitory_acc_id': fields.many2one('account.account', 'Transitory account', required=False), - } - - _defaults = { - 'company_id': lambda self, cr, uid, c: self.pool.get('res.company')._company_default_get( - cr, uid, 'account.move.template', context=c + 'transitory_acc_id': fields.many2one( + 'account.account', + 'Transitory account', + required=False ), } + def _get_default(self, cr, uid, context=None): + self.pool.get('res.company')._company_default_get( + cr, uid, 'account.move.template', context=context + ) + _defaults = { + 'company_id': _get_default + } + def _check_different_journal(self, cr, uid, ids, context=None): - # Check that the journal on these lines are different/same in the case of cross journals/single journal + # Check that the journal on these lines are different/same in the case + # of cross journals/single journal journal_ids = [] all_journal_ids = [] - move_template = self.pool.get('account.move.template').browse(cr, uid, ids)[0] + move_template = self.pool.get('account.move.template').browse( + cr, uid, ids)[0] if not move_template.template_line_ids: return True for template_line in move_template.template_line_ids: @@ -59,7 +76,8 @@ class account_move_template(orm.Model): _constraints = [ (_check_different_journal, 'If the template is "cross-journals", the Journals must be different,' - 'if the template does not "cross-journals" the Journals must be the same!', + 'if the template does not "cross-journals" ' + 'the Journals must be the same!', ['journal_id']) ] @@ -69,16 +87,28 @@ class account_move_template_line(orm.Model): _inherit = 'account.document.template.line' _columns = { - 'journal_id': fields.many2one('account.journal', 'Journal', required=True), - 'account_id': fields.many2one('account.account', 'Account', - required=True, ondelete="cascade"), + 'journal_id': fields.many2one( + 'account.journal', + 'Journal', + required=True + ), + 'account_id': fields.many2one( + 'account.account', + 'Account', + required=True, + ondelete="cascade" + ), 'move_line_type': fields.selection( [('cr', 'Credit'), ('dr', 'Debit')], 'Move Line Type', required=True ), - 'analytic_account_id': fields.many2one('account.analytic.account', 'Analytic Account', ondelete="cascade"), + 'analytic_account_id': fields.many2one( + 'account.analytic.account', + 'Analytic Account', + ondelete="cascade" + ), 'template_id': fields.many2one('account.move.template', 'Template'), 'account_tax_id': fields.many2one('account.tax', 'Tax'), } diff --git a/account_move_template/wizard/select_template.py b/account_move_template/wizard/select_template.py index 53906793..a074c6bf 100644 --- a/account_move_template/wizard/select_template.py +++ b/account_move_template/wizard/select_template.py @@ -86,7 +86,8 @@ class wizard_select_template(orm.TransientModel): return self.load_template(cr, uid, ids) wizard.write({'state': 'template_selected'}) - view_rec = model_data_obj.get_object_reference(cr, uid, 'account_move_template', 'wizard_select_template') + view_rec = model_data_obj.get_object_reference( + cr, uid, 'account_move_template', 'wizard_select_template') view_id = view_rec and view_rec[1] or False return { @@ -106,7 +107,10 @@ class wizard_select_template(orm.TransientModel): wizard = self.browse(cr, uid, ids, context=context)[0] if not template_obj.check_zero_lines(cr, uid, wizard): - raise orm.except_orm(_('Error !'), _('At least one amount has to be non-zero!')) + raise orm.except_orm( + _('Error !'), + _('At least one amount has to be non-zero!') + ) input_lines = {} for template_line in wizard.line_ids: @@ -114,10 +118,14 @@ class wizard_select_template(orm.TransientModel): period_id = account_period_obj.find(cr, uid, context=context) if not period_id: - raise orm.except_orm(_('No period found !'), _('Unable to find a valid period !')) + raise orm.except_orm( + _('No period found !'), + _('Unable to find a valid period !') + ) period_id = period_id[0] - computed_lines = template_obj.compute_lines(cr, uid, wizard.template_id.id, input_lines) + computed_lines = template_obj.compute_lines( + cr, uid, wizard.template_id.id, input_lines) moves = {} for line in wizard.template_id.template_line_ids: @@ -171,14 +179,16 @@ class wizard_select_template(orm.TransientModel): }) return move_id - def _make_move_line(self, cr, uid, line, computed_lines, move_id, period_id, partner_id): + def _make_move_line(self, cr, uid, line, computed_lines, + move_id, period_id, partner_id): account_move_line_obj = self.pool.get('account.move.line') analytic_account_id = False if line.analytic_account_id: if not line.journal_id.analytic_journal_id: raise orm.except_orm( _('No Analytic Journal !'), - _("You have to dfine an analytic journal on the '%s' journal!") + _("You have to define an analytic " + "journal on the '%s' journal!") % (line.journal_id.name,) ) @@ -212,7 +222,8 @@ class wizard_select_template(orm.TransientModel): if not line.journal_id.analytic_journal_id: raise orm.except_orm( _('No Analytic Journal !'), - _("You have to define an analytic journal on the '%s' journal!") + _("You have to define an analytic journal " + "on the '%s' journal!") % (line.template_id.journal_id.name,) ) analytic_account_id = line.analytic_account_id.id @@ -238,10 +249,16 @@ class wizard_select_template_line(orm.TransientModel): _description = 'Template Lines' _name = "wizard.select.move.template.line" _columns = { - 'template_id': fields.many2one('wizard.select.move.template', 'Template'), + 'template_id': fields.many2one('wizard.select.move.template', + 'Template'), 'sequence': fields.integer('Number', required=True), 'name': fields.char('Name', size=64, required=True, readonly=True), - 'account_id': fields.many2one('account.account', 'Account', required=True, readonly=True), + 'account_id': fields.many2one( + 'account.account', + 'Account', + required=True, + readonly=True + ), 'move_line_type': fields.selection( [('cr', 'Credit'), ('dr', 'Debit')],