Skip to content

Commit

Permalink
upd
Browse files Browse the repository at this point in the history
  • Loading branch information
AungKoKoLin1997 committed Jan 27, 2025
1 parent 5b5a093 commit 6e8365e
Show file tree
Hide file tree
Showing 12 changed files with 627 additions and 24 deletions.
104 changes: 104 additions & 0 deletions customer_mail_reply_stage/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
=========================
Customer Mail Reply Stage
=========================

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:3e0a708a7c69ddc0f3b1222b5c268d8d6acc6f32c6de186e7c9a5df995a98bb3
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |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%2Fsocial-lightgray.png?logo=github
:target: https://github.com/OCA/social/tree/15.0/customer_mail_reply_stage
:alt: OCA/social
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/social-15-0/social-15-0-customer_mail_reply_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/social&target_branch=15.0
:alt: Try me on Runboat

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

This module serves as a base for automatically updating the stage of a record when a non-internal user replies.
It controls stage updates based on a parent-child relationship, where the reply stage is defined at the parent model level and applied to its child records.

**Table of contents**

.. contents::
:local:

Configuration
=============

You need to configure your model when creating submodules:

1. Navigate to Settings > Technical > Models.
2. Locate the model and enable the Use Reply Stage option.

Usage
=====

An example for a submodule called `module_name` for a model:

A python class ::

from odoo import models

class ModelName(models.Model):
_inheirt = 'model_name'

def _remain_state_field(self):
return 'stage_field_name'
def _remain_state_value(self):
return "state_value"

def _parent_field(self):
return 'parent_field_name'

def _reply_stage_field(self):
return 'reply_stage_field_name'

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

Bugs are tracked on `GitHub Issues <https://github.com/OCA/social/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/social/issues/new?body=module:%20customer_mail_reply_stage%0Aversion:%2015.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
~~~~~~~

* Quartile

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/social <https://github.com/OCA/social/tree/15.0/customer_mail_reply_stage>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
7 changes: 4 additions & 3 deletions customer_mail_reply_stage/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
{
"name": "Customer Mail Reply Stage",
"category": "Tools",
"category": "Mail",
"version": "15.0.1.0.0",
"author": "Quartile Limited",
"website": "https://www.quartile.co",
"author": "Quartile, Odoo Community Association (OCA)",
"website": "https://github.com/OCA/social",
"license": "AGPL-3",
"depends": ["mail"],
"data": ["views/ir_model_views.xml"],
"installable": True,
}
1 change: 1 addition & 0 deletions customer_mail_reply_stage/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
from . import ir_model
from . import mail_message
12 changes: 12 additions & 0 deletions customer_mail_reply_stage/models/ir_model.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Copyright 2025 Quartile Limited
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl).

from odoo import fields, models


class IrModel(models.Model):
_inherit = "ir.model"

use_reply_stage = fields.Boolean(
help="If enabled, the reply stage feature will be activated for this model."
)
35 changes: 14 additions & 21 deletions customer_mail_reply_stage/models/mail_message.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Copyright 2025 Quartile Limited
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl).

from odoo import api, models

Expand All @@ -11,42 +11,39 @@ class MailMessage(models.Model):
def create(self, values_list):
messages = super().create(values_list)
for message in messages:
res_model = self.env['ir.model'].sudo().search([('model', '=', message.model)], limit=1)
res_model = (
self.env["ir.model"]
.sudo()
.search([("model", "=", message.model)], limit=1)
)
if not res_model.use_reply_stage:
continue
if not (
message.subtype_id
and not message.subtype_id.internal
):
if not (message.subtype_id and not message.subtype_id.internal):
continue
resource = self.env[message.model].browse(message.res_id)

Check warning on line 23 in customer_mail_reply_stage/models/mail_message.py

View check run for this annotation

Codecov / codecov/patch

customer_mail_reply_stage/models/mail_message.py#L22-L23

Added lines #L22 - L23 were not covered by tests
if getattr(resource, resource._remain_state_field()) == resource._remain_state_value():
if (
getattr(resource, resource._remain_state_field())
== resource._remain_state_value()
):
continue
user = message.author_id.user_ids[:1]

Check warning on line 29 in customer_mail_reply_stage/models/mail_message.py

View check run for this annotation

Codecov / codecov/patch

customer_mail_reply_stage/models/mail_message.py#L28-L29

Added lines #L28 - L29 were not covered by tests
if user and user.has_group("base.group_user"):
continue
parent = resource[resource._parent_field()]
reply_stage = getattr(parent, resource._reply_stage_field())

Check warning on line 33 in customer_mail_reply_stage/models/mail_message.py

View check run for this annotation

Codecov / codecov/patch

customer_mail_reply_stage/models/mail_message.py#L31-L33

Added lines #L31 - L33 were not covered by tests
if reply_stage:
resource.sudo().write({'stage_id': reply_stage.id})
resource.sudo().write({"stage_id": reply_stage.id})
continue

Check warning on line 36 in customer_mail_reply_stage/models/mail_message.py

View check run for this annotation

Codecov / codecov/patch

customer_mail_reply_stage/models/mail_message.py#L35-L36

Added lines #L35 - L36 were not covered by tests
reply_stage_id = int(
self.env["ir.config_parameter"]
.sudo()
.get_param(resource._config_key(), 0)
)
if reply_stage_id in getattr(parent, 'type_ids').ids:
resource.sudo().write({'stage_id': reply_stage_id})
return messages

def _resource_model(self):
"""Override this method in child models to specify the model name."""
raise NotImplementedError("Subclasses must implement `_resource_model`.")

Check warning on line 41 in customer_mail_reply_stage/models/mail_message.py

View check run for this annotation

Codecov / codecov/patch

customer_mail_reply_stage/models/mail_message.py#L41

Added line #L41 was not covered by tests

def _remain_state_field(self):
"""Override this method in child models to specify the remain state."""
raise NotImplementedError("Subclasses must implement `_remain_state_field`.")

Check warning on line 45 in customer_mail_reply_stage/models/mail_message.py

View check run for this annotation

Codecov / codecov/patch

customer_mail_reply_stage/models/mail_message.py#L45

Added line #L45 was not covered by tests

def _remain_state_value(self):
"""Override this method in child models to specify the remain state value."""
raise NotImplementedError("Subclasses must implement `_remain_state_value`.")

Check warning on line 49 in customer_mail_reply_stage/models/mail_message.py

View check run for this annotation

Codecov / codecov/patch

customer_mail_reply_stage/models/mail_message.py#L49

Added line #L49 was not covered by tests
Expand All @@ -58,7 +55,3 @@ def _reply_stage_field(self):
def _parent_field(self):
"""Override this method in child models to specify the parent field name."""
raise NotImplementedError("Subclasses must implement `_parent_field`.")

Check warning on line 57 in customer_mail_reply_stage/models/mail_message.py

View check run for this annotation

Codecov / codecov/patch

customer_mail_reply_stage/models/mail_message.py#L57

Added line #L57 was not covered by tests

def _config_key(self):
"""Override this method in child models to specify the config parameter key."""
raise NotImplementedError("Subclasses must implement `_config_key`.")
4 changes: 4 additions & 0 deletions customer_mail_reply_stage/readme/CONFIGURE.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
You need to configure your model when creating submodules:

1. Navigate to Settings > Technical > Models.
2. Locate the model and enable the Use Reply Stage option.
2 changes: 2 additions & 0 deletions customer_mail_reply_stage/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
This module serves as a base for automatically updating the stage of a record when a non-internal user replies.
It controls stage updates based on a parent-child relationship, where the reply stage is defined at the parent model level and applied to its child records.
20 changes: 20 additions & 0 deletions customer_mail_reply_stage/readme/USAGE.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
An example for a submodule called `module_name` for a model:

A python class ::

from odoo import models

class ModelName(models.Model):
_inheirt = 'model_name'

def _remain_state_field(self):
return 'stage_field_name'
def _remain_state_value(self):
return "state_value"

def _parent_field(self):
return 'parent_field_name'

def _reply_stage_field(self):
return 'reply_stage_field_name'
Loading

0 comments on commit 6e8365e

Please sign in to comment.