콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다
2 답글
1081 화면

Hi All. 

Refer to the picture attached. In CRM i have a custom field "Customer PO" (x_po).

Ones a user has entered the number to the field again this customer. For ex: PO123 against Vodafone Fiji. I don't want any other user to same number for this customer. 


However PO123 can be used against all customers but against same customer it should be only used ones and of anyone enters same number then it should give error upon saving. 


Can someone help me in writing a automated action.



Thanks

Rishal 

아바타
취소

Perhaps, this module - https://apps.odoo.com/apps/modules/16.0/crm_duplicates/ - will be useful to your goals

작성자

Great Team Thank you all for your feedback. I tried this rule and it worked. 

existing_records = env['crm.lead'].search_count([('x_po', '=', record.x_po) , ('partner_id', '=', record.partner_id.id)])


if existing_records > 1:

raise Warning("PO alreay processed.")



Thanks

베스트 답변

Hi,

As you are adding fields from user interface and if you need to add the restriction from the user interface itself, you can use the automated action in odoo and raise warning if the duplicated match is found in the db.

* Install base_automation in db
* from automated action menu under settings menu, create a new automated action for this model
* set type as execute python code
* and add below code

existing_records = env['model_name'].search([('x_po', '=', record.x_po), ('partner_ld', '=', record.partner_id)])

if existing_records > 1:
​raise warning("your warning")

You may have to adjust the code little, but you can follow this.

See an use case here:  https://www.youtube.com/watch?v=8V14lcJlkfA

Thanks

아바타
취소
작성자

Thank you.

베스트 답변

You will try to search from all the records and find x_po and save this in a variable, if the variable have value then try to raise error


@api.constrains('name')

def _check_duplicate_x_po(self):

for record in self:

existing_records = self.search([('name', '=', record.name)])

if len(existing_records) > 1:

raise ValidationError("An existing record with the same X PO value already exists.")


refer this code

아바타
취소
작성자

Thank you.