[FIX] website_sale: land on website in backend when previewing INV or SO

The invoices and sale orders got a button "Preview" to reach their
frontend/website page. One of the goal is to then be able to enter edit
mode and customize it.
But since we merged frontend > backend with [1] (and multiple iterations
since then), landing on the frontend is not a good idea to do that as
you would then need to click on the "Editor" button to go back to the
backend and be able to enter edit mode. Now we reach the iframe preview
directly.

Note: this will be improved in a further update to not require a reload
of the backend when clicking on the button.

[1]: https://github.com/odoo/odoo/commit/31cc10b91dc7762e23b4bde9b945be0c4ce3fe3b

closes odoo/odoo#102787

X-original-commit: 007ae49e9c94061adf34aa9f911c7a9a0e873e0e
Signed-off-by: Quentin Smetz (qsm) <qsm@odoo.com>
Signed-off-by: Romain Derie (rde) <rde@odoo.com>
This commit is contained in:
Romain Derie
2022-10-09 15:40:49 +02:00
committed by qsm-odoo
parent e216399b91
commit f7ab908abf
2 changed files with 21 additions and 5 deletions
+12 -4
View File
@@ -1,12 +1,20 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import fields, models, api
from odoo import fields, models
class AccountMove(models.Model):
_inherit = 'account.move'
website_id = fields.Many2one('website', related='partner_id.website_id', string='Website',
help='Website through which this invoice was created for eCommerce orders.',
store=True, readonly=True, tracking=True)
website_id = fields.Many2one(
'website', related='partner_id.website_id', string='Website',
help='Website through which this invoice was created for eCommerce orders.',
store=True, readonly=True, tracking=True)
def preview_invoice(self):
action = super().preview_invoice()
if action['url'].startswith('/'):
# URL should always be relative, safety check
action['url'] = f'/@{action["url"]}'
return action
+9 -1
View File
@@ -449,9 +449,17 @@ class SaleOrder(models.Model):
# If a potential customer creates one or more abandoned sale order and then completes a sale order before
# the recovery email gets sent, then the email won't be sent.
return self.filtered(lambda abandoned_sale_order:
return self.filtered(
lambda abandoned_sale_order:
abandoned_sale_order.partner_id.email
and not any(transaction.state == 'error' for transaction in abandoned_sale_order.transaction_ids)
and any(not float_is_zero(line.price_unit, precision_rounding=line.currency_id.rounding) for line in abandoned_sale_order.order_line)
and not has_later_sale_order.get(abandoned_sale_order.partner_id, False)
)
def action_preview_sale_order(self):
action = super().action_preview_sale_order()
if action['url'].startswith('/'):
# URL should always be relative, safety check
action['url'] = f'/@{action["url"]}'
return action