From 8bdb52c26df867f6a0a590ea7a23cc593a7c40ca Mon Sep 17 00:00:00 2001 From: Laurent Smet Date: Wed, 26 Jul 2023 09:07:23 +0000 Subject: [PATCH] [FIX] account: Send & Print only for sales documents We are currently able to open the send & print for a vendor bill. It doesn't make any sense to ask to a vendor to pay its own invoice. closes odoo/odoo#129793 X-original-commit: b3e8229d16be074a719fa07e3b2d5488ace66492 Signed-off-by: John Laterre (jol) Signed-off-by: Laurent Smet (las) --- addons/account/i18n/account.pot | 7 +++++++ addons/account/models/account_move.py | 18 ++++-------------- 2 files changed, 11 insertions(+), 14 deletions(-) diff --git a/addons/account/i18n/account.pot b/addons/account/i18n/account.pot index b882d6dd3db..a88145b25a2 100644 --- a/addons/account/i18n/account.pot +++ b/addons/account/i18n/account.pot @@ -4205,6 +4205,13 @@ msgstr "" msgid "Credit Note" msgstr "" +#. module: account +#. odoo-python +#: code:addons/account/models/account_move.py:0 +#, python-format +msgid "You can only send sales documents" +msgstr "" + #. module: account #. odoo-python #: code:addons/account/models/account_move.py:0 diff --git a/addons/account/models/account_move.py b/addons/account/models/account_move.py index 10061b7b223..13e5fc5c40e 100644 --- a/addons/account/models/account_move.py +++ b/addons/account/models/account_move.py @@ -3871,6 +3871,9 @@ class AccountMove(models.Model): def action_send_and_print(self): template = self.env.ref(self._get_mail_template(), raise_if_not_found=False) + if any(not x.is_sale_document(include_receipts=True) for x in self): + raise UserError(_("You can only send sales documents")) + return { 'name': _("Send"), 'type': 'ir.actions.act_window', @@ -3889,21 +3892,8 @@ class AccountMove(models.Model): message loaded by default """ self.ensure_one() - template = self.env.ref(self._get_mail_template(), raise_if_not_found=False) - - report_action = { - 'name': _("Send"), - 'type': 'ir.actions.act_window', - 'view_type': 'form', - 'view_mode': 'form', - 'res_model': 'account.move.send', - 'target': 'new', - 'context': { - 'active_ids': self.ids, - 'default_mail_template_id': template.id, - }, - } + report_action = self.action_send_and_print() if self.env.is_admin() and not self.env.company.external_report_layout_id and not self.env.context.get('discard_logo_check'): return self.env['ir.actions.report']._action_configure_external_report_layout(report_action)