コンテンツへスキップ
メニュー
この質問にフラグが付けられました
3 返信
2783 ビュー

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 

アバター
破棄

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 ?

著作者

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)

著作者 最善の回答

is had the error

アバター
破棄

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

著作者

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',
}

最善の回答

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

アバター
破棄

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"/>

著作者

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.

著作者

not working

最善の回答

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

アバター
破棄
著作者

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"

関連投稿 返信 ビュー 活動
2
2月 23
1752
2
9月 15
5331
1
3月 15
3549
1
2月 24
1697
0
1月 24
1695