From f7ab908abf3d6494e1c444835b1e0263db2596d3 Mon Sep 17 00:00:00 2001 From: Romain Derie Date: Tue, 13 Sep 2022 17:00:34 +0000 Subject: [PATCH] [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) Signed-off-by: Romain Derie (rde) --- addons/website_sale/models/account_move.py | 16 ++++++++++++---- addons/website_sale/models/sale_order.py | 10 +++++++++- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/addons/website_sale/models/account_move.py b/addons/website_sale/models/account_move.py index 1fb743223cb..0b3d3413e1d 100644 --- a/addons/website_sale/models/account_move.py +++ b/addons/website_sale/models/account_move.py @@ -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 diff --git a/addons/website_sale/models/sale_order.py b/addons/website_sale/models/sale_order.py index 70601c5d135..b56df2d431d 100644 --- a/addons/website_sale/models/sale_order.py +++ b/addons/website_sale/models/sale_order.py @@ -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