summaryrefslogtreecommitdiff
path: root/addons/account/wizard
diff options
context:
space:
mode:
authorwan <wan@odoo.com>2019-10-11 14:07:42 +0000
committerwan <wan@odoo.com>2019-11-15 14:05:30 +0000
commit2106dd3cd10da44cd0b25897aaa5104f93aea703 (patch)
treec4bae24cf8f1aebb4b63741527ce235d5bb0be20 /addons/account/wizard
parent3fe9402de40a57ec7dc90218ea50054ac390b5a6 (diff)
[IMP] account: clean entry/move reversal
Task 2085023 * Add a field that replaces the context to get the ids of the entries/invoices * Remove move_id, we can use move_ids instead * Add text to explain invioces/bills will create refunds closes odoo/odoo#38857 Related: odoo/enterprise#6263 Signed-off-by: Quentin De Paoli (qdp) <qdp@openerp.com>
Diffstat (limited to 'addons/account/wizard')
-rw-r--r--addons/account/wizard/account_move_reversal.py21
-rw-r--r--addons/account/wizard/account_move_reversal_view.xml4
2 files changed, 14 insertions, 11 deletions
diff --git a/addons/account/wizard/account_move_reversal.py b/addons/account/wizard/account_move_reversal.py
index d51de2a7e69..67683ac44b5 100644
--- a/addons/account/wizard/account_move_reversal.py
+++ b/addons/account/wizard/account_move_reversal.py
@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-
from odoo import models, fields, api
from odoo.tools.translate import _
+from odoo.exceptions import UserError
class AccountMoveReversal(models.TransientModel):
@@ -10,9 +11,8 @@ class AccountMoveReversal(models.TransientModel):
_name = 'account.move.reversal'
_description = 'Account Move Reversal'
- move_id = fields.Many2one('account.move', string='Journal Entry',
- domain=[('state', '=', 'posted'), ('type', 'not in', ('out_refund', 'in_refund'))])
- new_move_ids = fields.Many2many('account.move')
+ move_ids = fields.Many2many('account.move', 'account_move_reversal_move', 'reversal_id', 'move_id', domain=[('state', '=', 'posted')])
+ new_move_ids = fields.Many2many('account.move', 'account_move_reversal_new_move', 'reversal_id', 'new_move_id')
date = fields.Date(string='Reversal date', default=fields.Date.context_today, required=True)
reason = fields.Char(string='Reason')
refund_method = fields.Selection(selection=[
@@ -32,22 +32,23 @@ class AccountMoveReversal(models.TransientModel):
def default_get(self, fields):
res = super(AccountMoveReversal, self).default_get(fields)
move_ids = self.env['account.move'].browse(self.env.context['active_ids']) if self.env.context.get('active_model') == 'account.move' else self.env['account.move']
+ if any(move.state != "posted" for move in move_ids):
+ raise UserError(_('You can only reverse posted moves.'))
+ res['move_ids'] = [(6, 0, move_ids.ids)]
res['refund_method'] = (len(move_ids) > 1 or move_ids.type == 'entry') and 'cancel' or 'refund'
- res['residual'] = len(move_ids) == 1 and move_ids.amount_residual or 0
- res['currency_id'] = len(move_ids.currency_id) == 1 and move_ids.currency_id.id or False
- res['move_type'] = len(move_ids) == 1 and move_ids.type or False
return res
- @api.depends('move_id')
+ @api.depends('move_ids')
def _compute_from_moves(self):
- move_ids = self.env['account.move'].browse(self.env.context['active_ids']) if self.env.context.get('active_model') == 'account.move' else self.move_id
for record in self:
+ move_ids = record.move_ids
record.residual = len(move_ids) == 1 and move_ids.amount_residual or 0
record.currency_id = len(move_ids.currency_id) == 1 and move_ids.currency_id or False
- record.move_type = len(move_ids) == 1 and move_ids.type or False
+ record.move_type = move_ids.type if len(move_ids) == 1 else (any(move.type in ('in_invoice', 'out_invoice') for move in move_ids) and 'some_invoice' or False)
def reverse_moves(self):
- moves = self.env['account.move'].browse(self.env.context['active_ids']) if self.env.context.get('active_model') == 'account.move' else self.move_id
+ self.ensure_one()
+ moves = self.move_ids
# Create default values.
default_values_list = []
diff --git a/addons/account/wizard/account_move_reversal_view.xml b/addons/account/wizard/account_move_reversal_view.xml
index be34b07889f..28371f68c90 100644
--- a/addons/account/wizard/account_move_reversal_view.xml
+++ b/addons/account/wizard/account_move_reversal_view.xml
@@ -7,12 +7,14 @@
<field name="arch" type="xml">
<form string="Reverse Journal Entry">
<field name="residual" invisible="1"/>
+ <field name="move_ids" invisible="1"/>
<field name="move_type" invisible="1"/>
+ <span class="text-muted" attrs="{'invisible': [('move_type', 'not in', ('out_invoice', 'in_invoice', 'some_invoice'))]}">Invoices/>Bills won't be reversed but credit notes will be created instead: the tax tags will be adapted accordingly.</span>
<group>
<group attrs="{'invisible': [('move_type', 'not in', ('out_invoice', 'in_invoice'))]}">
<field name="refund_method" widget="radio" attrs="{'readonly': [('residual', '=', 0)]}"/>
</group>
- <group attrs="{'invisible': [('move_type', 'not in', ('out_invoice', 'in_invoice'))]}">
+ <group attrs="{'invisible': [('move_type', 'not in', ('out_invoice', 'in_invoice', 'some_invoice'))]}">
<div attrs="{'invisible':[('refund_method', '!=', 'refund')]}" class="oe_grey" colspan="4">
The credit note is created in draft and can be edited before being issued.
</div>