Skip to content

Commit

Permalink
[FIX] account: Send & Print only for sales documents
Browse files Browse the repository at this point in the history
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#129720

Signed-off-by: John Laterre (jol) <jol@odoo.com>
  • Loading branch information
smetl committed Jul 26, 2023
1 parent 6f9a3a6 commit b3e8229
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 14 deletions.
7 changes: 7 additions & 0 deletions addons/account/i18n/account.pot
Original file line number Diff line number Diff line change
Expand Up @@ -4202,6 +4202,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
Expand Down
18 changes: 4 additions & 14 deletions addons/account/models/account_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -3788,6 +3788,9 @@ def action_duplicate(self):
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',
Expand All @@ -3806,21 +3809,8 @@ def action_invoice_sent(self):
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)

Expand Down

0 comments on commit b3e8229

Please sign in to comment.