Skip to content

Commit

Permalink
⬆️ web_debranding: port to v17
Browse files Browse the repository at this point in the history
  • Loading branch information
yelizariev committed Dec 18, 2023
1 parent 705e680 commit ba00a39
Show file tree
Hide file tree
Showing 13 changed files with 59 additions and 141 deletions.
4 changes: 1 addition & 3 deletions web_debranding/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,6 @@
"views/res_config.xml",
],
"assets": {
"web.assets_qweb": [
"web_debranding/static/src/xml/web.xml",
],
"web.assets_backend": [
"web_debranding/static/src/css/web.css",
"web_debranding/static/src/js/base.js",
Expand All @@ -44,6 +41,7 @@
"web_debranding/static/src/js/native_notifications.js",
"web_debranding/static/src/js/user_menu_items.js",
"web_debranding/static/src/js/translation.js",
"web_debranding/static/src/xml/web.xml",
],
},
"auto_install": False,
Expand Down
4 changes: 4 additions & 0 deletions web_debranding/doc/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,7 @@ Examples
* Open two browser tabs with Odoo. Then logout in one of it. Open any menu in another one.

Your **Odoo** session expired. The current page is about to be refreshed.

* Install `sale_management` module and open menu ``[[ Settings ]] >> Sales``.

* RESULT: the Enterprise features are hidden
1 change: 0 additions & 1 deletion web_debranding/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from . import publisher_warranty_contract
from . import ir_config_parameter
from . import ir_ui_view
from . import mail_channel
from . import res_users
from . import ir_model
from . import res_company
Expand Down
20 changes: 4 additions & 16 deletions web_debranding/models/base.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2020,2022 Ivan Yelizariev
# Copyright 2020,2022-2023 Ivan Yelizariev
# License OPL-1 (https://www.odoo.com/documentation/user/14.0/legal/licenses/licenses.html#odoo-apps).
from odoo import api, models

Expand All @@ -11,22 +11,10 @@ class Base(models.AbstractModel):

_inherit = "base"

def _read(self, fields):
super(Base, self)._read(fields)
if self._name not in BRANDED_FIELDS.keys():
return

for f in BRANDED_FIELDS[self._name]:
values = []
for r in self:
values.append(debrand(self.env, r[f]))
field = self._fields[f]
self.env.cache.update(self, field, values)

@api.model
def search(self, domain, offset=0, limit=None, order=None, count=False):
res = super().search(domain, offset, limit, order, count)
if self._name == "payment.acquirer":
def search(self, domain, offset=0, limit=None, order=None):
res = super().search(domain, offset, limit, order)
if self._name == "payment.provider":
res = res.filtered(lambda a: not a.module_to_buy)
return res

Expand Down
6 changes: 3 additions & 3 deletions web_debranding/models/ir_module_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ class IrModuleModule(models.Model):
_inherit = "ir.module.module"

@api.model
def search(self, domain, offset=0, limit=None, order=None, count=False):
domain += [("to_buy", "=", False)]
return super().search(domain, offset, limit, order, count)
def search(self, domain, offset=0, limit=None, order=None):
domain = [("to_buy", "=", False)] + domain
return super().search(domain, offset, limit, order)
2 changes: 1 addition & 1 deletion web_debranding/models/ir_translation.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def decorated_clear_caches(self):
we wrapped it in the api.model decorator
"""
self.clear_caches()
self.env.registry.clear_cache()

@api.model
@tools.ormcache_context("model_name", "field_name", keys=("lang",))
Expand Down
17 changes: 0 additions & 17 deletions web_debranding/models/mail_channel.py

This file was deleted.

8 changes: 4 additions & 4 deletions web_debranding/static/src/js/base.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
/** @odoo-module **/
/* Copyright 2015-2018,2022 Ivan Yelizariev <https://twitter.com/yelizariev>
/* Copyright 2015-2018,2022-2023 Ivan Yelizariev <https://twitter.com/yelizariev>
Copyright 2017 ArtyomLosev <https://github.com/ArtyomLosev>
Copyright 2022 IT-Projects <https://it-projects.info/>
License MIT (https://opensource.org/licenses/MIT). */

import { debrandTranslation } from "@web_debranding/js/translation";
import { patch } from "web.utils";
import { patch } from "@web/core/utils/patch";
import { useService } from "@web/core/utils/hooks";
import { WebClient } from "@web/webclient/webclient";

const { onMounted } = owl;
const components = { WebClient };

patch(components.WebClient.prototype, "web_debranding/static/src/js/base.js", {
patch(components.WebClient.prototype, {
setup() {
this._super();
super.setup();
odoo.debranding_new_name = "";
odoo.debranding_new_website = "";
odoo.debranding_new_title = "";
Expand Down
8 changes: 4 additions & 4 deletions web_debranding/static/src/js/dialog.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
/** @odoo-module **/
/* Copyright 2015-2018,2021 Ivan Yelizariev <https://twitter.com/yelizariev>
/* Copyright 2015-2018,2021,2023 Ivan Yelizariev <https://twitter.com/yelizariev>
Copyright 2015 igallyamov <https://github.com/igallyamov>
Copyright 2017 Gabbasov Dinar <https://it-projects.info/team/GabbasovDinar>
Copyright 2022 IT-Projects <https://it-projects.info/>
License OPL-1 (https://www.odoo.com/documentation/user/14.0/legal/licenses/licenses.html#odoo-apps). */

import "@web_debranding/js/base";
import { Dialog } from "@web/core/dialog/dialog";
import { patch } from "web.utils";
import { patch } from "@web/core/utils/patch";

const component = { Dialog };

patch(component.Dialog.prototype, "web_debranding/static/src/js/dialog.js", {
patch(component.Dialog.prototype, {
setup() {
const debranding_new_name = odoo.debranding_new_name;
// // const debranding_new_website = odoo.debranding_new_website;
Expand All @@ -37,6 +37,6 @@ patch(component.Dialog.prototype, "web_debranding/static/src/js/dialog.js", {
content_html = content_html.replace(/Odoo/gi, debranding_new_name);
options.$content.html(content_html);
}*/
this._super();
super.setup();
},
});
58 changes: 22 additions & 36 deletions web_debranding/static/src/js/field_upgrade.js
Original file line number Diff line number Diff line change
@@ -1,40 +1,26 @@
/* Copyright 2016-2017 Ivan Yelizariev <https://it-projects.info/team/yelizariev>
Copyright 2017 ArtyomLosev <https://github.com/ArtyomLosev>
Copyright 2018-2019 Kolushov Alexandr <https://it-projects.info/team/KolushovAlexandr>
Copyright 2018 Ildar Nasyrov <https://it-projects.info/team/iledarn>
License MIT (https://opensource.org/licenses/MIT).
/** @odoo-module **/
/* Copyright 2023 Ivan Yelizariev <https://twitter.com/yelizariev>
License OPL-1 (https://www.odoo.com/documentation/user/14.0/legal/licenses/licenses.html#odoo-apps) for derivative work. */
odoo.define("web_debranding.field_upgrade", function (require) {
var FormRenderer = require("web.FormRenderer");
import { patch } from "@web/core/utils/patch";
import { SearchableSetting } from "@web/webclient/settings_form_view/settings/searchable_setting";

FormRenderer.include({
_renderTagForm: function (node) {
var $result = this._super(node);
patch(SearchableSetting.prototype, {
visible() {
if (!super.visible()) {
return false;
}

/*
Remove following element:
<div class="col-xs-12 col-md-6 o_setting_box" title="Boost your sales with two kinds of discount programs: promotions and coupon codes. Specific conditions can be set (products, customers, minimum purchase amount, period). Rewards can be discounts (% or amount) or free products.">
<div class="o_setting_left_pane">
<div class="o_field_boolean o_field_widget" name="module_sale_coupon">
</div>
</div>
<div class="o_setting_right_pane">
<label class="o_form_label" for="o_field_input_18" data-original-title="" title="" aria-describedby="tooltip822540">Coupons &amp; Promotions
</label>
<div class="text-muted" id="sale_coupon">
Manage promotion &amp; coupon programs
</div>
</div>
</div>
*/
if (this.state && this.state.model === "res.config.settings") {
// Hide enterprise labels with related fields
$result.find(".o_enterprise_label").parent().parent().parent().hide();
}
return $result;
},
});
// Copy-pasted from addons/web/static/src/webclient/settings_form_view/highlight_text/form_label_highlight_text.js
const isEnterprise = odoo.info && odoo.info.isEnterprise;
let upgradeEnterprise = false;
if (
this.props.fieldInfo &&
this.props.fieldInfo.field &&
this.props.fieldInfo.field.isUpgradeField &&
!isEnterprise
) {
upgradeEnterprise = true;
}
return !upgradeEnterprise;
},
});
53 changes: 0 additions & 53 deletions web_debranding/static/src/js/native_notifications.js

This file was deleted.

7 changes: 4 additions & 3 deletions web_debranding/static/src/js/translation.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/** @odoo-module **/
/* Copyright 2022 Ivan Yelizariev <https://twitter.com/yelizariev>
/* Copyright 2022-2023 Ivan Yelizariev <https://twitter.com/yelizariev>
License OPL-1 (https://www.odoo.com/documentation/user/14.0/legal/licenses/licenses.html#odoo-apps). */

import { localizationService } from "@web/core/l10n/localization_service";
Expand All @@ -14,7 +14,7 @@ export const debrandTranslation = () => {
if (!odoo.debranding_new_name) {
return;
}
_.each(odoo_terms, (term) => {
odoo_terms.forEach((term) => {
if (!translatedTerms[term]) {
translatedTerms[term] = term;
}
Expand All @@ -24,6 +24,7 @@ export const debrandTranslation = () => {

const start = localizationService.start;
localizationService.start = async (env, { user }) => {
await start(env, { user });
const localization = await start(env, { user });
debrandTranslation();
return localization;
};
12 changes: 12 additions & 0 deletions web_debranding/static/src/xml/upgradeEnterprise.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!-- Copyright 2023 Ivan Yelizariev <https://twitter.com/yelizariev>
License OPL-1 (https://www.odoo.com/documentation/17.0/legal/licenses.html#odoo-apps). -->
<templates xml:space="preserve">
<t t-inherit="web.SearchableSetting" t-inherit-mode="extension">
<xpath expr="//div[@t-att-class='classNames']" position="replace">
<t t-if="!upgradeEnterprise">
<div t-att-class="classNames" t-out="0" />
</t>
</xpath>
</t>
</templates>

0 comments on commit ba00a39

Please sign in to comment.