Initial commit: Odoo 18.0-20251222 extra-addons
Some checks failed
pre-commit / pre-commit (push) Has been cancelled
tests / Detect unreleased dependencies (push) Has been cancelled
tests / test with OCB (push) Has been cancelled
tests / test with Odoo (push) Has been cancelled

This commit is contained in:
tocmo0nlord
2026-03-13 20:43:25 +00:00
parent 36e847a7df
commit adbe430761
9472 changed files with 1265727 additions and 0 deletions

View File

@@ -0,0 +1,3 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from . import ir_rule
from . import res_partner

View File

@@ -0,0 +1,44 @@
# Copyright 2020 Tecnativa - Pedro M. Baeza
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html
from odoo import api, models, tools
from odoo.osv import expression
from odoo.tools import config
class IrRule(models.Model):
_inherit = "ir.rule"
@api.model
@tools.conditional(
"xml" not in config["dev_mode"],
tools.ormcache(
"self.env.uid",
"self.env.su",
"model_name",
"mode",
"tuple(self._compute_domain_context_values())",
),
)
def _compute_domain(self, model_name, mode="read"):
"""Inject extra domain for restricting partners when the user
has the group 'Sales / User: Own Documents Only'.
"""
res = super()._compute_domain(model_name, mode=mode)
user = self.env.user
group_my_records = "sales_team.group_sale_salesman"
group_all_records = "sales_team.group_sale_salesman_all_leads"
if model_name == "res.partner" and not self.env.su:
if user.has_group(group_my_records) and not user.has_group(
group_all_records
):
domain_followers = [
"|",
("message_partner_ids", "in", user.partner_id.ids),
("id", "=", user.partner_id.id),
]
domain_user = [("user_id", "in", [user.id, False])]
extra_domain = expression.OR([domain_followers, domain_user])
extra_domain = expression.normalize_domain(extra_domain)
res = expression.AND([extra_domain] + [res])
return res

View File

@@ -0,0 +1,53 @@
# Copyright 2016-2018 Tecnativa - Pedro M. Baeza
# Copyright 2021 Tecnativa - Víctor Martínez
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html
from odoo import api, fields, models
class ResPartner(models.Model):
_inherit = "res.partner"
# add indexes for better performance on record rules
user_id = fields.Many2one(index=True)
def _remove_key_followers(self, partner):
for record in self.mapped("commercial_partner_id"):
# Look for delivery and invoice addresses
childrens = record.child_ids.filtered(
lambda x: x.type in {"invoice", "delivery"}
)
(childrens + record).message_unsubscribe(partner_ids=partner.ids)
def _add_followers_from_salesmen(self):
"""Sync followers in commercial partner + delivery/invoice contacts."""
for record in self.commercial_partner_id:
followers = (record.child_ids + record).user_id.partner_id
# Look for delivery and invoice addresses
childrens = record.child_ids.filtered(
lambda x: x.type in {"invoice", "delivery"}
)
(childrens + record).message_subscribe(partner_ids=followers.ids)
@api.model_create_multi
def create(self, vals_list):
"""Sync followers on contact creation."""
records = super().create(vals_list)
records._add_followers_from_salesmen()
return records
def write(self, vals):
"""If the salesman is changed, first remove the old salesman as follower
of the key contacts (commercial + delivery/invoice), and then sync for
the new ones.
It performs as well the followers sync on contact type change.
"""
if "user_id" in vals:
for record in self.filtered("user_id"):
record._remove_key_followers(record.user_id.partner_id)
result = super().write(vals)
if "user_id" in vals or vals.get("type") in {"invoice", "delivery"}:
self._add_followers_from_salesmen()
return result