İçereği Atla
Menü
Bu soru işaretlendi
2 Cevaplar
1035 Görünümler

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
Vazgeç
Üretici

how can I do that?

En İyi Yanıt

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
Vazgeç
En İyi Yanıt

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
Vazgeç
İlgili Gönderiler Cevaplar Görünümler Aktivite
3
Ağu 25
887
3
Tem 25
344
1
May 25
781
0
May 25
927
0
Nis 25
871