[IMP] event_sale: remove is_paid and store payment_status
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/odoo#126431
This commit is contained in:
@@ -8,7 +8,6 @@ from odoo.tools import float_is_zero
|
||||
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)
|
||||
@@ -16,7 +15,7 @@ class EventRegistration(models.Model):
|
||||
('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,
|
||||
@@ -24,17 +23,13 @@ class EventRegistration(models.Model):
|
||||
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):
|
||||
@@ -125,7 +120,7 @@ class EventRegistration(models.Model):
|
||||
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()
|
||||
|
||||
@@ -36,7 +36,7 @@ class SaleOrderLine(models.Model):
|
||||
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()
|
||||
|
||||
|
||||
@@ -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'),
|
||||
@@ -81,7 +80,7 @@ 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,
|
||||
@@ -109,12 +108,7 @@ 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`...
|
||||
|
||||
@@ -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">
|
||||
|
||||
Reference in New Issue
Block a user