[CLN] global : full pre-commit & ruff lint
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
from . import event_registration
|
||||
from . import event_registration_financier
|
||||
from . import sale_order
|
||||
from . import account_move
|
||||
from . import account_move
|
||||
|
@@ -1,6 +1,7 @@
|
||||
from odoo import _, api, Command, fields, models
|
||||
from odoo import fields, models
|
||||
|
||||
|
||||
class AccountMove(models.Model):
|
||||
_inherit = "account.move"
|
||||
|
||||
event_registration_id = fields.Many2one('event.registration', string="Stagiaire")
|
||||
event_registration_id = fields.Many2one("event.registration", string="Stagiaire")
|
||||
|
@@ -1,12 +1,17 @@
|
||||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
|
||||
from odoo import fields, models, api, Command
|
||||
import logging
|
||||
|
||||
from odoo import api, fields, models
|
||||
|
||||
_logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class EventRegistration(models.Model):
|
||||
_inherit = "event.registration"
|
||||
|
||||
financier_ids = fields.One2many('event.registration.financier', 'registration_id', string="Financements")
|
||||
|
||||
financier_ids = fields.One2many(
|
||||
"event.registration.financier", "registration_id", string="Financements"
|
||||
)
|
||||
|
||||
def name_get(self):
|
||||
result = []
|
||||
@@ -15,32 +20,35 @@ class EventRegistration(models.Model):
|
||||
name = f"{registration.partner_id.name} ({registration.event_id.name})"
|
||||
result.append((registration.id, name))
|
||||
return result
|
||||
|
||||
|
||||
@api.depends("partner_id", "event_id")
|
||||
def _compute_display_name(self):
|
||||
for registration in self:
|
||||
if registration.partner_id and registration.event_id:
|
||||
registration.display_name = f"{registration.partner_id.name} ({registration.event_id.name})"
|
||||
registration.display_name = (
|
||||
f"{registration.partner_id.name} ({registration.event_id.name})"
|
||||
)
|
||||
else:
|
||||
registration.display_name = super(EventRegistration, registration)._compute_display_name()
|
||||
|
||||
|
||||
registration.display_name = super(
|
||||
EventRegistration, registration
|
||||
)._compute_display_name()
|
||||
|
||||
def generate_quotation(self):
|
||||
for registration in self:
|
||||
for financier in registration.financier_ids:
|
||||
if not financier.quotation_id:
|
||||
so_values = financier.get_sale_order_values()
|
||||
so_values['order_line'] = financier.get_sale_order_line_values()
|
||||
sale_order = self.env['sale.order'].create(so_values)
|
||||
so_values["order_line"] = financier.get_sale_order_line_values()
|
||||
sale_order = self.env["sale.order"].create(so_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()),
|
||||
('state', '!=', 'done'),
|
||||
])
|
||||
order_lines = self.env["sale.order.line"].search(
|
||||
[
|
||||
("order_id", "=", financier.quotation_id.id),
|
||||
("product_id", "=", financier.get_product_id()),
|
||||
("state", "!=", "done"),
|
||||
]
|
||||
)
|
||||
if order_lines:
|
||||
order_lines[0].price_unit = financier.amount
|
||||
financier.quotation_id.write(financier.get_sale_order_values())
|
||||
|
@@ -1,44 +1,52 @@
|
||||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
|
||||
from odoo import fields, models, api, Command
|
||||
import logging
|
||||
|
||||
from odoo import Command, fields, models
|
||||
from odoo.exceptions import UserError
|
||||
|
||||
_logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class EventRegistrationFinancier(models.Model):
|
||||
_name = "event.registration.financier"
|
||||
|
||||
_rec_name = 'financier_id'
|
||||
_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)
|
||||
terms = fields.Char('Modalités')
|
||||
amount = fields.Monetary('Montant', currency_field="company_currency_id")
|
||||
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)
|
||||
terms = fields.Char("Modalités")
|
||||
amount = fields.Monetary("Montant", currency_field="company_currency_id")
|
||||
state = fields.Selection(
|
||||
related='quotation_id.state',
|
||||
related="quotation_id.state",
|
||||
string="Order Status",
|
||||
copy=False, store=True, precompute=True)
|
||||
|
||||
copy=False,
|
||||
store=True,
|
||||
precompute=True,
|
||||
)
|
||||
|
||||
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')
|
||||
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 {
|
||||
'event_registration_id':self.registration_id.id,
|
||||
'partner_id':self.financier_id.id,
|
||||
"event_registration_id": self.registration_id.id,
|
||||
"partner_id": self.financier_id.id,
|
||||
}
|
||||
|
||||
|
||||
def get_sale_order_line_values(self):
|
||||
return [Command.create({
|
||||
"price_unit": self.amount,
|
||||
"product_id": self.get_product_id()
|
||||
})]
|
||||
|
||||
return [
|
||||
Command.create(
|
||||
{"price_unit": self.amount, "product_id": self.get_product_id()}
|
||||
)
|
||||
]
|
||||
|
@@ -1,39 +1,61 @@
|
||||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
|
||||
from odoo import fields, models, api, Command
|
||||
import logging
|
||||
|
||||
from odoo import fields, models
|
||||
|
||||
_logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class SaleOrder(models.Model):
|
||||
_inherit = "sale.order"
|
||||
|
||||
event_registration_id = fields.Many2one('event.registration', string="Stagiaire")
|
||||
event_registration_id = fields.Many2one("event.registration", string="Stagiaire")
|
||||
|
||||
def _prepare_invoice(self):
|
||||
"""Copy event_registration_id to generated invoice
|
||||
"""
|
||||
res = super(SaleOrder, self)._prepare_invoice()
|
||||
Copy event_registration_id to generated invoice.
|
||||
"""
|
||||
res = super()._prepare_invoice()
|
||||
res["event_registration_id"] = self.event_registration_id.id
|
||||
return res
|
||||
|
||||
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()
|
||||
return (
|
||||
len(
|
||||
self.env["event.registration.financier"].search(
|
||||
[("quotation_id", "=", self.id)]
|
||||
)
|
||||
)
|
||||
> 0
|
||||
)
|
||||
|
||||
#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():
|
||||
def action_confirm(self):
|
||||
res = super().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):
|
||||
|
||||
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)
|
||||
|
||||
|
||||
return super()._update_registrations(
|
||||
confirm, cancel_to_draft, registration_data, mark_as_paid
|
||||
)
|
||||
|
Reference in New Issue
Block a user