Skip to content

Commit

Permalink
[IMP] event_sale: remove is_paid and store payment_status
Browse files Browse the repository at this point in the history
We remove the is_paid field and based the logic on the payment_status
as these two fields are a bit redundant. It is also in preparation
to the removal of the field auto_confirm on the event.event model.
The goal is to ease and simplify the management of registrations.

UPG PR: odoo/upgrade#4836

task-3061849

Part-of: odoo#126431
  • Loading branch information
jeh-odoo committed Oct 13, 2023
1 parent 26e3a11 commit 692496c
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 23 deletions.
19 changes: 7 additions & 12 deletions addons/event_sale/models/event_registration.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,33 +8,28 @@
class EventRegistration(models.Model):
_inherit = 'event.registration'

is_paid = fields.Boolean('Is Paid')
# TDE FIXME: maybe add an onchange on sale_order_id
sale_order_id = fields.Many2one('sale.order', string='Sales Order', ondelete='cascade', copy=False)
sale_order_line_id = fields.Many2one('sale.order.line', string='Sales Order Line', ondelete='cascade', copy=False)
payment_status = fields.Selection(string="Payment Status", selection=[
('to_pay', 'Not Paid'),
('paid', 'Paid'),
('free', 'Free'),
], compute="_compute_payment_status", compute_sudo=True)
], compute="_compute_payment_status", compute_sudo=True, store=True)
utm_campaign_id = fields.Many2one(compute='_compute_utm_campaign_id', readonly=False,
store=True, ondelete="set null")
utm_source_id = fields.Many2one(compute='_compute_utm_source_id', readonly=False,
store=True, ondelete="set null")
utm_medium_id = fields.Many2one(compute='_compute_utm_medium_id', readonly=False,
store=True, ondelete="set null")

@api.depends('is_paid', 'sale_order_id.currency_id', 'sale_order_line_id.price_total')
@api.depends('sale_order_id.state', 'sale_order_id.currency_id', 'sale_order_line_id.price_total')
def _compute_payment_status(self):
for record in self:
so = record.sale_order_id
so_line = record.sale_order_line_id
if not so or float_is_zero(so_line.price_total, precision_digits=so.currency_id.rounding):
record.payment_status = 'free'
elif record.is_paid:
record.payment_status = 'paid'
for so_line, registrations in self.grouped('sale_order_line_id').items():
if not so_line or float_is_zero(so_line.price_total, precision_digits=so_line.currency_id.rounding):
registrations.payment_status = 'free'
else:
record.payment_status = 'to_pay'
registrations.payment_status = 'to_pay'

@api.depends('sale_order_id')
def _compute_utm_campaign_id(self):
Expand Down Expand Up @@ -125,7 +120,7 @@ def _sale_order_ticket_type_change_notify(self, new_event_ticket):
render_context=render_context)

def _action_set_paid(self):
self.write({'is_paid': True})
self.write({'payment_status': 'paid'})

def _get_registration_summary(self):
res = super(EventRegistration, self)._get_registration_summary()
Expand Down
2 changes: 1 addition & 1 deletion addons/event_sale/models/sale_order_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def _update_registrations(self, confirm=True, cancel_to_draft=False, registratio
if confirm:
existing_registrations.filtered(lambda self: self.state not in ['open', 'cancel']).action_confirm()
if mark_as_paid:
existing_registrations.filtered(lambda self: not self.is_paid)._action_set_paid()
existing_registrations.filtered(lambda self: self.payment_status == 'to_pay')._action_set_paid()
if cancel_to_draft:
existing_registrations.filtered(lambda self: self.state == 'cancel').action_set_draft()

Expand Down
10 changes: 2 additions & 8 deletions addons/event_sale/report/event_sale_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ class EventSaleReport(models.Model):
sale_price = fields.Float('Revenues', readonly=True)
sale_price_untaxed = fields.Float('Untaxed Revenues', readonly=True)
invoice_partner_id = fields.Many2one('res.partner', string='Invoice Address', readonly=True)
is_paid = fields.Boolean('Is Paid', readonly=True)
payment_status = fields.Selection(string="Payment Status", selection=[
('to_pay', 'Not Paid'),
('paid', 'Paid'),
Expand Down Expand Up @@ -81,7 +80,7 @@ def _select_clause(self, *select):
event_registration.active AS active,
event_registration.sale_order_id AS sale_order_id,
event_registration.sale_order_line_id AS sale_order_line_id,
event_registration.is_paid AS is_paid,
event_registration.payment_status AS payment_status,
event_event.event_type_id AS event_type_id,
event_event.date_begin AS event_date_begin,
Expand Down Expand Up @@ -109,12 +108,7 @@ def _select_clause(self, *select):
sale_order_line.price_subtotal
/ CASE COALESCE(sale_order.currency_rate, 0) WHEN 0 THEN 1.0 ELSE sale_order.currency_rate END
/ sale_order_line.product_uom_qty
END AS sale_price_untaxed,
CASE
WHEN sale_order_line.price_total = 0 THEN 'free'
WHEN event_registration.is_paid THEN 'paid'
ELSE 'to_pay'
END payment_status""" + (',\n ' + ',\n '.join(select) if select else '')
END AS sale_price_untaxed""" + (',\n ' + ',\n '.join(select) if select else '')

def _from_clause(self, *join_):
# Extra clauses formatted as `column1`, `column2`...
Expand Down
4 changes: 2 additions & 2 deletions addons/event_sale/views/event_registration_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@
<field name="sale_order_id" invisible="1"/>
</xpath>
<xpath expr="//group" position="before">
<field name="is_paid" invisible="1"/>
<widget name="web_ribbon" title="Paid" bg_color="text-bg-success" invisible="not is_paid"/>
<field name="payment_status" invisible="1"/>
<widget name="web_ribbon" title="Paid" bg_color="text-bg-success" invisible="payment_status != 'paid'"/>
</xpath>
<group name="utm_link" position="before">
<group string="Transaction" groups="base.group_no_one">
Expand Down

0 comments on commit 692496c

Please sign in to comment.