Skip to content

Commit

Permalink
[REM] *: calls to @api.multi
Browse files Browse the repository at this point in the history
Multi is the default api for methods, it is not necessary to explicitly
decorate methods with it, adds clutter and most people use it because
they see that the rest of the code uses it.

Done with `find . -type f -name '*.py' | xargs sed -i '/@api.multi/d'`
  • Loading branch information
Adrian Torres committed Jul 17, 2019
1 parent f6fdde9 commit 4b38cc6
Show file tree
Hide file tree
Showing 463 changed files with 4 additions and 2,155 deletions.
23 changes: 0 additions & 23 deletions addons/account/models/account.py
Expand Up @@ -173,14 +173,12 @@ class AccountAccount(models.Model):
_description = "Account"
_order = "code"

@api.multi
@api.constrains('internal_type', 'reconcile')
def _check_reconcile(self):
for account in self:
if account.internal_type in ('receivable', 'payable') and account.reconcile == False:
raise ValidationError(_('You cannot have a receivable/payable account that is not reconcilable. (account code: %s)') % account.code)

@api.multi
@api.constrains('user_type_id')
def _check_user_type_id(self):
data_unaffected_earnings = self.env.ref('account.data_unaffected_earnings')
Expand Down Expand Up @@ -340,15 +338,13 @@ def onchange_code(self):
code_prefix = code_prefix[:-1]
self.group_id = group

@api.multi
def name_get(self):
result = []
for account in self:
name = account.code + ' ' + account.name
result.append((account.id, name))
return result

@api.multi
@api.returns('self', lambda value: value.id)
def copy(self, default=None):
default = dict(default or {})
Expand Down Expand Up @@ -421,7 +417,6 @@ def _toggle_reconcile_to_false(self):
"""
self.env.cr.execute(query, [tuple(self.ids)])

@api.multi
def write(self, vals):
# Do not allow changing the company_id when account_move_line already exist
if vals.get('company_id', False):
Expand All @@ -442,7 +437,6 @@ def write(self, vals):

return super(AccountAccount, self).write(vals)

@api.multi
def unlink(self):
if self.env['account.move.line'].search([('account_id', 'in', self.ids)], limit=1):
raise UserError(_('You cannot perform this action on an account that contains journal items.'))
Expand All @@ -453,7 +447,6 @@ def unlink(self):
raise UserError(_('You cannot remove/deactivate an account which is set on a customer or vendor.'))
return super(AccountAccount, self).unlink()

@api.multi
def action_open_reconcile(self):
self.ensure_one()
# Open reconciliation view for this account
Expand Down Expand Up @@ -613,13 +606,11 @@ def _get_bank_statements_available_sources(self):
('code_company_uniq', 'unique (code, name, company_id)', 'The code and name of the journal must be unique per company !'),
]

@api.multi
def _compute_alias_domain(self):
alias_domain = self.env["ir.config_parameter"].sudo().get_param("mail.catchall.domain")
for record in self:
record.alias_domain = alias_domain

@api.multi
# do not depend on 'sequence_id.date_range_ids', because
# sequence_id._get_current_sequence() may invalidate it!
@api.depends('sequence_id.use_date_range', 'sequence_id.number_next_actual')
Expand All @@ -634,7 +625,6 @@ def _compute_seq_number_next(self):
else:
journal.sequence_number_next = 1

@api.multi
def _inverse_seq_number_next(self):
'''Inverse 'sequence_number_next' to edit the current sequence next number.
'''
Expand All @@ -643,7 +633,6 @@ def _inverse_seq_number_next(self):
sequence = journal.sequence_id._get_current_sequence()
sequence.sudo().number_next = journal.sequence_number_next

@api.multi
# do not depend on 'refund_sequence_id.date_range_ids', because
# refund_sequence_id._get_current_sequence() may invalidate it!
@api.depends('refund_sequence_id.use_date_range', 'refund_sequence_id.number_next_actual')
Expand All @@ -658,7 +647,6 @@ def _compute_refund_seq_number_next(self):
else:
journal.refund_sequence_number_next = 1

@api.multi
def _inverse_refund_seq_number_next(self):
'''Inverse 'refund_sequence_number_next' to edit the current sequence next number.
'''
Expand Down Expand Up @@ -697,7 +685,6 @@ def onchange_credit_account_id(self):
if not self.default_debit_account_id:
self.default_debit_account_id = self.default_credit_account_id

@api.multi
def _get_alias_values(self, type, alias_name=None):
if not alias_name:
alias_name = self.name
Expand All @@ -709,7 +696,6 @@ def _get_alias_values(self, type, alias_name=None):
'alias_name': re.sub(r'[^\w]+', '-', alias_name)
}

@api.multi
def unlink(self):
bank_accounts = self.env['res.partner.bank'].browse()
for bank_account in self.mapped('bank_account_id'):
Expand All @@ -721,7 +707,6 @@ def unlink(self):
bank_accounts.unlink()
return ret

@api.multi
@api.returns('self', lambda value: value.id)
def copy(self, default=None):
default = dict(default or {})
Expand All @@ -743,7 +728,6 @@ def _update_mail_alias(self, vals):
# remove alias_name to avoid useless write on alias
del(vals['alias_name'])

@api.multi
def write(self, vals):
for journal in self:
company = journal.company_id
Expand Down Expand Up @@ -922,7 +906,6 @@ def set_bank_account(self, acc_number, bank_id=None):
'partner_id': self.company_id.partner_id.id,
}).id

@api.multi
def name_get(self):
res = []
for journal in self:
Expand All @@ -943,13 +926,11 @@ def _name_search(self, name, args=None, operator='ilike', limit=100, name_get_ui
journal_ids = self._search(expression.AND([domain, args]), limit=limit, access_rights_uid=name_get_uid)
return self.browse(journal_ids).name_get()

@api.multi
@api.depends('company_id')
def _belong_to_company(self):
for journal in self:
journal.belong_to_company = (journal.company_id.id == self.env.company.id)

@api.multi
def _search_company_journals(self, operator, value):
if value:
recs = self.search([('company_id', operator, self.env.company.id)])
Expand All @@ -959,7 +940,6 @@ def _search_company_journals(self, operator, value):
recs = self.search([('company_id', operator, self.env.company.id)])
return [('id', 'in', [x.id for x in recs])]

@api.multi
@api.depends('inbound_payment_method_ids', 'outbound_payment_method_ids')
def _methods_compute(self):
for journal in self:
Expand Down Expand Up @@ -1119,7 +1099,6 @@ def _check_children_scope(self):
if not all(child.type_tax_use in ('none', tax.type_tax_use) for child in tax.children_tax_ids):
raise ValidationError(_('The application scope of taxes in a group must be either the same as the group or left empty.'))

@api.multi
@api.returns('self', lambda value: value.id)
def copy(self, default=None):
default = dict(default or {}, name=_("%s (Copy)") % self.name)
Expand Down Expand Up @@ -1212,7 +1191,6 @@ def _compute_amount(self, base_amount, price_unit, quantity=1.0, product=None, p
if self.amount_type == 'division' and price_include:
return base_amount - (base_amount * (self.amount / 100))

@api.multi
def json_friendly_compute_all(self, price_unit, currency_id=None, quantity=1.0, product_id=None, partner_id=None, is_refund=False):
""" Just converts parameters in browse records and calls for compute_all, because js widgets can't serialize browse records """
if currency_id:
Expand Down Expand Up @@ -1240,7 +1218,6 @@ def get_tax_tags(self, is_refund, repartition_type):
rep_lines = self.mapped(is_refund and 'refund_repartition_line_ids' or 'invoice_repartition_line_ids')
return rep_lines.filtered(lambda x: x.repartition_type == repartition_type).mapped('tag_ids')

@api.multi
def compute_all(self, price_unit, currency=None, quantity=1.0, product=None, partner=None, is_refund=False, handle_price_include=True):
""" Returns all information required to apply taxes (in self + their children in case of a tax group).
We consider the sequence of the parent for group of taxes.
Expand Down
17 changes: 0 additions & 17 deletions addons/account/models/account_bank_statement.py
Expand Up @@ -38,7 +38,6 @@ class AccountBankStmtCashWizard(models.Model):

cashbox_lines_ids = fields.One2many('account.cashbox.line', 'cashbox_id', string='Cashbox Lines')

@api.multi
def validate(self):
bnk_stmt_id = self.env.context.get('bank_statement_id', False) or self.env.context.get('active_id', False)
bnk_stmt = self.env['account.bank.statement'].browse(bnk_stmt_id)
Expand All @@ -61,7 +60,6 @@ class AccountBankStmtCloseCheck(models.TransientModel):
_name = 'account.bank.statement.closebalance'
_description = 'Bank Statement Closing Balance'

@api.multi
def validate(self):
bnk_stmt_id = self.env.context.get('active_id', False)
if bnk_stmt_id:
Expand All @@ -78,7 +76,6 @@ def _end_balance(self):
statement.balance_end = statement.balance_start + statement.total_entry_encoding
statement.difference = statement.balance_end_real - statement.balance_end

@api.multi
def _is_difference_zero(self):
for bank_stmt in self:
bank_stmt.is_difference_zero = float_is_zero(bank_stmt.difference, precision_digits=bank_stmt.currency_id.decimal_places)
Expand Down Expand Up @@ -112,14 +109,12 @@ def _default_journal(self):
return journals[0]
return self.env['account.journal']

@api.multi
def _get_opening_balance(self, journal_id):
last_bnk_stmt = self.search([('journal_id', '=', journal_id)], limit=1)
if last_bnk_stmt:
return last_bnk_stmt.balance_end
return 0

@api.multi
def _set_opening_balance(self, journal_id):
self.balance_start = self._get_opening_balance(journal_id)

Expand Down Expand Up @@ -169,7 +164,6 @@ def _default_opening_balance(self):
def onchange_journal_id(self):
self._set_opening_balance(self.journal_id.id)

@api.multi
def _balance_check(self):
for stmt in self:
if not stmt.currency_id.is_zero(stmt.difference):
Expand Down Expand Up @@ -198,7 +192,6 @@ def _balance_check(self):
% (balance_end_real, balance_end))
return True

@api.multi
def unlink(self):
for statement in self:
if statement.state != 'open':
Expand All @@ -207,7 +200,6 @@ def unlink(self):
statement.line_ids.unlink()
return super(AccountBankStatement, self).unlink()

@api.multi
def open_cashbox_id(self):
context = dict(self.env.context or {})
if context.get('cashbox_id'):
Expand All @@ -223,7 +215,6 @@ def open_cashbox_id(self):
'target': 'new'
}

@api.multi
def check_confirm_bank(self):
if self.journal_type == 'cash' and not self.currency_id.is_zero(self.difference):
action_rec = self.env['ir.model.data'].xmlid_to_object('account.action_view_account_bnk_stmt_check')
Expand All @@ -232,7 +223,6 @@ def check_confirm_bank(self):
return action
return self.button_confirm_bank()

@api.multi
def button_confirm_bank(self):
self._balance_check()
statements = self.filtered(lambda r: r.state == 'open')
Expand All @@ -255,7 +245,6 @@ def button_confirm_bank(self):
statement.message_post(body=_('Statement %s confirmed, journal items were created.') % (statement.name,))
statements.write({'state': 'confirm', 'date_done': time.strftime("%Y-%m-%d %H:%M:%S")})

@api.multi
def button_journal_entries(self):
context = dict(self._context or {})
context['journal_id'] = self.journal_id.id
Expand All @@ -269,7 +258,6 @@ def button_journal_entries(self):
'context': context,
}

@api.multi
def button_open(self):
""" Changes statement state to Running."""
for statement in self:
Expand All @@ -283,7 +271,6 @@ def button_open(self):
statement.name = st_number
statement.state = 'open'

@api.multi
def action_bank_reconcile_bank_statements(self):
self.ensure_one()
bank_stmt_lines = self.mapped('line_ids')
Expand Down Expand Up @@ -365,14 +352,12 @@ def create(self, vals):
line.amount = line.amount
return line

@api.multi
def unlink(self):
for line in self:
if line.journal_entry_ids.ids:
raise UserError(_('In order to delete a bank statement line, you must first cancel it to delete related journal items.'))
return super(AccountBankStatementLine, self).unlink()

@api.multi
def button_cancel_reconciliation(self):
aml_to_unbind = self.env['account.move.line']
aml_to_cancel = self.env['account.move.line']
Expand Down Expand Up @@ -500,7 +485,6 @@ def _prepare_reconciliation_move_line(self, move, amount):
aml_dict['move_id'] = move.id
return aml_dict

@api.multi
def fast_counterpart_creation(self):
"""This function is called when confirming a bank statement and will allow to automatically process lines without
going in the bank reconciliation widget. By setting an account_id on bank statement lines, it will create a journal
Expand Down Expand Up @@ -766,7 +750,6 @@ def process_reconciliation(self, counterpart_aml_dicts=None, payment_aml_rec=Non
counterpart_moves._check_balanced()
return counterpart_moves

@api.multi
def _prepare_move_line_for_currency(self, aml_dict, date):
self.ensure_one()
company_currency = self.journal_id.company_id.currency_id
Expand Down
2 changes: 0 additions & 2 deletions addons/account/models/account_cash_rounding.py
Expand Up @@ -25,7 +25,6 @@ class AccountCashRounding(models.Model):
selection=[('UP', 'UP'), ('DOWN', 'DOWN'), ('HALF-UP', 'HALF-UP')],
default='HALF-UP', help='The tie-breaking rule used for float rounding operations')

@api.multi
def round(self, amount):
"""Compute the rounding on the amount passed as parameter.
Expand All @@ -34,7 +33,6 @@ def round(self, amount):
"""
return float_round(amount, precision_rounding=self.rounding, rounding_method=self.rounding_method)

@api.multi
def compute_difference(self, currency, amount):
"""Compute the difference between the base_amount and the amount after rounding.
For example, base_amount=23.91, after rounding=24.00, the result will be 0.09.
Expand Down

3 comments on commit 4b38cc6

@william-andre
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was this really necessary though?

@Elkasitu
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No

@william-andre
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice

Please sign in to comment.