-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
[IMP] sales_security_team: revert changes to recover esencial functionality #3747
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: 18.0
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -28,17 +28,35 @@ def _compute_domain(self, model_name, mode="read"): | |
| user = self.env.user | ||
| group_my_records = "sales_team.group_sale_salesman" | ||
| group_all_records = "sales_team.group_sale_salesman_all_leads" | ||
| group1 = "sales_team.group_sale_salesman" | ||
| group2 = "sales_team_security.group_sale_team_manager" | ||
| group3 = "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 = [ | ||
| # if user.has_group(group_my_records) and not user.has_group( | ||
| # group_all_records | ||
| # ): | ||
| # domain_followers = [ | ||
| if user.has_group(group1) and not user.has_group(group3): | ||
| extra_domain = [ | ||
| "|", | ||
| ("message_partner_ids", "in", user.partner_id.ids), | ||
| "|", | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this is not useful as there is only one argument after this 'OR' |
||
| ("id", "=", user.partner_id.id), | ||
| ] | ||
| domain_user = [("user_id", "in", [user.id, False])] | ||
| extra_domain = expression.OR([domain_followers, domain_user]) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IMHO, using |
||
| # domain_user = [("user_id", "in", [user.id, False])] | ||
| # extra_domain = expression.OR([domain_followers, domain_user]) | ||
| if user.has_group(group2): | ||
| # Ver todos los contactos de su equipo | ||
| team_user_ids = user.sale_team_id.member_ids.ids | ||
| extra_domain += [ | ||
| ("user_id", "in", team_user_ids + [False]), | ||
| ] | ||
| else: | ||
| # Ver solo propios y sin asignar | ||
| extra_domain += [ | ||
| ("user_id", "in", [user.id, False]), | ||
| ] | ||
|
|
||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If I summarize the change here:
This should be reflected in documentation |
||
| extra_domain = expression.normalize_domain(extra_domain) | ||
| res = expression.AND([extra_domain] + [res]) | ||
| return res | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,6 +3,8 @@ | |
| # License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html | ||
|
|
||
|
|
||
| from lxml import etree | ||
|
|
||
| from odoo import api, fields, models | ||
|
|
||
|
|
||
|
|
@@ -11,6 +13,62 @@ class ResPartner(models.Model): | |
|
|
||
| # add indexes for better performance on record rules | ||
| user_id = fields.Many2one(index=True) | ||
| # team_id = fields.Many2one( | ||
| # "crm.team", | ||
| # string="Sales Team", | ||
| # compute="_compute_team_id", | ||
| # precompute=True, # avoid queries post-create | ||
| # ondelete="set null", | ||
| # readonly=False, | ||
| # store=True, | ||
| # index=True, | ||
| # ) | ||
|
|
||
| @api.model | ||
| def get_view(self, view_id=None, view_type="form", **options): | ||
| """ | ||
| Patch view to inject the default value for the team_id and user_id. | ||
| """ | ||
| # FIXME: Use base_view_inheritance_extension when available | ||
| res = super().get_view(view_id, view_type, **options) | ||
| if view_type == "form": | ||
| eview = etree.fromstring(res["arch"]) | ||
| xml_fields = eview.xpath("//field[@name='child_ids']") | ||
| if xml_fields: | ||
| context_str = ( | ||
| xml_fields[0] | ||
| .get("context", "{}") | ||
| .replace( | ||
| "{", | ||
| "{'default_user_id': user_id,", | ||
| 1, | ||
| ) | ||
| ) | ||
| xml_fields[0].set("context", context_str) | ||
| res["arch"] = etree.tostring(eview) | ||
| return res | ||
|
|
||
| @api.onchange("parent_id") | ||
| def _onchange_parent_id_sales_team_security(self): | ||
| """If assigning a parent partner and the contact doesn't have | ||
| team or salesman, we put the parent's one (if any). | ||
| """ | ||
| if self.parent_id and self.parent_id.user_id and not self.user_id: | ||
| self.user_id = self.parent_id.user_id.id | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IMHO, this is totally out of scope. Moreover this is already done by: https://github.com/odoo/odoo/blob/18.0/odoo/addons/base/models/res_partner.py#L397 Those changes should be done in computes. |
||
|
|
||
| # @api.onchange("user_id") | ||
| # def _onchange_user_id_sales_team_security(self): | ||
| # if self.user_id.sale_team_id: | ||
| # self.team_id = self.user_id.sale_team_id | ||
|
|
||
| # @api.depends("parent_id") | ||
| # def _compute_team_id(self): | ||
| # for partner in self.filtered( | ||
| # lambda partner: not partner.team_id | ||
| # and partner.company_type == "person" | ||
| # and partner.parent_id.team_id | ||
| # ): | ||
| # partner.team_id = partner.parent_id.team_id | ||
|
|
||
| def _remove_key_followers(self, partner): | ||
| for record in self.mapped("commercial_partner_id"): | ||
|
|
@@ -23,7 +81,7 @@ def _remove_key_followers(self, partner): | |
| 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 | ||
| followers = (record.child_ids + record).mapped("user_id.partner_id") | ||
| # Look for delivery and invoice addresses | ||
| childrens = record.child_ids.filtered( | ||
| lambda x: x.type in {"invoice", "delivery"} | ||
|
|
@@ -35,6 +93,7 @@ def create(self, vals_list): | |
| """Sync followers on contact creation.""" | ||
| records = super().create(vals_list) | ||
| records._add_followers_from_salesmen() | ||
| # records._sync_team_id_to_children() | ||
| return records | ||
|
|
||
| def write(self, vals): | ||
|
|
@@ -50,4 +109,14 @@ def write(self, vals): | |
| result = super().write(vals) | ||
| if "user_id" in vals or vals.get("type") in {"invoice", "delivery"}: | ||
| self._add_followers_from_salesmen() | ||
| # if "user_id" in vals or "team_id" in vals: | ||
| # self._sync_team_id_to_children() | ||
| return result | ||
|
|
||
| # def _sync_team_id_to_children(self): | ||
| # for parent in self: | ||
| # if parent.child_ids: | ||
| # for child in parent.child_ids: | ||
| # child.team_id = parent.team_id | ||
| # if parent.user_id: | ||
| # child.user_id = parent.user_id | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| <?xml version="1.0" encoding="utf-8" ?> | ||
| <odoo> | ||
| <record id="view_partner_form" model="ir.ui.view"> | ||
| <field name="name">Partner form (with sales info in contacts)</field> | ||
| <field name="model">res.partner</field> | ||
| <field name="inherit_id" ref="base.view_partner_form" /> | ||
| <field name="arch" type="xml"> | ||
| <field name="user_id" position="after"> | ||
| <field name="team_id" /> | ||
| </field> | ||
| </field> | ||
| </record> | ||
| </odoo> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@matiasperalta1 IMHO, changing variables names from explicit to not explicit (groupX) is a drawback (and is not needed).