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

I am trying to write code to raise a warning when a user forgets to enter phone number or email in the contact linked to a sales order. This is what I have so far and it works:

Model: sale.order


if not record.partner_id.phone and not record.partner_id.mobile:
raise Warning('Customer phone number is not set')
if not record.partner_id.email:
raise Warning('Customer email is not set')
if not record.partner_shipping_id.phone and not record.partner_shipping_id.mobile:
raise Warning('Shipping Address phone number is not set')
if not record.partner_shipping_id.email:
raise Warning('Shipping Address email is not set')
if len(record.partner_shipping_id.name) > 35:
raise Warning('Delivery Address: Name field is greater than 35 characters')
if len(record.partner_shipping_id.street) > 35:
raise Warning('Delivery Address: Street 1 field is greater than 35 characters')​

My question is how can I raise one Warning with all the missing fields? Basically Make my warning text to be dynamic and print a list of the Display Name of all the missing fields.


아바타
취소
베스트 답변

Hi,

You can show the field values inside the warning message like this, see the sample:


raise exceptions.ValidationError(_("Cannot create new attendance record for %(empl_name)s, the employee was already checked in on %(datetime)s") % {
'empl_name': attendance.employee_id.name_related,
'datetime': fields.Datetime.to_string(fields.Datetime.context_timestamp(self, fields.Datetime.from_string(attendance.check_in))),
})

Thanks

아바타
취소
작성자

@Niyas Thanks for the comment.

My question was to display the field name (NOT the string stored in that field)

For example:

If the user forgot to input a value for Field "Phone" (partner_id.phone) and "Email" (partner_id.email)

The warning message should say

"The following fields are not set: 'Phone', 'Email'"

Currently my code goes line by line, and will display a warning

"Customer phone is not set"

and then when user enters a phone number it will then display another warning

"Customer email is not set"

Using the if condition you can achieve it. What is complication you face in it

관련 게시물 답글 화면 활동
0
6월 21
6514
2
7월 19
4376
1
5월 16
10310
1
3월 16
12484
7
11월 15
10193