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

[12.0] Add module account_invoice_overdue_reminder #69

Merged
merged 10 commits into from
Mar 30, 2021

Conversation

alexis-via
Copy link
Contributor

No description provided.

@alexis-via
Copy link
Contributor Author

I'm working on backporting this module to v10. Where should I propose it ? There isn't any 10.0 branch on this project (starts at 11.0)...

@alexis-via
Copy link
Contributor Author

FYI, PR for v10 is here: #77

def name_get(self):
res = []
for rec in self:
name = _('%s Reminder %d') % (rec.invoice_id.number, rec.counter)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
name = _('%s Reminder %d') % (rec.invoice_id.number, rec.counter)
name = _("{} Reminder {}".format(rec.invoice_id.number, rec.counter))

I think a new format is better. What do you think about it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What is the real advantage of it ? The result is the same, no ?

Copy link
Member

Choose a reason for hiding this comment

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

In this place, the result is the same but the new format string syntax has become more powerful without complicating the simpler use cases. You can see other reasons in https://realpython.com/python-string-formatting/#which-string-formatting-method-should-you-use.

Copy link
Member

Choose a reason for hiding this comment

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

Thanks to inform us about string formatting. As it's python 3.6+ I wonder if it works like that
name = _(f'{rec.invoice_id.number} Reminder {rec.counter}')

If yes the syntax is really readable

Comment on lines +63 to +64
name = _('%s, Reminder %s') % (
action.commercial_partner_id.display_name, action.date)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
name = _('%s, Reminder %s') % (
action.commercial_partner_id.display_name, action.date)
name = _("{}, Reminder {}".format(action.commercial_partner_id.display_name, action.date))

Same comments as above.

Copy link
Member

@Saran440 Saran440 left a comment

Choose a reason for hiding this comment

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

Functional Test, LGTM 👍

and code reviewed:

@alexis-via
File name (,py and .xml) that depend core should be used name same as a core odoo
i.e.
company.py should be res_company.py
config_settings.py should be res_config_settings.py
partner.py should be res_partner.py


{
'name': 'Overdue Invoice Reminder',
'version': '12.0.2.0.0',
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
'version': '12.0.2.0.0',
'version': '12.0.1.0.0',

Module should be start at version 12.0.1.0.0

Copy link
Member

Choose a reason for hiding this comment

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

yes

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Héhé, this module already had a "long" life, is already used in production ! And there are migration scripts associated with this version number (due to changes in the datamodel), so I won't change it!

<odoo noupdate="1">


<record id="voicemail" model="overdue.reminder.result">
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
<record id="voicemail" model="overdue.reminder.result">
<record id="voicemail" model="overdue.reminder.result">

Could you tab before code, it'll look good.

Copy link
Member

Choose a reason for hiding this comment

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

When you have large spaced files begin at the first char make it more readable avoiding too many break lines

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In v13, I'll apply black formatting. In the meantime, let's focus on the important things please.

@bealdav
Copy link
Member

bealdav commented Aug 21, 2020

@Saran440 Thanks for your review. IMHO, renaming company.py (or other) to res_company.py is useless.
It's non ambiguous. Thanks for your approbation

oreju pushed a commit to archeti-org/credit-control that referenced this pull request Oct 7, 2020
…CA#69 :

- It added in our fork because in this time was not merged in OCA.
…update your mail templates)

Add ability to add contacts as Cc of the reminder email (added to the Cc of the mail template)
Add partner_policy with 3 options to give some choice about which contact should be selected to send reminders
Access reminders from partner via Action menu
Advantages:
1) easy access to the history in the chatter of the partner.
2) no problem to access the email by other users (avoid "The requested
operation cannot be completed due to security restrictions. Please
contact your system administrator.")
ypapouin added a commit to decgroupe/credit-control that referenced this pull request Nov 24, 2020
ypapouin added a commit to decgroupe/credit-control that referenced this pull request Nov 24, 2020
Alexis de Lattre and others added 2 commits November 24, 2020 15:44
Co-authored-by: ypapouin <y.papouin@dec-industrie.com>
Co-authored-by: ypapouin <y.papouin@dec-industrie.com>
@alexis-via
Copy link
Contributor Author

@ypapouin Thanks for your review; nice catch for the selection field.
Could you approve the PR now ?

Copy link
Sponsor Member

@marcelsavegnago marcelsavegnago left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@ypapouin ypapouin left a comment

Choose a reason for hiding this comment

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

Tested in production

@ypapouin
Copy link
Contributor

We just got an issue in production, I'm not sure if its an odoo bug or a misusing of transient model and attachments.
The full traceback is added below.

This is my analysis:

  1. Overdue reminder wizard start by the accountant.
  2. A first overdue.reminder.step instance has been created and an attachment (PDF invoice ?) is linked to this model.
  3. The accountant has stopped the wizard to do something else.
  4. Few minutes later, the accountant restart the overdue reminder wizard, but an exception is raised (see traceback) after clicking on start

This is my technical analysis:

  • At step 4, existing_actions.unlink() is called to delete all our overdue.reminder.step instances
  • When unlinking the existing overdue.reminder.step, one attachment is found so attachments.unlink() is called to remove it
  • In ir.attachment.check(...) there is call to self.env[res_model].browse(res_ids).exists() that returns an empty record and 🔥.
            records = self.env[res_model].browse(res_ids).exists()
            # For related models, check if we can write to the model, as unlinking
            # and creating attachments can be seen as an update to the model
            access_mode = 'write' if mode in ('create', 'unlink') else mode
            records.check_access_rights(access_mode)
            records.check_access_rule(access_mode)

Note that the deletion works perfectly when called from the auto-vacuum cron since _filter_access_rules is ignored for SUPERUSER_ID.

So my conclusion:

  • An attachment should not be linked to a transient model.
  • Or this is a bug in odoo and _filter_access_rules should not execute its SELECT query when the record is empty.

The traceback:

Traceback (most recent call last):
  File "/media/data/dec/projects/12.0/odoo/odoo/http.py", line 685, in _handle_exception
    return super(JsonRequest, self)._handle_exception(exception)
  File "/media/data/dec/projects/12.0/odoo/odoo/http.py", line 343, in _handle_exception
    raise pycompat.reraise(type(exception), exception, sys.exc_info()[2])
  File "/media/data/dec/projects/12.0/odoo/odoo/tools/pycompat.py", line 87, in reraise
    raise value
  File "/media/data/dec/projects/12.0/odoo/odoo/http.py", line 727, in dispatch
    result = self._call_function(**self.params)
  File "/media/data/dec/projects/12.0/odoo/odoo/http.py", line 375, in _call_function
    return checked_call(self.db, *args, **kwargs)
  File "/media/data/dec/projects/12.0/odoo/odoo/service/model.py", line 98, in wrapper
    return f(dbname, *args, **kwargs)
  File "/media/data/dec/projects/12.0/odoo/odoo/http.py", line 368, in checked_call
    result = self.endpoint(*a, **kw)
  File "/media/data/dec/projects/12.0/odoo/odoo/http.py", line 979, in __call__
    return self.method(*args, **kw)
  File "/media/data/dec/projects/12.0/odoo/odoo/http.py", line 548, in response_wrap
    response = f(*args, **kw)
  File "/media/data/dec/projects/12.0/odoo/addons/web/controllers/main.py", line 966, in call_button
    action = self._call_kw(model, method, args, {})
  File "/media/data/dec/projects/12.0/odoo/addons/web/controllers/main.py", line 954, in _call_kw
    return call_kw(request.env[model], method, args, kwargs)
  File "/media/data/dec/projects/12.0/odoo/odoo/api.py", line 761, in call_kw
    return _call_kw_multi(method, model, args, kwargs)
  File "/media/data/dec/projects/12.0/odoo/odoo/api.py", line 748, in _call_kw_multi
    result = method(recs, *args, **kwargs)
  File "/media/data/dec/projects/12.0/odoo-addons/oca/credit-control/account_invoice_overdue_reminder/wizard/overdue_reminder_wizard.py", line 125, in run
    existing_actions.unlink()
  File "/media/data/dec/projects/12.0/odoo/odoo/models.py", line 3199, in unlink
    attachments.unlink()
  File "/media/data/dec/projects/12.0/odoo/odoo/addons/base/models/ir_attachment.py", line 501, in unlink
    self.check('unlink')
  File "/media/data/dec/projects/12.0/odoo/odoo/addons/base/models/ir_attachment.py", line 384, in check
    records.check_access_rule(mode)
  File "/media/data/dec/projects/12.0/odoo/odoo/models.py", line 3073, in check_access_rule
    invalid = self - self._filter_access_rules(operation)
  File "/media/data/dec/projects/12.0/odoo/odoo/models.py", line 3118, in _filter_access_rules
    self._cr.execute(query, (tuple(self.ids), self._uid))
  File "/media/data/dec/projects/12.0/odoo/odoo/sql_db.py", line 154, in wrapper
    return f(self, *args, **kwargs)
  File "/media/data/dec/projects/12.0/odoo/odoo/sql_db.py", line 231, in execute
    res = self._obj.execute(query, params)
psycopg2.errors.SyntaxError: syntax error at or near ")"
LINE 1: SELECT id FROM overdue_reminder_step WHERE id IN () AND crea...

@bhaveshselarka
Copy link

@alexis-via any chance to merge in main branch ? Thanks for this great module.

@alexis-via
Copy link
Contributor Author

@ypapouin Strange... I don't see why you would have an ir.attachment on overdue.reminder.step. I don't see anywhere in the code where I would create an attachment on overdue.reminder.step.

@api.depends('type', 'state', 'date_due')
def _compute_overdue(self):
today = fields.Date.context_today(self)
for inv in self:
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
for inv in self:
for inv in self.filtered('date_due'):

Because inv.date_due < today will fail if date_due is False

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I wasn't aware that date_due could be False on an open invoice. When does it happen ?

Copy link
Contributor

Choose a reason for hiding this comment

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

When property_payment_term_id is not set on a partner, it is not filled when a new invoice in created so no date_due.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm sorry, but that's not true. When the payment term is empty, date_due = date_invoice. Here is the relevant code in the account module: https://github.com/odoo/odoo/blob/12.0/addons/account/models/account_invoice.py#L1287

Copy link
Contributor

Choose a reason for hiding this comment

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

Indeed you are right, the problem comes from open invoices created in OpenERP 6.1 before the migration.
Sorry for the buzz.

Copy link

@mrcast mrcast left a comment

Choose a reason for hiding this comment

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

Functional test ok

@eLBati
Copy link
Member

eLBati commented Mar 30, 2021

Hi @alexis-via thanks for this!
Are you aware of any change still to be done, or this could be merged?

@alexis-via
Copy link
Contributor Author

@eLBati it's ready to merge, of course. And also for the other versions.

@eLBati
Copy link
Member

eLBati commented Mar 30, 2021

@OCA/accounting-maintainers could you merge? Thanks

@kittiu
Copy link
Member

kittiu commented Mar 30, 2021

/ocabot merge nobump

@OCA-git-bot
Copy link
Contributor

Hey, thanks for contributing! Proceeding to merge this for you.
Prepared branch 12.0-ocabot-merge-pr-69-by-kittiu-bump-nobump, awaiting test results.

@OCA-git-bot OCA-git-bot merged commit 4f27472 into OCA:12.0 Mar 30, 2021
@OCA-git-bot
Copy link
Contributor

Congratulations, your PR was merged at 3609369. Thanks a lot for contributing to OCA. ❤️

ypapouin added a commit to decgroupe/credit-control that referenced this pull request Jul 10, 2021
ypapouin added a commit to decgroupe/credit-control that referenced this pull request Jul 10, 2021
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.

None yet