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 authored and carlosdauden committed Nov 14, 2024
1 parent 695a088 commit 3a9f6d7
Show file tree
Hide file tree
Showing 8 changed files with 139 additions and 1 deletion.
21 changes: 21 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,14 @@ 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,
)

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

def action_open_rating(self):
action = self.env["ir.actions.act_window"]._for_xml_id(
"sale_planner_calendar.action_sale_planner_calendar_rating"
)
action["res_id"] = self.id
return action

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

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.
116 changes: 115 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,106 @@
}</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" />
<field colspan="2" name="comment" 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 +418,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 calendar event status by adding a previous rating"
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 3a9f6d7

Please sign in to comment.