Conversation
qgroulard
left a comment
There was a problem hiding this comment.
Hi, this is an attempt at reviewing this PR but:
- I'm not really comfortable with this topic
- I think it's lacking a lot of explanation
To ease the review, could you please:
- Squash your 2 migration commits
- Minimize the diff as much as possible, i.e. push only relevant changes. Please don't remove still accurate docstrings, reword working code, etc. Unless it really improves the code of course.
- Provide explanation on the key changes. Please make use of the "description" section of this PR. Such a big PR should be heavily documented, not pushed with an empty description.
Once this PR is nice and clean, hopefully we can get the help of @hbrunn to get it reviewed and merged 👍
| Return list of dictionaries [{ | ||
| 'id': sms.sms id, | ||
| 'state': sms.sms#state, | ||
| 'failure_type': sms.sms#failure_type | ||
| 'uuid': sms.sms uuid, | ||
| 'state': sms state, | ||
| 'failure_reason': optional failure reason | ||
| }] |
| ["|", ("company_id", "=", False), ("company_id", "=", self.env.company.id)] | ||
| providers = self.search( | ||
| [ | ||
| ("active", "=", True), |
There was a problem hiding this comment.
I don't think adding ("active", "=", True) has any effect here.
| sms_records = SmsSms.browse([msg["id"] for msg in messages_to_send]) | ||
| provider_result = gateway._send_via_self(sms_records) or [] |
There was a problem hiding this comment.
Could you please explain why you need to browse the sms record before calling _send_via_self() now ?
| def _send_partition_providers(self, messages): | ||
| """ | ||
| Return a dict with providers in self as keys and lists of messages a provider | ||
| will handle as value | ||
| ie | ||
| { | ||
| ir.gateway.record(42,): [{message1}, {message2}], | ||
| ir.gateway.record(43,): [{message3}], | ||
| ir.gateway.record(44,): [], | ||
| ir.gateway.record(): [{messages not handled by any available provider}], | ||
| } | ||
| """ | ||
| result = {} | ||
| remaining_messages = messages[:] | ||
|
|
||
| # Sort providers by sequence (priority) | ||
| sorted_providers = self.sorted(key=lambda p: p.sequence) | ||
| _logger.info( | ||
| "Sorted providers by sequence: %s", | ||
| [(p.name, p.sequence) for p in sorted_providers], | ||
| ) | ||
|
|
||
| while remaining_messages: | ||
| message = remaining_messages.pop() | ||
| for this in self: | ||
| if this._can_send(message): | ||
| result.setdefault(this, []).append(message) | ||
| assigned = False | ||
| for provider in sorted_providers: | ||
| can_send = provider._can_send(message) | ||
| _logger.info( | ||
| "Provider %s can send to %s: %s", | ||
| provider.name, | ||
| message.get("number"), | ||
| can_send, | ||
| ) | ||
| if can_send: | ||
| result.setdefault(provider, []).append(message) | ||
| assigned = True | ||
| _logger.info( | ||
| "Assigned message %s to provider %s", | ||
| message.get("id"), | ||
| provider.name, | ||
| ) | ||
| break | ||
| else: | ||
| if not assigned: | ||
| result.setdefault(self.browse([]), []).append(message) | ||
| _logger.info("No provider found for message %s", message.get("id")) | ||
| return result |
There was a problem hiding this comment.
In general, could you please try to minimize the diff by avoiding unnecessary changes.
For instance here I don't understand the change in the docstring.
Also the model ir.sms.gateway is ordered by sequence, thus I don't understand the sort you are adding.
Finally, how is different the use of your variable assigned from the previous for else ?
d4c982b to
e3ff947
Compare
e3ff947 to
9e1cf38
Compare
|
Overseeded by #360 |
this is a partial migration of the Pr:#327 on v16
the major changements from v16 to 18:
the sms_api model does not exist anymore
on the previous implementation , if we found None passede we use the custom logic that we add , but in v18 if we pass None to the send method we always use the standard behaviour of odoo , this is why it is changed in this version