Skip to Content
Odoo Меню
  • Увійти
  • Спробуйте це безкоштовно
  • Додатки
    Фінанси
    • Бухоблік
    • Виставлення рахунку
    • Витрати
    • Електронні таблиці (BI)
    • Документи
    • Підпис
    Продажі
    • CRM
    • Продажі
    • POS Магазин
    • POS Ресторан
    • Підписки
    • Оренда
    Веб-сайти
    • Конструктор веб-сайту
    • Електронна комерція
    • Блог
    • Форум
    • Живий чат
    • Електронне навчання
    Ланцюг поставок
    • Склад
    • Виробництво
    • PLM
    • Купівлі
    • Технічне обслуговування
    • Якість
    Кадри
    • Співробітники
    • Рекрутинг
    • Відпустки
    • Оцінювання
    • Рекомендації
    • Автотранспорт
    Маркетинг
    • Маркетинг соцмереж
    • Email-маркетинг
    • SMS-маркетинг
    • Події
    • Автом. маркетингу
    • Опитування
    Послуги
    • Проект
    • Табелі
    • Виїзне обслуговування
    • Служба підтримки
    • Планування
    • Призначення
    Продуктивність
    • Обговорення
    • Схвалення
    • IoT
    • IP-телефонія
    • База знань
    • WhatsApp
    Сторонні модулі Odoo Studio Платформа Odoo Cloud
  • Сфери
    Роздрібна торгівля
    • Книжковий магазин
    • Магазин одягу
    • Магазин меблів
    • Продуктовий магазин
    • Магазин будівельних матеріалів
    • Магазин іграшок
    Food & Hospitality
    • Бар та паб
    • Ресторан
    • Фастфуд
    • Guest House
    • Дистриб'ютор напоїв
    • Hotel
    Нерухомість
    • Real Estate Agency
    • Архітектурна фірма
    • Будівництво
    • Управління нерухомістю
    • Садівництво
    • Асоціація власників нерухомості
    Консалтинг
    • Бухгалтерська компанія
    • Партнер Odoo
    • Агенція маркетингу
    • Юридична фірма
    • Придбання Талантів
    • Аудит та сертифікація
    Виробництво
    • Textile
    • Metal
    • Меблі
    • Їжа
    • Brewery
    • Корпоративні подарунки
    Здоров'я & Фітнес
    • Спортивний клуб
    • Оптика
    • Фітнес-центр
    • Практики здоров'я
    • Аптека
    • Салон краси
    Trades
    • Ремонтник
    • IT-обладнання та Підтримка
    • Системи сонячної енергії
    • Shoe Maker
    • Cleaning Services
    • HVAC Services
    Інші
    • Nonprofit Organization
    • Екологічна агенція
    • Оренда білбордів
    • Фотографія
    • Лізинг велосипедів
    • Реселлер програмного забезпечення
    Browse all Industries
  • Спільнота
    Навчання
    • Навчальний посібник
    • Документація
    • Сертифікації
    • Тренування
    • Блог
    • Подкаст
    Сприяйте Освіті
    • Програма навчання
    • Бізнес гра Scale Up!
    • Відвідайте Odoo
    Отримайте програмне забезпечення
    • Завантаження
    • Порівняйте версії
    • Релізи
    Співпрацюйте
    • Github
    • Форум
    • Події
    • Переклади
    • Стати партнером
    • Services for Partners
    • Зареєструйте вашу бухгалтерську фірму
    Отримайте послуги
    • Знайдіть партнера
    • Знайдіть бухгалтера
    • Зустріньтеся з консультантом
    • Послуги з впровадження
    • Референси клієнтів
    • Підтримка
    • Оновлення
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Отримати демо
  • Ціни
  • Допомога

Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:

  • CRM
  • e-Commerce
  • Бухоблік
  • Склад
  • PoS
  • Проект
  • MRP
All apps
Вам необхідно зареєструватися, щоб взаємодіяти зі спільнотою.
All Posts Люди Значки
Мітки (View all)
odoo accounting v14 pos v15
Про цей форум
Вам необхідно зареєструватися, щоб взаємодіяти зі спільнотою.
All Posts Люди Значки
Мітки (View all)
odoo accounting v14 pos v15
Про цей форум
Допомога

M2m attachment field issue in Odoo 16 CE: creator can access, but others cannot

Підписатися

Отримуйте сповіщення про активність щодо цієї публікації

Це запитання позначене
many2manym2mattachmentsAccessErrorodoo16features
4 Відповіді
5828 Переглядів
Аватар
Nisanth N

Hi there,

I'm having an issue with m2m attachment in Odoo 16 CE. I've created a custom module that includes an m2m attachment field. The creator of the record can access the document, while other users cannot and receive an error message that says "Sorry, you are not allowed to access this document." If I save the record first and attach it, no issues are found. However, there are no record rules or access rules defined. I tested this in multiple environments including fresh odoo16 instant. When I searched for a solution to this issue, I found a similar bug with mail_template and fixed it with a _fix_attachment_ownership function in the creation of the record. (addons/mail/models/mail_template.py)

Does anyone else have this issue with m2m attachment in other models, or did I do something wrong?

Any help is highly appreciated.


my class is :

class EmployeeApproval(models.Model):
_name = 'employee.approval.info'
_rec_name = 'employee_id'
_inherit = ['mail.thread']
_description = 'Employee Approval Info'


employee_id = fields.Many2one(comodel_name='hr.employee', string="Employee", ondelete='cascade',help='Select corresponding Employee')
attachment_id = fields.Many2many('ir.attachment', 'approval_attachment_rel', 'approval_ref',
'attach_ref1',
string="Attachment(pdf)",
help='Attach any documents if required.')


0
Аватар
Відмінити
Аватар
Alberto Mastini
Найкраща відповідь

Hello,

can you please give more informations about the error? Maybe you can copy and paste it.

1
Аватар
Відмінити
Nisanth N
Автор

Actually, it's falling to the raise error.

When debugging odoo\addons\base\models\ir_attachment.py Line:456

if not self.env.is_system() and (res_field or (not res_id and create_uid != self.env.uid)):
raise AccessError(_("Sorry, you are not allowed to access this document."))

In my case, if I create the record and then attach the document, the res_id is 0. However, if I save the record first and then attach the document, the res_id becomes the record ID

Alberto Mastini

Maybe you can trying to override the create of your record and forcely set the res_id to be the same as the Record Id. Let me know if can work for you!

Nisanth N
Автор

I was able to find a solution by adapting the method from mail_template.py line 137, which includes the following code:

def _fix_attachment_ownership(self):
for record in self:
record.attachment_ids.write({'res_model': record._name, 'res_id': record.id})
return self

@api.model_create_multi
def create(self, vals_list):
return super().create(vals_list). _fix_attachment_ownership()

Thanks, Alberto.

Alberto Mastini

No problem, happy to be helpful!

Have a good one

Аватар
Eslam Saber
Найкраща відповідь

i have the exact same issue with a third party app but i don't know where should i add this lines and the developer don't respond currently

0
Аватар
Відмінити
Аватар
Ghulam Murtaza
Найкраща відповідь

I am facing the same issue when I create a record with an attachment file (ir.attachment) and save it. this record does not open from another account error shows 

Sorry, you are not allowed to access this document.

anyone can help how I can resolve this issue in odoo 16?

Support will be highly appreciated 

Thanks 

0
Аватар
Відмінити
Аватар
Andro Chvertkini
Найкраща відповідь

By default, attachment is not "public" therefore only the creator can access it. You can manually set public = True when you create your attachments or think about a better security solution.

https://github.com/odoo/odoo/blob/16.0/odoo/addons/base/models/ir_attachment.py#L404

0
Аватар
Відмінити
Nisanth N
Автор

As I mentioned earlier, if I attach the documents after saving the record, then the record becomes accessible to others. I think, initially, res_id is not being saved at the moment the record is created.

Enjoying the discussion? Don't just read, join in!

Create an account today to enjoy exclusive features and engage with our awesome community!

Реєстрація
Related Posts Відповіді Переглядів Дія
Singleton error for Odoo 16 in action Вирішено
many2many singleton odoo16features
Аватар
Аватар
Аватар
2
бер. 24
2456
Can supports be attached in inventory adjustments in Odoo 16? Вирішено
attachments odoo16features InventoryAdjustment
Аватар
Аватар
2
бер. 24
2068
Assistance Needed for Bulk Attachment Import in Odoo Helpdesk
attachments Helpdesk odoo16features
Аватар
Аватар
1
лист. 23
2378
[SOLVED] How to make visible selected values in many2one or many2many fields on Settings page in Odoo 16 Вирішено
many2one many2many odoo16features
Аватар
Аватар
Аватар
3
груд. 23
7358
How to filter records based on a parent field's id Вирішено
many2many filter_domain odoo16features
Аватар
Аватар
2
бер. 23
3821
Спільнота
  • Навчальний посібник
  • Документація
  • Форум
Open Source
  • Завантаження
  • Github
  • Runbot
  • Переклади
Послуги
  • Хостинг Odoo.sh
  • Підтримка
  • Оновлення
  • Кастомні доробки
  • Навчання
  • Знайдіть бухгалтера
  • Знайдіть партнера
  • Стати партнером
Про нас
  • Наша компанія
  • Торгові активи
  • Зв'яжіться з нами
  • Вакансії
  • Події
  • Подкаст
  • Блог
  • Клієнти
  • Юридичні документи • Конфіденційність
  • Безпека
الْعَرَبيّة Català 简体中文 繁體中文 (台灣) Čeština Dansk Nederlands English Suomi Français Deutsch हिंदी Bahasa Indonesia Italiano 日本語 한국어 (KR) Lietuvių kalba Język polski Português (BR) română русский язык Slovenský jazyk slovenščina Español (América Latina) Español ภาษาไทย Türkçe українська Tiếng Việt

Odoo - це набір програм для роботи з відкритим кодом, які охоплюють всі ваші потреби компанії: CRM, електронна комерція, бухгалтерський облік, склад, точка продажу, управління проектами тощо.

Унікальна пропозиція Odoo - це одночасно дуже проста у використанні та повністю інтегрована.

Website made with

Odoo Experience on YouTube

1. Use the live chat to ask your questions.
2. The operator answers within a few minutes.

Live support on Youtube
Watch now