[CLN] global : full pre-commit & ruff lint
This commit is contained in:
@@ -1 +1 @@
|
||||
from . import models
|
||||
from . import models
|
||||
|
@@ -5,18 +5,18 @@
|
||||
"version": "16.0.1.0.0",
|
||||
"license": "AGPL-3",
|
||||
"author": "Elabore",
|
||||
"website": "https://www.elabore.coop",
|
||||
"website": "https://github.com/elabore-coop/event-tools",
|
||||
"category": "",
|
||||
'summary': 'Generate quotation from event registration',
|
||||
'description': """
|
||||
Generate quotation from event registration :
|
||||
"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',
|
||||
'views/sale_order_views.xml',
|
||||
'views/account_move_views.xml',
|
||||
],
|
||||
"data": [
|
||||
"security/ir.model.access.csv",
|
||||
"views/event_registration_views.xml",
|
||||
"views/sale_order_views.xml",
|
||||
"views/account_move_views.xml",
|
||||
],
|
||||
"installable": True,
|
||||
}
|
||||
|
@@ -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
|
||||
)
|
||||
|
@@ -1,2 +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
|
||||
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
|
||||
|
|
@@ -1,4 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<odoo>
|
||||
<record id="view_move_form" model="ir.ui.view">
|
||||
<field name="name">view.move.form.inherit.event.generate.quotation</field>
|
||||
@@ -12,7 +12,9 @@
|
||||
</record>
|
||||
|
||||
<record id="view_out_invoice_tree" model="ir.ui.view">
|
||||
<field name="name">view.out.invoice.tree.inherit.event.generate.quotation</field>
|
||||
<field
|
||||
name="name"
|
||||
>view.out.invoice.tree.inherit.event.generate.quotation</field>
|
||||
<field name="model">account.move</field>
|
||||
<field name="inherit_id" ref="account.view_out_invoice_tree" />
|
||||
<field name="arch" type="xml">
|
||||
|
@@ -1,26 +1,42 @@
|
||||
<?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>
|
||||
|
||||
<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="state" invisible="1"/>
|
||||
<field name="financier_id" attrs="{'readonly': [('state', 'in', ['done', 'cancel'])]}"/>
|
||||
<field name="amount" attrs="{'readonly': [('state', 'in', ['done', 'cancel'])]}" />
|
||||
<field name="state" invisible="1" />
|
||||
<field
|
||||
name="financier_id"
|
||||
attrs="{'readonly': [('state', 'in', ['done', 'cancel'])]}"
|
||||
/>
|
||||
<field
|
||||
name="amount"
|
||||
attrs="{'readonly': [('state', 'in', ['done', 'cancel'])]}"
|
||||
/>
|
||||
<field name="terms" />
|
||||
<field name="quotation_id" readonly="True" />
|
||||
</tree>
|
||||
</field>
|
||||
<button name="generate_quotation" type="object" string="Créer/adapter les devis" colspan="2" />
|
||||
<button
|
||||
name="generate_quotation"
|
||||
type="object"
|
||||
string="Créer/adapter les devis"
|
||||
colspan="2"
|
||||
/>
|
||||
</group>
|
||||
</sheet>
|
||||
</sheet>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
|
||||
</odoo>
|
||||
|
@@ -1,4 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<odoo>
|
||||
<record id="sale_order_view_form" model="ir.ui.view">
|
||||
<field name="name">sale.order.form.inherit.event.generate.quotation</field>
|
||||
|
Reference in New Issue
Block a user