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

Adding value to custom field

Subscribe

Get notified when there's activity on this post

This question has been flagged
updateproduct_id
3 Replies
5828 Views
Avatar
rudyanto santoso

I allready made a modul to create field base_price at sales order line, now I want to fill that field with list_price from product template and change everytime product_id change, how to write a modul for that purpose.

I wrote this modul for trial , but didn't work.

this is modul to create field base_price

from openerp.osv import orm, fields

import openerp.addons.decimal_precision as dp

class sale_order_line(orm.Model):

_name = 'sale.order.line'

_inherit = 'sale.order.line'

_columns = {

'base_price':fields.float('Base Price', required=True, digits_compute=dp.get_precision('Product Price'), readonly=True, states={'draft':[('readonly', False)]}),

}

_default = {

'base_price': 0.0,

}

this is the xml file

<?xml version="1.0"?>
<openerp>
<data>
<record model="ir.ui.view" id="view_order_form">
<field name="name">sale.order.form</field>
<field name="model">sale.order</field>
<field name="inherit_id" ref="sale.view_order_form"/>
<field name="type">form</field>
<field name="arch" type="xml">
<xpath expr="//form/sheet/notebook/page/field[@name='order_line']/form/group/group/field[@name='price_unit' ]" position="before">
<field name="base_price"/>
</xpath>
<xpath expr="//form/sheet/notebook/page/field[@name='order_line']/tree/field[@name='price_unit' ]" position="before">
<field name="base_price"/>
</xpath>
</field>
</record>
</data>
</openerp>

And this is a modul to fiiling value to that fields, and I make it at different modul.

from openerp.osv import orm, fields, api

class sale_order_line(orm.Model):

    _inherit = "sale.order.line"

    def product_id_change( self, cr, uid, ids, pricelist, product, qty=0, uom=False, qty_uos=0, uos=False, name='',

        partner_id=False, lang=False, update_tax=True, date_order=False, packaging=False,

        fiscal_position=False, flag=False, context=None):

        

        vals=super(sale_order_line.self).product_id_change(cr, uid, ids, pricelist, product, qty=qty, uom=uom,

        qty_uos=qty_uos, uos=uos, name=name, partner_id=partner_id, lang=lang, update_tax=update_tax,         date_order=date_order, packaging=packaging, fiscal_position=fiscal_position, flag=flag, context=context)

        vals['value'].update({'base_price':999.99})

        return vals

There are no error when I'm installing this modul, but when I change Product at sales order line form, nothing happened to field base_price.

Sorry there are no equal before 999.99, it's mistype.


0
Avatar
Discard
rudyanto santoso
Author

@Goswani : Sorry, it's not worked, nothing change. thanks

Atchuthan - Technical Consultant, Sodexis Inc

Try to change this line without "equal to"(=) symbol in it vals['value'].update({'base_price': 999.99})

Atchuthan - Technical Consultant, Sodexis Inc

also, it would be helpful if you provide us with the error traceback in the question itself by editing it.

Avatar
Pawan
Best Answer

Rudyanto,

First of all as you said "I allready made a modul to create field base_price at sales order line", i can't see any defination of creating "base_price" field in your module!!. so, please add it if you missed.....

Second, there is no need of "_name" attribute, it will create a new object with sale.order.line and you will not have any access to the methods of previous one, for that please try to print "vals" to see if you are getting any values returned in "vals" varialble after calling super. Please remove "_name" attribute, "_inherit" only is enough for the purpose.

Hope this will help you...

0
Avatar
Discard
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
Odoo auto updates for on-premises Enterprise version (cloud/ in-house server) - v10 v11 v12 Solved
update
Avatar
Avatar
Avatar
2
May 24
7564
odoo module update error Solved
update
Avatar
Avatar
1
Jan 20
7022
How to update a field in recordset v10? Solved
update
Avatar
Avatar
2
Jul 17
8428
How to update Odoo
update
Avatar
Avatar
1
Jan 16
4503
[8.0] update - unexpected behavior
update
Avatar
0
Sep 15
5145
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