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
    • Artificial Intelligence
    • 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
    • Property 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
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

cursor object has no attribute 'write'?

Subscribe

Get notified when there's activity on this post

This question has been flagged
pythonv7cursor
2 Replies
9250 Views
Avatar
mike

The traceback complains about sql_db.py line 358 in __getattr__ and before that it is line 162 in wrapper which is inside the decorator function 'check'. I agree with it, class Cursor has no attribute 'write'. However, my function (app_approve) is trying to write and it is in the traceback prior to the above. I just don't understand how it thinks I am trying to call 'write' on the cursor when I'm explicitly calling self.write. Or am I not myself here? This is getting too metaphysical anybody have any ideas?

def _create_application_history(self, cr, uid, ids, vals, context=None):
    """ Creates new application history objects """
    current_application = self.browse(cr, uid, ids, context=context)[0]
    # we are only working with a single record here 
    vals['application_id'] = current_application.id
    vals['current_status'] = current_application.state
    vals['completion'] = current_application.completion
    vals['note'] = current_application.note
    # get id from the ORM browse record since ORM can't recognize its own objects
    vals['dbe_specialist'] = current_application.dbe_specialist.id
    vals['onsite_visit_date'] = current_application.onsite_visit_date
    vals['onsite_visit_notes'] = current_application.onsite_visit_notes
    vals['visit_approved'] = current_application.visit_approved
    vals['docs_completed'] = current_application.docs_completed
    # get application history object and call its create
    _logger.debug("Application history create called with ids %s and vals %s", str(ids), str(vals))
    history_id = self.pool.get('dbe.application.history').create(cr, uid, vals, context=context)
    return history_id

def _transaction_history(func):
    """ Decorator function for historical logging of transactions """
    @functools.wraps(func) # ensuring we still have a name after wrapping
    def wrapped(self, cr, uid, ids, vals, context=None):
        func_name = func.__name__
        # if the wrapped function name matches a transaction type create a corresponding history record
        if func_name in _transaction_types.keys():
            vals['transaction_type'] = _transaction_types[func_name]                
            history_id = self._create_application_history(cr, uid, ids, vals, context)

        if history_id:
            _logger.debug("Application history created for transaction type %s with record #%d", _transaction_types[func_name], history_id)
        # call wrapped function without explicit self
        return func(cr, uid, ids, vals, context)
    return wrapped

@_transaction_history
def app_approve(self, cr, uid, ids, context={}):
    """ Setting the application record state to 'approve' from form action """
    return self.write(cr, uid, ids, {'state': 'approve'}, context=context)
0
Avatar
Discard
Avatar
mike
Author Best Answer

Fixed! This...

def app_approve(self, cr, uid, ids, context={}):

Should have been this...

def app_approve(self, cr, uid, ids, vals, context):

It was an impedance mismatch because either vals was missing or I had multiple values for context (or both). I needed to pass self through the wrapper and not return the wrapper as self because at the end of it all I was attempting self.write anyway.

Also, I had an unrelated mistake in original code for _transaction_history instead of passing vals to the create method pass vals.copy() to prevent resetting values in vals with values for self.

1
Avatar
Discard
Avatar
Francesco OpenCode
Best Answer

Self has write but cr not, if you call this function

return func(cr, uid, ids, vals, context)

you obtain an error becase the firts parameter (cr) must be self

return self.func(cr, uid, ids, vals, context)
0
Avatar
Discard
mike
Author

but then it complains: line 345 in wrapped return func(self, cr, uid, vals, context) TypeError: app_approve() takes at most 5 arguments (6 given). So self is passed anyway and the reason I didn't call with it before. This is normal from wrapped functions? Seems like it shouldn't be...

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
Please define these Python Fetch types
python v7
Avatar
2
Mar 24
30323
openerp 7 alpha "No handler found" error?
python v7
Avatar
0
Mar 15
7728
How to create a custom module in openerp 7 community edition?
python v7
Avatar
Avatar
1
Mar 15
12311
How add a float to a Datetime field.
python v7
Avatar
Avatar
Avatar
Avatar
3
Mar 15
10887
How to pass input filter value (domain) to python code?
python v7
Avatar
Avatar
1
Mar 15
11991
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 Svenska ภาษาไทย 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