Skip to content

Commit

Permalink
[Add] Added modules membership_group and mass_mailing_membership_grou…
Browse files Browse the repository at this point in the history
…p modules
  • Loading branch information
ByteMeAsap committed Oct 9, 2024
1 parent ef2d7af commit 3391a69
Show file tree
Hide file tree
Showing 31 changed files with 753 additions and 0 deletions.
1 change: 1 addition & 0 deletions mass_mailing_membership_group/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
28 changes: 28 additions & 0 deletions mass_mailing_membership_group/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Copyright 2022 Onestein (<http://www.onestein.eu>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

{
"name": "Mass Mailing Membership Group",
"category": "Membership",
"version": "16.0.1.0.0",
"author": "Onestein",
"license": "AGPL-3",
"website": "https://www.onestein.nl",
"depends": [
"mass_mailing",
"mass_mailing_partner",
"membership",
"membership_group",
],
"data": [
"views/membership_group_view.xml",
"views/membership_group_member_view.xml",
"views/res_partner_view.xml",
],
"demo": [
"data/mailing_list_demo.xml",
"data/membership_group_demo.xml",
"data/mailing_contact_demo.xml",
"data/res_partner_demo.xml",
],
}
27 changes: 27 additions & 0 deletions mass_mailing_membership_group/data/mailing_contact_demo.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data noupdate="1">

<record id="mass_mail_contact_1" model="mailing.contact">
<field name="name">John Doe</field>
<field name="email">[email protected]</field>
<field name="partner_id" ref="membership_group.demo_member_1" />
<field name="list_ids" eval="[(6, 0, [ref('demo_mailing_list_group_1'), ref('demo_mailing_list_group_2')])]"/>
</record>

<record id="mass_mail_contact_2" model="mailing.contact">
<field name="name">Jane Smith</field>
<field name="email">[email protected]</field>
<field name="partner_id" ref="membership_group.demo_member_2" />
<field name="list_ids" eval="[(6, 0, [ref('demo_mailing_list_group_4')])]"/>
</record>

<record id="mass_mail_contact_3" model="mailing.contact">
<field name="name">Alice Johnson</field>
<field name="email">[email protected]</field>
<field name="partner_id" ref="membership_group.demo_member_3" />
<field name="list_ids" eval="[(6, 0, [ref('demo_mailing_list_group_3')])]"/>
</record>

</data>
</odoo>
22 changes: 22 additions & 0 deletions mass_mailing_membership_group/data/mailing_list_demo.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data noupdate="1">

<record id="demo_mailing_list_group_1" model="mailing.list">
<field name="name">Executive Board</field>
</record>

<record id="demo_mailing_list_group_2" model="mailing.list">
<field name="name">Marketing Team</field>
</record>

<record id="demo_mailing_list_group_3" model="mailing.list">
<field name="name">Finance Committee</field>
</record>

<record id="demo_mailing_list_group_4" model="mailing.list">
<field name="name">Youth Club</field>
</record>

</data>
</odoo>
22 changes: 22 additions & 0 deletions mass_mailing_membership_group/data/membership_group_demo.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data noupdate="1">

<record id="membership_group.demo_membership_group_1" model="membership.group">
<field name="mailing_list_id" ref="demo_mailing_list_group_1" />
</record>

<record id="membership_group.demo_membership_group_2" model="membership.group">
<field name="mailing_list_id" ref="demo_mailing_list_group_2" />
</record>

<record id="membership_group.demo_membership_group_3" model="membership.group">
<field name="mailing_list_id" ref="demo_mailing_list_group_3" />
</record>

<record id="membership_group.demo_membership_group_4" model="membership.group">
<field name="mailing_list_id" ref="demo_mailing_list_group_4" />
</record>

</data>
</odoo>
34 changes: 34 additions & 0 deletions mass_mailing_membership_group/data/res_partner_demo.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data noupdate="1">

<record id="membership_group.demo_member_1" model="res.partner">
<field name="membership_group_member_ids" eval="[
(5, 0),
(0, 0, {'group_id': ref('membership_group.demo_membership_group_1'), 'on_mailing_list': True}),
(0, 0, {'group_id': ref('membership_group.demo_membership_group_2'), 'on_mailing_list': True}),
(0, 0, {'group_id': ref('membership_group.demo_membership_group_3')})
]"
/>
</record>

<record id="membership_group.demo_member_2" model="res.partner">
<field name="membership_group_member_ids" eval="[
(5, 0),
(0, 0, {'group_id': ref('membership_group.demo_membership_group_1')}),
(0, 0, {'group_id': ref('membership_group.demo_membership_group_4'), 'on_mailing_list': True})
]"
/>
</record>

<record id="membership_group.demo_member_3" model="res.partner">
<field name="membership_group_member_ids" eval="[
(5, 0),
(0, 0, {'group_id': ref('membership_group.demo_membership_group_2')}),
(0, 0, {'group_id': ref('membership_group.demo_membership_group_3'), 'on_mailing_list': True})
]"
/>
</record>

</data>
</odoo>
3 changes: 3 additions & 0 deletions mass_mailing_membership_group/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from . import membership_group
from . import membership_group_member
from . import mailing_list
7 changes: 7 additions & 0 deletions mass_mailing_membership_group/models/mailing_list.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from odoo import fields, models


class MailingList(models.Model):
_inherit = "mailing.list"

membership_group_ids = fields.One2many("membership.group", "mailing_list_id")
7 changes: 7 additions & 0 deletions mass_mailing_membership_group/models/membership_group.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from odoo import fields, models


class MembershipGroup(models.Model):
_inherit = "membership.group"

mailing_list_id = fields.Many2one("mailing.list")
53 changes: 53 additions & 0 deletions mass_mailing_membership_group/models/membership_group_member.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
from odoo import api, fields, models


class MembershipGroupMember(models.Model):
_inherit = "membership.group.member"

on_mailing_list = fields.Boolean(
compute="_compute_on_mailing_list",
inverse="_inverse_on_mailing_list",
store=True,
readonly=False,
)

@api.depends(
"group_id",
"group_id.mailing_list_id",
"partner_id",
"partner_id.mass_mailing_contact_ids",
)
def _compute_on_mailing_list(self):
for membership in self:
if (
not membership.group_id
or not membership.group_id.mailing_list_id
or not membership.partner_id
):
membership.on_mailing_list = False
else:
related_lists = membership.partner_id.mass_mailing_contact_ids.mapped(
"subscription_list_ids"
).mapped("list_id")
membership.on_mailing_list = (
membership.group_id.mailing_list_id in related_lists
)

def _inverse_on_mailing_list(self):
mailing_contact_obj = self.env["mailing.contact"]
for membership in self:
related_contacts = mailing_contact_obj.search(
[("partner_id", "=", membership.partner_id.id)]
)
if membership.on_mailing_list:
if not related_contacts:
related_contacts = mailing_contact_obj.create(
{"email": membership.partner_id.email}
)
membership.group_id.mailing_list_id.write(
{"contact_ids": [(4, related_contacts[0].id)]}
)
elif related_contacts:
membership.group_id.mailing_list_id.write(
{"contact_ids": [(3, c.id) for c in related_contacts]}
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>

<record id="membership_group_member_view_tree" model="ir.ui.view">
<field name="model">membership.group.member</field>
<field name="inherit_id" ref="membership_group.membership_group_member_view_tree" />
<field name="arch" type="xml">
<xpath expr="//field[@name='group_id']" position="after">
<field name="on_mailing_list" />
</xpath>
</field>
</record>

<record id="membership_group_member_view_search" model="ir.ui.view">
<field name="model">membership.group.member</field>
<field name="inherit_id" ref="membership_group.membership_group_member_view_search" />
<field name="arch" type="xml">
<xpath expr="//field[@name='group_id']" position="after">
<separator />
<filter string="On Mailing List" name="on_mailing_list" domain="[('on_mailing_list','=', True)]" />
</xpath>
</field>
</record>

</odoo>
29 changes: 29 additions & 0 deletions mass_mailing_membership_group/views/membership_group_view.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?xml version="1.0"?>
<odoo>

<record id="membership_group_view_tree" model="ir.ui.view">
<field name="model">membership.group</field>
<field name="inherit_id" ref="membership_group.membership_group_view_tree" />
<field name="arch" type="xml">
<xpath expr="//field[@name='name']" position="after">
<field name="mailing_list_id" />
</xpath>
</field>
</record>

<record id="membership_group_view_form" model="ir.ui.view">
<field name="model">membership.group</field>
<field name="inherit_id" ref="membership_group.membership_group_view_form" />
<field name="arch" type="xml">
<xpath expr="//group[@name='form_body']" position="inside">
<group name="mass_mailing_informations" string="Email Marketing">
<field name="mailing_list_id" />
</group>
</xpath>
<xpath expr="//field[@name='membership_group_member_ids']//field[@name='partner_id']" position="after">
<field name="on_mailing_list" />
</xpath>
</field>
</record>

</odoo>
14 changes: 14 additions & 0 deletions mass_mailing_membership_group/views/res_partner_view.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>

<record id="view_partner_form" model="ir.ui.view">
<field name="inherit_id" ref="membership_group.view_partner_form" />
<field name="model">res.partner</field>
<field name="arch" type="xml">
<xpath expr="//field[@name='membership_group_member_ids']//field[@name='group_id']" position="after">
<field name="on_mailing_list" />
</xpath>
</field>
</record>

</odoo>
1 change: 1 addition & 0 deletions membership_group/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
25 changes: 25 additions & 0 deletions membership_group/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Copyright 2023 Onestein (<http://www.onestein.eu>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
{
"name": "Membership Group",
"category": "Membership",
"version": "16.0.1.0.0",
"author": "Onestein, Odoo Community Association (OCA)",
"license": "AGPL-3",
"website": "https://www.onestein.nl",
"depends": [
"contacts",
"membership",
],
"data": [
"security/ir.model.access.csv",
"views/membership_group_member_view.xml",
"views/membership_group_view.xml",
"views/res_partner_view.xml",
"menuitems.xml",
],
"demo": [
"data/membership_group_demo.xml",
"data/res_partner_demo.xml",
],
}
22 changes: 22 additions & 0 deletions membership_group/data/membership_group_demo.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data noupdate="1">

<record id="demo_membership_group_1" model="membership.group">
<field name="name">Executive Board</field>
</record>

<record id="demo_membership_group_2" model="membership.group">
<field name="name">Marketing Team</field>
</record>

<record id="demo_membership_group_3" model="membership.group">
<field name="name">Finance Committee</field>
</record>

<record id="demo_membership_group_4" model="membership.group">
<field name="name">Youth Club</field>
</record>

</data>
</odoo>
40 changes: 40 additions & 0 deletions membership_group/data/res_partner_demo.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data noupdate="1">

<record id="demo_member_1" model="res.partner">
<field name="name">John Doe</field>
<field name="free_member" eval="True" />
<field name="membership_group_member_ids" eval="[
(5, 0),
(0, 0, {'group_id': ref('membership_group.demo_membership_group_1')}),
(0, 0, {'group_id': ref('membership_group.demo_membership_group_2')}),
(0, 0, {'group_id': ref('membership_group.demo_membership_group_3')})
]"
/>
</record>

<record id="demo_member_2" model="res.partner">
<field name="name">Jane Smith</field>
<field name="free_member" eval="True" />
<field name="membership_group_member_ids" eval="[
(5, 0),
(0, 0, {'group_id': ref('membership_group.demo_membership_group_1')}),
(0, 0, {'group_id': ref('membership_group.demo_membership_group_4')})
]"
/>
</record>

<record id="demo_member_3" model="res.partner">
<field name="name">Alice Johnson</field>
<field name="free_member" eval="True" />
<field name="membership_group_member_ids" eval="[
(5, 0),
(0, 0, {'group_id': ref('membership_group.demo_membership_group_2')}),
(0, 0, {'group_id': ref('membership_group.demo_membership_group_3')})
]"
/>
</record>

</data>
</odoo>
Loading

0 comments on commit 3391a69

Please sign in to comment.