Help

欢迎!

该社区面向专业人士和我们产品和服务的爱好者。
分享和讨论最好的内容和新的营销理念,建立您的专业形象,一起成为更好的营销人员。


0

custom_function is not a valid action on...

Avatar
odoo
Avatar
Discard
1 Answer
0
Avatar
odoo
Best Answer

Hi,

Please go through the Odoo documentation:

https://www.odoo.com/documentation/15.0/developer/reference/backend/orm.html#classical-inheritance

You are creating a new class through Classical inheritance(Prototype inheritance). You can't inherit the existing view in this case(You are supposed to use the new class instead of sale.order). So, create a new view for your new model.

Example

If you check the fields in 'sale.order', you can see these fields:

transaction_ids = fields.Many2many('payment.transaction',
'sale_order_transaction_rel',
'sale_order_id', 'transaction_id',
string='Transactions', copy=False,
readonly=True)
authorized_transaction_ids = fields.Many2many(
string="Authorized Transactions", comodel_name='payment.transaction',
compute='_compute_authorized_transaction_ids', readonly=True, copy=False)

The authorized_transaction_ids is a computed field which depends on the transaction_ids field. So, changing the field will cause another error. The tag_ids field is also there.

During development, if you are not intending to update any field, then please use a different name for the new fields to avoid unnecessary errors and to not break existing workflows!

Now, you are supposed to add 3 fields in 'sale.order' and a button in its form view. I have refactored the code here(please make the changes as per your requirement). I think you are adding the customization through the module "custom_addon"(based on the path in the error message.)

custom_addon/models/sale_order.py

from odoo import fields, models

class SaleOrder(models.Model):
_inherit = 'sale.order'

field_1 = fields.Char(string="Field One", required=True)
sale_order_transaction_ids = fields.Many2many(
'sale.order.transaction', 'sale_order_transaction_sale_order_rel',
'sale_order_id', 'sale_order_transaction_id',
string='Sale Order Transactions')
sale_order_tag_ids = fields.Many2many(
'sale.order.tag', 'sale_order_tag_sale_order_rel', 'sale_order_id',
'sale_order_tag_id', string='Sale Order Tags')

def action_test_function(self):
print("Test Print")
return

custom_addon/views/sale_order_views.xml

<?xml version="1.0" encoding="utf-8"?>


<odoo>


    <record id="sale_order_view_form" model="ir.ui.view">


        <field name="name">sale.order.view.form.inherit.custom_addon</field>


        <field name="model">sale.order</field>


        <field name="inherit_id" ref="sale.view_order_form"/>


        <field name="arch" type="xml">


            <xpath expr="/form/sheet/group/group[1]" position="inside">


                <button name="action_test_function" string="Test" type="object"


                        class="btn-primary"/>


            </xpath>


        </field>


    </record>


</odoo>


Ensure that you have added the python files and directories in the respective __init__.py files, added the xml files in the __manifest__.py, and added "sale_management" module in the depends list.

Regards

4 Comments
Avatar
Discard
Avatar
odoo
-

i'm trying to add a new button linked to a new function in a existing view, according to documentation I should avoid "_name" parameter if I want to add a new element or function, but still not works

Avatar
odoo
-

any help?

Avatar
odoo
-

Hi,
We have updated the answer, please check

Avatar
odoo
-

i struggled for days to look for a solution, and this finally worked, thank you so much! have a great day!