Skip to content

Commit

Permalink
[IMP] event_registration_sale_line_contract: Fecha inicio/fin en part…
Browse files Browse the repository at this point in the history
…icipantes, y lineas de contracto
  • Loading branch information
alfredoavanzosc committed Sep 17, 2021
1 parent 56f07a6 commit 4412a20
Show file tree
Hide file tree
Showing 11 changed files with 116 additions and 11 deletions.
2 changes: 1 addition & 1 deletion event_registration_sale_line_contract/README.rst
Expand Up @@ -6,7 +6,7 @@
Event registration sale line contract
=====================================

* In event registration 2 new fields, sale contract line, and sale contract.
* In event registration 2 new fields, sale contract line, and sale contract.

Bug Tracker
===========
Expand Down
2 changes: 1 addition & 1 deletion event_registration_sale_line_contract/__manifest__.py
Expand Up @@ -2,7 +2,7 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
{
"name": "Event Registration Sale Line Contract",
'version': '14.0.1.1.0',
'version': '14.0.1.2.0',
"author": "Avanzosc",
"category": "Marketing/Events",
"depends": [
Expand Down
1 change: 1 addition & 0 deletions event_registration_sale_line_contract/models/__init__.py
@@ -1,2 +1,3 @@
from . import event_registration
from . import sale_order
from . import sale_order_line
10 changes: 2 additions & 8 deletions event_registration_sale_line_contract/models/sale_order.py
Expand Up @@ -12,12 +12,6 @@ def _action_confirm(self):
lines = sale.order_line.filtered(
lambda x: x.contract_line_id and x.event_id and
x.event_ticket_id)
for line in lines:
cond = [('event_id', '=', line.event_id.id),
('event_ticket_id', '=', line.event_ticket_id.id),
('sale_order_line_id', '=', line.id),
('contract_line_id', '=', False)]
registration = self.env['event.registration'].search(cond)
if registration and len(registration) == 1:
registration.contract_line_id = line.contract_line_id.id
if lines:
lines._update_event_registration_contract_line()
return result
17 changes: 17 additions & 0 deletions event_registration_sale_line_contract/models/sale_order_line.py
@@ -0,0 +1,17 @@
# Copyright 2021 Alfredo de la Fuente - AvanzOSC
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from odoo import models


class SaleOrderLine(models.Model):
_inherit = 'sale.order.line'

def _update_event_registration_contract_line(self):
for line in self:
cond = [('event_id', '=', line.event_id.id),
('event_ticket_id', '=', line.event_ticket_id.id),
('sale_order_line_id', '=', line.id),
('contract_line_id', '=', False)]
registration = self.env['event.registration'].search(cond)
if registration and len(registration) == 1:
registration.contract_line_id = line.contract_line_id.id
9 changes: 9 additions & 0 deletions event_registration_student/README.rst
Expand Up @@ -8,6 +8,15 @@ Event registration student

* Student, education center, real date start, date start, real date
end, and date end in event registration.
* After confirming a sales order, if the sales order lines are associated with
a contract line, and this sales line is associated with a single event
registration: the start/end date of the contract line will be the start/end
date of event registration.
* If the start/end date is changed in the contract line, or in the event
registration, and if the contract line is associated with a single event
registration, and a single event registration has a single contract line: if
it is changed in the participant, they will change on the contract line and
vice versa.

Bug Tracker
===========
Expand Down
2 changes: 1 addition & 1 deletion event_registration_student/__manifest__.py
Expand Up @@ -2,7 +2,7 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
{
"name": "Event Registration Student",
'version': '14.0.1.2.0',
'version': '14.0.1.3.0',
"author": "Avanzosc",
"category": "Sales/CRM",
"depends": [
Expand Down
2 changes: 2 additions & 0 deletions event_registration_student/models/__init__.py
@@ -1 +1,3 @@
from . import event_registration
from . import contract_line
from . import sale_order_line
33 changes: 33 additions & 0 deletions event_registration_student/models/contract_line.py
@@ -0,0 +1,33 @@
# Copyright 2021 Alfredo de la Fuente - AvanzOSC
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from odoo import models


class ContractLine(models.Model):
_inherit = 'contract.line'

def write(self, vals):
result = super(ContractLine, self).write(vals)
if 'no_update_event_reg_dates' not in self.env.context:
if (('date_start' in vals and vals.get('date_start', False)) or
('date_end' in vals and vals.get('date_end', False))):
lines = self.filtered(
lambda x: x.sale_order_id and x.sale_order_line_id and
x.sale_order_line_id.event_id and
x.sale_order_line_id.event_ticket_id)
if lines:
lines.update_dates_in_event_registration(vals)
return result

def update_dates_in_event_registration(self, vals):
for line in self:
cond = [('contract_line_id', '=', line.id)]
registration = self.env['event.registration'].search(cond)
if registration and len(registration) == 1:
vals2 = {}
if 'date_start' in vals and vals.get('date_start', False):
vals2['date_start'] = vals.get('date_start')
if 'date_end' in vals and vals.get('date_end', False):
vals2['date_end'] = vals.get('date_end')
registration.with_context(
no_update_contract_line_dates=True).write(vals2)
25 changes: 25 additions & 0 deletions event_registration_student/models/event_registration.py
Expand Up @@ -94,3 +94,28 @@ def _update_real_date_end(self):
registration.real_date_end = (
event_end if today > event_end else today)
registration._onchange_real_date_end()

def write(self, vals):
result = super(EventRegistration, self).write(vals)
if 'no_update_contract_line_dates' not in self.env.context:
if (('date_start' in vals and vals.get('date_start', False)) or
('date_end' in vals and vals.get('date_end', False))):
registrations = self.filtered(
lambda x: x.sale_order_line_id and x.contract_line_id)
if registrations:
registrations.update_dates_in_contract_line(vals)
return result

def update_dates_in_contract_line(self, vals):
for registration in self:
contract_line = registration.contract_line_id
cond = [('contract_line_id', '=', contract_line.id)]
registration = self.env['event.registration'].search(cond)
if registration and len(registration) == 1:
vals2 = {}
if 'date_start' in vals and vals.get('date_start', False):
vals2['date_start'] = vals.get('date_start')
if 'date_end' in vals and vals.get('date_end', False):
vals2['date_end'] = vals.get('date_end')
contract_line.with_context(
no_update_event_reg_dates=True).write(vals2)
24 changes: 24 additions & 0 deletions event_registration_student/models/sale_order_line.py
@@ -0,0 +1,24 @@
# Copyright 2021 Alfredo de la Fuente - AvanzOSC
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from odoo import models


class SaleOrderLine(models.Model):
_inherit = 'sale.order.line'

def _update_event_registration_contract_line(self):
result = super(
SaleOrderLine, self)._update_event_registration_contract_line()
for line in self:
cond = [('contract_line_id', '=', line.contract_line_id.id)]
registration = self.env['event.registration'].search(cond)
if registration and len(registration) == 1:
vals = {}
if registration.date_start:
vals['date_start'] = registration.date_start
if registration.date_end:
vals['date_end'] = registration.date_end
if vals:
registration.contract_line_id.with_context(
no_update_event_reg_dates=True).write(vals)
return result

0 comments on commit 4412a20

Please sign in to comment.