Overslaan naar inhoud
Menu
Je moet geregistreerd zijn om te kunnen communiceren met de community.
Deze vraag is gerapporteerd
2 Antwoorden
1051 Weergaven

I want to set up contacts so that confirmation from a significant person is required whenever anyone creates a new contact. Is there a way to do this?

Avatar
Annuleer
Auteur

how can I do that?

Beste antwoord

Hi,


Odoo does not offer this feature out of the box.

However, it can be achieved through customization.

Solution :-          

When a user creates a new contact, it is automatically archived and an approval request is generated. Once approved, the contact becomes active and usable across Odoo.

Steps:


1- Define the approval category (data file).

<odoo>
<record id="approval_category_contact" model="approval.category">
<field name="name">Contact Approval</field>
</record>
</odoo>

Assign the users responsible for approving new contacts within the created approval category.


2- Extend 'res.partner' to create approval on contact creation.


Here is a sample code example to archive a newly created contact and initiate an approval request.

from odoo import models, fields, api, _
from odoo.exceptions import UserError

class ResPartner(models.Model):
_inherit = 'res.partner'

approval_request_id = fields.Many2one('approval.request', string="Approval Request", readonly=True)

@api.model
def create(self, vals):
vals['active'] = False # Archive the contact initially
partner = super().create(vals)

# Create approval request
approval = self.env['approval.request'].create({
'name': _('Approval for New Contact: %s') % partner.name,
'request_owner_id': self.env.user.id,
'category_id': self.env.ref('your_module.approval_category_contact').id,
'partner_id': partner.id,
})

partner.approval_request_id = approval.id
return partner

3- Extend 'approval.request' to activate the partner upon approval.

class ApprovalRequest(models.Model):
_inherit = 'approval.request'

partner_id = fields.Many2one('res.partner', string="Pending Contact")

def action_approve(self):
res = super().action_approve()
for request in self:
if request.category_id.xml_id == 'your_module.approval_category_contact' and request.partner_id:
request.partner_id.active = True
return res



Please note the following while developing


* Replace 'your_module.approval_category_contact' with your module’s actual external ID.

* You can customize the approval template for more fields if needed (phone, email, etc.).

* Contacts created manually via the UI will also follow this logic.

* Ensure that the module depends on the approvals module in its manifest.


Hope it helps

Avatar
Annuleer
Beste antwoord

1.Create a Custom Module

2.Add an "Approval Status" Field

add a new field to contacts so that each contact has a status:

  • Pending Approval (Default)
  • Approved (Allowed to be used)
  • Rejected (Not allowed)

3.Add "Approve" and "Reject" Buttons in xml code

4. Restrict Users from Seeing Unapproved Contacts in your security.xml

5.Send an Email to the Approver
6.install your custom module and see everything is right what u wanted....

Avatar
Annuleer
Gerelateerde posts Antwoorden Weergaven Activiteit
3
aug. 25
931
3
jul. 25
385
1
mei 25
803
0
mei 25
953
0
apr. 25
899