-
-
Notifications
You must be signed in to change notification settings - Fork 633
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d12c41b
commit 81fa334
Showing
16 changed files
with
130 additions
and
85 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
File renamed without changes.
File renamed without changes.
7 changes: 5 additions & 2 deletions
7
customer_mail_reply_stage/__manifest__.py → mail_reply_stage/__manifest__.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,16 @@ | ||
# Copyright 2025 Quartile Limited | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
{ | ||
"name": "Customer Mail Reply Stage", | ||
"name": "Mail Reply Stage", | ||
"category": "Mail", | ||
"version": "15.0.1.0.0", | ||
"author": "Quartile, Odoo Community Association (OCA)", | ||
"website": "https://github.com/OCA/social", | ||
"license": "AGPL-3", | ||
"depends": ["mail"], | ||
"data": ["views/ir_model_views.xml"], | ||
"data": [ | ||
"security/ir.model.access.csv", | ||
"views/mail_reply_config_views.xml", | ||
], | ||
"installable": True, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
from . import mail_message | ||
from . import mail_reply_config |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
# Copyright 2025 Quartile Limited | ||
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl). | ||
|
||
from odoo import api, models | ||
|
||
|
||
class MailMessage(models.Model): | ||
_inherit = "mail.message" | ||
|
||
@api.model_create_multi | ||
def create(self, values_list): | ||
messages = super().create(values_list) | ||
for message in messages: | ||
# user = message.author_id.user_ids[:1] | ||
# if user and user.has_group("base.group_user"): | ||
# continue | ||
if message.subtype_id and message.subtype_id.internal: | ||
continue | ||
res_model = self.env["ir.model"].sudo().search([("model", "=", message.model)], limit=1) | ||
if not res_model: | ||
continue | ||
resource = self.env[message.model].browse(message.res_id) | ||
config_records = self.env["mail.reply.config"].search([ | ||
('model_id', '=', res_model.id) | ||
]) | ||
matched_config = None | ||
for config in config_records: | ||
parent_field_value = getattr(resource, config.parent_field_id.name, None) | ||
if parent_field_value and getattr(parent_field_value, 'name', None) == config.parent_field_value: | ||
matched_config = config | ||
break | ||
if not matched_config: | ||
matched_config = self.env["mail.reply.config"].search([ | ||
('model_id', '=', res_model.id), ('parent_field_id', '=', False) | ||
], limit=1) | ||
if not matched_config: | ||
continue | ||
current_stage = getattr(resource, matched_config.reply_stage_field_id.name, None) | ||
if current_stage == matched_config.remain_stage: | ||
continue | ||
reply_stage_rec = self.env[matched_config.reply_stage_field_id.relation].search([ | ||
('name', '=', matched_config.reply_stage) | ||
]) | ||
if config.parent_stage_field_id: | ||
allowed_stages = getattr(parent_field_value, config.parent_stage_field_id.name, self.env[matched_config.parent_stage_field_id.relation]) | ||
reply_stage_rec = reply_stage_rec.filtered(lambda stage: stage in allowed_stages) | ||
if reply_stage_rec: | ||
resource.sudo().write({matched_config.reply_stage_field_id.name: reply_stage_rec.id}) | ||
return messages | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# Copyright 2025 Quartile Limited | ||
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl). | ||
|
||
from odoo import api, fields, models | ||
|
||
|
||
class MailReplyStage(models.Model): | ||
_name = "mail.reply.config" | ||
|
||
|
||
model_id = fields.Many2one('ir.model', string='Model', required=True, ondelete="cascade") | ||
parent_field_id = fields.Many2one('ir.model.fields', string='Parent Field', domain="[('model_id', '=', model_id), ('ttype', '=', 'many2one')]", required=True,ondelete="cascade") | ||
parent_model_name = fields.Char( | ||
related="parent_field_id.relation", | ||
store=True, | ||
help="Automatically stores the model name of the related parent entity." | ||
) | ||
parent_stage_field_id = fields.Many2one( | ||
'ir.model.fields', | ||
string='Parent Stage Field', | ||
domain="[('model_id.model', '=', parent_model_name), ('ttype', '=', 'many2many')]", | ||
ondelete="cascade", | ||
help="A Many2Many field within the parent model that defines valid stages for this configuration." | ||
) | ||
parent_field_value = fields.Char( | ||
help="The specific value of the parent field that this configuration applies to. For example, a project name." | ||
) | ||
reply_stage_field_id = fields.Many2one('ir.model.fields', string='Field', domain="[('model_id', '=', model_id), ('ttype', '=', 'many2one')]", required=True,ondelete="cascade") | ||
reply_stage = fields.Char(required=True, help="This stage of record will be changed when a non-internal user replies to the record.") | ||
remain_stage = fields.Char(string='No Reply Stage', required=True, help="Record in this stage will not update to the mail reply stage when a non-internal user replies to the record.") | ||
|
||
@api.onchange('model_id') | ||
def _onchange_model_id(self): | ||
self.reply_stage_field_id = False | ||
|
||
@api.onchange('reply_stage_field_id') | ||
def _onchange_reply_stage_field_id(self): | ||
self.reply_stage = False | ||
self.remain_stage = False | ||
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink | ||
access_mail_reply_config_all,mail.reply.config.all,model_mail_reply_config,,1,0,0,0 | ||
access_mail_reply_config_admin,mail.reply.config.admin,model_mail_reply_config,base.group_system,1,1,1,1 |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<odoo> | ||
<record id="view_mail_reply_config_tree" model="ir.ui.view"> | ||
<field name="name">mail.reply.config.tree</field> | ||
<field name="model">mail.reply.config</field> | ||
<field name="arch" type="xml"> | ||
<tree editable="top"> | ||
<field name="model_id"/> | ||
<field name="parent_field_id" /> | ||
<field name="parent_model_name" /> | ||
<field name="parent_stage_field_id" attrs="{'required': [('parent_field_id', '!=', False)]}" /> | ||
<field name="parent_field_value" attrs="{'required': [('parent_field_id', '!=', False)]}" /> | ||
<field name="reply_stage_field_id"/> | ||
<field name="reply_stage"/> | ||
<field name="remain_stage"/> | ||
</tree> | ||
</field> | ||
</record> | ||
<record id="action_mail_reply_config" model="ir.actions.act_window"> | ||
<field name="name">Mail Reply Configurations</field> | ||
<field name="res_model">mail.reply.config</field> | ||
<field name="view_mode">tree</field> | ||
<field name="view_id" ref="view_mail_reply_config_tree"/> | ||
</record> | ||
<menuitem id="menu_mail_reply_config" | ||
name="Mail Reply Configurations" | ||
parent="base.menu_administration" | ||
action="action_mail_reply_config" | ||
sequence="10" | ||
/> | ||
</odoo> |