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

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.

관련 게시물 답글 화면 활동
3
2월 24
3890
2
1월 24
6193
2
9월 24
2315
0
1월 24
1671
3
5월 23
17088