Перейти к содержимому
Меню
Чтобы взаимодействовать с сообществом, необходимо зарегистрироваться.
Этот вопрос был отмечен
2 Ответы
3091 Представления

how i can show or print value of a field or variable to verify, i am adding Compute method on field of a model through Technical -> Models ?

i tried print() and raise userError but not working. for print() it is throwing error, said 'print' is undefined.

please guide

regards

Аватар
Отменить
Автор

any hope???

Автор

any hope of an Answer?

Лучший ответ

You cant send the info from the frontend to backend, so if you require it in logging file of Odoo that's not possible.

You could create a server action:


raise UserError(str(record.x_field_name))


1. Add server action to action button

2. Open de record where you want to see the value of the field

3. Click on 'Action > Action Name'


A pop-up will be shown with the value of the compute result.

Аватар
Отменить
Автор

i just want to debug code and see the values in log file. is it possible or not while adding field through Technical -> Models ?

if yes, then how... a very simple question.

regards

Автор

thank you @Dennis Ochse for your interest to help us. will check this.

Лучший ответ

Hi,

to add a compute field under a model, try this code, for your reference


from odoo import api, fields, models


class YourModel(models.Model):

    _name = 'your.model'


    field1 = fields.Float(string='Field 1')

    field2 = fields.Float(string='Field 2')


    computed_field = fields.Float(string='Computed Field', compute='_compute_computed_field', store=True)


    @api.depends('field1', 'field2')

    def _compute_computed_field(self):

        for record in self:

            # Your computation logic here

            result = record.field1 + record.field2


            # Set the value of the computed field

            record.computed_field = result


when we apply the 'store=True', that value will be stored in the database, and add the field in the form view or list view of the model you can see the field value, If the field value is not displayed you can use the 'force_save="1"' attribute ude the xml code


xml code here:



<odoo>

    <data>


        <!-- Tree View -->

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

            <field name="name">your.model.tree</field>

            <field name="model">your.model</field>

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

                <tree>

                    <field name="field1"/>

                    <field name="field2"/>

                    <field name="computed_field" force_save="1"/>

                </tree>

            </field>

        </record>


        <!-- Form View -->

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

            <field name="name">your.model.form</field>

            <field name="model">your.model</field>

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

                <form>

                    <group>

                        <field name="field1"/>

                        <field name="field2"/>

                        <field name="computed_field" readonly="1"/>

                    </group>

                </form>

            </field>

        </record>


        <!-- Menu Action -->

        <record id="action_your_model" model="ir.actions.act_window">

            <field name="name">Your Model</field>

            <field name="res_model">your.model</field>

            <field name="view_mode">tree,form</field>

        </record>


        <!-- Menu Item -->

        <menuitem id="menu_your_model" name="Your Model" parent="base.menu_sales" action="action_your_model"/>


    </data>

</odoo>




Regards

Аватар
Отменить
Автор

omg.... i think you failed to understand what i asked for. in a computed field which i created through Technical, in compute method how i can print / show the value of a field or a variable in log file.

hope this clear now.

Related Posts Ответы Просмотры Активность
3
февр. 24
3798
2
янв. 24
6075
2
сент. 24
2233
0
янв. 24
1613
3
мая 23
17034