[IMP] account,account_debit_note: Change credit / debit note buttons

Debit Notes are a type of financial documents that is not very often used. Even though it's an official document type, in many countries their usage is not

Odoo does not come with a preinstalled Debit Note management, but it can be added by installing the module account_debit_note. The module as mostly been developped following localisation requirements, and while it's a corner case, it appears all the time in one of our most critical screen. Let's make it a bit more discrete.

task-3125955

closes odoo/odoo#109539

Signed-off-by: Laurent Smet <las@odoo.com>
This commit is contained in:
smdc-odoo
2023-01-27 17:29:16 +01:00
parent a7b205d48d
commit 4f7d03829e
4 changed files with 23 additions and 8 deletions
+1 -1
View File
@@ -606,7 +606,7 @@
<button name="%(action_view_account_move_reversal)d" string="Reverse Entry"
type="action" groups="account.group_account_invoice" data-hotkey="z"
attrs="{'invisible': ['|', ('move_type', '!=', 'entry'), '|', ('state', '!=', 'posted'), ('payment_state', '=', 'reversed')]}"/>
<button name="action_reverse" string='Add Credit Note'
<button name="action_reverse" string='Credit Note'
type='object' groups="account.group_account_invoice"
attrs="{'invisible': ['|', ('move_type', 'not in', ('out_invoice', 'in_invoice')), ('state', '!=', 'posted')]}"/>
<!-- Cancel -->
@@ -28,3 +28,7 @@ class AccountMove(models.Model):
'view_mode': 'tree,form',
'domain': [('debit_origin_id', '=', self.id)],
}
def action_debit_note(self):
action = self.env.ref('account_debit_note.action_view_account_move_debit').read()[0]
return action
@@ -5,13 +5,6 @@
<field name="model">account.move</field>
<field name="inherit_id" ref="account.view_move_form"/>
<field name="arch" type="xml">
<button name="action_reverse" position="after">
<field name="debit_origin_id" invisible="1"/>
<button name="%(action_view_account_move_debit)d" string='Add Debit Note'
type='action' groups="account.group_account_invoice"
attrs="{'invisible': ['|', '|', ('debit_origin_id', '!=', False),
('move_type', 'not in', ('out_invoice', 'in_invoice', 'out_refund', 'in_refund')), ('state', '!=', 'posted')]}"/>
</button>
<div class="oe_button_box" position="inside">
<button type="object" class="oe_stat_button" name="action_view_debit_notes" icon="fa-plus" attrs="{'invisible': [('debit_note_count', '=', 0)]}">
<div class="o_field_widget o_stat_info">
@@ -25,4 +18,18 @@
</field>
</field>
</record>
<record model="ir.actions.server" id="action_move_debit_note">
<field name="name">Debit Note</field>
<field name="model_id" ref="model_account_move"/>
<field name="groups_id" eval="[(4, ref('account.group_account_invoice'))]"/>
<field name="binding_model_id" ref="account.model_account_move" />
<field name="binding_view_types">form</field>
<field name="state">code</field>
<field name="code">
if records:
action = records.action_debit_note()
</field>
</record>
</odoo>
@@ -33,6 +33,10 @@ class AccountDebitNote(models.TransientModel):
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 debit posted moves.'))
elif any(move.debit_origin_id for move in move_ids):
raise UserError(_("You can't make a debit note for an invoice that is already linked to a debit note."))
elif any(move.move_type not in ['out_invoice', 'in_invoice', 'out_refund', 'in_refund'] for move in move_ids):
raise UserError(_("You can make a debit note only for a Customer Invoice, a Customer Credit Note, a Vendor Bill or a Vendor Credit Note."))
res['move_ids'] = [(6, 0, move_ids.ids)]
return res