Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
3 Trả lời
5037 Lượt xem

Hi,


I need to show one field of the tree view in a modal window so as to edit it conveniently rather than jumbling up in the Tree View. The code seems to run good, but "return action" does not open the form. What must I be doing wrong? Below is my code -


XML code - View


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

            <field name="name">purchase.order.line.form</field>

            <field name="model">purchase.order.line</field>

            <field name="type">form</field>

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

                <form string="Edit Description">

<!--                    <group colspan="4" >  -->

                        <field name="description" widget="html"/>

<!--                    </group>  -->

               </form>

            </field>

        </record>


XML Code - Button


<button name="edit_description" string="Edit description" type="object" icon="fa-magic"/>



Python Code:


@api.one

    def edit_description(self):

        self.description = self.name

        view_id = self.env.ref('fmcg_purchase.view_edithtml_description').id

        context = self._context.copy()

        my_view = {

            'name': 'view_edithtml_description',

            'view_type': 'form',

            'view_mode': 'form',

            'views': [(view_id, 'form')],

            'res_model': 'purchase.order.line',

            'view_id': view_id,

            'type': 'ir.actions.act_window',

            'res_id': self.id,

            'target': 'new',

            'context': context,

        }

        return my_view


I checked the values of my_view and everything appears as appropriate. However, the form doesn't open. I am using Odoo v11 CE

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

Hello

use @api.multi instead of @api.one

for eg. 

@api.multi

def edit_description(self):

    # here your code

Ảnh đại diện
Huỷ bỏ
Tác giả Câu trả lời hay nhất

Hi Mitu,

That is simply genius. Yes. It worked.

The only other problem I notice is that the data inside the "description" field is not getting saved when I click the "Save" button on the modal form. If I reopen the same row again, the changes are lost. Can you point on what could be the reason?

Ảnh đại diện
Huỷ bỏ

there are many things: (1) if the field is readonly and that field value is coming from the onchange of the another value. (2) into the form/tree view, by mistake define that field multiple times. also this is the possibility.

Tác giả

Hi Mitul, thanks again for responding to my question. Actually, neither is the case. This field is a new field I created in my module. Not readonly, no compute, onchange methods, also, the code I shared is the only place it appears in my XML.

Bài viết liên quan Trả lời Lượt xem Hoạt động
2
thg 9 23
8101
1
thg 5 19
6392
3
thg 10 18
19551
1
thg 10 16
10709
4
thg 12 23
13431