Ir al contenido
Menú
Se marcó esta pregunta
3 Respuestas
139 Vistas

Hello,

On the Partner record under the Sales & Purchase tab, the field property_account_position_id (Fiscal Position) is currently visible to all users in the Sales and Accounting groups — except those in the Accounting Read-Only group.

I would like to adjust the access as follows:

  • Accounting users (e.g. Accountant, Accounting Manager) → Editable
  • Sales usersInvisible or Read-only

What is the recommended way to configure this behavior (via XML, Studio, or access rules)?

Thank you in advance.

Avatar
Descartar
Autor Mejor respuesta

Thank you for the answers. Using Odoo Online I believe I cannot edit Python Code but xml? Could you please describe me how to access the code?

Avatar
Descartar
Mejor respuesta

Hi,

Odoo's best practice for controlling field visibility/editability per group is via XML view customization — using the groups attribute (to restrict visibility to groups), and attrs for making the field read-only dynamically.

Hide/Make Read-Only for Sales users:

<field name="property_account_position_id"

       groups="account.group_account_user,account.group_account_manager"

       attrs="{'readonly': [('groups_id', 'not in', [ref('account.group_account_manager'), ref('account.group_account_user')])]}" />


The field is only shown to users in the Accounting groups via groups attribute.

It is read-only for users who are not in those groups.

Sales users won't see it (if they're not part of accounting groups).

This method keeps the logic clean and group-based, and doesn't require creating custom boolean fields or computed conditions.


i hope it is usefull

Avatar
Descartar
Mejor respuesta

Hi,

Please refer to the code below:

Python

from odoo import models, fields, api

class ResPartner(models.Model):
_inherit = 'res.partner'

is_account_user = fields.Boolean(
string="Is Accounting User",
compute='_compute_is_account_user',
store=False
)

@api.depends_context('uid')
def _compute_is_account_user(self):
for record in self:
user = self.env.user
record.is_account_user = user.has_group('account.group_account_user') or user.has_group('account.group_account_manager')

XML:

<record id="view_partner_form" model="ir.ui.view">
<field name="name">res.partner.view.form</field>
<field name="model">res.partner</field>
<field name="inherit_id" ref="base.view_partner_form"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='property_account_position_id']"
position="before">
<field name="is_account_user" invisible="1"/>
</xpath>
<xpath expr="//field[@name='property_account_position_id']"
position="attributes">
<attribute name="readonly">not is_account_user</attribute>
</xpath>
</field>
</record>

Hope it helps.

Avatar
Descartar
Publicaciones relacionadas Respuestas Vistas Actividad
0
jun 21
2777
1
dic 22
4502
2
ene 22
3770
1
feb 21
3124
6
nov 19
62866