mirror of
https://github.com/bringout/oca-mrp.git
synced 2026-04-25 21:12:04 +02:00
Initial commit: OCA Mrp packages (117 packages)
This commit is contained in:
commit
277e84fd7a
4403 changed files with 395154 additions and 0 deletions
|
|
@ -0,0 +1,3 @@
|
|||
from . import event_registration
|
||||
from . import event_session
|
||||
from . import sale_order_line
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
# Copyright 2017-19 Tecnativa - David Vidal
|
||||
# Copyright 2021 Moka Tourisme (https://www.mokatourisme.fr).
|
||||
# @author Iván Todorovich <ivan.todorovich@gmail.com>
|
||||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
|
||||
|
||||
from odoo import models
|
||||
|
||||
|
||||
class EventRegistration(models.Model):
|
||||
_inherit = "event.registration"
|
||||
|
||||
def _synchronize_so_line_values(self, so_line):
|
||||
res = super()._synchronize_so_line_values(so_line)
|
||||
if so_line:
|
||||
res["session_id"] = so_line.event_session_id.id
|
||||
return res
|
||||
|
|
@ -0,0 +1,97 @@
|
|||
# Copyright 2017-19 Tecnativa - David Vidal
|
||||
# Copyright 2021 Moka Tourisme (https://www.mokatourisme.fr).
|
||||
# @author Iván Todorovich <ivan.todorovich@gmail.com>
|
||||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
|
||||
|
||||
from odoo import api, fields, models
|
||||
|
||||
|
||||
class EventSession(models.Model):
|
||||
_inherit = "event.session"
|
||||
|
||||
# NOTE: This field name doesn't follow the convention but it's kept like this
|
||||
# to match the field name in core `event.event` model.
|
||||
sale_order_lines_ids = fields.One2many(
|
||||
comodel_name="sale.order.line",
|
||||
inverse_name="event_session_id",
|
||||
groups="sales_team.group_sale_salesman",
|
||||
string="All sale order lines pointing to this session",
|
||||
)
|
||||
sale_price_subtotal = fields.Monetary(
|
||||
string="Sales (Tax Excluded)",
|
||||
compute="_compute_sale_price_subtotal",
|
||||
groups="sales_team.group_sale_salesman",
|
||||
)
|
||||
|
||||
@api.depends(
|
||||
"currency_id",
|
||||
"sale_order_lines_ids.price_subtotal",
|
||||
"sale_order_lines_ids.currency_id",
|
||||
"sale_order_lines_ids.company_id",
|
||||
"sale_order_lines_ids.order_id.date_order",
|
||||
)
|
||||
def _compute_sale_price_subtotal(self):
|
||||
"""Compute Sales (Tax Excluded)
|
||||
|
||||
This method is almost exactly the same than the one in core event_sale module
|
||||
:meth:`~event_sale.models.event_event._compute_sale_price_subtotal`, only here
|
||||
we compute the event.session data instead.
|
||||
"""
|
||||
date_now = fields.Datetime.now()
|
||||
sale_price_by_session = {}
|
||||
if self.ids:
|
||||
session_subtotals = self.env["sale.order.line"].read_group(
|
||||
[
|
||||
("state", "!=", "cancel"),
|
||||
("event_session_id", "in", self.ids),
|
||||
("price_subtotal", "!=", 0),
|
||||
],
|
||||
["event_session_id", "currency_id", "price_subtotal:sum"],
|
||||
["event_session_id", "currency_id"],
|
||||
lazy=False,
|
||||
)
|
||||
currency_ids = [
|
||||
session_subtotal["currency_id"][0]
|
||||
for session_subtotal in session_subtotals
|
||||
]
|
||||
company_by_session = {
|
||||
rec._origin.id or rec.id: rec.company_id for rec in self
|
||||
}
|
||||
currency_by_session = {
|
||||
rec._origin.id or rec.id: rec.currency_id for rec in self
|
||||
}
|
||||
currency_by_id = {
|
||||
currency.id: currency
|
||||
for currency in self.env["res.currency"].browse(currency_ids)
|
||||
}
|
||||
for session_subtotal in session_subtotals:
|
||||
price_subtotal = session_subtotal["price_subtotal"]
|
||||
session_id = session_subtotal["event_session_id"][0]
|
||||
currency_id = session_subtotal["currency_id"][0]
|
||||
sale_price = currency_by_session[session_id]._convert(
|
||||
price_subtotal,
|
||||
currency_by_id[currency_id],
|
||||
company_by_session[session_id],
|
||||
date_now,
|
||||
)
|
||||
if session_id in sale_price_by_session:
|
||||
sale_price_by_session[session_id] += sale_price
|
||||
else:
|
||||
sale_price_by_session[session_id] = sale_price
|
||||
|
||||
for rec in self:
|
||||
rec.sale_price_subtotal = sale_price_by_session.get(
|
||||
rec._origin.id or rec.id, 0
|
||||
)
|
||||
|
||||
def action_view_linked_orders(self):
|
||||
"""View sales orders
|
||||
|
||||
Simlar to :meth:`~event_sale.models.event_event.action_view_linked_orders`
|
||||
"""
|
||||
action = self.env["ir.actions.actions"]._for_xml_id("sale.action_orders")
|
||||
action["domain"] = [
|
||||
("state", "!=", "cancel"),
|
||||
("order_line.event_session_id", "in", self.ids),
|
||||
]
|
||||
return action
|
||||
|
|
@ -0,0 +1,50 @@
|
|||
# Copyright 2017-19 Tecnativa - David Vidal
|
||||
# Copyright 2021 Moka Tourisme (https://www.mokatourisme.fr).
|
||||
# @author Iván Todorovich <ivan.todorovich@gmail.com>
|
||||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
|
||||
|
||||
from odoo import api, fields, models
|
||||
|
||||
|
||||
class SaleOrderLine(models.Model):
|
||||
_inherit = "sale.order.line"
|
||||
|
||||
event_use_sessions = fields.Boolean(related="event_id.use_sessions")
|
||||
event_session_id = fields.Many2one(
|
||||
string="Session",
|
||||
comodel_name="event.session",
|
||||
compute="_compute_event_session_id",
|
||||
domain="[('event_id', '=', event_id)]",
|
||||
store=True,
|
||||
readonly=False,
|
||||
precompute=True,
|
||||
)
|
||||
|
||||
@api.depends("event_id")
|
||||
def _compute_event_session_id(self):
|
||||
event_lines = self.filtered("event_id")
|
||||
(self - event_lines).event_session_id = False
|
||||
for line in event_lines:
|
||||
if (
|
||||
not line.event_id.use_sessions
|
||||
or line.event_id != line.event_session_id.event_id
|
||||
):
|
||||
line.event_session_id = False
|
||||
if line.event_id.session_count == 1:
|
||||
line.event_session_id = line.event_id.session_ids[0]
|
||||
|
||||
@api.depends("event_session_id")
|
||||
def _compute_name(self):
|
||||
# OVERRIDE to add the compute method dependency.
|
||||
#
|
||||
# Simliar to what's done in core for the `event_ticket_id` field.
|
||||
# See :meth:`~_get_sale_order_line_multiline_description_sale`
|
||||
return super()._compute_name()
|
||||
|
||||
def _get_sale_order_line_multiline_description_sale(self):
|
||||
res = super()._get_sale_order_line_multiline_description_sale()
|
||||
if self.event_session_id:
|
||||
lang = self.order_id.partner_id.lang
|
||||
session = self.event_session_id.with_context(lang=lang)
|
||||
res += "\n" + session.with_context(with_event_name=False).display_name
|
||||
return res
|
||||
Loading…
Add table
Add a link
Reference in a new issue