From 6c2b54ff9c536500407223f86bbbd59216689f00 Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Thu, 14 Mar 2019 09:34:53 +0000 Subject: [PATCH] [IMP] base_address_partner: optimise transfer betwen parent and child Mostly a concern during bulk import of partners with parents. First remove syncing extended fields, that seems completely unnecessary since the street gets sync'd and will get split through the normal process (updating the sub-fields), by also syncing the split fields we're redundantly calling _set_steet and rewriting the address we just sync'd. Second if write()ing both the country and street, the override would then go and re-write the street based on what had *just* been split into sub-street fields, which could waste a lot of time during the import post-process as address fields get moved back and forth between parents and children leading to *lots* of writing both country and address together, we're talking: ncalls tottime percall cumtime percall filename:lineno(function) 10002/2 0.111 0.000 344.390 172.195 res_partner.py:181(write) [...] 2 0.455 0.228 165.264 82.632 base_address_extended.py:41(_set_street) My initial instinct was to just add the country_id to _set_street and remove the write override but it would break 88ff6beb016702cbda710aa31bbf10d51ab68fab: if the country alone is updated on a partner, we do want to re-format the "unified" address based on individual fields and the new country's format. Note: it might be that the logic would be more sensible by inversing the entire thing, such that the split fields are the proper source (regular stored fields) and street is converted to a computed field instead, but that'd be a larger model change. Seems like it'd make more sense though, at least given what the modules attempts to do (OTOH the module probably fails https://www.mjt.me.uk/posts/falsehoods-programmers-believe-about-addresses/ in just about all the ways). --- .../base_address_extended/models/base_address_extended.py | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/addons/base_address_extended/models/base_address_extended.py b/addons/base_address_extended/models/base_address_extended.py index 766fac55a8b..0fd99cc8e63 100644 --- a/addons/base_address_extended/models/base_address_extended.py +++ b/addons/base_address_extended/models/base_address_extended.py @@ -33,11 +33,6 @@ class Partner(models.Model): street_number2 = fields.Char('Door', compute='_split_street', help="Door Number", inverse='_set_street', store=True) - @api.model - def _address_fields(self): - """Returns the list of address fields that are synced from the parent.""" - return super(Partner, self)._address_fields() + ['street_name', 'street_number', 'street_number2'] - def get_street_fields(self): """Returns the fields that can be used in a street format. Overwrite this function if you want to add your own fields.""" @@ -144,7 +139,7 @@ class Partner(models.Model): def write(self, vals): res = super(Partner, self).write(vals) - if 'country_id' in vals: + if 'country_id' in vals and 'street' not in vals: self._set_street() return res