Skip to Content
Meniu
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
Această întrebare a fost marcată
3 Răspunsuri
2970 Vizualizări

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 

Imagine profil
Abandonează

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 ?

Autor

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)

Autor Cel mai bun răspuns

is had the error

Imagine profil
Abandonează

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

Autor

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

Cel mai bun răspuns

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

Imagine profil
Abandonează

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

Autor

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.

Autor

not working

Cel mai bun răspuns

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

Imagine profil
Abandonează
Autor

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"

Related Posts Răspunsuri Vizualizări Activitate
2
feb. 23
1801
2
sept. 15
5421
1
mar. 15
3602
1
feb. 24
1768
0
ian. 24
1767