Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[17.0][MIG] partner_stage_only_confirmed: Migration to 17.0 #1710

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 84 additions & 0 deletions partner_stage_only_confirmed/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
===============================================
Partner Stage - Display only confirmed partners
===============================================

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:e2841b9d819f38be8a8fbfe4812c27201d24cea0e4a60186a9cda95dcf56b23f
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
:target: https://odoo-community.org/page/development-status
:alt: Beta
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fpartner--contact-lightgray.png?logo=github
:target: https://github.com/OCA/partner-contact/tree/17.0/partner_stage_only_confirmed
:alt: OCA/partner-contact
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/partner-contact-17-0/partner-contact-17-0-partner_stage_only_confirmed
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
:target: https://runboat.odoo-community.org/builds?repo=OCA/partner-contact&target_branch=17.0
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|

Automatic filtering of partners in form views' Many2one fields with
relation to "res.partner". If enabled (which is the default behavior
when the module is installed), only confirmed partners will be shown.

**Table of contents**

.. contents::
:local:

Usage
=====

See "Configuration".

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

Bugs are tracked on `GitHub Issues <https://github.com/OCA/partner-contact/issues>`_.
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
`feedback <https://github.com/OCA/partner-contact/issues/new?body=module:%20partner_stage_only_confirmed%0Aversion:%2017.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

Do not contact contributors directly about support or help with technical issues.

Credits
=======

Authors
-------

* Camptocamp

Contributors
------------

- Silvio Gregorini <silvio.gregorini@camptocamp.com>
- Maksym Yankin <maksym.yankin@camptocamp.com>

Maintainers
-----------

This module is maintained by the OCA.

.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org

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.

This module is part of the `OCA/partner-contact <https://github.com/OCA/partner-contact/tree/17.0/partner_stage_only_confirmed>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
1 change: 1 addition & 0 deletions partner_stage_only_confirmed/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
14 changes: 14 additions & 0 deletions partner_stage_only_confirmed/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Copyright 2022 Camptocamp SA
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html)

{
"name": "Partner Stage - Display only confirmed partners",
"summary": "Adds filters on form views to display only confirmed partners",
"author": "Odoo Community Association (OCA), Camptocamp",
"website": "https://github.com/OCA/partner-contact",
"category": "Partner Management",
"version": "17.0.1.0.0",
"license": "AGPL-3",
"depends": ["partner_stage"],
"installable": True,
}
1 change: 1 addition & 0 deletions partner_stage_only_confirmed/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import base
68 changes: 68 additions & 0 deletions partner_stage_only_confirmed/models/base.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# Copyright 2022 Camptocamp SA
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from lxml import etree

from odoo import api, models


class Base(models.AbstractModel):
_inherit = "base"

@api.model
def get_view(self, view_id=None, view_type="form", **options):
# OVERRIDE: display only confirmed partners on Many2one fields related
# to ``res.partner`` on form views.
res = super().get_view(view_id, view_type, **options)

Check warning on line 16 in partner_stage_only_confirmed/models/base.py

View check run for this annotation

Codecov / codecov/patch

partner_stage_only_confirmed/models/base.py#L16

Added line #L16 was not covered by tests
if view_type == "form" and self._filter_only_confirmed():
doc = etree.XML(res["arch"])

Check warning on line 18 in partner_stage_only_confirmed/models/base.py

View check run for this annotation

Codecov / codecov/patch

partner_stage_only_confirmed/models/base.py#L18

Added line #L18 was not covered by tests
for model_name, model_fields in res["models"].items():
for fname in model_fields:
model = self.env[model_name]
field_obj = model._fields.get(fname)

Check warning on line 22 in partner_stage_only_confirmed/models/base.py

View check run for this annotation

Codecov / codecov/patch

partner_stage_only_confirmed/models/base.py#L21-L22

Added lines #L21 - L22 were not covered by tests
if field_obj:
ftype, fcomodel_name = field_obj.type, field_obj.comodel_name

Check warning on line 24 in partner_stage_only_confirmed/models/base.py

View check run for this annotation

Codecov / codecov/patch

partner_stage_only_confirmed/models/base.py#L24

Added line #L24 was not covered by tests
if (ftype, fcomodel_name) != ("many2one", "res.partner"):
continue

Check warning on line 26 in partner_stage_only_confirmed/models/base.py

View check run for this annotation

Codecov / codecov/patch

partner_stage_only_confirmed/models/base.py#L26

Added line #L26 was not covered by tests
for node in doc.xpath("//field[@name='%s']" % fname):
domain = node.get("domain")

Check warning on line 28 in partner_stage_only_confirmed/models/base.py

View check run for this annotation

Codecov / codecov/patch

partner_stage_only_confirmed/models/base.py#L28

Added line #L28 was not covered by tests
if not domain:
domain = "[('state', '=', 'confirmed')]"

Check warning on line 30 in partner_stage_only_confirmed/models/base.py

View check run for this annotation

Codecov / codecov/patch

partner_stage_only_confirmed/models/base.py#L30

Added line #L30 was not covered by tests
elif isinstance(domain, str):
if domain in ("", "[]"):
domain = "[('state', '=', 'confirmed')]"

Check warning on line 33 in partner_stage_only_confirmed/models/base.py

View check run for this annotation

Codecov / codecov/patch

partner_stage_only_confirmed/models/base.py#L33

Added line #L33 was not covered by tests
else:
domain = domain[:-1]
domain += ", ('state', '=', 'confirmed')]"

Check warning on line 36 in partner_stage_only_confirmed/models/base.py

View check run for this annotation

Codecov / codecov/patch

partner_stage_only_confirmed/models/base.py#L35-L36

Added lines #L35 - L36 were not covered by tests
else:
domain = list(domain)
domain.append(("state", "=", "confirmed"))
domain = str(domain)
node.set("domain", domain)
res["arch"] = etree.tostring(doc)
return res

Check warning on line 43 in partner_stage_only_confirmed/models/base.py

View check run for this annotation

Codecov / codecov/patch

partner_stage_only_confirmed/models/base.py#L38-L43

Added lines #L38 - L43 were not covered by tests

@api.model
def _filter_only_confirmed(self) -> bool:
"""Determines whether only confirmed partners should be shown

Retrieves condition based on context or system parameters (in this
order).
Else, defaults to True.
"""
# Retrieve value from context (which can be defined in views field by
# field)
if "only_confirmed_partners" in self._context:
return bool(self._context["only_confirmed_partners"])

Check warning on line 56 in partner_stage_only_confirmed/models/base.py

View check run for this annotation

Codecov / codecov/patch

partner_stage_only_confirmed/models/base.py#L56

Added line #L56 was not covered by tests

# Retrieve value from system parameters
val = (

Check warning on line 59 in partner_stage_only_confirmed/models/base.py

View check run for this annotation

Codecov / codecov/patch

partner_stage_only_confirmed/models/base.py#L59

Added line #L59 was not covered by tests
self.env["ir.config_parameter"]
.sudo()
.get_param("partner_stage.only_confirmed_partners", default=None)
)
if val is not None:
return val not in ("False", "false", "", "0")

Check warning on line 65 in partner_stage_only_confirmed/models/base.py

View check run for this annotation

Codecov / codecov/patch

partner_stage_only_confirmed/models/base.py#L65

Added line #L65 was not covered by tests

# Return default value
return True

Check warning on line 68 in partner_stage_only_confirmed/models/base.py

View check run for this annotation

Codecov / codecov/patch

partner_stage_only_confirmed/models/base.py#L68

Added line #L68 was not covered by tests
3 changes: 3 additions & 0 deletions partner_stage_only_confirmed/pyproject.toml
yankinmax marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[build-system]
requires = ["whool"]
build-backend = "whool.buildapi"
11 changes: 11 additions & 0 deletions partner_stage_only_confirmed/readme/CONFIGURATION.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
To define global behavior:

#. create a system parameter with key "partner_stage.only_confirmed_partners"

#. set its value as "True" or "1" to enable filtering or as "False" or "0" to disable it

To define specific behavior for single fields on form views:

#. add key "only_confirmed_partners" to field's context in form view

#. set its value as "True" or "1" to enable filtering or as "False" or "0" to disable it
2 changes: 2 additions & 0 deletions partner_stage_only_confirmed/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- Silvio Gregorini \<<silvio.gregorini@camptocamp.com>\>
- Maksym Yankin \<<maksym.yankin@camptocamp.com>\>
3 changes: 3 additions & 0 deletions partner_stage_only_confirmed/readme/DESCRIPTION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Automatic filtering of partners in form views' Many2one fields with
relation to "res.partner". If enabled (which is the default behavior
when the module is installed), only confirmed partners will be shown.
1 change: 1 addition & 0 deletions partner_stage_only_confirmed/readme/USAGE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
See "Configuration".
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading