Skip to Content
Odoo Menu
  • Sign in
  • Try it free
  • Apps
    Finance
    • Accounting
    • Invoicing
    • Expenses
    • Spreadsheet (BI)
    • Documents
    • Sign
    Sales
    • CRM
    • Sales
    • POS Shop
    • POS Restaurant
    • Subscriptions
    • Rental
    Websites
    • Website Builder
    • eCommerce
    • Blog
    • Forum
    • Live Chat
    • eLearning
    Supply Chain
    • Inventory
    • Manufacturing
    • PLM
    • Purchase
    • Maintenance
    • Quality
    Human Resources
    • Employees
    • Recruitment
    • Time Off
    • Appraisals
    • Referrals
    • Fleet
    Marketing
    • Social Marketing
    • Email Marketing
    • SMS Marketing
    • Events
    • Marketing Automation
    • Surveys
    Services
    • Project
    • Timesheets
    • Field Service
    • Helpdesk
    • Planning
    • Appointments
    Productivity
    • Discuss
    • Approvals
    • IoT
    • VoIP
    • Knowledge
    • WhatsApp
    Third party apps Odoo Studio Odoo Cloud Platform
  • Industries
    Retail
    • Book Store
    • Clothing Store
    • Furniture Store
    • Grocery Store
    • Hardware Store
    • Toy Store
    Food & Hospitality
    • Bar and Pub
    • Restaurant
    • Fast Food
    • Guest House
    • Beverage Distributor
    • Hotel
    Real Estate
    • Real Estate Agency
    • Architecture Firm
    • Construction
    • Estate Management
    • Gardening
    • Property Owner Association
    Consulting
    • Accounting Firm
    • Odoo Partner
    • Marketing Agency
    • Law firm
    • Talent Acquisition
    • Audit & Certification
    Manufacturing
    • Textile
    • Metal
    • Furnitures
    • Food
    • Brewery
    • Corporate Gifts
    Health & Fitness
    • Sports Club
    • Eyewear Store
    • Fitness Center
    • Wellness Practitioners
    • Pharmacy
    • Hair Salon
    Trades
    • Handyman
    • IT Hardware & Support
    • Solar Energy Systems
    • Shoe Maker
    • Cleaning Services
    • HVAC Services
    Others
    • Nonprofit Organization
    • Environmental Agency
    • Billboard Rental
    • Photography
    • Bike Leasing
    • Software Reseller
    Browse all Industries
  • Community
    Learn
    • Tutorials
    • Documentation
    • Certifications
    • Training
    • Blog
    • Podcast
    Empower Education
    • Education Program
    • Scale Up! Business Game
    • Visit Odoo
    Get the Software
    • Download
    • Compare Editions
    • Releases
    Collaborate
    • Github
    • Forum
    • Events
    • Translations
    • Become a Partner
    • Services for Partners
    • Register your Accounting Firm
    Get Services
    • Find a Partner
    • Find an Accountant
    • Meet an advisor
    • Implementation Services
    • Customer References
    • Support
    • Upgrades
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Get a demo
  • Pricing
  • Help

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

  • CRM
  • e-Commerce
  • Accounting
  • Inventory
  • PoS
  • Project
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Tags (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Tags (View all)
odoo accounting v14 pos v15
About this forum
Help

Odoo11 - onChange - Update copy/duplicate field to other model.

Subscribe

Get notified when there's activity on this post

This question has been flagged
many2manycopyduplicateonchange_eventodoo11
1 Reply
8837 Views
Avatar
Gabriel
Hello everyone,
 I have two models product_template  and sale_order_line.
In the product_template template I have some fields that are characteristic
of this product this field calls product characteristic

class productCharacteristcs (models.Model):
   _inherit = 'product.template'
   caractheristic_product = fields.Many2many (comodel_name = 'caracteristic.product.')
In my model sale_order_line there is this same field, but now it is 
related to another table, which may or may not be different for each sale. 
​
saleProductCharacteristcs (models.Model):
   _inherit = 'sale.order.line
   sale_caractheristic_product = fields.Many2many (comodel_name = 'sale.caracteristic.product.')

I would like the event onchange to automatically populate sale.order.line but 
based on the product information and change as i like

I found information like this: self.update ({ 'attendance_line': [(0, 0, {values})], }) But I tried here and unfortunately it was unsuccessful


0
Avatar
Discard
Avatar
Waleed Ali Mohsen
Best Answer

Hi, if I understand you correctly, you can try the below:

You already in sale.order.line model and you want to use onchange for sale_caractheristic_product field to populate sale line data

So you can use the below:

@api.onchange('sale_caractheristic_product ')
def _onchange_sale_caractheristic_product (self):
//Do you check here to retrieve the required data //Set values to sale line  
self.product_id = 
self.product_uom_qty =
..
etc
0
Avatar
Discard
Gabriel
Author

Hi, unffortily wont work.

What i want to do is, grab product caracteristics and use it on sale_product_caracteristc,.

If i change sale_product_caracterist i wont it change on product_caracteristcs.

Waleed Ali Mohsen

You will use something like that:

self.update({'move_line_ids': [(0, 0, {

'product_id': self.product1.id,

'product_uom_id': self.uom_unit.id,

'qty_done': 2,

'product_uom_qty': 0,

'lot_id': False,

'package_id': False,

'result_package_id': False,

'location_id': move1.location_id.id,

'location_dest_id': move1.location_dest_id.id,

})]})

Gabriel
Author

Hi, that was perfect.. but i need one last help :/

I'm trying insert multiples lines, when i use a for, like

for x in move_line_ids:

It will just show the last line, the cursor pass over the first,secound, etc, but only show the last one.

Some Tip?

Waleed Ali Mohsen

Yes, it will show only the last one so you have to have a loop and append all line into list and then assigned it to your ids in update method as below:

You can do something like this:

update = []

for record in data.order_line:

update.append((0, 0, {

'product_id': record.product_id.id,

'product_uom': record.product_uom.id,

'order_id': record.order_id.id,

'name': record.name,

'product_qty': record.product_uom_qty,

'price_unit': record.price_unit,

'taxes_id': False,

'product_subtotal': record.price_subtotal,

'analytic_account_id': record.order_id.analytic_account_id.id,

}))

self.update({'new_order_line_ids': update})

Gabriel
Author

Last 2 question i promisse...

If a field, integer, its not show in the many2many table widget, it wont be update corret? even if i got:

update.append((0, 0, {

'product_id': record.product_id.id, -- Show field in the table

'numeric_field': record.product_id.numeric_field.id, -- Not show field in the widget table

}))

If inside the order_line_id i got a field many2one i wont be able to update that to?

update.append((0, 0, {

'product_id': record.product_id.id,

'attributes': record.product_id.ids, -- this field is many2many

}))

Even if this case i use something like

'attributes': ((0,0{'id':1})),

I promisse i will compile every information and make a anser in the end :P

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

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

Sign up
Related Posts Replies Views Activity
Add column to a many2many rel table Solved
many2many odoo11
Avatar
Avatar
1
Nov 19
6077
Why my custom copy button functionality is not working?
copy duplicate
Avatar
0
Apr 15
4303
how to format mapped() result Solved
many2many mapping odoo11
Avatar
Avatar
2
Jun 20
12471
Problem with M2M Fields Solved
many2many problem odoo11
Avatar
Avatar
Avatar
2
Nov 18
7042
Copying Many2many field values to another Many2many field
fields many2many copy
Avatar
0
May 16
6849
Community
  • Tutorials
  • Documentation
  • Forum
Open Source
  • Download
  • Github
  • Runbot
  • Translations
Services
  • Odoo.sh Hosting
  • Support
  • Upgrade
  • Custom Developments
  • Education
  • Find an Accountant
  • Find a Partner
  • Become a Partner
About us
  • Our company
  • Brand Assets
  • Contact us
  • Jobs
  • Events
  • Podcast
  • Blog
  • Customers
  • Legal • Privacy
  • Security
الْعَرَبيّة 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 is a suite of open source business apps that cover all your company needs: CRM, eCommerce, accounting, inventory, point of sale, project management, etc.

Odoo's unique value proposition is to be at the same time very easy to use and fully integrated.

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