Skip to content

8.0 base field validator - #246

Merged
gurneyalex merged 25 commits into
OCA:8.0from
eLBati:8.0-base_field_validator
Aug 9, 2016
Merged

gurneyalex merged 25 commits into
OCA:8.0from
eLBati:8.0-base_field_validator

Conversation

@eLBati

@eLBati eLBati commented Sep 2, 2015

Copy link
Copy Markdown
Member

Following #238

@eLBati eLBati mentioned this pull request Sep 2, 2015
@hurrinico

Copy link
Copy Markdown

IMHO 👍

Comment thread base_field_validator/README.rst Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make the title a real title by adding a lot of '===' above the title OCA/maintainer-tools@d51c38f

@eLBati

eLBati commented Sep 4, 2015

Copy link
Copy Markdown
Member Author

@lmignon thanks. I have made some changes 😁

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you remove size param?
In v8 size don't is required

@eLBati

eLBati commented Sep 7, 2015

Copy link
Copy Markdown
Member Author

@moylop260 thanks, I made the suggested changes

@moylop260

Copy link
Copy Markdown
Contributor

👍

Comment thread base_field_validator/models/ir_model.py Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe iterate directly over

self.env['ir.model.validator.line'].search(
    [('name.model', '=', model_name),
     ('field_id.name', 'in', vals.keys())])

?

@eLBati

eLBati commented Oct 19, 2015

Copy link
Copy Markdown
Member Author

@StefanRijnhart thanks, improved with 50f50c3

@eLBati

eLBati commented Dec 15, 2015

Copy link
Copy Markdown
Member Author

Hi @StefanRijnhart can this be merged?

Comment thread base_field_validator/models/ir_model.py Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This check is now redundant, as we already filter on the field name in the search call.

@StefanRijnhart

Copy link
Copy Markdown
Member

Nearly!

@eLBati
eLBati force-pushed the 8.0-base_field_validator branch from 50f50c3 to d196c92 Compare December 15, 2015 10:13
@eLBati

eLBati commented Dec 15, 2015

Copy link
Copy Markdown
Member Author

@StefanRijnhart thanks, done

Comment thread base_field_validator/models/ir_model.py Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As @hbrunn mentioned recently in another PR, changing the signature of _register_hook can be dangerous as it is not compatible with other overrides of this method on the same model. https://github.com/OCA/server-tools/pull/300/files#r45976286. BTW @eLBati as the author of the module from that pull request you might want to read up on the general discussion there.

@eLBati
eLBati force-pushed the 8.0-base_field_validator branch from d196c92 to a1e82ca Compare January 26, 2016 11:21
@eLBati
eLBati force-pushed the 8.0-base_field_validator branch from a1e82ca to 37380ba Compare February 5, 2016 11:20
@eLBati

eLBati commented Feb 5, 2016

Copy link
Copy Markdown
Member Author

@StefanRijnhart thanks for #340
I committed eLBati@8efad99

Comment thread base_field_validator/models/ir_model.py Outdated

class IrModelValidatorLine(models.Model):
_name = "ir.model.validator.line"
name = fields.Many2one('ir.model', string="Model", required=True)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should call this field model_id.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, changed

@yajo

yajo commented Feb 5, 2016

Copy link
Copy Markdown
Member

In runbot, after I added the validator to the email field of res.partner, I got this:

Odoo Server Error

Traceback (most recent call last):
  File "/srv/openerp/instances/openerp-oca-runbot/parts/odoo-extra/runbot/static/build/3141119-246-8efad9/openerp/http.py", line 537, in _handle_exception
    return super(JsonRequest, self)._handle_exception(exception)
  File "/srv/openerp/instances/openerp-oca-runbot/parts/odoo-extra/runbot/static/build/3141119-246-8efad9/openerp/http.py", line 574, in dispatch
    result = self._call_function(**self.params)
  File "/srv/openerp/instances/openerp-oca-runbot/parts/odoo-extra/runbot/static/build/3141119-246-8efad9/openerp/http.py", line 310, in _call_function
    return checked_call(self.db, *args, **kwargs)
  File "/srv/openerp/instances/openerp-oca-runbot/parts/odoo-extra/runbot/static/build/3141119-246-8efad9/openerp/service/model.py", line 118, in wrapper
    return f(dbname, *args, **kwargs)
  File "/srv/openerp/instances/openerp-oca-runbot/parts/odoo-extra/runbot/static/build/3141119-246-8efad9/openerp/http.py", line 307, in checked_call
    return self.endpoint(*a, **kw)
  File "/srv/openerp/instances/openerp-oca-runbot/parts/odoo-extra/runbot/static/build/3141119-246-8efad9/openerp/http.py", line 803, in __call__
    return self.method(*args, **kw)
  File "/srv/openerp/instances/openerp-oca-runbot/parts/odoo-extra/runbot/static/build/3141119-246-8efad9/openerp/http.py", line 403, in response_wrap
    response = f(*args, **kw)
  File "/srv/openerp/instances/openerp-oca-runbot/parts/odoo-extra/runbot/static/build/3141119-246-8efad9/openerp/addons/web/controllers/main.py", line 944, in call_kw
    return self._call_kw(model, method, args, kwargs)
  File "/srv/openerp/instances/openerp-oca-runbot/parts/odoo-extra/runbot/static/build/3141119-246-8efad9/openerp/addons/web/controllers/main.py", line 936, in _call_kw
    return getattr(request.registry.get(model), method)(request.cr, request.uid, *args, **kwargs)
  File "/srv/openerp/instances/openerp-oca-runbot/parts/odoo-extra/runbot/static/build/3141119-246-8efad9/openerp/api.py", line 268, in wrapper
    return old_api(self, *args, **kwargs)
  File "/srv/openerp/instances/openerp-oca-runbot/parts/odoo-extra/runbot/static/build/3141119-246-8efad9/openerp/addons/base_optional_quick_create/model.py", line 62, in write
    self._register_hook(cr, ids)
  File "/srv/openerp/instances/openerp-oca-runbot/parts/odoo-extra/runbot/static/build/3141119-246-8efad9/openerp/api.py", line 268, in wrapper
    return old_api(self, *args, **kwargs)
TypeError: _register_hook() takes exactly 2 arguments (3 given)

@eLBati

eLBati commented Feb 5, 2016

Copy link
Copy Markdown
Member Author

@yajo thanks for review.

The error

TypeError: _register_hook() takes exactly 2 arguments (3 given)

is fixed with #352

@eLBati
eLBati force-pushed the 8.0-base_field_validator branch from a603af8 to cd60474 Compare February 22, 2016 14:38
@eLBati

eLBati commented Feb 22, 2016

Copy link
Copy Markdown
Member Author

@yajo as per #352 , I refactored method wrapping using _patch_method (d436897)
Please review.
Thanks

Comment thread base_field_validator/models/ir_model.py Outdated
return True


class IrModel(orm.Model):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You do not need to declare this twice. Old and new api methods can be freely mixed in the same models.Model subclass.

@yajo

yajo commented Feb 23, 2016

Copy link
Copy Markdown
Member

Finished code review, cannot test functionally due to lack of runbot. I see that in many PR recently, any clues?

@eLBati

eLBati commented Feb 23, 2016

Copy link
Copy Markdown
Member Author

Thanks @yajo , I addressed your remarks.

I don't know about runbot, you can try asking in #oca https://botbot.me/freenode/oca/

_name = "ir.model.validator.line"
_rec_name = 'model_id'
model_id = fields.Many2one('ir.model', string="Model", required=True)
field_id = fields.Many2one('ir.model.fields', 'Field', required=True)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still feel these 2 fields are redundant. model_id could be a related field to field_id.model_id.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't see how to make the interface work using a related field.
Now runbot should work : https://runbot.odoo-community.org/runbot/build/3142519
Please try it there and tell me how you would change it.
Thanks

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think yout do not need to replace the UI. Just add related='field_id.model_id', store=True to the model_id field. It should keep on working as now, but you would not need to fill that field.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In both cases user does not have to fill model_id field, as it is the inverse m2o of validator_line_ids and is not visible

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I suppose I would have strucutred it a bit differently, but current structure works fine and is not too far away of that, so 👍

@yajo

yajo commented Feb 26, 2016

Copy link
Copy Markdown
Member

👍

@gurneyalex
gurneyalex merged commit 9245f7c into OCA:8.0 Aug 9, 2016
SiesslPhillip pushed a commit to grueneerde/OCA-server-tools that referenced this pull request Nov 20, 2024
Syncing from upstream OCA/server-tools (10.0)
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

Successfully merging this pull request may close these issues.

8 participants