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

Hello , 
I want to open the form view (from the menu item) to edit the company that the current user is authenticated.
that's mean the res.partner that equal to partner.parent_id 


I use odoo 17 

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

Your question seem odd, correct me if i'm wrong. You want the current user (the one who logged in) only be able to edit his/her company (res.partner) and can not edit any other company beside his/hers ?

Tác giả

Yes, but nott that only i want that he can do that from a button in menu item with an action to a form view (without open a tree view)

Tác giả Câu trả lời hay nhất

is had the error

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

What error did you get? Give the stack trace and the your code

Tác giả

This is my code

<odoo>

<record id="view_company_form" model="ir.ui.view">
<field name="name">company_form</field>
<field name="model">res.partner</field>
<field name="arch" type='xml'>
<form>
<sheet>
<group>
<field name="name"></field>
<field name="description"></field>
</group>
</sheet>
</form>
</field>
</record>

<record id="update_portfolio_decription_action" model="ir.actions.server">
<field name="name">Open Company Form</field>
<field name="model_id" ref="res.partner"/>
<field name="binding_model_id" ref="res.partner"/>
<field name="binding_view_types">form</field>
<field name="view_id" ref="view_company_form"/>
<field name="state">code</field>
<field name="code">model.open_company_form()</field>
</record>

<menuitem
id="portfolio_decription_menu_item"
name="Portfolio Decription"
parent="portfolio_decription_root_menu"
action="update_portfolio_decription_action"
/>

</odoo>

@api.model
def open_company_form(self):
form_view_id = self.env.ref('base.view_company_form').id
return {
'type': 'ir.actions.act_window',
'name': 'Company Form',
'res_model': 'res.partner',
'res_id': self.env.user.partner_id.id,
'view_mode': 'form',
'view_id': form_view_id,
'target': 'current',
}

Câu trả lời hay nhất

Hi,

Try this

Python:


from odoo import models, fields, api

class CustomModel(models.Model):
​_name = "custom.model"

@api.model
​​def open_company_form(self):
​form_view_id = ​self.env.ref('base.view_company_form').id
​return {
​'type': 'ir.actions.act_window',
​'name': 'Company Form',
​'res_model': 'res.company',
​'res_id': self.env.company.id,
​'view_mode': 'form',
​'view_id': form_view_id,
​'target': 'current',​
​}

XML code to call python method from menu item in comments.


Check this and let me know

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

XML:

<record id="server_action_open_company_form" model="ir.actions.server">
<field name="name">Open Company Form</field>
<field name="model_id" ref="model_custom_model"/>
<field name="state">code</field>
<field name="code">action = model.open_company_form()</field>
</record>


<menuitem id="menu_server_action_open_company" action="server_action_open_company_form" sequence="5"/>

Tác giả

I had this error when I try your code
raise ParseError('while parsing %s:%s, somewhere inside\n%s' % (
odoo.tools.convert.ParseError: while parsing /mnt/...._view.xml:36, somewhere inside
<record id="server_action_open_company_form" model="ir.actions.server">
<field name="name">Open Company Form</field>
<field name="model_id" ref="model_custom_model"/>
<field name="state">code</field>
<field name="code">action = model.open_company_form()</field>
</record>

Try this:
<record id="server_action_open_company_form" model="ir.actions.server">
<field name="name">Open Company Form</field>
<field name="model_id" ref="custom_module.model_custom_model"/>
<field name="binding_model_id" ref="custom_module.model_custom_model"/>
<feld name="binding_view_types">form</field>
<field name="state">code</field>
<field name="code">action = model.open_company_form()</field>
</record>

I have also updated my original answer.

Tác giả

not working

Câu trả lời hay nhất

Hi,

Try like this
<record id="menu_partner_edit" model="ir.ui.menu">
    <field name="name">Edit Company</field>
    <field name="action" ref="action_partner_edit"/>
</record>

<record id="action_partner_edit" model="ir.actions.act_window">
    <field name="name">Edit Company</field>
<field name="res_model">res.partner</field>
    <field name="view_mode">form</field>
<field name="domain">[('parent_id', '=', env.user.company_id.partner_id.id)]</field>
</record>


Hope it helps

Ảnh đại diện
Huỷ bỏ
Tác giả

it show me this error
"EvalError: Can not evaluate python expression: ([('parent_id', '=', env.user.company_id.partner_id.id)])
Error: Name 'env' is not defined"

Bài viết liên quan Trả lời Lượt xem Hoạt động
2
thg 2 23
1812
2
thg 9 15
5441
1
thg 3 15
3616
1
thg 2 24
1781
0
thg 1 24
1777