Skip to content

Commit

Permalink
Merge PR #621 into 14.0
Browse files Browse the repository at this point in the history
Signed-off-by pedrobaeza
  • Loading branch information
OCA-git-bot committed May 30, 2024
2 parents 5597be7 + fc0a241 commit 118aca6
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 27 deletions.
6 changes: 6 additions & 0 deletions company_dependent_flag/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ With this module all company dependent fields are decorated with an adhoc class.
.. contents::
:local:

Known issues / Roadmap
======================

This moudle won't work cleanly if the field in question is present twice in the view.
It's very rare, but it could happen.

Bug Tracker
===========

Expand Down
41 changes: 29 additions & 12 deletions company_dependent_flag/models/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,35 +21,40 @@ def _fields_view_get(
return res

def _update_company_dependent_css(self, arch):
def _subview_check(field):
parent_el = field.parentNode
while parent_el.tagName != "form":
if parent_el.tagName == "field":
return False # we are in a subview
parent_el = parent_el.parentNode

if parent_el is None:
return False

return parent_el

cpny_dep_fields = [
field_name
for field_name, field_rec in self.env[self._name]._fields.items()
if field_rec.company_dependent
]

for field_name in cpny_dep_fields:
for field in arch.getElementsByTagName("field"):
if field.getAttribute("name") == field_name:
# Create a new div element
div = arch.createElement("div")
div.setAttribute("class", "o_row")

# Create a new span element
span = arch.createElement("span")
span.setAttribute(
"class",
"fa fa-lg fa-building-o",
)
span.setAttribute("title", "Values set here are company-specific.")
parent_form = _subview_check(field)
if not parent_form:
continue

# Check if a label already exists for the field
existing_labels = arch.getElementsByTagName("label")
existing_labels = parent_form.getElementsByTagName("label")

if not any(
label.getAttribute("for") == field.getAttribute("name")
for label in existing_labels
):
# Create a new label element

label = arch.createElement("label")
label.setAttribute("for", field.getAttribute("name"))
label.setAttribute("class", "o_form_label")
Expand All @@ -60,6 +65,18 @@ def _update_company_dependent_css(self, arch):
# Insert the label before the field in the parent node
field.parentNode.insertBefore(label, field)

# Create a new div element
div = arch.createElement("div")
div.setAttribute("class", "o_row")

# Create a new span element
span = arch.createElement("span")
span.setAttribute(
"class",
"fa fa-lg fa-building-o",
)
span.setAttribute("title", "Values set here are company-specific.")

div.appendChild(span)
div.appendChild(field.cloneNode(True))

Expand Down
2 changes: 2 additions & 0 deletions company_dependent_flag/readme/ROADMAP.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
This moudle won't work cleanly if the field in question is present twice in the view.
It's very rare, but it could happen.
38 changes: 23 additions & 15 deletions company_dependent_flag/static/description/index.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
Expand All @@ -9,10 +8,11 @@

/*
:Author: David Goodger (goodger@python.org)
:Id: $Id: html4css1.css 8954 2022-01-20 10:10:25Z milde $
:Id: $Id: html4css1.css 9511 2024-01-13 09:50:07Z milde $
:Copyright: This stylesheet has been placed in the public domain.

Default cascading style sheet for the HTML output of Docutils.
Despite the name, some widely supported CSS2 features are used.

See https://docutils.sourceforge.io/docs/howto/html-stylesheets.html for how to
customize this style sheet.
Expand Down Expand Up @@ -275,7 +275,7 @@
margin-left: 2em ;
margin-right: 2em }

pre.code .ln { color: grey; } /* line numbers */
pre.code .ln { color: gray; } /* line numbers */
pre.code, code { background-color: #eeeeee }
pre.code .comment, code .comment { color: #5C6576 }
pre.code .keyword, code .keyword { color: #3B0D06; font-weight: bold }
Expand All @@ -301,7 +301,7 @@
span.pre {
white-space: pre }

span.problematic {
span.problematic, pre.problematic {
color: red }

span.section-subtitle {
Expand Down Expand Up @@ -377,33 +377,39 @@ <h1 class="title">Company Dependent Flag</h1>
<p><strong>Table of contents</strong></p>
<div class="contents local topic" id="contents">
<ul class="simple">
<li><a class="reference internal" href="#bug-tracker" id="toc-entry-1">Bug Tracker</a></li>
<li><a class="reference internal" href="#credits" id="toc-entry-2">Credits</a><ul>
<li><a class="reference internal" href="#authors" id="toc-entry-3">Authors</a></li>
<li><a class="reference internal" href="#contributors" id="toc-entry-4">Contributors</a></li>
<li><a class="reference internal" href="#maintainers" id="toc-entry-5">Maintainers</a></li>
<li><a class="reference internal" href="#known-issues-roadmap" id="toc-entry-1">Known issues / Roadmap</a></li>
<li><a class="reference internal" href="#bug-tracker" id="toc-entry-2">Bug Tracker</a></li>
<li><a class="reference internal" href="#credits" id="toc-entry-3">Credits</a><ul>
<li><a class="reference internal" href="#authors" id="toc-entry-4">Authors</a></li>
<li><a class="reference internal" href="#contributors" id="toc-entry-5">Contributors</a></li>
<li><a class="reference internal" href="#maintainers" id="toc-entry-6">Maintainers</a></li>
</ul>
</li>
</ul>
</div>
<div class="section" id="known-issues-roadmap">
<h1><a class="toc-backref" href="#toc-entry-1">Known issues / Roadmap</a></h1>
<p>This moudle won’t work cleanly if the field in question is present twice in the view.
It’s very rare, but it could happen.</p>
</div>
<div class="section" id="bug-tracker">
<h1><a class="toc-backref" href="#toc-entry-1">Bug Tracker</a></h1>
<h1><a class="toc-backref" href="#toc-entry-2">Bug Tracker</a></h1>
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/multi-company/issues">GitHub Issues</a>.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed
<a class="reference external" href="https://github.com/OCA/multi-company/issues/new?body=module:%20company_dependent_flag%0Aversion:%2014.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<p>Do not contact contributors directly about support or help with technical issues.</p>
</div>
<div class="section" id="credits">
<h1><a class="toc-backref" href="#toc-entry-2">Credits</a></h1>
<h1><a class="toc-backref" href="#toc-entry-3">Credits</a></h1>
<div class="section" id="authors">
<h2><a class="toc-backref" href="#toc-entry-3">Authors</a></h2>
<h2><a class="toc-backref" href="#toc-entry-4">Authors</a></h2>
<ul class="simple">
<li>Akretion</li>
</ul>
</div>
<div class="section" id="contributors">
<h2><a class="toc-backref" href="#toc-entry-4">Contributors</a></h2>
<h2><a class="toc-backref" href="#toc-entry-5">Contributors</a></h2>
<ul class="simple">
<li><dl class="first docutils">
<dt><a class="reference external" href="https://akretion.com">Akretion</a>:</dt>
Expand All @@ -418,9 +424,11 @@ <h2><a class="toc-backref" href="#toc-entry-4">Contributors</a></h2>
</ul>
</div>
<div class="section" id="maintainers">
<h2><a class="toc-backref" href="#toc-entry-5">Maintainers</a></h2>
<h2><a class="toc-backref" href="#toc-entry-6">Maintainers</a></h2>
<p>This module is maintained by the OCA.</p>
<a class="reference external image-reference" href="https://odoo-community.org"><img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" /></a>
<a class="reference external image-reference" href="https://odoo-community.org">
<img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" />
</a>
<p>OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.</p>
Expand Down

0 comments on commit 118aca6

Please sign in to comment.