Přejít na obsah
Menu
You need to be registered to interact with the community.
This question has been flagged
3 Odpovědi
349 Zobrazení

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
Zrušit
Autor Nejlepší odpověď

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
Zrušit
Nejlepší odpověď

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
Zrušit
Nejlepší odpověď

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
Zrušit
Related Posts Odpovědi Zobrazení Aktivita
0
čvn 21
2861
1
pro 22
4573
2
led 22
3822
1
úno 21
3225
6
lis 19
62959