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
    • Real Estate Agency
    • Архітектурна фірма
    • Будівництво
    • Управління нерухомістю
    • Садівництво
    • Асоціація власників нерухомості
    Consulting
    • Accounting Firm
    • Партнер Odoo
    • Marketing Agency
    • Юридична фірма
    • Придбання Талантів
    • Аудит та сертифікація
    Виробництво
    • Textile
    • Metal
    • Furnitures
    • Food
    • Brewery
    • Корпоративні подарунки
    Здоров'я & Фітнес
    • Спортивний клуб
    • Оптика
    • Фітнес-центр
    • Практики здоров'я
    • Аптека
    • Салон краси
    Trades
    • Ремонтник
    • IT-обладнання та Підтримка
    • Solar Energy Systems
    • Shoe Maker
    • Cleaning Services
    • HVAC Services
    Others
    • 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
Про цей форум
Допомога

How can I get data from the rows being created in a list view before saving?

Підписатися

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

Це запитання позначене
one2manycreateaccess
2 Відповіді
17735 Переглядів
Аватар
Pablo

Is there any way to access to the items beign added in a list view before saving the form and writing them?

Scenario:

product.product has a o2m relation (packaging field) with product.packaging. If I edit a product in its form view and add a packaging, is there any way to access to all the packaging rows (the ones it had previously and those not saved yet) before saving the product form?

Edit: The moment I need to retrieve the data of the unsaved rows is when adding a new row. I need to set a default value for a field in the new row taking into account the previous packagings the product has, whether they are saved or beign just added.

Thanks in advance

2
Аватар
Відмінити
Pablo
Автор

Finally I have found the solution. I share it here for future reference in case someone comes up with the same problem, see answer below.

Аватар
Sudhir Arya (ERP Harbor Consulting Services)
Найкраща відповідь

You can override create method. create method called each time when you save the records.

def create(self, cr, uid, vals, context=None):
    #Your code
    create_id = super(your_class_name, self).create(cr, uid, vals, context=context)
    #Your code
    return create_id

In vals you can find values of all the fields you have filled.


You can override write method. write method called each time when you update the records.

def write(self, cr, uid, ids, vals, context=None):
    #Your code
    res = super(your_class_name, self).write(cr, uid, ids, vals, context=context)
    #Your code
    return res

In vals you can find values of all the fields you are updating.

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

Sorry, I'll change the question to be more explicit. I meant even before going to save those values. When I add a new row, I need to be "conscious" of the previously added rows, whether they are saved.

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

You can access to all the rows (even those unsaved) when you add a new one passing the one2many field in the context or as a parameter instead of browsing for it using the orm. If the moment you need to access to them is when a field of the form changes, you can follow the instructions shown here:

doc.openerp.com/trunk/developers/server/06_misc_on_change_tips/

In this case you need to pass the o2m field as a paramter. On the other hand, if the moment is when generating the default value for a field of a record beign added, you can pass this information using the context (I had to add the context attribute to an existing view):

<xpath expr="/form/sheet/notebook/page[@string='Sales']/field[@name='packaging']" position="attributes"> <attribute name="context">{'prod_id': id, 'pack': packaging}</attribute> </xpath>

And then retrieve it on the function you defined to calculate the default value:

def _dfl_ean(self, cr, uid, context=None): prod_id = context.get('prod_id',False) packaging = context.get('pack', False)

I hope it helps!

3
Аватар
Відмінити
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 Відповіді Переглядів Дія
Can not replicate one2many field of one model to other model. Вирішено
one2many create
Аватар
2
квіт. 20
4859
[8.0] Error saving one2many when edit before save.
one2many create
Аватар
Аватар
1
лист. 17
5124
Best way to create one2many records in backend
one2many create update
Аватар
0
лист. 22
4923
one2many update() vs self.env[]
one2many create api
Аватар
0
лип. 21
4515
Failing to write Many2one field Вирішено
one2many create relationfield
Аватар
Аватар
1
лют. 19
4492
Спільнота
  • Навчальний посібник
  • Документація
  • Форум
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