กฎอัตโนมัติ¶
Automation rules are used to trigger automatic changes based on user actions (e.g., apply a modification when a field is set to a specific value), email events, time conditions (e.g., archive a record 7 days after its last update), or external events.
To create an automation rule with Studio, proceed as follows:
เปิดสตูดิโอ และคลิก ระบบอัตโนมัติ จากนั้นคลิก ใหม่
Select the เปิดใช้งาน and, if necessary, fill in the fields that appear on the screen based on the chosen trigger.
คลิก เพิ่มการกระทำ จากนั้นเลือก ประเภท ของ:ref:
การกระทำ <studio/automated-actions/action>และกรอกข้อมูลในฟิลด์ที่ปรากฏบนหน้าจอตามการกระทำที่คุณเลือกคลิก บันทึกและปิด หรือ บันทึกและสร้าง
Example
Tip
To modify the model of the automation rule, switch models before clicking Automations in Studio, or activate the developer mode, create or edit an automation rule, and select the Model in the Automation Rules form.
You can also create automation rules from any kanban stage by clicking the gear icon (⚙ ) next to the kanban stage name, then selecting Automations. In this case, the Trigger is set to Stage is set to by default, but you can change it if necessary.
เปิดใช้งาน¶
The Trigger is used to define when the automation rule should be applied. The available triggers depend on the model. Five trigger categories are available overall:
Tip
You can also define a Before Update Domain to specify the conditions that must be met before the automation rule is triggered. In contrast, the conditions defined using the Extra Conditions and Apply on filters are checked during the execution of the automation rule.
To define a Before Update Domain, activate the developer mode, create or edit an automation rule, click Edit Domain, then click New Rule.
ตัวอย่างเช่น หากคุณต้องการให้มีการดำเนินการอัตโนมัติเมื่อมีการตั้งค่าที่อยู่อีเมลสำหรับผู้ติดต่อที่ไม่เคยมีที่อยู่มาก่อน (ตรงกันข้ามกับการแก้ไขที่อยู่ที่มีอยู่เดิมของผู้ติดต่อ) ให้กำหนด ก่อนการอัปเดตโดเมน เป็น ยังไม่ได้ตั้งค่าอีเมล และกำหนด นำไปใช้บน โดเมน เป็น ตั้งค่าอีเมลแล้ว
อัปเดตค่าแล้ว¶
The triggers available in this category depend on the model and are based on common field changes, such as adding a specific tag (e.g., to a task) or setting the User field. Select the trigger, then select a value if required.
กิจกรรมอีเมล¶
กระตุ้นการดำเนินการอัตโนมัติเมื่อได้รับหรือส่งอีเมล
เงื่อนไขการกำหนดเวลา¶
Trigger automated actions based on a date field. The following triggers are available:
Based on date field: Select the field to be used next to the Delay field.
After creation: The action is triggered when a record is created and saved.
After last update: The action is triggered when an existing record is edited and saved.
จากนั้นคุณสามารถกำหนด:
a Delay: Specify the number of minutes, hours, days, or months. To trigger the action before the trigger date, specify a negative number. If you selected the Based on date field trigger, you must also select the date field to be used to determine the delay.
Extra Conditions: Click Add condition, then specify the conditions to be met to trigger the automation rule. Click New Rule to add another condition.
The action is triggered when the delay is reached and the conditions are met.
Example
If you want to send a reminder email 30 minutes before the start of a calendar event, select the Start (Calendar Event) under Trigger Date and set the Delay to -30 Minutes.
Note
By default, the scheduler checks for trigger dates every 4 hours, meaning lower granularity in time-based automations may not always be honored.
กำหนดเอง¶
กระตุ้นการดำเนินการอัตโนมัติ:
On save: When the record is saved;
On deletion: When a record is deleted;
On UI change: When a field's value is changed on the Form view, even before saving the record.
สำหรับทริกเกอร์ เมื่อบันทึก และ เมื่อ UI เปลี่ยนแปลง คุณ**ต้อง**เลือกฟิลด์ที่จะใช้ในการทริกเกอร์กฎอัตโนมัติในฟิลด์ เมื่ออัปเดต
Warning
หากไม่ได้เลือกฟิลด์ในฟิลด์ เมื่ออัปเดต การดำเนินการอัตโนมัติอาจถูกดำเนินการหลายครั้งต่อระเบียน
นอกจากนี้ คุณยังสามารถกำหนดเงื่อนไขเพิ่มเติมที่ต้องปฏิบัติตามเพื่อกระตุ้นกฎระบบอัตโนมัติในฟิลด์ ใช้กับ
Note
The On UI change trigger can only be used with the ดำเนินการรหัส action and only works when a modification is made manually. The action is not executed if the field is changed through another automation rule.
ภายนอก¶
Trigger automated actions based on an external event using a webhook. A webhook is a method of communication between two systems where the source system sends an HTTP(S) request to a destination system based on a specific event. It usually includes a data payload containing information about the event that occurred.
To configure the On webhook trigger, copy the URL generated by Odoo into the destination system (i.e., the system receiving the request). Then, in the Target Record field, enter the code to run to define the record(s) to be updated using the automation rule.
Warning
The URL must be treated as confidential; sharing it online or without caution could potentially expose your system to malicious parties. Click the Rotate Secret button to change the URL's secret if necessary.
Note
The code defined by default in the Target Record field works for webhooks coming from another Odoo database. It is used to determine the record(s) to be updated using the information in the payload.
หากคุณต้องการใช้เนื้อหาของเว็บฮุกเพื่อวัตถุประสงค์อื่นนอกเหนือจากการค้นหาระเบียน (เช่น สร้าง บันทึก) ทางเลือกเดียวของคุณคือใช้การดำเนินการ ดำเนินการรหัส ในกรณีนี้ ฟิลด์ บันทึกเป้าหมาย จะต้องมีรหัสที่ถูกต้อง แต่ผลลัพธ์จะไม่มีผลต่อการดำเนินการอัตโนมัติแต่อย่างใด
The webhook content is available in the server action context as a
payloadvariable (i.e., a dictionary that contains the GET parameters or POST JSON body of the incoming request).
คุณสามารถเลือก บันทึกการโทร เพื่อบันทึกข้อมูลที่ได้รับ เช่น เพื่อให้แน่ใจว่าข้อมูลที่ส่งโดยระบบต้นทางตรงกับรูปแบบและเนื้อหาที่คาดหวัง นอกจากนี้ยังช่วยระบุและวิเคราะห์ปัญหาที่อาจเกิดขึ้นได้อีกด้วย หากต้องการเข้าถึงบันทึก ให้คลิกปุ่มอัจฉริยะ บันทึก ที่ด้านบนของแบบฟอร์ม กฏเกณฑ์อัตโนมัติ
การกระทำที่ต้องทำ¶
Once you have defined the automation rule's trigger, click Add an action to define the action to be executed.
Tip
คุณสามารถกำหนดการกระทำได้หลายอย่างสำหรับกฎทริกเกอร์/อัตโนมัติเดียวกัน การดำเนินการจะดำเนินการตามลำดับที่กำหนดไว้ ซึ่งหมายความว่า หากคุณกำหนดการดำเนินการ อัปเดตบันทึก แล้วตามด้วย ส่งอีเมล อีเมลจะใช้ค่าที่อัปเดต อย่างไรก็ตาม หากมีการกำหนดการดำเนินการ ส่งอีเมล ก่อนการดำเนินการ อัปเดตบันทึก อีเมลจะใช้ค่าที่ตั้งไว้ ก่อน การดำเนินการอัปเดตจะทำงาน
อัปเดตบันทึก¶
This action allows to update one of the record's (related) fields. Click the Update field and, in the list that opens, select or search for the field to be updated; click the right arrow next to the field name to access the list of related fields if needed.
หากคุณเลือก:ref:ฟิลด์ many2many <studio/fields/relational-fields-many2many> ให้เลือกว่าฟิลด์ต้องได้รับการอัปเดตโดย เพิ่ม ลบ หรือ ตั้งค่าเป็น ค่าที่เลือก หรือโดย:guilabel:ล้างข้อมูล
Example
If you want the automated action to remove a tag from the customer record, set the Update field to Customer > Tags, select By Removing, then select the tag.
Tip
อีกทางหนึ่ง คุณยังสามารถตั้งค่าฟิลด์ของเรกคอร์ดแบบไดนามิกโดยใช้โค้ด Python ได้ โดยเลือก คำนวณ แทน อัปเดต จากนั้นป้อนโค้ดที่จะใช้สำหรับคำนวณค่าของฟิลด์ ตัวอย่างเช่น หากคุณต้องการให้กฎอัตโนมัติคำนวณ:ref:ฟิลด์ datetime <studio/fields/simple-fields-date-time> ที่กำหนดเองเมื่อความสำคัญของงานถูกตั้งเป็น High (โดยการติดดาวงาน) คุณสามารถกำหนดทริกเกอร์ ความสำคัญถูกตั้งเป็น High และกำหนดการกระทำ อัปเดตเรกคอร์ด ดังนี้:
สร้างกิจกรรม¶
การกระทำนี้ใช้สำหรับกำหนดกิจกรรมใหม่ที่เชื่อมโยงกับเรกคอร์ด เลือก ประเภทกิจกรรม ป้อน ชื่อ และคำอธิบาย จากนั้นระบุว่าคุณต้องการกำหนดกิจกรรมเมื่อใดในฟิลด์ วันครบกำหนดใน และเลือก ประเภทผู้ใช้:
To always assign the activity to the same user, select Specific User and add the user in the Responsible field;
หากต้องการกำหนดเป้าหมายผู้ใช้ที่เชื่อมโยงกับเรกคอร์ดแบบไดนามิก ให้เลือก ผู้ใช้แบบไดนามิก (ตามเรกคอร์ด) และเปลี่ยน ฟิลด์ผู้ใช้ หากจำเป็น
Example
หลังจากที่ลีดถูกเปลี่ยนเป็นโอกาสทางการขาย คุณต้องการให้การกระทำอัตโนมัติตั้งค่าการโทรสำหรับผู้ใช้ที่รับผิดชอบลีด โดยตั้งค่า ประเภทกิจกรรม เป็น โทร และ ประเภทผู้ใช้ เป็น ผู้ใช้แบบไดนามิก (ตามเรกคอร์ด)
ส่งอีเมลและส่ง SMS¶
การดำเนินการเหล่านี้ใช้เพื่อส่งอีเมลหรือข้อความถึงผู้ติดต่อที่เชื่อมโยงกับบันทึกที่ระบุ เมื่อต้องการดำเนินการดังกล่าว ให้เลือกหรือสร้าง เทมเพลตอีเมล หรือ เทมเพลต SMS จากนั้นในฟิลด์ ส่งอีเมลเป็น หรือ ส่ง SMS เป็น ให้เลือกวิธีที่คุณต้องการส่งอีเมลหรือข้อความ:
อีเมล: เพื่อส่งข้อความเป็นอีเมลไปยังผู้รับของ:guilabel:
เทมเพลตอีเมลข้อความ: เพื่อโพสต์ข้อความในระเบียนและแจ้งเตือนผู้ติดตามของระเบียน
บันทึกภายใน: เพื่อส่งข้อความเป็นบันทึกภายในที่ผู้ใช้ภายในจะมองเห็นได้ในช่องแชท
SMS (ไม่มีบันทึก): เพื่อส่งข้อความเป็นข้อความสั้นไปยังผู้รับของ:guilabel:
เทมเพลต SMSSMS (พร้อมบันทึก): ส่งข้อความเป็นข้อความไปยังผู้รับของ เทมเพลต SMS และโพสต์เป็นบันทึกภายในในช่องแชท
หมายเหตุเท่านั้น: โพสต์ข้อความเป็นบันทึกภายในในช่องแชทเท่านั้น
เพิ่มผู้ติดตามและลบผู้ติดตาม¶
Use these actions to (un)subscribe existing contacts to/from the record.
สร้างบันทึก¶
การกระทำนี้ใช้สำหรับสร้างเรกคอร์ดใหม่บนโมเดลใดก็ได้
เลือกโมเดลที่ต้องการในฟิลด์ บันทึกเพื่อสร้าง ซึ่งมีโมเดลปัจจุบันตามค่าเริ่มต้น ระบุ ชื่อ ให้กับบันทึก จากนั้น หากคุณต้องการสร้างบันทึกในโมเดลอื่น ให้เลือกฟิลด์ในฟิลด์ ฟิลด์ลิงก์ เพื่อลิงก์บันทึกที่กระตุ้นให้สร้างบันทึกใหม่
Note
รายการแบบเลื่อนลงที่เกี่ยวข้องกับฟิลด์ ฟิลด์เชื่อมโยง มีเฉพาะ:ref:ฟิลด์ one2many <studio/fields/relational-fields-one2many> ที่มีอยู่ในโมเดลปัจจุบันที่เชื่อมโยงกับ:ref:ฟิลด์ many2one <studio/fields/relational-fields-many2one> บนโมเดลเป้าหมาย
Tip
You can create another automation rule with อัปเดตบันทึก actions to update the fields of the new record if necessary. For example, you can use a Create Record action to create a new project task and then assign it to a specific user using an Update Record action.
ดำเนินการรหัส¶
การดำเนินการนี้ใช้สำหรับเรียกใช้โค้ด Python คุณสามารถเขียนโค้ดของคุณในแท็บ:guilabel:`โค้ด`โดยใช้ตัวแปรต่อไปนี้:
env: สภาพแวดล้อมที่การดำเนินการถูกเรียกใช้model: โมเดลของระเบียนที่การดำเนินการถูกเรียกใช้ เป็นชุดระเบียนว่างrecord: ระเบียนที่การดำเนินการถูกเรียกใช้ อาจเป็นค่าว่างrecords: ชุดระเบียนของระเบียนทั้งหมดที่การดำเนินการถูกเรียกใช้ในโหมดหลายรายการ อาจเว้นว่างไว้time,datetime,dateutil,timezone: ไลบรารี Python ที่มีประโยชน์float_compare: ฟังก์ชันยูทิลิตี้สำหรับเปรียบเทียบตัวเลขทศนิยมตามความแม่นยำที่กำหนดlog(message, level='info'): ฟังก์ชันการบันทึกเพื่อบันทึกข้อมูลดีบักในตาราง ir.logging_logger.info(message): ตัวบันทึกเพื่อส่งข้อความในบันทึกของเซิร์ฟเวอร์UserError: คลาสข้อยกเว้นสำหรับแสดงข้อความเตือนที่มีต่อผู้ใช้Command: เนมสเปซคำสั่ง x2manyaction = {...}: เพื่อส่งคืนการดำเนินการ
Tip
ตัวแปรที่ใช้ได้อธิบายไว้ทั้งในแท็บ:guilabel:โค้ด`และ:guilabel:`ช่วยเหลือ
ส่งการแจ้งเตือน Webhook¶
This action allows to send a POST request with the values of the Fields to the URL specified in the URL field.
ตัวอย่างข้อมูล ให้การแสดงตัวอย่างของข้อมูลที่รวมอยู่ในคำขอโดยใช้ข้อมูลของระเบียนแบบสุ่มหรือข้อมูลจำลองหากไม่มีระเบียนพร้อมใช้งาน
ดำเนินการการกระทำที่มีอยู่¶
การกระทำนี้ใช้สำหรับทริกเกอร์การกระทำหลายรายการ (ที่เชื่อมโยงกับโมเดลปัจจุบัน) พร้อมกัน โดยคลิก เพิ่มรายการ จากนั้นในป๊อปอัป เพิ่ม: การกระทำย่อย ให้เลือกการกระทำที่มีอยู่ หรือคลิก ใหม่ เพื่อสร้างใหม่