تخطي للذهاب إلى المحتوى
أودو القائمة
  • تسجيل الدخول
  • جرب مجاناً
  • التطبيقات
    المالية
    • المحاسبة
    • فوترة
    • النفقات
    • جدول البيانات (BI)
    • المستندات
    • توقيع إلكتروني
    المبيعات
    • إدارة علاقات العملاء
    • المبيعات
    • نقطة البيع للمتاجر
    • نقطة البيع للمطاعم
    • الاشتراكات
    • تأجير
    المواقع الإلكترونية
    • أداة بناء المواقع الإلكترونية
    • متاجر إلكترونية
    • مدونة
    • المنتدى
    • دردشة مباشرة
    • التعليم الإلكتروني
    سلسلة التوريد
    • المستودعات
    • التصنيع
    • إدارة دورة حياة المنتج
    • المشتريات
    • الصيانة
    • الجودة
    الموارد البشرية
    • موظفون
    • التوظيف
    • إجازة عمل
    • التقييمات
    • الإحالات
    • تطبيق الأسطول
    التسويق
    • التسويق الإجتماعي
    • التسويق عبر البريد الإلكتروني
    • التسويق عبر الرسائل النصية
    • فعاليات
    • أتمتة التسويق
    • الاستطلاعات
    الخدمات
    • المشاريع
    • الجداول الزمنية
    • الخدمة الميدانية
    • مكتب المساعدة
    • التخطيط
    • مواعيد
    اﻹنتاجية
    • مناقشة
    • الموافقات
    • إنترنت الأشياء "IoT"
    • بروتوكول ربط المحادثات الصوتية عبر الإنترنت
    • المعرفة
    • WhatsApp
    التطبيقات الخارجية ستوديو أودو منصة أودو السحابية
  • قطاعات الأعمال
    البيع بالتجزئة
    • متجر كتب
    • متجر ملابس
    • متجر أثاث
    • متجر بقالة
    • متجر معدات
    • متجر ألعاب
    الطعام والضيافة
    • بار وحانة
    • المطعم
    • مطعم للوجبات السريعة
    • نزل للضيوف
    • موزّع مشروبات
    • فندق
    العقارات
    • وكالة عقارات
    • شركة هندسة معمارية
    • البناء
    • إدارة العقارات
    • العناية بالحدائق
    • اتحاد مُلاّك العقارات
    استشارة
    • مؤسسة محاسبية
    • شريك أودو
    • وكالة تسويقية
    • منشأة قانونية
    • استقطاب المواهب
    • التدقيق والتوثيق
    التصنيع
    • الأقمشة
    • معدني
    • الأثاث
    • الطعام
    • مصنع خمور
    • هدايا الشركات
    الصحة واللياقة البدنية
    • نادي رياضي
    • متجر نظارات
    • مركز لياقة بدنية
    • الممارسون الصحيون
    • صيدلية
    • صالون تصفيف الشعر
    التجارة
    • عامل صيانة
    • الأجهزة والمعدات التقنية ودعمها
    • أنظمة الطاقة الشمسية
    • صانع أحذية
    • خدمات التنظيف
    • خدمات التكييف (HVAC)
    غير ذلك
    • منظمة غير ربحية
    • وكالة بيئية
    • تأجير لوحات إعلانية
    • تصوير
    • تأجير دراجات
    • بائع وسيط للبرمجيات
    تصفح كافة قطاعات الأعمال
  • مجتمع أودو
    تعلم
    • دروس
    • التوثيق
    • شهادات
    • التدريب
    • مدونة
    • بودكاست
    قم بتعزيز التعليم
    • برنامج تعليم
    • Scale UP! لعبة الأعمال
    • قم بزيارة أودو
    احصل على البرنامج
    • تحميل
    • قارنْ الإصدارات
    • إطلاق
    تعاون
    • جيت هاب "Github"
    • المنتدى
    • فعاليات
    • الترجمات
    • كنْ شريكاً
    • خدمات الشركاء
    • سجل مكتب المحاسبة الخاص بك
    احصل على الخدمات
    • اعثر على شريك
    • اعثر على محاسب
    • قابل أحد مرشدي الأعمال
    • خدمات التنفيذ
    • مراجع العملاء
    • الدعم
    • الترقيات
    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:

  • إدارة علاقات العملاء
  • e-Commerce
  • المحاسبة
  • المخزون
  • PoS
  • المشروع
  • MRP
All apps
يجب أن تكون مسجلاً حتى تتفاعل مع المجتمع.
كافة المنشورات الأفراد الشارات
علامات التصنيف (عرض الكل)
odoo accounting v14 pos v15
حول هذا المنتدى
يجب أن تكون مسجلاً حتى تتفاعل مع المجتمع.
كافة المنشورات الأفراد الشارات
علامات التصنيف (عرض الكل)
odoo accounting v14 pos v15
حول هذا المنتدى
المساعدة

Use Onchange on one record to change fields on other records.

اشتراك

تسلم الإشعارات عندما يكون هناك نشاط في هذا المنشور

لقد تم الإبلاغ عن هذا السؤال
saleonchangev14
2 الردود
45456 أدوات العرض
الصورة الرمزية
Dries Cox

Hello Community,
I am writing some code that changes the value of a field in all the lines of a sales order.  So if a user changed the category_id in one sale order line, other lines should be change this categ_id as well.

But for some reason this is not working. The values on other lines are not updated and stay the same like nothing happened. 

class SaleOrderLine(models.Model):
_inherit="sale.order.line"

@api.onchange('categ_id')
def _onchange_categ_id(self):
    
    for changed_line in self:
            #find all lines of the parent sale_order
             all_lines = changed_line.order_id.order_line
            vals = {'categ_id': changed_line.categ_id}
            for line in all_lines:
                line.update(vals)
    return {}

-> update to give more clarification on what the reason behind this code is.

The reason for this that, in the bigger picture, is that I can create groups of sale order lines, separated by line_sections. Each group of lines has the same categ_id, so if the categ_id of a section changes, all the lines in this section should change to the categ_id as well.

All the help is welcome.

Greetings,

1
الصورة الرمزية
إهمال
Cayprol

In that case I think it's not possible,

In the ORM API documentation,

It is not possible for a one2many or many2many field to modify itself via onchange. This is a webclient limitation - see #2693.

https://www.odoo.com/documentation/13.0/reference/orm.html

https://github.com/odoo/odoo/issues/2693

Dries Cox
الكاتب

I think you're right. That is a pity, I will have to look for an other solution.

can you change your remark to an answer so we can set that as the right answer? Thanks again for the help.

الصورة الرمزية
Dries Cox
الكاتب أفضل إجابة

Hello, I found a solution for this problem.

I changed the onchange function that happens in the line of a One2many so it sets a flag that it is changed.

Then I added a onchange function on the "order_line"-field in the order model. This onchange method is triggered as well after a line changed and it is triggered the last in line after a change in the records.

In the onchange-orderline function I check the states of the flags, reset them and preform the necessary action using a function call on the sale object. (don't know if it is necessary to do it with a function call, but I saw that in sale.order.line onchange fiscal postition)

That does the job. The lines are changed on-screen!

class SaleOrderLine(models.Model):
    _inherit="sale.order.line"

    categ_changed = fields.Boolean("technical field, do not use or show to user", default = False)

    @api.onchange('categ_id')
    def _onchange_categ_id(self)
        for line in self:
            line.categ_changed = True
        return True

    def change_categs(self, changed_lines_lst)
        for line in self
            if self.id in changed_lines_lst:
                self.categ_changed = False
                #do necessary update actions within this line
        return

class SaleOrder(models.Model):
    _inherit="sale.order"

    @api.onchange('order_line')
    def _onchange_order_line(self)
        #we need to get this from te context because object might not be the same as screen values.
        ctx_lines = self.env.context.get('order_line')
        changed_lines_lst = []
        if ctx_lines:
            for ctx_line in ctx_lines:
                if ctx_line[2]:
                    if ctx_line[2].get("categ_changed")
                        changed_lines_lst.append(ctx_line[1])

           for order in self:
                self.order_line.change_categs(changed_lines_lst)

adding context to view:
<xpath expr="//field[@name='order_line']" position="attributes">
<attribute
name="context">{"order_line": order_line}</attribute>
</xpath>


Good luck :-)
3
الصورة الرمزية
إهمال
الصورة الرمزية
Cayprol
أفضل إجابة

Update:

In that case I think it's not possible,

In the ORM API documentation,

It is not possible for a one2many or many2many field to modify itself via onchange. This is a webclient limitation - see #2693.

https://www.odoo.com/documentation/13.0/reference/orm.html

https://github.com/odoo/odoo/issues/2693


If I understand correctly,

You are trying to change a field name 'categ_id' in model 'sale.order', and you modify this field from a view in model 'sale.order', likely from view_id 'sale.view_order_form'

The expected behavior is that all 'order_line' records will have a corresponding field to be changed to the same.

If so, you don't need to use onchange, I use a Char field named 'categ_idd' as an example

class SaleOrder(models.Model): 
    _inherit = 'sale.order'
    categ_idd = fields.Char('Categ IDD')

class SaleOrderLine(models.Model):
    _inherit = 'sale.order.line'
    categ_idd = fields.Char('Categ IDD', related='order_id.categ_idd')
0
الصورة الرمزية
إهمال
Dries Cox
الكاتب

Hello, this is not really what I am looking for. It should be that categ_id is a field of the sale.order.line and if the field categ_id is changed on one line it should change on other sale.order.lines as well.

The reason for this that, in the bigger picture, i can create groups of sale order lines, separated by line_sections. Each group of lines has the same categ_id, so if the categ_id of a section changes, all the lines in this section should change as well to the same categ_id. -> I will add this explanation to my question as well this might clarify my question more. Thank you for your answer.

هل أعجبك النقاش؟ لا تكن مستمعاً فقط. شاركنا!

أنشئ حساباً اليوم لتستمتع بالخصائص الحصرية، وتفاعل مع مجتمعنا الرائع!

تسجيل
المنشورات ذات الصلة الردود أدوات العرض النشاط
Onchange not triggered when record is altered from python code تم الحل
onchange v14
الصورة الرمزية
الصورة الرمزية
1
ديسمبر 21
7089
Is there a way to create dependencies between sale order lines?
sale v14
الصورة الرمزية
الصورة الرمزية
1
أبريل 21
2624
Pause user interface during the calculation
onchange v14
الصورة الرمزية
الصورة الرمزية
2
ديسمبر 20
4881
Set UOM and precision on product without inventory module.
invoice sale v14
الصورة الرمزية
1
يونيو 21
2651
How to set a Dynamic domain in odooV14 on a One2many list?
sale domain_filter dynamic v14
الصورة الرمزية
الصورة الرمزية
1
مايو 24
7006
المجتمع
  • دروس
  • التوثيق
  • المنتدى
مصدر مفتوح
  • تحميل
  • جيت هاب "Github"
  • المشغل الآلي رنبوت
  • الترجمات
خدماتنا
  • استضافة أودو إس إتش
  • الدعم
  • الترقية
  • التطويرات المخصصة
  • التعليم
  • اعثر على محاسب
  • اعثر على شريك
  • كنْ شريكاً
معلومات عنا
  • شركتنا
  • أصول العلامة التجارية
  • اتصلْ بنا
  • الوظائف
  • فعاليات
  • بودكاست
  • مدونة
  • عملاء
  • قانوني • الخصوصية
  • الحماية
الْعَرَبيّة 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

أودو هو عبارة عن مجموعة من تطبيقات الأعمال مفتوحة المصدر التي تغطي جميع احتياجات شركتك، مثل: إدارة علاقات العملاء والتجارة الإلكترونية والمحاسبة والمخزون ونقاط البيع وإدارة المشاريع وما إلى ذلك.

ما يجعل من أودو مميزاً هو هدفه بأن يكون سهل الاستخدام للغاية ومتكاملاً تمامًا في الوقت ذاته.

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