Skip to content

Commit

Permalink
[IMP] sale_planner_calendar: Add rating to calendar events
Browse files Browse the repository at this point in the history
TT51662
  • Loading branch information
pilarvargas-tecnativa committed Nov 11, 2024
1 parent 3f248fd commit 49a15d0
Show file tree
Hide file tree
Showing 8 changed files with 145 additions and 1 deletion.
22 changes: 22 additions & 0 deletions sale_planner_calendar/models/calendar_event.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,15 @@ class CalendarEvent(models.Model):
sanitized_partner_mobile = fields.Char(compute="_compute_sanitized_partner_mobile")
location_url = fields.Char(compute="_compute_location_url")
categ_icons = fields.Char(compute="_compute_categ_icons")
sale_planner_rating = fields.Selection(
[
("1", "Bad"),
("3", "Fair"),
("5", "Good"),
],
required=True,
)
comment_rating = fields.Text()

@api.depends("recurrence_id", "recurrence_id.calendar_event_ids")
def _compute_is_base_recurrent_event(self):
Expand Down Expand Up @@ -363,6 +372,19 @@ def action_open_issue(self):
def action_apply_issue(self):
pass

Check warning on line 373 in sale_planner_calendar/models/calendar_event.py

View check run for this annotation

Codecov / codecov/patch

sale_planner_calendar/models/calendar_event.py#L373

Added line #L373 was not covered by tests

def action_open_rating(self):
action = self.env["ir.actions.act_window"]._for_xml_id(

Check warning on line 376 in sale_planner_calendar/models/calendar_event.py

View check run for this annotation

Codecov / codecov/patch

sale_planner_calendar/models/calendar_event.py#L376

Added line #L376 was not covered by tests
"sale_planner_calendar.action_sale_planner_calendar_rating"
)
action["res_id"] = self.id
return action

Check warning on line 380 in sale_planner_calendar/models/calendar_event.py

View check run for this annotation

Codecov / codecov/patch

sale_planner_calendar/models/calendar_event.py#L379-L380

Added lines #L379 - L380 were not covered by tests

def action_set_sale_planner_rating(self):
rating = self.env.context.get("rating_value")

Check warning on line 383 in sale_planner_calendar/models/calendar_event.py

View check run for this annotation

Codecov / codecov/patch

sale_planner_calendar/models/calendar_event.py#L383

Added line #L383 was not covered by tests
if rating:
self.sale_planner_rating = rating
self.action_done()

Check warning on line 386 in sale_planner_calendar/models/calendar_event.py

View check run for this annotation

Codecov / codecov/patch

sale_planner_calendar/models/calendar_event.py#L385-L386

Added lines #L385 - L386 were not covered by tests

def _get_hour_tz_offset(self):
timezone = self._context.get("tz") or self.env.user.partner_id.tz or "UTC"
self_tz = self.with_context(tz=timezone)
Expand Down
Binary file added sale_planner_calendar/static/img/rating_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions sale_planner_calendar/static/img/rating_1.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added sale_planner_calendar/static/img/rating_3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions sale_planner_calendar/static/img/rating_3.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added sale_planner_calendar/static/img/rating_5.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions sale_planner_calendar/static/img/rating_5.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
121 changes: 120 additions & 1 deletion sale_planner_calendar/views/sale_planner_calendar_event_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,111 @@
}</field>
</record>

<record id="view_sale_planner_calendar_rating_form" model="ir.ui.view">
<field name="name">sale.planner.calendar.rating.form</field>
<field name="model">calendar.event</field>
<field name="priority" eval="999" />
<field name="arch" type="xml">
<form string="Sale planner calendar event">
<group>
<field name="sale_planner_rating" invisible="1" />
<field name="target_partner_id" readonly="1" />
</group>
<group colspan="4">
<label for="comment_rating" />
<field
colspan="2"
name="comment_rating"
class="border"
nolabel="1"
/>
</group>
<button
name="action_set_sale_planner_rating"
type="object"
class="btn btn-secondary"
context="{'rating_value': '1'}"
attrs="{'invisible': [('sale_planner_rating', '=', '1')]}"
>
<img
alt="Poor"
src="sale_planner_calendar/static/img/rating_1.png"
title="Poor"
/>
</button>
<button
class="btn btn-secondary border"
attrs="{'invisible': [('sale_planner_rating', '!=', '1')]}"
>
<img
alt="Poor"
src="sale_planner_calendar/static/img/rating_1.png"
title="Poor"
/>
</button>
<button
name="action_set_sale_planner_rating"
type="object"
class="btn btn-secondary"
context="{'rating_value': '3'}"
attrs="{'invisible': [('sale_planner_rating', '=', '3')]}"
>
<img
alt="Fair"
src="sale_planner_calendar/static/img/rating_3.png"
title="Fair"
/>
</button>
<button
class="btn btn-secondary border"
attrs="{'invisible': [('sale_planner_rating', '!=', '3')]}"
>
<img
alt="Fair"
src="sale_planner_calendar/static/img/rating_3.png"
title="Fair"
/>
</button>
<button
name="action_set_sale_planner_rating"
type="object"
class="btn btn-secondary"
context="{'rating_value': '5'}"
attrs="{'invisible': [('sale_planner_rating', '=', '5')]}"
>
<img
alt="Good"
src="sale_planner_calendar/static/img/rating_5.png"
title="Good"
/>
</button>
<button
class="btn btn-secondary border"
attrs="{'invisible': [('sale_planner_rating', '!=', '5')]}"
>
<img
alt="Good"
src="sale_planner_calendar/static/img/rating_5.png"
title="Good"
/>
</button>
<footer>
<button string="Cancel" class="btn-secondary" special="cancel" />
</footer>
</form>
</field>
</record>

<record id="action_sale_planner_calendar_rating" model="ir.actions.act_window">
<field name="name">Sale planner calendar rating</field>
<field name="res_model">calendar.event</field>
<field name="view_mode">form</field>
<field name="target">new</field>
<field name="context">
{'form_view_ref': 'sale_planner_calendar.view_sale_planner_calendar_rating_form'}
</field>
</record>

<record id="view_sale_planner_calendar_kanban" model="ir.ui.view">
<field name="name">sale.planner.calendar.event.kanban</field>
<field name="model">calendar.event</field>
Expand Down Expand Up @@ -318,8 +423,22 @@
<field
name="sale_planner_state"
widget="label_selection"
options="{'classes': {'pending': 'info', 'cancel': 'danger', 'done': 'success'}}"
class="btn btn-danger btn-lg p-0 pb-1"
attrs="{'invisible': [('sale_planner_state', '!=', 'cancel')]}"
options="{'classes': {'cancel': 'danger'}}"
/>
<button
name="action_open_rating"
type="object"
attrs="{'invisible': [('sale_planner_state', '=', 'cancel')]}"
title="Change Order State"
t-att-class="'btn p-0 px-1 btn-lg text-capitalize ' + (record.sale_planner_state.raw_value == 'done' and 'btn-success' or 'btn-info')"
>
<span
class="badge pb-2"
t-esc="record.sale_planner_state.raw_value"
/>
</button>
</div>
</div>
</div>
Expand Down

0 comments on commit 49a15d0

Please sign in to comment.