Skip to content

Commit

Permalink
Merge PR #183 into 17.0
Browse files Browse the repository at this point in the history
Signed-off-by pedrobaeza
  • Loading branch information
OCA-git-bot committed Dec 5, 2023
2 parents f11b530 + b224589 commit 6edbf4f
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 79 deletions.
78 changes: 33 additions & 45 deletions brand/models/res_brand_mixin.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
# Copyright 2019 ACSONE SA/NV
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from lxml import etree
from lxml.builder import E

from odoo import _, api, fields, models
from odoo.exceptions import ValidationError

from odoo.addons.base.models import ir_ui_view

from .res_company import BRAND_USE_LEVEL_NO_USE_LEVEL, BRAND_USE_LEVEL_REQUIRED_LEVEL


Expand Down Expand Up @@ -52,47 +50,37 @@ def _onchange_brand_id(self):
if rec.brand_id and rec.brand_id.company_id:
rec.company_id = rec.brand_id.company_id

def setup_modifiers(self, node, field=None):
modifiers = {}
attributes = ["invisible", "readonly", "required"]
if field is not None:
ir_ui_view.transfer_field_to_modifiers(field, modifiers, attributes)
ir_ui_view.transfer_node_to_modifiers(node, modifiers)
ir_ui_view.transfer_modifiers_to_node(modifiers, node)

@api.model
def get_view(self, view_id=None, view_type="form", **options):
def _get_view(self, view_id=None, view_type="form", **options):
"""set visibility and requirement rules"""
result = super().get_view(view_id=view_id, view_type=view_type, **options)

if view_type in ["tree", "form"]:
doc = etree.XML(result["arch"])
for node in doc.xpath(
"""
//field[@name='brand_id']
[not(ancestor::*[@widget='one2many' or @widget='many2many'])]
"""
):
elem = etree.Element(
"field",
{
"name": "brand_use_level",
"invisible": "True",
"string": _("Brand Use Level"),
},
)
brand_use_level_field = self.fields_get(["brand_use_level"])[
"brand_use_level"
]
brand_id_field = self.fields_get(["brand_id"])["brand_id"]
node.addprevious(elem)
self.setup_modifiers(elem, field=brand_use_level_field)
node.set(
"invisible", f"brand_use_level == {BRAND_USE_LEVEL_NO_USE_LEVEL}"
print("_get_view")
arch, view = super()._get_view(view_id, view_type, **options)
if self.env["res.brand"].check_access_rights("read", raise_exception=False):
if view.type in ["form", "tree"]:
brand_node = next(
iter(
arch.xpath(
'//field[@name="brand_id"][not(ancestor::*[@widget="one2many" or @widget="many2many"])]'
)
),
None,
)
node.set(
"required", f"brand_use_level == {BRAND_USE_LEVEL_REQUIRED_LEVEL}"
)
self.setup_modifiers(node, field=brand_id_field)
result["arch"] = etree.tostring(doc, encoding="unicode")
return result

if brand_node is not None:
brand_node.addprevious(
E.field(
name="brand_use_level",
invisible="True",
column_invisible="True",
)
)

brand_node.set(
"invisible",
f"brand_use_level == '{BRAND_USE_LEVEL_NO_USE_LEVEL}'",
)
brand_node.set(
"required",
f"brand_use_level == '{BRAND_USE_LEVEL_REQUIRED_LEVEL}'",
)

return arch, view
45 changes: 11 additions & 34 deletions brand/views/res_config_settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,40 +6,17 @@
<field name="model">res.config.settings</field>
<field name="inherit_id" ref="base_setup.res_config_settings_view_form" />
<field name="arch" type="xml">
<xpath expr="//div[@id='companies']" position="inside">
<div id="brand">
<div class="row mt16 o_settings_container">
<div class="col-12 col-lg-6 o_setting_box">
<div class="o_setting_right_pane">
<span class="o_form_label">Brand</span>
<span
class="fa fa-lg fa-building-o"
title="Values set here are company-specific."
aria-label="Values set here are company-specific."
groups="base.group_multi_company"
role="img"
/>
<div class="text-muted">
Configure branding of customer facing business documents (SO, invoices, etc).
</div>
<div class="content-group">
<div class="mt16 row">
<label
for="brand_use_level"
string="Brand Use Level"
class="col-3 col-lg-3 o_light_label"
/>
<field
name="brand_use_level"
class="oe_inline"
required="1"
/>
</div>
</div>
</div>
</div>
</div>
</div>
<xpath
expr="//block[@name='companies_setting_container']"
position="inside"
>
<setting
string="Brand"
help="Configure branding of customer facing business documents (SO, invoices, etc)."
company_dependent="1"
>
<field name="brand_use_level" required="1" />
</setting>
</xpath>
</field>
</record>
Expand Down

0 comments on commit 6edbf4f

Please sign in to comment.