+
Skip to content

Conversation

raumschmiede-joshuaL
Copy link

@raumschmiede-joshuaL raumschmiede-joshuaL commented Sep 5, 2025

Hi,

I moved the new def _get_sub_exception_field_names from PR #3354 to here.
This here uses the commits of the other PR. I will do a rebase after the other was merged.

I implemented a way to add exceptions to the record on which the exceptions where detected on in case _get_main_records returns something else than self, like self.order_id.
That commit breaks sale_exception because I added _get_main_records to detect_exceptions so that it is not necessary anymore to do this in an overridden _detect_exceptions.

EDIT: I checked sale_exception again to update PR OCA/sale-workflow#3861. Seems that it is not breaking the module. The overridden _detect_exceptions in sale.order.line returns the same as the overridden _get_main_records. After that _get_main_records is called again on the returned sales orders. So only one useless _get_main_records call.

I removed the comment in detect_exceptions because it refered to the _reverse_field and the Many2many field on the exception rule. As this does not exist anymore, the comment is also not needed anymore

@OCA-git-bot
Copy link
Contributor

Hi @sebastienbeau, @hparfr,
some modules you are maintaining are being modified, check this out!

@raumschmiede-joshuaL
Copy link
Author

Will add the 2nd commit after the tests for the 1st commit are done to be sure I committed the right things

This ensures that the model on which the exceptions are detected get the exceptions assigned by default. Previously it was only possible if this def was overridden manually
@raumschmiede-joshuaL
Copy link
Author

@hparfr and @lmignon, did a rebase. Can you check this here please?

@raumschmiede-joshuaL
Copy link
Author

@hparfr, if a model inherits from base.exception.method, it must implement field ignore_exception because that class uses the field in _get_base_domain when it tries to find the records on which the rule needs to be applied on. If this field is not implemented, an error is raised.

That's why I want to move it from base.exception to base.exception.method to have it automatically implemented through inheritance. Is this ok?
If models need a special implementation for this field, it needs to be implemented anyway manually. Like in sale.order.line so that the field is related to order_id.ignore_exception.
For other models the field will always be False and never changed. But this would be the case anyway if you have to implement it eventhough you wouldn't use it

Comment on lines +103 to +107
if not self._add_detected_exceptions_to_self():
return records

(self - records).exception_ids = [(3, rule.id)]
records.exception_ids = [(4, rule.id)]
Copy link

@mt-software-de mt-software-de Sep 29, 2025

Choose a reason for hiding this comment

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

Here a small minor request.

Suggested change
if not self._add_detected_exceptions_to_self():
return records
(self - records).exception_ids = [(3, rule.id)]
records.exception_ids = [(4, rule.id)]
if self._add_detected_exceptions_to_self():
(self - records).exception_ids = [(3, rule.id)]
records.exception_ids = [(4, rule.id)]

Choose a reason for hiding this comment

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

Is it correct that since you are writing the rules now on the records, the logic in detect_exceptions in base.exception.method is not used anymore. Or only if the returned main record isn't the same as where it was executed from?

Isn't this quite bad because the checks and writes in detect_exceptions are done twice?

Isn't it possible to have the writing in just one place?

Choose a reason for hiding this comment

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

detect_exceptions in base.exception.method is still needed.
If a model inherits from base.exception.method, it has no exception_ids, that's why it must return another record in _get_main_records. The detected rules in base.exception.method are written to that other model. Like it is done right now in account_move_exception.

If a model inherits from base.exception, there are 2 ways:

  1. It overrides _get_main_records, like it is done in my PR for sale_exception. But as it returns another record, it will not write the detected rules on the sale order lines, only on the sales orders returned by _get_main_records. That's why this override here is needed
  2. It does not override _get_main_records: Then the detected rules are added to self in base.exception.method and this here has no effect as it is always False

Choose a reason for hiding this comment

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

Ok. Since you are only adding it if the main record isn't the same. So if the exception is on sale.order and it is detected on sale.order it will add it in detect_exceptions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载