Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

write() got multiple values for keyword argument 'context'

By
Uppili Arivukkannu
on 6/9/16, 6:47 AM 646 views

I'm overriding the write() method in validation of odoo hr_attendance

My code is


def write(self, cr, uid, ids, context=None):

    for att in self.browse(cr, uid, ids, context=context):

        prev_att_ids = self.search(cr, uid, [('employee_id', '=', att.employee_id.id), ('name', '<', att.name),

('action', 'in', ('sign_in', 'sign_out'))], limit=1, order='name DESC')

        next_add_ids = self.search(cr, uid, [('employee_id', '=', att.employee_id.id), ('name', '>', att.name),

('action', 'in', ('sign_in', 'sign_out'))], limit=1, order='name ASC')

        prev_atts = self.browse(cr, uid, prev_att_ids, context=context)

        next_atts = self.browse(cr, uid, next_add_ids, context=context)

            if prev_atts and prev_atts[0].action == att.action:

                return self.write(cr, uid, ids, {'state': True})

            if next_atts and next_atts[0].action == att.action: # next exists and is same action

                return self.write(cr, uid, ids, {'state': True})

            if (not prev_atts) and (not next_atts) and att.action != 'sign_in': # first attendance must be sign_in

                return self.write(cr, uid, ids, {'state': True})

            else:

                return self.write(cr, uid, ids, {'state': False})

return True

This is my code. While writing a record in attendance it should check the three "if condition" and want to change the value of the field "state" either "true or false" according to the "if conditions".


But the problem is, in attendance module I have created a record and when I press save it show this error


"

ValidateError

Error while validating constraint

write() got multiple values for keyword argument 'context'      "


How can I solve this issue? Help me


Thanks.


Regards,

Uppili Arivukkannu


1
inian
On 6/9/16, 8:22 AM

Thanks for your reply Emipro Technologies


I have changed the code but it show this error


ValidateError

Error while validating constraint

maximum recursion depth exceeded


I have tried this code

import resource,sys
resource.setrlimit(resource.RLIMIT_STACK, (2**29,-1))
sys.setrecursionlimit(10**6)

But it automatically stops the odoo server

Please do not call write() method from defination of the write() method. It is the cause infinite recursion. Please remove """ self.write(cr, uid, ids, {'state': True})""" from your code.

Emipro Technologies Pvt. Ltd.
on 6/10/16, 1:05 AM
2

Emipro Technologies Pvt. Ltd.

--Emipro Technologies Pvt. Ltd.--
Tiny ERP Pvt Ltd
http://www.odoo.com
5975
| 6 7 8
Rajkot, India
--Emipro Technologies Pvt. Ltd.--

Being an emerging leader in IT market since 2011, Emipro Technologies Pvt. Ltd. has been providing a wide range of business solutions in Odoo & Magento. We are pleased to have a large pool of contented customers with our meticulous work in the domain of ERP & e-Commerce. A ray of relief & satisfaction to  our customers heart by our successful deployment in their organization, purely represents our success in Odoo platform. Hence, we take pride for being an Odoo partner with a vision of expanding our strategic alliances with our customers to offer them high value-added, trustworthy & cost effective solutions.

 

Since establishment, our business has span across 11 countries of the world. Our customers are companies of all sizes ranging from start-ups to large enterprises, who realize that they need a professional business solutions to generate revenue streams, establish proper communication channels or streamline business operations. Standing with strong determination of customer satisfaction, observing each minute detail of their business processes, providing proper guidance and moving forth to develop product accordingly adds our value and reliability among our customers. 

 

We are blessed with efficient, passionate & eclectic young developers who have come across almost all kinds of business profiles, working with full dedication, applying creativity & new features in existing modules and completing customer's projects successfully on predefined target. Our in-depth knowledge while giving business solutions in Odoo allows us to offer following services to our customers :

 

  • Consulting
  • Installation, Configuration & Customization
  • Training & Support
  • Maintenance
  • Upgradation
  • Documentation
  • Crafting community modules
  • Drafting videos on demand
  • Smart Apps development

We will be :) to welcome you @ www.emiprotechnologies.com to solve any kind of your business needs around Odoo. However we are just an inch away from you by email info@emiprotechnologies.com or a tweet to @EmiproTech

Emipro Technologies Pvt. Ltd.
On 6/9/16, 7:49 AM

Hello,

You have define wrong write method

def write(self, cr, uid, ids, context=None):

You have not write one argument "vals". So, vals are passed in context as well as default context is set. So, you got this error.

In that you have to pass following arguments thats it.

def write(self, cr, uid, ids, vals, context={})

It will resolve your issue.


Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 6/9/16, 6:47 AM
Seen: 646 times
Last updated: 7/1/16, 9:53 AM