Skip to content

Commit

Permalink
upd
Browse files Browse the repository at this point in the history
  • Loading branch information
AungKoKoLin1997 committed Jan 28, 2025
1 parent d12c41b commit 81fa334
Show file tree
Hide file tree
Showing 16 changed files with 130 additions and 85 deletions.
2 changes: 0 additions & 2 deletions customer_mail_reply_stage/models/__init__.py

This file was deleted.

12 changes: 0 additions & 12 deletions customer_mail_reply_stage/models/ir_model.py

This file was deleted.

57 changes: 0 additions & 57 deletions customer_mail_reply_stage/models/mail_message.py

This file was deleted.

12 changes: 0 additions & 12 deletions customer_mail_reply_stage/views/ir_model_views.xml

This file was deleted.

File renamed without changes.
File renamed without changes.
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,
}
2 changes: 2 additions & 0 deletions mail_reply_stage/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import mail_message
from . import mail_reply_config
50 changes: 50 additions & 0 deletions mail_reply_stage/models/mail_message.py
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)

Check warning on line 28 in mail_reply_stage/models/mail_message.py

View check run for this annotation

Codecov / codecov/patch

mail_reply_stage/models/mail_message.py#L28

Added line #L28 was not covered by tests
if parent_field_value and getattr(parent_field_value, 'name', None) == config.parent_field_value:
matched_config = config
break

Check warning on line 31 in mail_reply_stage/models/mail_message.py

View check run for this annotation

Codecov / codecov/patch

mail_reply_stage/models/mail_message.py#L30-L31

Added lines #L30 - L31 were not covered by tests
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)

Check warning on line 38 in mail_reply_stage/models/mail_message.py

View check run for this annotation

Codecov / codecov/patch

mail_reply_stage/models/mail_message.py#L38

Added line #L38 was not covered by tests
if current_stage == matched_config.remain_stage:
continue
reply_stage_rec = self.env[matched_config.reply_stage_field_id.relation].search([

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

View check run for this annotation

Codecov / codecov/patch

mail_reply_stage/models/mail_message.py#L40-L41

Added lines #L40 - L41 were not covered by tests
('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])

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

View check run for this annotation

Codecov / codecov/patch

mail_reply_stage/models/mail_message.py#L45

Added line #L45 was not covered by tests
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})

Check warning on line 48 in mail_reply_stage/models/mail_message.py

View check run for this annotation

Codecov / codecov/patch

mail_reply_stage/models/mail_message.py#L48

Added line #L48 was not covered by tests
return messages

39 changes: 39 additions & 0 deletions mail_reply_stage/models/mail_reply_config.py
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

Check warning on line 34 in mail_reply_stage/models/mail_reply_config.py

View check run for this annotation

Codecov / codecov/patch

mail_reply_stage/models/mail_reply_config.py#L34

Added line #L34 was not covered by tests

@api.onchange('reply_stage_field_id')
def _onchange_reply_stage_field_id(self):
self.reply_stage = False
self.remain_stage = False

Check warning on line 39 in mail_reply_stage/models/mail_reply_config.py

View check run for this annotation

Codecov / codecov/patch

mail_reply_stage/models/mail_reply_config.py#L38-L39

Added lines #L38 - L39 were not covered by tests
File renamed without changes.
File renamed without changes.
File renamed without changes.
3 changes: 3 additions & 0 deletions mail_reply_stage/security/ir.model.access.csv
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
31 changes: 31 additions & 0 deletions mail_reply_stage/views/mail_reply_config_views.xml
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>

0 comments on commit 81fa334

Please sign in to comment.