Skip to content
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

[IMP+FIX] account_credit_control: traceable communications #86

Conversation

yajo
Copy link
Member

@yajo yajo commented Aug 11, 2020

Before this patch, credit.control.communication was a TransientModel that sent emails. This produced that, when someone responded to one of those emails, Odoo detected it was a response but couldn't know where to store it, so it was lost. Also, users with credit control access got a 500 error when clicking on the "View" button in the email.

Now, credit.control.communication is a normal Model which inherits from mail.thread and mail.activity.mixin. This makes more sense, because when you are tracking credit control communications, you usually communicate with a customer regarding several lines at once (no sense on asking a customer to pay each line separately).

More changes:

  • credit.control.run now displays an additional smart button that leads users to generated communications.
  • credit.control.line now is linked to a communication instead of a simple message (the old link is preserved in a hidden legacy column).
  • Some fields are renamed, as they didn't follow guidelines.
  • Some menu names are less verbose now.
  • Mail templates code is migrated.

@Tecnativa TT24841

@pedrobaeza pedrobaeza added this to the 12.0 milestone Aug 11, 2020
Copy link
Member

@pedrobaeza pedrobaeza left a comment

Choose a reason for hiding this comment

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

Maybe you can add little checks in tests for count or existence of the records.

account_credit_control/demo/res_users.xml Outdated Show resolved Hide resolved
string='Credit Lines',
)
contact_address = fields.Many2one(
contact_address_id = fields.Many2one(
Copy link
Member

Choose a reason for hiding this comment

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

There's a chance that the records on the table are not vacuum, so better to rename these fields in scripts for not losing references. Shouldn't this field be required by the way?

Copy link
Member Author

Choose a reason for hiding this comment

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

There's a chance that the records on the table are not vacuum, so better to rename these fields in scripts for not losing references

Good catch, but actually in that case, this table would become problematic, because it would contain data that was not meant to be persistent. What I'm going to do is force a vacuum in the pre-migration.

Shouldn't this field be required by the way?

It's used automatically when the action is executed, and in those cases is always filled automatically. From then, the only thing that actually matters is message followers, so I think it is OK as it is.

@@ -86,6 +90,9 @@ def _compute_credit_control_count(self):
for data in fetch_data}
for rec in self:
rec.credit_control_count = result.get(rec.id, 0)
rec.credit_control_communication_count = len(
Copy link
Member

Choose a reason for hiding this comment

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

Please don't add this non optimized way. Can you do a read_group?

Copy link
Member Author

Choose a reason for hiding this comment

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

Not here, because I'd need to count distinct values for the communication_id field. The only possibly optimized way to get that AFAIK is raw SQL. Since this is only to be executed in form views, which shouldn't have many values, I didn't see this as a big problem.

Should I do it through SQL?

Copy link
Member

Choose a reason for hiding this comment

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

Well, you could add the one2many to communication and add the credit_control_run_id on communication

@pedrobaeza
Copy link
Member

I forgot the runbot warning:

WARNING openerp_test odoo.addons.base.models.ir_model: Two fields (credit_control_communication_count, credit_control_count) of credit.control.run() have the same label: # of Credit Control Lines.

@yajo yajo force-pushed the 12.0-account_credit_control-traceable_communications branch from 4b4ec7a to 5894c52 Compare August 12, 2020 08:17
Copy link
Member Author

@yajo yajo left a comment

Choose a reason for hiding this comment

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

All attended/responded.

string='Credit Lines',
)
contact_address = fields.Many2one(
contact_address_id = fields.Many2one(
Copy link
Member Author

Choose a reason for hiding this comment

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

There's a chance that the records on the table are not vacuum, so better to rename these fields in scripts for not losing references

Good catch, but actually in that case, this table would become problematic, because it would contain data that was not meant to be persistent. What I'm going to do is force a vacuum in the pre-migration.

Shouldn't this field be required by the way?

It's used automatically when the action is executed, and in those cases is always filled automatically. From then, the only thing that actually matters is message followers, so I think it is OK as it is.

@@ -86,6 +90,9 @@ def _compute_credit_control_count(self):
for data in fetch_data}
for rec in self:
rec.credit_control_count = result.get(rec.id, 0)
rec.credit_control_communication_count = len(
Copy link
Member Author

Choose a reason for hiding this comment

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

Not here, because I'd need to count distinct values for the communication_id field. The only possibly optimized way to get that AFAIK is raw SQL. Since this is only to be executed in form views, which shouldn't have many values, I didn't see this as a big problem.

Should I do it through SQL?

@yajo yajo force-pushed the 12.0-account_credit_control-traceable_communications branch 2 times, most recently from 89ec75c to 36eadc6 Compare August 12, 2020 10:02
@sbidoul
Copy link
Member

sbidoul commented Aug 12, 2020

cc/ @qgroulard

Copy link
Contributor

@qgroulard qgroulard left a comment

Choose a reason for hiding this comment

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

Most welcome improvements, thank you! (code review)

Before this patch, `credit.control.communication` was a `TransientModel` that sent emails. This produced that, when someone responded to one of those emails, Odoo detected it was a response but couldn't know where to store it, so it was lost. Also, users with credit control access got a 500 error when clicking on the "View" button in the email.

Now, `credit.control.communication` is a normal `Model` which inherits from `mail.thread` and `mail.activity.mixin`. This makes more sense, because when you are tracking credit control communications, you usually communicate with a customer regarding several lines at once (no sense on asking a customer to pay each line separately).

More changes:

- `credit.control.run` now displays an additional smart button that leads users to generated communications.
- `credit.control.line` now is linked to a communication instead of a simple message (the old link is preserved in a hidden legacy column).
- `credit.control.line` has a new state "queued", which indicates that the communication is executed but still not sent. When sent, it's changed to "done" or "email_error".
- Comunication emails have a specific subtype.
- Some fields are renamed, as they didn't follow guidelines.
- Some menu names are less verbose now.
- Mail templates code is migrated.

@Tecnativa TT24841
@yajo yajo force-pushed the 12.0-account_credit_control-traceable_communications branch from 36eadc6 to f9053c5 Compare August 21, 2020 10:23
@yajo
Copy link
Member Author

yajo commented Aug 21, 2020

New changes:

  • Comunication emails have a specific subtype.
  • credit.control.line has a new state "queued", which indicates that the communication is executed but still not sent. When sent, it's changed to "done" or "email_error".

@rafaelbn review again please.

Copy link
Member

@rafaelbn rafaelbn left a comment

Choose a reason for hiding this comment

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

After reviewing with @chienandalu this PR need some fixes for who are currently using it as when you send the emails, templates fails. Don't fail in runbot just for existing databases.

@chienandalu chienandalu force-pushed the 12.0-account_credit_control-traceable_communications branch from 9ed247f to 9159920 Compare August 26, 2020 14:24
- Template translations migration scripts
- Template recipients
@chienandalu chienandalu force-pushed the 12.0-account_credit_control-traceable_communications branch from 9159920 to 9a9a5fe Compare August 27, 2020 09:46
@rafaelbn
Copy link
Member

@yajo

  1. we need to allow Credit control Manager to change state from "Todo" to "Draft".

If state is todo and user is manager then allow change state to draft

2020-08-27_18-22-48

  1. Also we should review why the emails to customers are sent as Internal notes

  2. Improve test - codecov/patch — 54.23% of diff hit (target 90.72%)

In the last test this are the final points.

Thanks

Copy link
Member

@etobella etobella left a comment

Choose a reason for hiding this comment

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

I think this is a great improvement!!! Can we help with tests or something?

@pedrobaeza
Copy link
Member

@yajo please check latest comments and let's merge this.

@yajo
Copy link
Member Author

yajo commented Sep 9, 2020

we need to allow Credit control Manager to change state from "Todo" to "Draft".

Fixed with last commit.

You just have to go to Action > Change Lines' State

@yajo
Copy link
Member Author

yajo commented Sep 9, 2020

1. Also we should review why the emails to customers are sent as Internal notes

It seems the message subtype must be mail.mt_comment if we want it as a normal discussion comment.

That's not very nice because it means that I couldn't use the account_credit_control.mt_request mail subtype, which adds some features such as detecting if a queued message was an actual request or not, to set the process from queued to done.

However, the fact it appears as grayed-out doesn't mean it's really a note. Maybe it's just Odoo distinguishing between messages written by users from messages written by the system, isn't it?

@pedrobaeza
Copy link
Member

It doesn't sound to me that Odoo grays out that. Anyway, it should be non gray for proper UX. Can you please investigate the reason? Also the subtype can be important to be respected.

@etobella
Copy link
Member

etobella commented Sep 9, 2020

The gray is defined on:

https://github.com/odoo/odoo/blob/f0508b3fd43339241c3a75273871ddc06690db31/addons/mail/models/mail_message.py#L526

The white is set if is_discussion or is_notification are true.

So, at the end, the subtype needs to be comment (as is_discussion will not be an option, as there is model and resource) or the function must be inherited and modifed 🤔

@yajo
Copy link
Member Author

yajo commented Sep 18, 2020

Thanks @etobella, it confirms what I said in #86 (comment).

So this leaves us 2 options:

  1. Modify the mail stack to display some subtypes as messages.
  2. Leave it as it is and assume this is how Odoo works.

I think the correct option is 2. At least for this PR.

@pedrobaeza
Copy link
Member

But can we put any subtype that puts things as not grey as Odoo does with mail templates manually sent for example?

naglis pushed a commit to versada/credit-control that referenced this pull request Jul 28, 2021
Update patch imported from OCA#86 to new style guidelines.
naglis pushed a commit to versada/credit-control that referenced this pull request Jul 28, 2021
Adapt imported patch OCA#86 to v13.

@Tecnativa TT24841
naglis pushed a commit to versada/credit-control that referenced this pull request Jul 29, 2021
Update patch imported from OCA#86 to new style guidelines.
naglis pushed a commit to versada/credit-control that referenced this pull request Jul 29, 2021
Adapt imported patch OCA#86 to v13.

@Tecnativa TT24841
chouab pushed a commit to chouab/credit-control that referenced this pull request Nov 3, 2021
Update patch imported from OCA#86 to new style guidelines.
chouab pushed a commit to chouab/credit-control that referenced this pull request Nov 3, 2021
Adapt imported patch OCA#86 to v13.

@Tecnativa TT24841
fredzamoabg pushed a commit to fredzamoabg/credit-control that referenced this pull request Jan 31, 2022
Update patch imported from OCA#86 to new style guidelines.
fredzamoabg pushed a commit to fredzamoabg/credit-control that referenced this pull request Jan 31, 2022
Adapt imported patch OCA#86 to v13.

@Tecnativa TT24841
cesar-tecnativa pushed a commit to Tecnativa/credit-control that referenced this pull request Jun 12, 2022
Update patch imported from OCA#86 to new style guidelines.
cesar-tecnativa pushed a commit to Tecnativa/credit-control that referenced this pull request Jun 12, 2022
Adapt imported patch OCA#86 to v13.

@Tecnativa TT24841
cesar-tecnativa pushed a commit to Tecnativa/credit-control that referenced this pull request Jun 13, 2022
Update patch imported from OCA#86 to new style guidelines.
cesar-tecnativa pushed a commit to Tecnativa/credit-control that referenced this pull request Jun 13, 2022
Adapt imported patch OCA#86 to v13.

@Tecnativa TT24841
cesar-tecnativa pushed a commit to Tecnativa/credit-control that referenced this pull request Jul 4, 2022
Update patch imported from OCA#86 to new style guidelines.
cesar-tecnativa pushed a commit to Tecnativa/credit-control that referenced this pull request Jul 4, 2022
Adapt imported patch OCA#86 to v13.

@Tecnativa TT24841
cesar-tecnativa pushed a commit to Tecnativa/credit-control that referenced this pull request Jul 6, 2022
Update patch imported from OCA#86 to new style guidelines.
cesar-tecnativa pushed a commit to Tecnativa/credit-control that referenced this pull request Jul 6, 2022
Adapt imported patch OCA#86 to v13.

@Tecnativa TT24841
FernandoRomera pushed a commit to MallorcaSoft/credit-control that referenced this pull request Jan 2, 2023
Update patch imported from OCA#86 to new style guidelines.
FernandoRomera pushed a commit to MallorcaSoft/credit-control that referenced this pull request Jan 2, 2023
Adapt imported patch OCA#86 to v13.

@Tecnativa TT24841
FernandoRomera pushed a commit to MallorcaSoft/credit-control that referenced this pull request Feb 18, 2023
Update patch imported from OCA#86 to new style guidelines.
FernandoRomera pushed a commit to MallorcaSoft/credit-control that referenced this pull request Feb 18, 2023
Adapt imported patch OCA#86 to v13.

@Tecnativa TT24841
astirpe pushed a commit to astirpe/credit-control that referenced this pull request Mar 15, 2024
Update patch imported from OCA#86 to new style guidelines.
astirpe pushed a commit to astirpe/credit-control that referenced this pull request Mar 15, 2024
Adapt imported patch OCA#86 to v13.

@Tecnativa TT24841
astirpe pushed a commit to astirpe/credit-control that referenced this pull request Mar 15, 2024
Update patch imported from OCA#86 to new style guidelines.
astirpe pushed a commit to astirpe/credit-control that referenced this pull request Mar 15, 2024
Adapt imported patch OCA#86 to v13.

@Tecnativa TT24841
astirpe pushed a commit to astirpe/credit-control that referenced this pull request Sep 14, 2024
Update patch imported from OCA#86 to new style guidelines.
astirpe pushed a commit to astirpe/credit-control that referenced this pull request Sep 14, 2024
Adapt imported patch OCA#86 to v13.

@Tecnativa TT24841
kevinkhao pushed a commit to kevinkhao/credit-control that referenced this pull request Jan 10, 2025
Update patch imported from OCA#86 to new style guidelines.
kevinkhao pushed a commit to kevinkhao/credit-control that referenced this pull request Jan 10, 2025
Adapt imported patch OCA#86 to v13.

@Tecnativa TT24841
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants