สร้างรายการเมนูการทำงานอื่นใน Odoo

ฉันกำลังพยายามขยายฟังก์ชันการทำงานของการดำเนินการที่กำหนดไว้ในมุมมองโมดูลที่กำหนดเองโดยเพิ่มรายการเมนูใหม่ ฉันไม่แน่ใจว่ามีการกำหนดรหัสในการทำมันอย่างไร

โมเดลที่ใช้คือ education.group

โมดูลที่กำหนดไว้คือ: การศึกษา

ป้อนคำอธิบายรูปภาพที่นี่

<record id="education_group_mailing_action" model="ir.actions.server">
    <field name="name">Generate group lists</field>
    <field name="type">ir.actions.server</field>
    <field name="model_id" ref="model_education_group"/>
    <field name="binding_model_id" ref="model_education_group"/>
    <field name="state">code</field>
    <field name="code">action = records.generate_lists()</field>
</record>

<record id="education_group_mailing_action2" model="ir.default">
        <field name="model_id" ref="model_education_group" />
        <field name="field_id" eval="1" />
        <field name="json_value">False</field>
        <field name="name">Generate group lsts</field>
        <field name="key2">client_action_multi</field>
        <field name="key">action</field>
        <field name="model">education.group</field>
        <field name="value" eval="'ir.actions.server,' + str(ref('education_group_mailing_action'))" />
    </record>
class EducationGroup(models.Model):
    _inherit='education.group'

   def generate_lists(self):
        print("HELLO!")

ใครรู้บ้างว่าต้องทำอย่างไร? ขอบคุณที่อ่าน!


person arevilla009    schedule 16.03.2020    source แหล่งที่มา


คำตอบ (2)


หากคุณใช้ Odoo12.0 คุณจะต้องทำเช่นนี้

    <record id="new_action1" model="ir.actions.server">
        <field name="name">New Action</field>
        <field name="model_id" ref="model_product_template" />
        <field name="binding_model_id" ref="model_product_template" />
        <field name="state">code</field>
        <field name="code">records.export_product()</field>
    </record>
    <record id="run_product_new_order_action2" model="ir.default">
        <field name="model_id" ref="model_product_template" />
        <field name="field_id" eval="1" />
        <field name="json_value">False</field>
        <field name="name">New Action</field>
        <field name="key2">client_action_multi</field>
        <field name="key">action</field>
        <field name="model">product.template</field>
        <field name="value" eval="'ir.actions.server,' + str(ref('new_action1'))" />
    </record>

หากคุณใช้ Odoo13.0 ก็จะเป็นเช่นนั้น

       <record id="product_order_new_action1" model="ir.actions.server">
            <field name="name">New Action</field>
            <field name="type">ir.actions.server</field>
            <field name="model_id" ref="model_product_template" />
            <field name="binding_model_id" ref="model_product_template" />
            <field name="state">code</field>
            <field name="code">records.sync_product(False)</field>
        </record>
person Adam Strauss    schedule 17.03.2020
comment
เฮ้ อดัม ฉันลองใช้โค้ดถัดไปแล้วในขณะที่แก้ไข แต่ใช้งานไม่ได้ ฉันไม่เห็นรายการแบบเลื่อนลงใหม่ คุณรู้ไหมว่าเกิดอะไรขึ้น @อดัม สเตราส์ - person arevilla009; 18.03.2020
comment
อันไหน ? อันที่หนึ่งหรืออันที่สอง? - person Adam Strauss; 18.03.2020
comment
ฉันใช้ Odoo12 ดังนั้นฉันจึงลองใช้อันแรก ฉันแก้ไขโค้ดด้วยการลองใหม่ แต่ยังไม่เห็นรายการแบบเลื่อนลง ขอบคุณที่ช่วยเหลือ! @อดัม สเตราส์ - person arevilla009; 18.03.2020
comment
ฉันจำเป็นต้องใช้ในมุมมองแบบต้นไม้เพื่อเรียกใช้ฟังก์ชัน python สำหรับบันทึกที่เลือก @อดัม สเตราส์ - person arevilla009; 18.03.2020

ตรวจสอบรหัสนี้

<record id="mail_mass_mailing_lists_action" model="ir.actions.server">
    <field name="name">Generate group lists</field>
    <field name="type">ir.actions.server</field>
    <field name="model_id" ref="mass_mailing.model_mail_mass_mailing_list"/>
    <field name="binding_model_id" ref="mass_mailing.model_mail_mass_mailing_list"/>
    <field name="state">code</field>
    <field name="code">action = records.generate_lists()</field>
</record>

ขอบคุณ

person Dipen Shah    schedule 17.03.2020