summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRaphael Collet <rco@odoo.com>2019-08-19 15:04:22 +0000
committerRaphael Collet <rco@odoo.com>2019-08-22 10:05:52 +0000
commit8918bbbb5e0e3ac70b89470dd79b9717f3b67ab6 (patch)
tree2c3f3bac03ccd1065a0f0e280c4d0f6a84d502da
parent723a2682bc5c9ae0af821bb461b0121818882dd9 (diff)
[IMP] fields: do not trigger recomputations on transient models from regular models
This is a performance optimization: modifying a regular record will not trigger some recomputation on a transient record. Most transient records are simply waiting to be garbage-collected, so there is no need to keep their fields up-to-date. closes odoo/odoo#35909 Signed-off-by: Raphael Collet (rco) <rco@openerp.com>
-rw-r--r--addons/mrp/wizard/mrp_product_produce.py5
-rw-r--r--addons/sms/models/mail_notification.py19
-rw-r--r--odoo/fields.py6
3 files changed, 11 insertions, 19 deletions
diff --git a/addons/mrp/wizard/mrp_product_produce.py b/addons/mrp/wizard/mrp_product_produce.py
index 6cdde0f8ae4..c1a7dc1bba2 100644
--- a/addons/mrp/wizard/mrp_product_produce.py
+++ b/addons/mrp/wizard/mrp_product_produce.py
@@ -134,6 +134,11 @@ class MrpProductProduce(models.TransientModel):
move_id = self.env['stock.move'].create(values)
line.move_id = move_id.id
+ # because of an ORM limitation (fields on transient models are not
+ # recomputed by updates in non-transient models), the related fields on
+ # this model are not recomputed by the creations above
+ self.invalidate_cache(['move_raw_ids', 'move_finished_ids'])
+
# Save product produce lines data into stock moves/move lines
quantity = self.qty_producing
if float_compare(quantity, 0, precision_rounding=self.product_uom_id.rounding) <= 0:
diff --git a/addons/sms/models/mail_notification.py b/addons/sms/models/mail_notification.py
index 6ab3dbecff3..c45981ea0b0 100644
--- a/addons/sms/models/mail_notification.py
+++ b/addons/sms/models/mail_notification.py
@@ -16,22 +16,3 @@ class Notification(models.Model):
('sms_credit', 'Insufficient Credit'),
('sms_server', 'Server Error')]
)
- # Though this is an interesting case:
- # On sms.resend.recipient, partner_id depends on mail.notification.partner_id as it is defined as a related
- # fields.Many2one('res.partner', 'Partner', related='notification_id.res_partner_id', readonly=True)
- # The below is to add an inverse to the many2one sms.resend.recipient.notification_id
- # so it maintains a list of sms.resend.recipient.partner_id to invalidate
- # when modifying the partner_id of mail.notification. Otherwise the ORM has to do a plain search to find the sms.resend.recipient
- # which have as notification id the one that has been modified
- # Though:
- # - We already discussed the matter it would rather be more interesting to do this automatically for these cases,
- # with a kind of virtual one2many the developer/user doesn't know about,
- # so the developer doesnt have to create it himself for this technical/performance reason
- # - In this case, the modified happens on the creation of the mail.notification, and has it has just been created it
- # would be quite safe to assume there was no `sms.resend.recipient` and we could have avoided the search,
- # even without this virtual/technical one2many.
- # - Besides, its a wizard, and we also discussed the possibility to stop the modified when going from a regular model to a transient model
- # meaning when we update something on the record on which is based the wizard
- # e.g. a related to the invoice name, something like that,
- # we let the modified do its change when we specifically change the invoice on the wizard, but not when changing the name on the invoice
- sms_resend_recipient_ids = fields.One2many('sms.resend.recipient', 'notification_id', strong='SMS recipients to resend')
diff --git a/odoo/fields.py b/odoo/fields.py
index 3a6824433cc..295ac96cbf4 100644
--- a/odoo/fields.py
+++ b/odoo/fields.py
@@ -730,6 +730,12 @@ class Field(MetaField('DummyField', (object,), {})):
path = [] # fields from model to field_model
for fname in dotnames.split('.'):
field = field_model._fields[fname]
+
+ if model._transient and not field_model._transient:
+ # modifying fields on regular models should not trigger
+ # recomputations of fields on transient models
+ break
+
# Do not make self trigger itself
# e.g. `fields.One2many('stock.move.line', 'move_id', domain=[('product_qty', '=', 0.0)])`
# will have 'move_line_nosuggest_ids.product_qty' as a dependency