Sourcery refactored main branch#1
Conversation
| if not duration: | ||
| duration = _("unknown") | ||
| else: | ||
| duration = str(duration) | ||
| duration = str(duration) if duration else _("unknown") | ||
| meet_date = fields.Datetime.from_string(meeting_date) | ||
| meeting_usertime = fields.Datetime.to_string( | ||
| fields.Datetime.context_timestamp(self, meet_date) | ||
| ) | ||
| html_time = "<time datetime='%s+00:00'>%s</time>" % ( | ||
| meeting_date, | ||
| meeting_usertime, | ||
| ) | ||
| html_time = f"<time datetime='{meeting_date}+00:00'>{meeting_usertime}</time>" |
There was a problem hiding this comment.
Function Event.log_meeting refactored with the following changes:
- Replace if statement with if expression (
assign-if-exp) - Replace interpolated string formatting with f-string (
replace-interpolation-with-fstring) - Swap if/else branches of if expression to remove negation (
swap-if-expression)
| description = "Event: " + self.name | ||
| description = f"Event: {self.name}" |
There was a problem hiding this comment.
Function Event.action_schedule_meeting refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation)
| # event_id = details.get("_event_id") | ||
| registrations = super( | ||
| return super( | ||
| ExtendedWebsiteEventController, self | ||
| )._process_registration_details(details) | ||
| # event_id = request.env["event.registration"].sudo().browse([int(event_id)]) | ||
|
|
||
| # for registration in registrations: | ||
| # registration["event_id"] = event_id.id | ||
| # registration["is_a_template"] = True | ||
| return registrations |
There was a problem hiding this comment.
Function AttTemplateWebsiteEvent._process_registration_details refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable)
This removes the following comments ( why? ):
# event_id = request.env["event.registration"].sudo().browse([int(event_id)])
# event_id = details.get("_event_id")
# for registration in registrations:
# registration["event_id"] = event_id.id
# registration["is_a_template"] = True
| _logger.info("Available Events:{} - {}".format(all_attendee_ids.ids, all_attendee_ids.mapped('event_id'))) | ||
| _logger.info( | ||
| f"Available Events:{all_attendee_ids.ids} - {all_attendee_ids.mapped('event_id')}" | ||
| ) |
There was a problem hiding this comment.
Function AttTemplateLateReg.website_registration_complete refactored with the following changes:
- Replace call to format with f-string [×2] (
use-fstring-for-formatting)
| registrations.setdefault(att_id, dict())[field_name] = value | ||
| registrations.setdefault(att_id, {})[field_name] = value |
There was a problem hiding this comment.
Function AttTemplateLateReg.website_registration_complete_submit refactored with the following changes:
- Replace
dict()with{}(dict-literal)
| "A reminder containing the following link has been sent to the attendee's related partner: %s" | ||
| % self.event_token_url | ||
| f"A reminder containing the following link has been sent to the attendee's related partner: {self.event_token_url}" |
There was a problem hiding this comment.
Function SaleOrder.send_late_reg_event_notification refactored with the following changes:
- Replace interpolated string formatting with f-string (
replace-interpolation-with-fstring)
| event_template = product_id.event_template_id | ||
| if product_id.product_tmpl_id.is_event_product: | ||
| event_template = product_id.event_template_id |
There was a problem hiding this comment.
Function SaleOrderLine.create_event_from_order_line refactored with the following changes:
- Move assignments closer to their usage (
move-assign)
| event_template = product_id.event_template_id | ||
|
|
There was a problem hiding this comment.
Function SaleOrderLine.join_event_from_order_line refactored with the following changes:
- Move assignments closer to their usage (
move-assign)
| event_template_id = ( | ||
| if event_template_id := ( | ||
| order_line.event_id | ||
| or order_line.product_id.product_tmpl_id.event_template_id | ||
| ) | ||
| if event_template_id: | ||
| ): |
There was a problem hiding this comment.
Function SaleOrderLine._update_registrations refactored with the following changes:
- Use named expression to simplify assignment and conditional (
use-named-expression) - Replace unused for index with underscore (
for-index-underscore)
| event_template = product_id.product_tmpl_id.event_template_id | ||
|
|
There was a problem hiding this comment.
Function Task.join_event_from_task refactored with the following changes:
- Move assignments closer to their usage (
move-assign)
| attendee_template_id = a.template_id if a.template_id else a | ||
| attendee_template_id = a.template_id or a | ||
| attendee_ids = a | ||
| #event_ids = a.event_id | ||
|
|
There was a problem hiding this comment.
Function CertificateReport._get_report_values refactored with the following changes:
- Simplify if expression by using or (
or-if-exp-identity) - Replace interpolated string formatting with f-string (
replace-interpolation-with-fstring)
| view_id=view_id, view_type=view_type, toolbar=toolbar, submenu=submenu | ||
| ) | ||
| _logger.info('Context %s'%self.env.context) | ||
| _logger.info(f'Context {self.env.context}') |
There was a problem hiding this comment.
Function AccountInvoiceSend.fields_view_get refactored with the following changes:
- Replace interpolated string formatting with f-string [×6] (
replace-interpolation-with-fstring)
| if self.generate_certificates and self.event_ids: | ||
| so_line_ids = [] | ||
| active_id = self.env.context.get('active_id', False) | ||
| if self.env.context.get('params', False): | ||
| params = self.env.context.get('params', False) | ||
| if params['model'] == 'account.move': | ||
| active_id = params['id'] | ||
| invoice_id = self.env["account.move"].browse(active_id) | ||
| for inv_line in invoice_id.invoice_line_ids: | ||
| so_line_ids += inv_line.sale_line_ids.ids | ||
| cert_ids = self.event_ids.generate_event_certificates( | ||
| invoice_id.id, so_line_ids | ||
| ) | ||
| _logger.info('Certificate %s'%cert_ids) | ||
| if cert_ids: | ||
| cert_attachment_ids = self.env["ir.attachment"].search( | ||
| [ | ||
| ("res_model", "in", ["event.certificate"]), | ||
| ("res_id", "in", cert_ids.ids) | ||
| ] | ||
| ) | ||
| if cert_attachment_ids: | ||
| self.attachment_ids = [(6,0,self.attachment_ids.ids + cert_attachment_ids.ids)] No newline at end of file | ||
| if not self.generate_certificates or not self.event_ids: | ||
| return | ||
| so_line_ids = [] | ||
| active_id = self.env.context.get('active_id', False) | ||
| if self.env.context.get('params', False): | ||
| params = self.env.context.get('params', False) | ||
| if params['model'] == 'account.move': | ||
| active_id = params['id'] | ||
| invoice_id = self.env["account.move"].browse(active_id) | ||
| for inv_line in invoice_id.invoice_line_ids: | ||
| so_line_ids += inv_line.sale_line_ids.ids | ||
| cert_ids = self.event_ids.generate_event_certificates( | ||
| invoice_id.id, so_line_ids | ||
| ) | ||
| _logger.info(f'Certificate {cert_ids}') | ||
| if cert_ids: | ||
| if cert_attachment_ids := self.env["ir.attachment"].search( | ||
| [ | ||
| ("res_model", "in", ["event.certificate"]), | ||
| ("res_id", "in", cert_ids.ids), | ||
| ] | ||
| ): | ||
| self.attachment_ids = [(6,0,self.attachment_ids.ids + cert_attachment_ids.ids)] No newline at end of file |
There was a problem hiding this comment.
Function AccountInvoiceSend.button_generate_certificates refactored with the following changes:
- Add guard clause (
last-if-guard) - Replace interpolated string formatting with f-string (
replace-interpolation-with-fstring) - Use named expression to simplify assignment and conditional (
use-named-expression)
| order.has_event_product = False | ||
| for line in order.order_line: | ||
| if ( | ||
| order.has_event_product = any( | ||
| ( | ||
| line.product_id.is_event_product | ||
| and line.product_id.event_template_id | ||
| ): | ||
| order.has_event_product = True | ||
| break | ||
| ) | ||
| for line in order.order_line | ||
| ) |
There was a problem hiding this comment.
Function SaleOrder._compute_has_event_product refactored with the following changes:
- Use any() instead of for loop (
use-any)
| product_id = line.product_id | ||
| event_template = product_id.event_template_id | ||
| if product_id.is_event_product: | ||
| event_template = product_id.event_template_id |
There was a problem hiding this comment.
Function SaleOrder.button_create_event refactored with the following changes:
- Move assignments closer to their usage (
move-assign)
| event_template = product_id.event_template_id | ||
| if product_id.is_event_product: | ||
| event_template = product_id.event_template_id |
There was a problem hiding this comment.
Function SaleOrderLine.create_event_from_order_line refactored with the following changes:
- Move assignments closer to their usage (
move-assign)
| if not self.sale_order_line_id: | ||
| return {"domain": {"event_id": []}} | ||
| return { | ||
| "domain": { | ||
| "event_id": [ | ||
| ( | ||
| "event_template_id.id", | ||
| "=", | ||
| self.sale_order_line_id.product_id.event_template_id.id, | ||
| ), | ||
| ("state", "!=", "cancel"), | ||
| ("date_begin", ">=", datetime.today().strftime("%Y-%m-%d")), | ||
| ] | ||
| return ( | ||
| { | ||
| "domain": { | ||
| "event_id": [ | ||
| ( | ||
| "event_template_id.id", | ||
| "=", | ||
| self.sale_order_line_id.product_id.event_template_id.id, | ||
| ), | ||
| ("state", "!=", "cancel"), | ||
| ("date_begin", ">=", datetime.now().strftime("%Y-%m-%d")), | ||
| ] | ||
| } | ||
| } | ||
| } | ||
| if self.sale_order_line_id | ||
| else {"domain": {"event_id": []}} | ||
| ) |
There was a problem hiding this comment.
Function EventJoinExisting.onchange_sale_order_line_id refactored with the following changes:
- Lift code into else after jump in control flow (
reintroduce-else) - Replace if statement with if expression (
assign-if-exp) - Replace datetime.datetime.today() with datetime.datetime.now() (
use-datetime-now-not-today) - Swap if/else branches of if expression to remove negation (
swap-if-expression)
| if not self.event_id: | ||
| return {"domain": {"ticket_id": []}} | ||
| return { | ||
| "domain": {"ticket_id": [("id", "in", self.event_id.event_ticket_ids.ids)]} | ||
| } | ||
| return ( | ||
| { | ||
| "domain": { | ||
| "ticket_id": [("id", "in", self.event_id.event_ticket_ids.ids)] | ||
| } | ||
| } | ||
| if self.event_id | ||
| else {"domain": {"ticket_id": []}} | ||
| ) |
There was a problem hiding this comment.
Function EventJoinExisting.onchange_event_id refactored with the following changes:
- Lift code into else after jump in control flow (
reintroduce-else) - Replace if statement with if expression (
assign-if-exp) - Swap if/else branches of if expression to remove negation (
swap-if-expression)
| if self.event_id: | ||
| if self.ticket_id: | ||
| self.sale_order_line_id.join_event_from_order_line( | ||
| self.event_id, self.ticket_id | ||
| ) | ||
| else: | ||
| raise UserError(_("Please select a ticket.")) | ||
| else: | ||
| if not self.event_id: | ||
| raise UserError(_("Please select an event to join.")) | ||
| if self.ticket_id: | ||
| self.sale_order_line_id.join_event_from_order_line( | ||
| self.event_id, self.ticket_id | ||
| ) | ||
| else: | ||
| raise UserError(_("Please select a ticket.")) |
There was a problem hiding this comment.
Function EventJoinExisting.button_manage_events refactored with the following changes:
- Swap positions of nested conditionals [×2] (
swap-nested-ifs) - Hoist nested repeated code outside conditional statements [×2] (
hoist-similar-statement-from-if) - Swap if/else branches (
swap-if-else-branches) - Remove unnecessary else after guard condition (
remove-unnecessary-else)
| if not self.task_id: | ||
| return {"domain": {"event_id": []}} | ||
| return { | ||
| "domain": { | ||
| "event_id": [ | ||
| ( | ||
| "event_template_id.id", | ||
| "=", | ||
| self.task_id.sale_line_id.product_id.event_template_id.id, | ||
| ), | ||
| ("state", "!=", "cancel"), | ||
| ("date_begin", ">=", datetime.today()), | ||
| ] | ||
| return ( | ||
| { | ||
| "domain": { | ||
| "event_id": [ | ||
| ( | ||
| "event_template_id.id", | ||
| "=", | ||
| self.task_id.sale_line_id.product_id.event_template_id.id, | ||
| ), | ||
| ("state", "!=", "cancel"), | ||
| ("date_begin", ">=", datetime.now()), | ||
| ] | ||
| } | ||
| } | ||
| } | ||
| if self.task_id | ||
| else {"domain": {"event_id": []}} | ||
| ) |
There was a problem hiding this comment.
Function EventJoinExisting.onchange_sale_order_line_id refactored with the following changes:
- Lift code into else after jump in control flow (
reintroduce-else) - Replace if statement with if expression (
assign-if-exp) - Replace datetime.datetime.today() with datetime.datetime.now() (
use-datetime-now-not-today) - Swap if/else branches of if expression to remove negation (
swap-if-expression)
Branch
mainrefactored by Sourcery.If you're happy with these changes, merge this Pull Request using the Squash and merge strategy.
See our documentation here.
Run Sourcery locally
Reduce the feedback loop during development by using the Sourcery editor plugin:
Review changes via command line
To manually merge these changes, make sure you're on the
mainbranch, then run:Help us improve this pull request!