Skip to content

Commit

Permalink
Merge PR #974 into 12.0
Browse files Browse the repository at this point in the history
Signed-off-by pedrobaeza
  • Loading branch information
OCA-git-bot committed Oct 29, 2019
2 parents e151512 + 8885b6c commit 3cf8b8e
Show file tree
Hide file tree
Showing 15 changed files with 786 additions and 0 deletions.
99 changes: 99 additions & 0 deletions partner_contact_sale_info_propagation/README.rst
@@ -0,0 +1,99 @@
=====================================
Partner contact sale info propagation
=====================================

.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
:target: https://odoo-community.org/page/development-status
:alt: Beta
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fsale--workflow-lightgray.png?logo=github
:target: https://github.com/OCA/sale-workflow/tree/12.0/partner_contact_sale_info_propagation
:alt: OCA/sale-workflow
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/sale-workflow-12-0/sale-workflow-12-0-partner_contact_sale_info_propagation
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png
:target: https://runbot.odoo-community.org/runbot/167/12.0
:alt: Try me on Runbot

|badge1| |badge2| |badge3| |badge4| |badge5|

This module propagates Salesperson and Sales Channel from Company to Contacts

* Put the *Salesperson* or *Sales Channel* of the parent company when the
contact doesn't have a *Salesperson* or *Sales Channel* and this parent
company is assigned.
* When the company changes the *Salesperson*, it fills with the same
*Salesperson* all the contacts that don't have any or have the previous
*Salesperson* of the parent company.
* When the company changes the *Sales Channel*, it fills with the same
*Sales Channel* all the contacts that don't have any or have the previous
*Sales Channel* of the parent company.


**Table of contents**

.. contents::
:local:

Usage
=====

To use this module, if *Contacts Directory* module is installed:

#. Go to *Contacts -> Contacts* and create a new contact with Company radio
button checked and a Salesperson selected in *Sales & Purchases* tab
#. Edit this record and add a new contact child in *Contacts & Addresses* tab
#. Go to *Contacts -> Contacts* and open the company created
(contact type company) and its contact child and you will see they have the
same *Salesperson*

Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/OCA/sale-workflow/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us smashing it by providing a detailed and welcomed
`feedback <https://github.com/OCA/sale-workflow/issues/new?body=module:%20partner_contact_sale_info_propagation%0Aversion:%2012.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

Do not contact contributors directly about support or help with technical issues.

Credits
=======

Authors
~~~~~~~

* Tecnativa

Contributors
~~~~~~~~~~~~

* `Tecnativa <https://www.tecnativa.com>`_:

* Ernesto Tejeda
* Pedro M. Baeza

Maintainers
~~~~~~~~~~~

This module is maintained by the OCA.

.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org

OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.

This module is part of the `OCA/sale-workflow <https://github.com/OCA/sale-workflow/tree/12.0/partner_contact_sale_info_propagation>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
3 changes: 3 additions & 0 deletions partner_contact_sale_info_propagation/__init__.py
@@ -0,0 +1,3 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from . import models
20 changes: 20 additions & 0 deletions partner_contact_sale_info_propagation/__manifest__.py
@@ -0,0 +1,20 @@
# Copyright 2019 Tecnativa - Ernesto Tejeda
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
{
"name": "Partner contact sale info propagation",
"summary": "Propagate Salesperson and Sales Channel "
"from Company to Contacts",
"version": "12.0.1.0.0",
"category": "Sales Management",
"website": "https://github.com/OCA/sale-workflow",
"author": "Tecnativa, Odoo Community Association (OCA)",
"license": "AGPL-3",
"application": False,
"installable": True,
"depends": [
"sales_team",
],
"data": [
"views/res_partner_view.xml",
],
}
20 changes: 20 additions & 0 deletions partner_contact_sale_info_propagation/i18n/de.po
@@ -0,0 +1,20 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * partner_contact_sale_info_propagation
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 11.0\n"
"Report-Msgid-Bugs-To: \n"
"Last-Translator: Automatically generated\n"
"Language-Team: none\n"
"Language: de\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: nplurals=2; plural=n != 1;\n"

#. module: partner_contact_sale_info_propagation
#: model:ir.model,name:partner_contact_sale_info_propagation.model_res_partner
msgid "Contact"
msgstr ""
@@ -0,0 +1,20 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * partner_contact_sale_info_propagation
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 11.0\n"
"Report-Msgid-Bugs-To: \n"
"Last-Translator: <>\n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: \n"

#. module: partner_contact_sale_info_propagation
#: model:ir.model,name:partner_contact_sale_info_propagation.model_res_partner
msgid "Contact"
msgstr ""

3 changes: 3 additions & 0 deletions partner_contact_sale_info_propagation/models/__init__.py
@@ -0,0 +1,3 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from . import res_partner
69 changes: 69 additions & 0 deletions partner_contact_sale_info_propagation/models/res_partner.py
@@ -0,0 +1,69 @@
# Copyright 2019 Tecnativa - Ernesto Tejeda
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import api, models
from lxml import etree


class ResPartner(models.Model):
_inherit = "res.partner"

@api.multi
def write(self, vals):
"""Propagate Salesperson and Sales Channel change in the partner to the
child contacts."""
for record in self:
if 'user_id' in vals:
childs = record.mapped('child_ids').filtered(
lambda r: not r.user_id or r.user_id == record.user_id)
if childs:
childs.write({'user_id': vals['user_id']})
if 'team_id' in vals:
childs = record.mapped('child_ids').filtered(
lambda r: not r.team_id or r.team_id == record.team_id)
if childs:
childs.write({'team_id': vals['team_id']})
return super(ResPartner, self).write(vals)

@api.model
def create(self, vals):
if 'parent_id' in vals:
if 'user_id' not in vals:
vals.update(user_id=self.browse(vals['parent_id']).user_id.id)
if 'team_id' not in vals:
vals.update(team_id=self.browse(vals['parent_id']).team_id.id)
return super(ResPartner, self).create(vals)

@api.onchange('parent_id')
def onchange_parent_id(self):
"""Change Salesperson or Sales Channel if the parent company changes
and there's no Salesperson or Sales Channel defined yet"""
res = super(ResPartner, self).onchange_parent_id()
if self.parent_id and self.parent_id != self:
parent = self.parent_id
if not self.user_id:
res.setdefault('value', {}).update(user_id=parent.user_id)
if not self.team_id:
res.setdefault('value', {}).update(team_id=parent.team_id)
return res

@api.model
def fields_view_get(self, view_id=None, view_type='form', toolbar=False,
submenu=False):
res = super().fields_view_get(
view_id=view_id, view_type=view_type, toolbar=toolbar,
submenu=submenu,
)
if view_type == 'form':
partner_xml = etree.XML(res['arch'])
partner_fields = partner_xml.xpath("//field[@name='child_ids']")
if partner_fields:
partner_field = partner_fields[0]
context = partner_field.attrib.get("context", "{}").replace(
"{",
"{'default_user_id': user_id, 'default_team_id': team_id,",
1,
)
partner_field.attrib['context'] = context
res['arch'] = etree.tostring(partner_xml)
return res
4 changes: 4 additions & 0 deletions partner_contact_sale_info_propagation/readme/CONTRIBUTORS.rst
@@ -0,0 +1,4 @@
* `Tecnativa <https://www.tecnativa.com>`_:

* Ernesto Tejeda
* Pedro M. Baeza
12 changes: 12 additions & 0 deletions partner_contact_sale_info_propagation/readme/DESCRIPTION.rst
@@ -0,0 +1,12 @@
This module propagates Salesperson and Sales Channel from Company to Contacts

* Put the *Salesperson* or *Sales Channel* of the parent company when the
contact doesn't have a *Salesperson* or *Sales Channel* and this parent
company is assigned.
* When the company changes the *Salesperson*, it fills with the same
*Salesperson* all the contacts that don't have any or have the previous
*Salesperson* of the parent company.
* When the company changes the *Sales Channel*, it fills with the same
*Sales Channel* all the contacts that don't have any or have the previous
*Sales Channel* of the parent company.

8 changes: 8 additions & 0 deletions partner_contact_sale_info_propagation/readme/USAGE.rst
@@ -0,0 +1,8 @@
To use this module, if *Contacts Directory* module is installed:

#. Go to *Contacts -> Contacts* and create a new contact with Company radio
button checked and a Salesperson selected in *Sales & Purchases* tab
#. Edit this record and add a new contact child in *Contacts & Addresses* tab
#. Go to *Contacts -> Contacts* and open the company created
(contact type company) and its contact child and you will see they have the
same *Salesperson*
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 3cf8b8e

Please sign in to comment.