Přejít na obsah
Menu
You need to be registered to interact with the community.
This question has been flagged
965 Zobrazení

I'm trying to change an ir.rule that is from odoo base crm module. Specifically in odoo-server/addons/crm/security/crm_security.xml. The ir.rule is registered as no_update then I find this thread "How to inherit and change the domain of standard rules in odoo 8.0?". It work. The ir.rule is changed. 


My goal is to change the domain_force so that when the user's "Sales" access right was set to "User: Own document only", it will see the user status in "Sales Team" (crm.team). If he is a leader, he can see the member's opportunity and his opportunity when opening the CRM menu




I add new many2many field in res.partner to store all crm.lead that a user can be viewed 


The problem is when I open CRM menu, the data is not updated when I change the leader in "Sales Team". But it change when I upgrade the module OR set the argument --dev=xml​ when running the service





class CrmLead(models.Model):

    _inherit = 'crm.lead'

    def write(self, vals):

        res = super(CrmLead, self).write(vals)

        _logger.info("Editing in crm.lead")


        # user_ids = self.user_id

        partner_ids = self.env['res.users'].search([]).partner_id.ids

        if partner_ids:

            self._update_visible_crm_lead_ids(partner_ids)

        _logger.info("Finish editing in crm.lead")

        return res


    visible_res_users_ids = fields.Many2many('res.partner', string='Leads')

    def _update_visible_crm_lead_ids(self, partner_ids):

        """

        1. Check the user. If the user is leader, get the members user_id. If not, just get user_id

        2. Get all crm_lead that has the user_id that we got from the first step

        3. Replace all visible_crm_lead_ids with the new one


        """

        _logger.info("Entering update_visible_crm_lead with users: %s", partner_ids)

        partners = self.env['res.partner'].sudo().search([('id', 'in', partner_ids)])

        for partner in partners:

            res_user = self.env['res.users'].search([('partner_id', '=', res_user.id)])

            all_user_to_get_all_crm_lead = res_user.ids

            if crm_team_based_on_leader:

                all_user_to_get_all_crm_lead = all_user_to_get_all_crm_lead + crm_team_based_on_leader.member_ids.ids

                all_user_to_get_all_crm_lead = list(set(all_user_to_get_all_crm_lead))

                

            all_crm_lead = self.env['crm.lead'].search([('user_id', 'in', all_user_to_get_all_crm_lead)]).ids

            _logger.debug("partner display name: %s", partner.display_name)

            _logger.debug("res users: %s", res_user.display_name)

            _logger.debug("all_crm_lead: %s", all_crm_lead)

            partner.visible_crm_lead_ids = [(6, 0, all_crm_lead)]



class ResPartner(models.Model):

    _inherit = "res.partner"

    visible_crm_lead_ids = fields.Many2many('crm.lead', string='Leads')


class CrmTeam(models.Model):

    _inherit = 'crm.team'


    def write(self, vals):

        res = super(CrmTeam, self).write(vals)

        self.create_depart_users_write()

        # self.update_res_partner()

        _logger.info("Editing in crm.team")

        crm_lead = self.env['crm.lead'].search([], limit=1)

        if crm_lead:

            partner_ids = self.env['res.users'].search([]).partner_id.ids

            crm_lead._update_visible_crm_lead_ids(partner_ids)


        _logger.info("Finish editing in crm.team")

        return res

  



<?xml version="1.0" encoding="utf-8"?>

<odoo>


    <!--Find the corresponding "to be inherited record" with noupdate="1" -->

    <function name="write" model="ir.model.data">

        <function model="ir.model.data" name="search">

            <value eval="[('module', '=', 'crm'), ('name', '=', 'crm_rule_personal_lead')]" />

        </function>

        <value eval="{'noupdate': False}"/>

    </function>


    <!--Finish the job, i.e. inheriting/modifying some fields-->

    <record id="crm.crm_rule_personal_lead" model="ir.rule">            

        <field name="domain_force">[('id', 'in', user.partner_id.visible_crm_lead_ids.ids)]</field>        

    </record>


    <!--Optional, if you want to set noupdate to True again-->

    

    <function name="write" model="ir.model.data">

        <function model="ir.model.data" name="search">

            <value eval="[('module', '=', 'crm'), ('name', '=', 'crm_rule_personal_lead')]" />

        </function>

        <value eval="{'noupdate': True}"/>

    </function>


</odoo>







Avatar
Zrušit
Related Posts Odpovědi Zobrazení Aktivita
1
srp 25
436
1
kvě 25
1267
0
lis 24
1389
2
říj 24
1466
0
srp 24
1231