Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error on update operations with datetime fields #32

Closed
bhuisgen opened this issue Aug 10, 2022 · 3 comments
Closed

Error on update operations with datetime fields #32

bhuisgen opened this issue Aug 10, 2022 · 3 comments

Comments

@bhuisgen
Copy link
Contributor

I have generated my models for odoo v15. Create and read operations are OK, but there is a problem with update operation about datetime fields:

	id, err := c.CreateResPartner(&odoo.ResPartner{
		Name: odoo.NewString("test"),
	})
	if err != nil {
		log.Print(err)
		return
	}

	resPartner, err := c.GetResPartner(id)
	if err != nil {
		log.Print(err)
		return
	}

	resPartner.Comment = odoo.NewString("test")

	// FIXME update error
	err = c.UpdateResPartner(resPartner)
	if err != nil {
		log.Print(err)
		return
	}
2022/08/10 12:21:51 Fault(1): Traceback (most recent call last):
  File "/usr/local/odoo/odoo/addons/base/controllers/rpc.py", line 93, in xmlrpc_2
    response = self._xmlrpc(service)
  File "/usr/local/odoo/odoo/addons/base/controllers/rpc.py", line 73, in _xmlrpc
    result = dispatch_rpc(service, method, params)
  File "/usr/local/odoo/odoo/http.py", line 141, in dispatch_rpc
    result = dispatch(method, params)
  File "/usr/local/odoo/odoo/service/model.py", line 41, in dispatch
    res = fn(db, uid, *params)
  File "/usr/local/odoo/odoo/service/model.py", line 169, in execute_kw
    return execute(db, uid, obj, method, *args, **kw or {})
  File "/usr/local/odoo/odoo/service/model.py", line 94, in wrapper
    return f(dbname, *args, **kwargs)
  File "/usr/local/odoo/odoo/service/model.py", line 176, in execute
    res = execute_cr(cr, uid, obj, method, *args, **kw)
  File "/usr/local/odoo/odoo/service/model.py", line 160, in execute_cr
    result = odoo.api.call_kw(recs, method, args, kw)
  File "/usr/local/odoo/odoo/api.py", line 464, in call_kw
    result = _call_kw_multi(method, model, args, kwargs)
  File "/usr/local/odoo/odoo/api.py", line 451, in _call_kw_multi
    result = method(recs, *args, **kwargs)
  File "/usr/local/odoo/addons/base_vat/models/res_partner.py", line 616, in write
    return super(ResPartner, self).write(values)
  File "/usr/local/odoo/addons/snailmail/models/res_partner.py", line 26, in write
    return super(ResPartner, self).write(vals)
  File "/usr/local/odoo/addons/partner_autocomplete/models/res_partner.py", line 179, in write
    res = super(ResPartner, self).write(values)
  File "/usr/local/odoo/odoo/addons/base/models/res_partner.py", line 603, in write
    result = result and super(Partner, self).write(vals)
  File "/usr/local/odoo/addons/mail/models/mail_activity_mixin.py", line 243, in write
    return super(MailActivityMixin, self).write(vals)
  File "/usr/local/odoo/addons/mail/models/mail_thread.py", line 323, in write
    result = super(MailThread, self).write(values)
  File "/usr/local/odoo/odoo/models.py", line 3858, in write
    field.write(self, value)
  File "/usr/local/odoo/odoo/fields.py", line 1015, in write
    cache_value = self.convert_to_cache(value, records)
  File "/usr/local/odoo/odoo/fields.py", line 2037, in convert_to_cache
    return self.to_datetime(value)
  File "/usr/local/odoo/odoo/fields.py", line 2017, in to_datetime
    return datetime.strptime(value, DATETIME_FORMAT[:len(value)-2])
TypeError: object of type 'DateTime' has no len()

Any suggestion about this ?

@bhuisgen
Copy link
Contributor Author

I did a small fix into the function convertFromStaticToDynamicValue in conversion.go:

func convertFromStaticToDynamicValue(staticValue interface{}) interface{} {
	switch sv := staticValue.(type) {
	case *Time:
		// v = sv.v
		v = sv.v.String()

Updates are working now. Maybe a PR in few days :)

@ahuret
Copy link
Collaborator

ahuret commented Aug 11, 2022

Hey @bhuisgen 👋 Thank you for the catch and nice debugging !
If the fix works well for you, that's fine !
But I think the fundamental issue is about a lack of decoupling between the different "time" odoo types: datetime and date, we probably need two different types with their own encoding/decoding logic, I still need to go deeper to be sure, feel free to give your opinion. I'll keep you in touch !

@ahuret
Copy link
Collaborator

ahuret commented Aug 19, 2022

resolved in 96d00b8 !

As I can see, odoo can receive request with the same format for both date and datetime types.
However, those two types are different and not stored the same way in the database, we should handle that correctly.

I planned to work on a future release with:

  • per major version specific APIs
  • latest golang version (generics ???)
  • rework way to generate models and interact with library
  • tests ???
  • datetime / date + check for other new odoo types
  • ...

thanks again for the report, feel free to give your opinion / needs / wishes for this library to improve :D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants