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

How to get a field value from another model in odoo 13?

Subscribe

Get notified when there's activity on this post

This question has been flagged
inheritancemodelsOdoo13.0
1 Reply
6457 Views
Avatar
ARJUN BAIDYA

I have two model and code is given below 


class SellProduct (models.Model):
_name = 'sell.product'
_rec_name = 'product_seq'
# def product (self): # name = self.env ['product.create']. search ([]) # print (name ) product_seq = fields.Many2one ( comodel_name = "product.create" , string = "Product ID" , required = False ,) product_name = fields.Char ( related = 'product_seq.product_name' , string = "Product Name" ,required = False ,)






sell_product_quantity = fields.Integer ( string = "Product Quantity" , required = True ,)
gold_price_new = fields.Integer ( string = "Total Price" , compute = 'compute_price' , store = True ,)

payment = fields.Integer ( string = "Payment" )
due_amount = fields.Integer (string = "Due" , compute = 'due_compute' , store = True )
company_id = fields.Many2one ( 'res.company' , 'Company' , required = True , index = True ,
default = lambda self: self.env.company .id)
currency_id = fields.Many2one ( "res.currency" , string = "Currency" , readonly = True ,
default = lambdaself: self.env.company.currency_id.id, required = True )

sell_line = fields.Many2one ( comodel_name = "product.create" , string = "Sell Line" , required = False ,)





class ProductCreate (models.Model):
_name = 'product.create'
_inherit = [ 'mail.thread' , 'mail.activity.mixin' ,]
_rec_name = 'product_seq'
@ api.depends ( 'create_sell_line' , 'create_sell_line. sell_product_quantity ' ) def update_value ( self ): for rec in self : rec.product_quantity_new = rec.create_sell_line.sell_product_quantity product_seq = fields.Char ( string = ' PID ' ,required =





True , copy = False ,
randomly = True , index = True ,
default = lambda self: _ ( 'New' ))
product_name = fields.Char ( string = "Product Name" )
product_image = fields.Binary ( string = "Product Image " )
product_quantity_new = fields.Integer ( compute = 'update_value' )
product_quantity = fields.Integer ( string = "Product Quantity" ,)
gold_quality = fields.Selection ( string = "Gold Quality" , selection = [( '18k' , '18K' ), ( '21k' , '21K' ), ( '22k' , '22K' )],
required = True ,)
gold_rate = fields.Integer ( string = "Gold Rate" )
gold_weight = fields.Float ( string = "Weight / Gram" , required = True )
making_cost = fields.Integer ( string = " Making Cost")
gold_price = fields.Integer ( string = "Sub-total Price" , compute = 'compute_sub_total_price' , store = True )
tax = fields.Integer ( string = "Tax" , )
tax_cal = fields.Integer ( string = "tax Calculation" , compute = 'compute_tax' , store = True )
total_cost = fields.Integer ( string= "Total Price" , compute = 'compute_total_price' , store = True )

create_sell_line = fields.One2many ( comodel_name = "sell.product" , inverse_name = "sell_line" , string = "create sell line" ,
required = False ,)


Fom  sell.product model, sell_product_quantity field's value will be store product.create model's prouct_quantity_new field
How to solve this problem?

0
Avatar
Discard
Avatar
Begineer
Best Answer

Hi Arjun,

        I guess  "sell.product"  model is given as one2many  to  "product.create",  so you must take the sum of the values of sell_product_quantity  and store it in  "prouct_quantity_new" .

So just try,

class ProductCreate(models.Model): 

    _name = 'product.create' 

    @api.multi

    @api.depends('create_sell_line', 'create_sell_line.sell_product_quantity')

    def update_value(self):

        for each in self:

            each.product_quantity_new = sum(line.sell_product_quantity for line in each.create_sell_line)

 Hope it helps,

Thanks





0
Avatar
Discard
ARJUN BAIDYA
Author

Thank you sir for your answer.

But it is not working.

Actually Firstly I create a product in product.create model here has a unique ID for each product.

After that in the sell.product model here I will sell that product by selecting product ID and here I give product quantity. Suppose when I created product product quantity was 30 now I will sell 20 after that my product is 10?

Kindly see this and if you can solve this problem kindly

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
Can't add a new field inside inherited model even with server restart
inheritance Odoo13.0
Avatar
Avatar
Avatar
2
Jun 23
5212
Setting a computed default value on a field Solved
inheritance models defaultvalues
Avatar
1
Aug 23
5142
How to show children elements in parent form view?
treeview inheritance models
Avatar
0
Apr 23
3759
Accessing a value from another model
inheritance values models
Avatar
Avatar
1
Dec 21
5813
inherit 'account.move' and creating a new object 'accouont.move.oi' Solved
inheritance account.move Odoo13.0
Avatar
Avatar
1
Sep 21
6393
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