From 4f4bfe2c9c8184bb5064f1fe2e152e4e4399101e Mon Sep 17 00:00:00 2001 From: harsh Date: Thu, 25 Feb 2021 05:50:52 +0000 Subject: [PATCH] [IMP] account,website_sale: improve the UX of terms and conditions Purpose of the task is, to use our awesome website builder instead of pad when creating a website page for terms & condition. Also suggest default T&C to save user time when user enable the feature So in this commit did the below changes: * Added new indicational text below "Terms as note" & "Terms as web page" * After enabling "Term as web page', user should be able to see the term page url * For Terms editing: - User that have 'website' or 'ecommerce' module should edit the page directly using the website builder with link "edit in website builder" link. - User that don't have nor website not ecommerce module should update the text in the pad but in a pop-up window. * Also added the dynamic default term for company when term type is html. PS: changed website_sale pre_init_hook to post_init_hook because invoice_terms_html is compute field which depends on term_type so when term_type is changed from init_hook it will give the key error for the invoice_terms_html as it's not loaded to registry. closes odoo/odoo#68225 Taskid: 2414659 Signed-off-by: Victor Feyens (vfe) --- addons/account/models/company.py | 15 +++++++-- addons/account/models/res_config_settings.py | 12 +++++++ addons/account/views/res_company_views.xml | 18 +++++++++++ .../views/res_config_settings_views.xml | 17 +++++----- addons/account/views/terms_template.xml | 32 +++++++++++++++++++ addons/website_sale/__init__.py | 2 +- addons/website_sale/__manifest__.py | 2 +- .../models/res_config_settings.py | 14 ++++++++ .../views/res_config_settings_views.xml | 17 ++++++++++ 9 files changed, 115 insertions(+), 14 deletions(-) diff --git a/addons/account/models/company.py b/addons/account/models/company.py index 79a1a53fc78..d34d04a798e 100644 --- a/addons/account/models/company.py +++ b/addons/account/models/company.py @@ -6,6 +6,7 @@ from dateutil.relativedelta import relativedelta from odoo import fields, models, api, _ from odoo.exceptions import ValidationError, UserError, RedirectWarning +from odoo.tools.mail import is_html_empty from odoo.tools.misc import format_date from odoo.tools.float_utils import float_round, float_is_zero from odoo.tests.common import Form @@ -104,11 +105,10 @@ class ResCompany(models.Model): account_invoice_onboarding_state = fields.Selection(DASHBOARD_ONBOARDING_STATES, string="State of the account invoice onboarding panel", default='not_done') account_dashboard_onboarding_state = fields.Selection(DASHBOARD_ONBOARDING_STATES, string="State of the account dashboard onboarding panel", default='not_done') invoice_terms = fields.Html(string='Default Terms and Conditions', translate=True) - terms_type = fields.Selection([('plain', 'Terms as Notes'), ('html', 'Terms as Web Page')], + terms_type = fields.Selection([('plain', 'Add a Note'), ('html', 'Add a link to a Web Page')], string='Terms & Conditions format', default='plain') invoice_terms_html = fields.Html(string='Default Terms and Conditions as a Web page', translate=True, - default="""

Terms & Conditions

-

Your conditions...

""") + compute='_compute_invoice_terms_html', store=True, readonly=False) account_setup_bill_state = fields.Selection(ONBOARDING_STEP_STATES, string="State of the onboarding bill step", default='not_done') @@ -183,6 +183,15 @@ class ResCompany(models.Model): foreign_vat_fpos = self.env['account.fiscal.position'].search([('company_id', '=', record.id), ('foreign_vat', '!=', False)]) record.account_enabled_tax_country_ids = foreign_vat_fpos.country_id + record.account_fiscal_country_id + @api.depends('terms_type') + def _compute_invoice_terms_html(self): + term_template = self.env.ref("account.account_default_terms_and_conditions", False) + if not term_template: + return + + for company in self.filtered(lambda company: is_html_empty(company.invoice_terms_html) and company.terms_type == 'html'): + company.invoice_terms_html = term_template._render({'company_name': company.name, 'company_country': company.country_id.name}, engine='ir.qweb') + def get_and_update_account_invoice_onboarding_state(self): """ This method is called on the controller rendering method and ensures that the animations are displayed only one time. """ diff --git a/addons/account/models/res_config_settings.py b/addons/account/models/res_config_settings.py index a2d788aa9af..42e5c692f19 100644 --- a/addons/account/models/res_config_settings.py +++ b/addons/account/models/res_config_settings.py @@ -200,3 +200,15 @@ class ResConfigSettings(models.TransientModel): # We display the preview button only if the terms_type is html in the setting but also on the company # to avoid landing on an error page (see terms.py controller) setting.preview_ready = self.env.company.terms_type == 'html' and setting.terms_type == 'html' + + def action_update_terms(self): + self.ensure_one() + return { + 'name': _('Update Terms & Conditions'), + 'type': 'ir.actions.act_window', + 'view_mode': 'form', + 'res_model': 'res.company', + 'view_id': self.env.ref("account.res_company_view_form_terms", False).id, + 'target': 'new', + 'res_id': self.company_id.id, + } diff --git a/addons/account/views/res_company_views.xml b/addons/account/views/res_company_views.xml index cbb4d9ee470..c8d06842747 100644 --- a/addons/account/views/res_company_views.xml +++ b/addons/account/views/res_company_views.xml @@ -11,4 +11,22 @@ + + + res.company.view.form.terms + res.company + 1000 + +
+ + +
+
+
+
+
+ diff --git a/addons/account/views/res_config_settings_views.xml b/addons/account/views/res_config_settings_views.xml index f9f7c9ab5a7..54090368158 100644 --- a/addons/account/views/res_config_settings_views.xml +++ b/addons/account/views/res_config_settings_views.xml @@ -288,24 +288,23 @@