-
-
Notifications
You must be signed in to change notification settings - Fork 873
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
10.0 #3963 partner relation in tab port #459
10.0 #3963 partner relation in tab port #459
Conversation
before I do an in-depth review:
|
I would propose a new name for the module, as it is an extension of partner_multi_relation (that was renamed from partner_relations). So to keep the link with partner_multi_relation, of which this is an extension, I would propose partner_multi_relation_tabs. |
return self.env.cr.fetchall() | ||
|
||
def _create_relation_type_tab(self, rel_type, inverse, field_names): | ||
'''Create an xml node containing the relation's tab to be added to the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Double quotes for function docstring!!
view.append(etree.Element('field', name='id', | ||
invisible='True')) | ||
field_names.append('id') | ||
for rel_type in own_tab_types: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code can be mutch simplified if you just pass rel_type to underlying methods. No need then for separate function calls with inverse = True of inverse = False. inverse is translated back to left or right in underlying methods anyway, which just confuses things. (I know you just migrated the old code, and I think this was there as well, but now a good opportunity to clean up).
own_tab_left = fields.Boolean('Show in own tab', default=False) | ||
own_tab_right = fields.Boolean('Show in own tab', default=False) | ||
|
||
def _update_res_partner_fields(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thinking about performance I really do not like the way this is implemented. With any tab added or deleted, all the tabfields, also those not touched at all, are created from scratch. I should not be to difficult (and probably even less code) to just check for changes in the own_tab_left field or the own_tab_right field, and create/delete the tabfields accordingly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@NL66278 How can this be done? Keep in mind that that self
here is a recordset not the model so it does not search on all the records, only on those who had their own_tab_left
and/or own_tab_right
changed.
class ResPartner(Model): | ||
_inherit = 'res.partner' | ||
|
||
def _get_relation_ids_select(self, field_name, arg): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function is not needed anymore. In the old version of partner_relations, all relations where shown in a tab. This override was to exclude the relations from the main tab, that were shown in their own tab.
Somehow the names for the relations in the tab are shown including their ID. The id (and comma separator) should not be shown. I tried a screenprint, but github fails in the upload. |
If I add a relation on a tab, the inverse relation is somehow not created or never shown, on the connected relation. |
dde2489
to
8960d7d
Compare
@NL66278 The inverse relation is not shown probably because the following domain assembled and in place:
|
@daramousk I found the problem with the inverse relation not showing up. The problem was limited to symmetrical relations. When a relation is symmetrical, some fields have to be the same for left and right. In the main module this is done here: https://github.com/OCA/partner-contact/blob/10.0/partner_multi_relation/models/res_partner_relation_type.py#L88 You have to override this method and fill own_tab_right with the value of own_tab_left. |
@daramousk One more thing: in the past we often had directories like model (singular), view (singular). This should really be models (plural) and views (plural). |
@NL66278 Both implemented |
def onchange_is_symmetric(self): | ||
"""Set right side to left side if symmetric.""" | ||
if self.is_symmetric: | ||
self.update({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Like always, first call super, then add just the update for own_tab_right. Who knows what other modules will add symmetrical fields?
@daramousk So we are left with:
|
@NL66278 Implemented all of three points |
@daramousk On testing the symmetrical stuff still does not work. (Did you test it?) The error is already in the existing module partner_multi_relation: |
f84e871
to
bd357c3
Compare
@daramousk The synchronization between left and right will in many cases not be done. If you have an existing record and just change the is_symmetric flag, the *_right fields will not be updated, because the *-left fields are not in vals. The easiest way to do this is to do the update after the super.write or second create. Normally I am a bit allergic for extra database actions, because this will result in a second update, or an update right after insert, but the frequency of these actions should be very low, and in programming it is much simpler. This is a very good thing to put in a test case. By the way the test_person_to_person_relation method contains also tests for company to person relations. Make separate test cases and give them appropiate names. Succes! |
@NL66278 Everything pushed here as well, with new changes to increase code coverage |
@@ -1,5 +1,5 @@ | |||
# -*- coding: utf-8 -*- | |||
# © 2014-2016 Therp BV <http://therp.nl> | |||
# © 2017 Therp BV <http://therp.nl> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All the copyrights for existing files should be 2014-2017. Only the really new files should be 2017. Please check this everywhere.
res_partner_relation_type_model = self.env['res.partner.relation.type'] | ||
res_partner_relation_type_selection_model = self.env[ | ||
'res.partner.relation.type.selection'] | ||
p2p_rel = res_partner_relation_type_model.create( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please for all create and write calls with multiple fields do:
some_model.create({
'first_field': 'first_value',
'second_field': 'second_value',
})
So put ( and { on one line,
then indent four spaces on all subsequent lines
then }) on last line.
In the test for multiple relations in tabs I miss:
|
Copyright, now you changed the copyright date in a lot of files that do not have any other change. Please revert those, so the files do not show up in the Pull Request for nothing. |
And the test in the ..._tabs module fail. Please check and correct |
@NL66278 Tests fixed. As for the changed files, all of them have been changed not only because of the dates but because they had long headers, see Holger's first comment. |
@daramousk Thanks a lot. Now squash all the commits into one and it would be ready to merge. |
36b9450
to
3e9e327
Compare
@NL66278 Squashed everything |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 Tested and LGTM
@@ -1,5 +1,5 @@ | |||
# -*- coding: utf-8 -*- | |||
# © 2013-2016 Therp BV <http://therp.nl> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Atomize these MRs make one for partner_multi_relation v10 and one for partner_multi_relation_in_tab v10.
Put on your second MR the note that it depends on partner_multi_relation being merged.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@gfcapalbo I do not see the need for this, as it is all part of one functional package.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok.
'contact_type_right': self.contact_type_left, | ||
'partner_category_right': self.partner_category_left, | ||
}) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What where the reasons to remove the onchange and replace it with a write/create overwrite ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@gfcapalbo Using write/create means that values will be computed the correct way, even if relations inserted/modified through back-end. For instance on import.
name = vals.get('name') | ||
if name: | ||
right_vals['name_inverse'] = name | ||
left_keys = filter(lambda key: key.endswith('_left'), vals.keys()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Obsessive check , but possible scenario
will cause problems if somebody has a field that ends with _left in vals other than the ones we want. filtering explicitly contact_type_left and partner_category_left looks safer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@gfcapalbo Doing this in a generic way is needed to make sure that when extention modules add extra _left and _right fields, thses will be covered automatically. So this is quit intentional.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok. i had forwarned it was obsessive,
Second proposal. modularize this in a function "_get_left_keys" where the extending modules can add their left keys and protect against my . albeit , rare scenario.
@api.multi | ||
def write(self, vals): | ||
"""Handle existing relations if conditions change.""" | ||
self.check_existing(vals) | ||
is_symmetric = vals.get('is_symmetric') | ||
if is_symmetric or self.is_symmetric and is_symmetric is not False: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this covers is_symmetric True or None in vals, Ok.
@@ -1,5 +1,5 @@ | |||
# -*- coding: utf-8 -*- |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Every MR should be for a single module, increases probability of merge. Divide it in two for the two modules
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ignore. one functional package
@@ -1,5 +1,5 @@ | |||
# -*- coding: utf-8 -*- | |||
# © 2013-2016 Therp BV <http://therp.nl> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok.
name = vals.get('name') | ||
if name: | ||
right_vals['name_inverse'] = name | ||
left_keys = filter(lambda key: key.endswith('_left'), vals.keys()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok. i had forwarned it was obsessive,
Second proposal. modularize this in a function "_get_left_keys" where the extending modules can add their left keys and protect against my . albeit , rare scenario.
I found a nasty bug in the override of fields_view_get of res_partner. You will need to cherrypick the commit added to this branch: https://github.com/nl66278/partner-contact/tree/10.0-partner_multi_relation_tabs-apimodel For some reason I cannot make a PR to your branch, The commit basically puts @api.model before the method declaration. |
6127c35
to
a343225
Compare
@NL66278 Rebased and squashed |
@daramousk You might want to close this PR in favour of this one (building on your work): #498. Please review also. |
Port of module
partner_relation_in_tab
to v10