Skip to content

Commit

Permalink
[IMP] shopinvader_unit_api_request: Extract notification for request …
Browse files Browse the repository at this point in the history
…feedback
  • Loading branch information
paradoxxxzero committed Oct 14, 2024
1 parent a9bae47 commit 426ec06
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 22 deletions.
12 changes: 9 additions & 3 deletions shopinvader_api_unit_member/security/res_partner.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,15 @@
name="groups"
eval="[(4, ref('shopinvader_api_unit_member.shopinvader_unit_management_user_group'))]"
/>
<field
name="domain_force"
>['|', ('unit_id.manager_ids','=',authenticated_partner_id), ('manager_ids','=',authenticated_partner_id)]</field>
<field name="domain_force">[
'|',
('manager_ids','=',authenticated_partner_id),
'|',
('unit_id.manager_ids','=',authenticated_partner_id),
'|',
('parent_id.manager_ids','=',authenticated_partner_id),
('parent_id.unit_id.manager_ids','=',authenticated_partner_id)
]</field>

</record>

Expand Down
51 changes: 33 additions & 18 deletions shopinvader_api_unit_request/models/sale_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,29 +69,44 @@ def action_confirm(self):
] |= line

for partner, lines in request_lines_by_partner.items():
message = ""
if lines["accepted"]:
message += _("Your following requests have been accepted:\n")
for line in lines["accepted"]:
message += f"{line.product_id.name} - {line.product_uom_qty}\n"

if lines["rejected"]:
message += _("Your following requests have been rejected:\n")
for line in lines["rejected"]:
message += f"{line.product_id.name} - {line.product_uom_qty}"
if line.request_rejection_reason:
message += f": {line.request_rejection_reason}"
message += "\n"
if not message:
if not lines["accepted"] and not lines["rejected"]:
continue
partner.message_post(
body=message,
subject=_("Request feedback for order %s") % record.name,
subtype_id=self.env.ref("mail.mt_comment").id,
self._notify_partner_on_request_feedback(
partner, lines["accepted"], lines["rejected"]
)

return res

def _notify_partner_on_request_feedback(
self, partner, accepted_lines, rejected_lines
):
"""Override this method to customize the notification message.
Sending a mail template for example.
:param partner: res.partner record Concerned partner
:param accepted_lines: sale.order.line recordset Accepted lines
:param rejected_lines: sale.order.line recordset Rejected lines
"""
message = ""
if accepted_lines:
message += _("Your following requests have been accepted:\n")
for line in accepted_lines:
message += f"{line.product_id.name} - {line.product_uom_qty}\n"

if rejected_lines:
message += _("Your following requests have been rejected:\n")
for line in rejected_lines:
message += f"{line.product_id.name} - {line.product_uom_qty}"
if line.request_rejection_reason:
message += f": {line.request_rejection_reason}"
message += "\n"

partner.message_post(
body=message,
subject=_("Request feedback"),
subtype_id=self.env.ref("mail.mt_comment").id,
)

def action_request_cart(self):
for record in self:
if record.typology == "request":
Expand Down
2 changes: 1 addition & 1 deletion shopinvader_unit_management/models/res_partner.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,5 +85,5 @@ def _delete_shopinvader_unit_member(self, member_id):
self._ensure_same_unit(member)
if member.unit_profile not in ["collaborator", "manager"]:
raise AccessError(_("Cannot perform this action on this member"))
member.active = False
member.sudo().active = False
return member

0 comments on commit 426ec06

Please sign in to comment.