Skip to content

Commit

Permalink
Updates as per suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
ByteMeAsap committed Nov 13, 2024
1 parent 487e3ca commit 35c7460
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<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">
<xpath expr="//field[@name='complete_name']" position="after">
<field name="mailing_list_id" />
</xpath>
</field>
Expand Down
12 changes: 9 additions & 3 deletions membership_group/menuitems.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,24 @@

<menuitem
id="membership_group_info_menu"
name="Membership Groups"
name="All"
action="membership_group_action"
parent="membership_group.membership_group_top_menu"
sequence="1"
/>

<menuitem
id="membership_group_reporting_menu"
name="Reporting"
parent="membership_group.membership_group_top_menu"
sequence="2"
/>

<menuitem
id="membership_group_membership_menu"
name="Membership Group Members"
action="action_membership_group_member"
parent="membership_group.membership_group_top_menu"
sequence="2"
parent="membership_group.membership_group_reporting_menu"
/>

</odoo>
17 changes: 15 additions & 2 deletions membership_group/models/membership_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,36 @@ class MembershipGroup(models.Model):
_description = "Membership Group"
_parent_store = True
_parent_name = "parent_id"
_rec_name = "complete_name"
_order = "complete_name"

name = fields.Char()
complete_name = fields.Char(
'Complete Name', compute='_compute_complete_name', recursive=True,
store=True)
membership_group_member_ids = fields.One2many("membership.group.member", "group_id")
parent_id = fields.Many2one(
comodel_name="membership.group", string="Parent Membership Group", index=True
comodel_name="membership.group", string="Parent", index=True
)
child_ids = fields.One2many(
comodel_name="membership.group",
inverse_name="parent_id",
string="Sub Membership Groups",
string="Subgroups",
)
parent_path = fields.Char(index=True, unaccent=False)
partner_ids = fields.Many2many(
"res.partner", string="Contacts", compute="_compute_partner_ids"
)
partner_ids_count = fields.Integer("# of Members", compute="_compute_partner_ids")

@api.depends('name', 'parent_id.complete_name')
def _compute_complete_name(self):
for group in self:
if group.parent_id:
group.complete_name = '%s / %s' % (group.parent_id.complete_name, group.name)
else:
group.complete_name = group.name

@api.depends(
"membership_group_member_ids", "membership_group_member_ids.partner_id"
)
Expand Down
8 changes: 8 additions & 0 deletions membership_group/models/membership_group_member.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,11 @@ class MembershipGroupMember(models.Model):

partner_id = fields.Many2one("res.partner", required=True, ondelete="cascade")
group_id = fields.Many2one("membership.group", required=True, ondelete="cascade")

_sql_constraints = [
(
"partner_group_uniq",
"unique(partner_id, group_id)",
"Member already exists for this group!",
)
]
4 changes: 2 additions & 2 deletions membership_group/views/membership_group_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<field name="model">membership.group</field>
<field name="arch" type="xml">
<tree>
<field name="name" />
<field name="complete_name" />
<field string="Members" name="partner_ids_count" />
</tree>
</field>
Expand Down Expand Up @@ -60,7 +60,7 @@
</tree>
</field>
</page>
<page string="Sub Membership Groups">
<page string="Subgroups">
<field name="child_ids"/>
</page>
</notebook>
Expand Down
2 changes: 1 addition & 1 deletion membership_group/views/res_partner_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
</button>
</xpath>
<xpath expr="//field[@name='member_lines']" position="after">
<field name="membership_group_member_ids" nolabel="1" colspan="4">
<field name="membership_group_member_ids" string="Groups" colspan="4">
<tree editable="top">
<field name="group_id" />
</tree>
Expand Down

0 comments on commit 35c7460

Please sign in to comment.