跳至内容
菜单
此问题已终结

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.

形象
丢弃
编写者 最佳答案

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?

形象
丢弃
最佳答案

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

形象
丢弃
最佳答案

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.

形象
丢弃
相关帖文 回复 查看 活动
0
6月 21
2900
1
12月 22
4628
2
1月 22
3933
1
2月 21
3275
6
11月 19
63031