-
-
Notifications
You must be signed in to change notification settings - Fork 112
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
[16.0][IMP] membership_extension & _variable_period: Make sure necessary fields are always truthy #157
Conversation
d475f3e
to
3f8afd4
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @carmenbianca I'm ok with your suggestions. Just a couple of comments:
for record in self: | ||
if record.membership: | ||
if not record.membership_date_from or not record.membership_date_to: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for record in self: | |
if record.membership: | |
if not record.membership_date_from or not record.membership_date_to: | |
if self.filtered(lambda x: x.membership and (not x.membership_date_from or not x.membership_date_to): |
for record in self: | ||
if record.membership: | ||
if record.membership_type == "fixed": | ||
return super(ProductTemplate, record)._check_membership_dates() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're breaking your loop here. Maybe what you want to do is:
for record in self: | |
if record.membership: | |
if record.membership_type == "fixed": | |
return super(ProductTemplate, record)._check_membership_dates() | |
return super(ProductTemplate, self.filtered(lambda x: x.membership_type == "fixed"))._check_membership_dates() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch!
…elds are always truthy This is an additional sanity check to make sure that fields that are expected to be available are actually available. The situation here is a little tricky. Especially as pertains date_from and date_to; these fields are `required=True` nowhere. Not on the product, not on the membership invoice, and not on the membership line. However, they _are_ set as required in the product and membership line views. If these values are ever empty, it's a sure sign that something went wrong somewhere, because the user should not be able to reach such a state via the UI. One sure way to reach that state was via the demo data, however, which had no start and end dates. This is now fixed. The situation for the variable period fields is similar. These fields should never be empty when the membership type is variable, and it's not typically possible to empty these values via the UI. For convenience's sake, I simply set them to required an sich, with a default value. Signed-off-by: Carmen Bianca BAKKER <[email protected]>
3f8afd4
to
315bdba
Compare
@chienandalu I've implemented and pushed your suggestions. Thank you for the review. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks :)
cls.product_1.membership = True | ||
cls.product_1.write( | ||
{ | ||
"membership_date_from": "2023-01-01", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do you need to change this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pedrobaeza Because the new constraint won't let a membership product have no start/end dates.
@api.constrains("membership_date_from", "membership_date_to", "membership")
def _check_membership_dates(self):
if self.filtered(
lambda record: record.membership
and (not record.membership_date_from or not record.membership_date_to)
):
raise ValidationError(
_("A membership product must have a start date and an end date.")
)
(Interestingly, the write function is sensitive to the order of key-value pairs. If "membership": True
appears before the other items, the constraint complains. Not sure why that happens.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's weird, as in other places, you are removing such fields, but it's not a big deal.
/ocabot merge patch
/ocabot merge patch |
Hey, thanks for contributing! Proceeding to merge this for you. |
Congratulations, your PR was merged at 3ee9de5. Thanks a lot for contributing to OCA. ❤️ |
This is an additional sanity check to make sure that fields that are expected to be available are actually available.
The situation here is a little tricky. Especially as pertains date_from and date_to; these fields are
required=True
nowhere. Not on the product, not on the membership invoice, and not on the membership line. However, they are set as required in the product and membership line views. If these values are ever empty, it's a sure sign that something went wrong somewhere, because the user should not be able to reach such a state via the UI.One sure way to reach that state was via the demo data, however, which had no start and end dates. This is now fixed.
The situation for the variable period fields is similar. These fields should never be empty when the membership type is variable, and it's not typically possible to empty these values via the UI. For convenience's sake, I simply set them to required an sich, with a default value.