[NEW] event_generate_quotation_from_registration
This commit is contained in:
1
event_generate_quotation_from_registration/__init__.py
Normal file
1
event_generate_quotation_from_registration/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
from . import models
|
20
event_generate_quotation_from_registration/__manifest__.py
Normal file
20
event_generate_quotation_from_registration/__manifest__.py
Normal file
@@ -0,0 +1,20 @@
|
||||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
|
||||
|
||||
{
|
||||
"name": "event_generate_quotation_from_registration",
|
||||
"version": "16.0.1.0.0",
|
||||
"license": "AGPL-3",
|
||||
"author": "Elabore",
|
||||
"website": "https://www.elabore.coop",
|
||||
"category": "",
|
||||
'summary': 'Generate quotation from event registration',
|
||||
'description': """
|
||||
Generate quotation from event registration :
|
||||
""",
|
||||
"depends": ["event_sale"],
|
||||
"data": [
|
||||
'security/ir.model.access.csv',
|
||||
'views/event_registration_views.xml',
|
||||
],
|
||||
"installable": True,
|
||||
}
|
@@ -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)
|
||||
|
||||
|
@@ -0,0 +1,2 @@
|
||||
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
|
||||
access_event_registration_financier,access.event.registration.financier,model_event_registration_financier,sales_team.group_sale_salesman,1,1,1,1
|
|
@@ -0,0 +1,24 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<odoo>
|
||||
|
||||
<record model="ir.ui.view" id="view_event_registration_form_event_generate_quotation_from_registration">
|
||||
<field name="name">view.event.registration.form.event.generate.quotation.from.registration</field>
|
||||
<field name="model">event.registration</field>
|
||||
<field name="inherit_id" ref="event_sale.event_registration_ticket_view_form" />
|
||||
<field name="arch" type="xml">
|
||||
<sheet position="inside">
|
||||
<group name="quotation" string="Financement" colspan="1">
|
||||
<field name="financier_ids" nolabel="1" colspan="2">
|
||||
<tree editable="bottom">
|
||||
<field name="financier_id" />
|
||||
<field name="amount" />
|
||||
<field name="quotation_id" readonly="True" />
|
||||
</tree>
|
||||
</field>
|
||||
<button name="generate_quotation" type="object" string="Créer/adapter les devis" colspan="2" />
|
||||
</group>
|
||||
</sheet>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
</odoo>
|
Reference in New Issue
Block a user