Skip to content
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

[IMP] event_sale_session: Recovery unconfirmed quantity event #373

Open
wants to merge 1 commit into
base: 16.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions event_sale_session/i18n/es.po
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,11 @@ msgstr "Informe analítico de ventas"
msgid "Sales Order Line"
msgstr "Línea de pedido de venta"

#. module: event_sale_session
#: model:ir.model.fields,field_description:event_sale_session.field_event_session__order_line_ids
msgid "Sales Order Lines"
msgstr "Líneas de pedido de venta"

#. module: event_sale_session
#: model:ir.model.fields,field_description:event_sale_session.field_event_event_configurator__event_session_id
#: model:ir.model.fields,field_description:event_sale_session.field_registration_editor_line__session_id
Expand All @@ -136,6 +141,26 @@ msgstr "Evento estándar + catering"
msgid "Total sales for this session"
msgstr "Total de ventas para esta sesión"

#. module: event_sale_session
#: model_terms:ir.ui.view,arch_db:event_sale_session.view_event_session_tree
msgid "Total unconfirmed seats in orders"
msgstr "Total plazas de pedidos no confirmados"

#. module: event_sale_session
#: model:ir.model.fields,field_description:event_sale_session.field_event_session__unconfirmed_qty
msgid "Unconfirmed Qty"
msgstr "Cantidad sin asignar"

#. module: event_sale_session
#: model_terms:ir.ui.view,arch_db:event_sale_session.view_event_session_form
msgid "Unconfirmed order seats"
msgstr "Plazas en pedidos sin confirmar"

#. module: event_sale_session
#: model_terms:ir.ui.view,arch_db:event_sale_session.view_event_session_form
msgid "Unconfirmed orders seats"
msgstr "Plazas en pedidos sin confirmar"

#. module: event_sale_session
#: model:event.event.ticket,name:event_sale_session.event_ticket_007_vip
msgid "VIP"
Expand Down
25 changes: 25 additions & 0 deletions event_sale_session/i18n/event_sale_session.pot
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,11 @@ msgstr ""
msgid "Sales Order Line"
msgstr ""

#. module: event_sale_session
#: model:ir.model.fields,field_description:event_sale_session.field_event_session__order_line_ids
msgid "Sales Order Lines"
msgstr ""

#. module: event_sale_session
#: model:ir.model.fields,field_description:event_sale_session.field_event_event_configurator__event_session_id
#: model:ir.model.fields,field_description:event_sale_session.field_registration_editor_line__session_id
Expand All @@ -132,6 +137,26 @@ msgstr ""
msgid "Total sales for this session"
msgstr ""

#. module: event_sale_session
#: model_terms:ir.ui.view,arch_db:event_sale_session.view_event_session_tree
msgid "Total unconfirmed seats in orders"
msgstr ""

#. module: event_sale_session
#: model:ir.model.fields,field_description:event_sale_session.field_event_session__unconfirmed_qty
msgid "Unconfirmed Qty"
msgstr ""

#. module: event_sale_session
#: model_terms:ir.ui.view,arch_db:event_sale_session.view_event_session_form
msgid "Unconfirmed order seats"
msgstr ""

#. module: event_sale_session
#: model_terms:ir.ui.view,arch_db:event_sale_session.view_event_session_form
msgid "Unconfirmed orders seats"
msgstr ""

#. module: event_sale_session
#: model:event.event.ticket,name:event_sale_session.event_ticket_007_vip
msgid "VIP"
Expand Down
31 changes: 31 additions & 0 deletions event_sale_session/models/event_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,37 @@
compute="_compute_sale_price_subtotal",
groups="sales_team.group_sale_salesman",
)
unconfirmed_qty = fields.Integer(
compute="_compute_unconfirmed_qty",
store=True,
)

@api.depends(
"sale_order_lines_ids",
"sale_order_lines_ids.product_uom_qty",
"sale_order_lines_ids.order_id.state",
)
def _compute_unconfirmed_qty(self):
for session in self:
session.unconfirmed_qty = int(
sum(
session.sale_order_lines_ids.filtered(
lambda x: x.order_id.state in ("draft", "sent")
).mapped("product_uom_qty")
)
)

def button_open_unconfirmed_event_order(self):
action = self.env["ir.actions.act_window"]._for_xml_id("sale.action_quotations")
sales = (

Check warning on line 47 in event_sale_session/models/event_session.py

View check run for this annotation

Codecov / codecov/patch

event_sale_session/models/event_session.py#L46-L47

Added lines #L46 - L47 were not covered by tests
self.env["sale.order.line"]
.search([("event_id", "in", self.ids)])
.mapped("order_id")
.ids
)
action["domain"] = [("id", "in", sales), ("state", "in", ("draft", "sent"))]
action["context"] = {}
return action

Check warning on line 55 in event_sale_session/models/event_session.py

View check run for this annotation

Codecov / codecov/patch

event_sale_session/models/event_session.py#L53-L55

Added lines #L53 - L55 were not covered by tests

@api.depends(
"currency_id",
Expand Down
19 changes: 3 additions & 16 deletions event_sale_session/tests/test_event_sale_session.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Copyright 2017 Tecnativa - David Vidal
# Copyright 2022 Moka Tourisme (https://www.mokatourisme.fr).
# Copyright 2024 Tecnativa - Carolina Fernandez
# @author Iván Todorovich <[email protected]>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl-3.0).

Expand Down Expand Up @@ -36,7 +37,9 @@ def setUpClass(cls):

def test_sale_session(self):
"""Sell an event with session"""
self.assertEqual(self.session.unconfirmed_qty, 5)
self.order.action_confirm()
self.assertEqual(self.session.unconfirmed_qty, 0)
regs = self.env["event.registration"].search(
[("sale_order_id", "=", self.order.id)]
)
Expand All @@ -54,22 +57,6 @@ def test_sale_session(self):
orders = self.env["sale.order"].search(action["domain"])
self.assertIn(self.order, orders)

def test_sale_order_line_session_onchange_autocomplete(self):
"""Test that session is automatically filled and or unset on form"""
form = Form(self.order)
line = form.order_line.new()
line.product_id = self.product
# Case 1: The event is a session event, but has multiple sessions
line.event_id = self.event
self.assertFalse(line.event_session_id)
# Case 2: The event is a session event with only 1 session
(self.event.session_ids - self.session).active = False
line.event_id = self.event
self.assertEqual(line.event_session_id, self.session)
# Case 3: The event is not a session event, session should be unset
line.event_id = self.env.ref("event.event_0")
self.assertFalse(line.event_session_id)

Comment on lines -57 to -72
Copy link
Member

Choose a reason for hiding this comment

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

Why removing this whole test?

Choose a reason for hiding this comment

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

Onchange is only applied when you are in form view

Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry, I still don't understand the reason to remove it 😓 are you facing an issue with this test while implementing the new feature?

def test_sale_order_event_configurator_onchange_autocomplete(self):
"""Test that session is automatically filled and or unset on wizard"""
wizard = self.env["event.event.configurator"].create(
Expand Down
26 changes: 26 additions & 0 deletions event_sale_session/views/event_session.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,33 @@
widget="statinfo"
/>
</button>
<button
name="button_open_unconfirmed_event_order"
type="object"
class="oe_stat_button"
icon="fa-eye-slash"
help="Unconfirmed orders seats"
>
<field
name="unconfirmed_qty"
widget="statinfo"
string="Unconfirmed order seats"
/>
</button>
</div>
</field>
</record>
<record id="view_event_session_tree" model="ir.ui.view">
<field name="model">event.session</field>
<field name="inherit_id" ref="event_session.view_event_session_tree" />
<field name="arch" type="xml">
<field name="seats_expected" position="after">
<field
name="unconfirmed_qty"
attrs="{'invisible': [('unconfirmed_qty','&lt;', 1)]}"
sum="Total unconfirmed seats in orders"
/>
</field>
</field>
</record>
</odoo>
Loading