Skip to content

Commit

Permalink
[MIG] crm_required_field_by_stage: Migration
Browse files Browse the repository at this point in the history
  • Loading branch information
Tiago Amaral committed Sep 25, 2024
1 parent 0ad4d03 commit d939ca6
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 14 deletions.
10 changes: 5 additions & 5 deletions crm_required_field_by_stage/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ Required Fields by Stage in CRM
:target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html
:alt: License: LGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fcrm-lightgray.png?logo=github
:target: https://github.com/OCA/crm/tree/17.0/crm_required_field_by_stage
:target: https://github.com/OCA/crm/tree/16.0/crm_required_field_by_stage
:alt: OCA/crm
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/crm-17-0/crm-17-0-crm_required_field_by_stage
:target: https://translation.odoo-community.org/projects/crm-16-0/crm-16-0-crm_required_field_by_stage
: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/crm&target_branch=17.0
:target: https://runboat.odoo-community.org/builds?repo=OCA/crm&target_branch=16.0
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|
Expand Down Expand Up @@ -56,7 +56,7 @@ Bug Tracker
Bugs are tracked on `GitHub Issues <https://github.com/OCA/crm/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/crm/issues/new?body=module:%20crm_required_field_by_stage%0Aversion:%2017.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
`feedback <https://github.com/OCA/crm/issues/new?body=module:%20crm_required_field_by_stage%0Aversion:%2016.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.

Expand Down Expand Up @@ -96,6 +96,6 @@ Current `maintainer <https://odoo-community.org/page/maintainer-role>`__:

|maintainer-alan196|

This module is part of the `OCA/crm <https://github.com/OCA/crm/tree/17.0/crm_required_field_by_stage>`_ project on GitHub.
This module is part of the `OCA/crm <https://github.com/OCA/crm/tree/16.0/crm_required_field_by_stage>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
2 changes: 1 addition & 1 deletion crm_required_field_by_stage/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
{
"name": "Required Fields by Stage in CRM",
"summary": "Define required fields by stage in CRM leads",
"version": "17.0.1.0.0",
"version": "16.0.1.0.0",
"category": "Customer Relationship Management",
"website": "https://github.com/OCA/crm",
"author": "Jarsa, Odoo Community Association (OCA)",
Expand Down
46 changes: 42 additions & 4 deletions crm_required_field_by_stage/models/crm_lead.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
# Copyright 2024 Jarsa
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).

from odoo import api, models
import ast
import json as simplejson

from odoo import _, api, models
from odoo.exceptions import UserError


class CrmLead(models.Model):
Expand All @@ -17,9 +21,20 @@ def _get_view(self, view_id=None, view_type="form", **options):
lambda stage, field=field: field in stage.required_field_ids
)
for node in arch.xpath("//field[@name='%s']" % field.name):
node.attrib["required"] = "stage_id in [%s]" % ",".join(
[str(id) for id in stages_with_field.ids]
)
attrs = ast.literal_eval(node.attrib.get("attrs", "{}"))
if attrs:
if attrs.get("required"):
attrs["required"] = [
"|",
("stage_id", "in", stages_with_field.ids),
] + attrs["required"]
else:
attrs["required"] = [
("stage_id", "in", stages_with_field.ids)
]
else:
attrs["required"] = [("stage_id", "in", stages_with_field.ids)]
node.set("attrs", simplejson.dumps(attrs))
return arch, view

@api.model
Expand All @@ -32,3 +47,26 @@ def _get_view_cache_key(self, view_id=None, view_type="form", **options):
.search([("required_field_ids", "!=", False)])
.mapped("required_field_ids.name")
)

@api.constrains("stage_id")
def _check_stage_id_(self):
for rec in self:
stage = self.env["crm.stage"].search([("id", "=", self.stage_id.id)])
for s in stage:
fields = self.env["ir.model.fields"].search(
[("id", "in", s.required_field_ids.ids)]
)
for field in fields:
if hasattr(self, "%s" % field.name):
if not getattr(self, "%s" % field.name):
raise UserError(
_(
"Field '%(field)s' is mandatory in stage '%(stage)s'."
)
% (
{
"field": field.display_name.split(" (")[0],
"stage": s.display_name,
}
)
)
7 changes: 3 additions & 4 deletions crm_required_field_by_stage/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 Down Expand Up @@ -370,7 +369,7 @@ <h1 class="title">Required Fields by Stage in CRM</h1>
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:fd5d37d78ea01679f05c1a52d1e1720c31e2c941682c529f03be2c21bb0c462f
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/lgpl-3.0-standalone.html"><img alt="License: LGPL-3" src="https://img.shields.io/badge/licence-LGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/crm/tree/17.0/crm_required_field_by_stage"><img alt="OCA/crm" src="https://img.shields.io/badge/github-OCA%2Fcrm-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/crm-17-0/crm-17-0-crm_required_field_by_stage"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/crm&amp;target_branch=17.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/lgpl-3.0-standalone.html"><img alt="License: LGPL-3" src="https://img.shields.io/badge/licence-LGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/crm/tree/16.0/crm_required_field_by_stage"><img alt="OCA/crm" src="https://img.shields.io/badge/github-OCA%2Fcrm-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/crm-16-0/crm-16-0-crm_required_field_by_stage"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/crm&amp;target_branch=16.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p>This module was written to extend the functionality of CRM leads to
require certain fields to be filled out based on the stage of the lead.</p>
<p><strong>Table of contents</strong></p>
Expand Down Expand Up @@ -405,7 +404,7 @@ <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/crm/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/crm/issues/new?body=module:%20crm_required_field_by_stage%0Aversion:%2017.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<a class="reference external" href="https://github.com/OCA/crm/issues/new?body=module:%20crm_required_field_by_stage%0Aversion:%2016.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">
Expand Down Expand Up @@ -436,7 +435,7 @@ <h2><a class="toc-backref" href="#toc-entry-6">Maintainers</a></h2>
promote its widespread use.</p>
<p>Current <a class="reference external" href="https://odoo-community.org/page/maintainer-role">maintainer</a>:</p>
<p><a class="reference external image-reference" href="https://github.com/alan196"><img alt="alan196" src="https://github.com/alan196.png?size=40px" /></a></p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/crm/tree/17.0/crm_required_field_by_stage">OCA/crm</a> project on GitHub.</p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/crm/tree/16.0/crm_required_field_by_stage">OCA/crm</a> project on GitHub.</p>
<p>You are welcome to contribute. To learn how please visit <a class="reference external" href="https://odoo-community.org/page/Contribute">https://odoo-community.org/page/Contribute</a>.</p>
</div>
</div>
Expand Down
6 changes: 6 additions & 0 deletions setup/crm_required_field_by_stage/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import setuptools

setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)

0 comments on commit d939ca6

Please sign in to comment.