[NEW] event_generate_quotation_from_registration
This commit is contained in:
@@ -0,0 +1,3 @@
|
||||
from . import event_registration
|
||||
from . import event_registration_financier
|
||||
from . import sale_order
|
@@ -0,0 +1,24 @@
|
||||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
|
||||
from odoo import fields, models, api, Command
|
||||
import logging
|
||||
_logger = logging.getLogger(__name__)
|
||||
|
||||
class EventRegistration(models.Model):
|
||||
_inherit = "event.registration"
|
||||
|
||||
financier_ids = fields.One2many('event.registration.financier', 'registration_id', string="Financements")
|
||||
|
||||
|
||||
def generate_quotation(self):
|
||||
for registration in self:
|
||||
for financier in registration.financier_ids:
|
||||
if not financier.quotation_id:
|
||||
sale_order = self.env['sale.order'].create(financier.get_sale_order_values())
|
||||
financier.quotation_id = sale_order
|
||||
else:
|
||||
order_lines = self.env['sale.order.line'].search([
|
||||
('order_id','=',financier.quotation_id.id),
|
||||
('product_id','=',financier.get_product_id())
|
||||
])
|
||||
if order_lines:
|
||||
order_lines[0].price_unit = financier.amount
|
@@ -0,0 +1,37 @@
|
||||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
|
||||
from odoo import fields, models, api, Command
|
||||
import logging
|
||||
|
||||
from odoo.exceptions import UserError
|
||||
_logger = logging.getLogger(__name__)
|
||||
|
||||
class EventRegistrationFinancier(models.Model):
|
||||
_name = "event.registration.financier"
|
||||
|
||||
_rec_name = 'financier_id'
|
||||
|
||||
company_id = fields.Many2one("res.company")
|
||||
company_currency_id = fields.Many2one('res.currency', related="company_id.currency_id")
|
||||
registration_id = fields.Many2one('event.registration')
|
||||
quotation_id = fields.Many2one('sale.order', string="Devis")
|
||||
financier_id = fields.Many2one('res.partner', string="Financeur", required=True)
|
||||
amount = fields.Monetary('Montant', currency_field="company_currency_id")
|
||||
|
||||
|
||||
def get_product_id(self):
|
||||
if self.registration_id.event_ticket_id:
|
||||
return self.registration_id.event_ticket_id.product_id.id
|
||||
elif self.registration_id.event_id.event_ticket_ids:
|
||||
return self.registration_id.event_id.event_ticket_ids[0].product_id.id
|
||||
raise UserError('Un ticket doit être défini dans la session de formation afin de générer le devis')
|
||||
|
||||
def get_sale_order_values(self):
|
||||
return {
|
||||
'partner_id':self.financier_id.id,
|
||||
'order_line':[
|
||||
Command.create({
|
||||
"price_unit": self.amount,
|
||||
"product_id": self.get_product_id()
|
||||
})
|
||||
]
|
||||
}
|
@@ -0,0 +1,30 @@
|
||||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
|
||||
from odoo import fields, models, api, Command
|
||||
import logging
|
||||
_logger = logging.getLogger(__name__)
|
||||
|
||||
class SaleOrder(models.Model):
|
||||
_inherit = "sale.order"
|
||||
|
||||
def linked_to_registration(self):
|
||||
return len(self.env['event.registration.financier'].search([('quotation_id','=',self.id)])) > 0
|
||||
|
||||
def action_confirm(self):
|
||||
res = super(SaleOrder, self).action_confirm()
|
||||
|
||||
#if sale order is linked to event.registration.financier, don't open wizard
|
||||
if isinstance(res, dict) and res.get('xml_id') == 'event_sale.action_sale_order_event_registration' and self.linked_to_registration():
|
||||
return True
|
||||
|
||||
return res
|
||||
|
||||
class SaleOrderLine(models.Model):
|
||||
_inherit = "sale.order.line"
|
||||
|
||||
def _update_registrations(self, confirm=True, cancel_to_draft=False, registration_data=None, mark_as_paid=False):
|
||||
# bypass _update_registrations if order generated by event registration
|
||||
if self.order_id.linked_to_registration():
|
||||
return
|
||||
return super(SaleOrderLine, self)._update_registrations(confirm, cancel_to_draft, registration_data, mark_as_paid)
|
||||
|
||||
|
Reference in New Issue
Block a user