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
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
- CRM
- e-Commerce
- 会計
- 在庫
- PoS
- Project
- MRP
この質問にフラグが付けられました
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 name="view_mode">form</field>
<field name="domain">[('parent_id', '=', env.user.company_id.partner_
</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"
up
関連投稿 | 返信 | ビュー | 活動 | |
---|---|---|---|---|
|
2
2月 23
|
1752 | ||
|
2
9月 15
|
5331 | ||
|
1
3月 15
|
3549 | ||
|
1
2月 24
|
1697 | ||
|
0
1月 24
|
1695 |
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)