Skip to content
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

[16.0][MIG] crm_multicompany_reporting_currency: Migration to 16.0 #535

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 88 additions & 0 deletions crm_multicompany_reporting_currency/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
===================================
CRM Multicompany Reporting Currency
===================================

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:5a00efc6b1298b56ae5461a54395c6e56b30719b473fb3b27a7183fb2584794b
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

.. |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%2Fcrm-lightgray.png?logo=github
:target: https://github.com/OCA/crm/tree/16.0/crm_multicompany_reporting_currency
:alt: OCA/crm
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/crm-16-0/crm-16-0-crm_multicompany_reporting_currency
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
:target: https://runboat.odoo-community.org/builds?repo=OCA/crm&target_branch=16.0
:alt: Try me on Runboat

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

This Module adds Amount in multicompany reporting currency to CRM Lead which can be used as a reporting tool.
You can then compare Expected Revenue in company currency to amount in multicompany reporting currency.
Multicompany reporting currency is installed from dependent https://github.com/OCA/sale-reporting/base_multicompany_reporting_currency module.

**Table of contents**

.. contents::
:local:

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

Bugs are tracked on `GitHub Issues <https://github.com/OCA/crm/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed
`feedback <https://github.com/OCA/crm/issues/new?body=module:%20crm_multicompany_reporting_currency%0Aversion:%2016.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
~~~~~~~

* Camptocamp SA

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

* Maksym Yankin <[email protected]>
* [APSL](https://apsl.tech):
* Antoni Marroig <[email protected]>

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.

.. |maintainer-yankinmax| image:: https://github.com/yankinmax.png?size=40px
:target: https://github.com/yankinmax
:alt: yankinmax

Current `maintainer <https://odoo-community.org/page/maintainer-role>`__:

|maintainer-yankinmax|

This module is part of the `OCA/crm <https://github.com/OCA/crm/tree/16.0/crm_multicompany_reporting_currency>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
1 change: 1 addition & 0 deletions crm_multicompany_reporting_currency/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
15 changes: 15 additions & 0 deletions crm_multicompany_reporting_currency/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Copyright 2022 Camptocamp SA
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
{
"name": "CRM Multicompany Reporting Currency",
"summary": "Adds Amount in multicompany reporting currency to CRM Lead",
"version": "16.0.1.0.0",
"category": "Sales",
"author": "Camptocamp SA, Odoo Community Association (OCA)",
"license": "AGPL-3",
"depends": ["crm", "base_multicompany_reporting_currency"],
"website": "https://github.com/OCA/crm",
"data": ["views/crm_lead_views.xml"],
"installable": True,
"maintainers": ["yankinmax"],
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * crm_multicompany_reporting_currency
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 15.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: crm_multicompany_reporting_currency
#: model:ir.model.fields,field_description:crm_multicompany_reporting_currency.field_crm_lead__amount_multicompany_reporting_currency
msgid "Amount Multicompany Reporting Currency"
msgstr ""

#. module: crm_multicompany_reporting_currency
#: model:ir.model,name:crm_multicompany_reporting_currency.model_res_config_settings
msgid "Config Settings"
msgstr ""

#. module: crm_multicompany_reporting_currency
#: model:ir.model.fields,field_description:crm_multicompany_reporting_currency.field_crm_lead__currency_rate
msgid "Currency Rate"
msgstr ""

#. module: crm_multicompany_reporting_currency
#: model:ir.model,name:crm_multicompany_reporting_currency.model_crm_lead
msgid "Lead/Opportunity"
msgstr ""

#. module: crm_multicompany_reporting_currency
#: model:ir.model.fields,field_description:crm_multicompany_reporting_currency.field_crm_lead__multicompany_reporting_currency_id
msgid "Multicompany Reporting Currency"
msgstr ""

#. module: crm_multicompany_reporting_currency
#: model_terms:ir.ui.view,arch_db:crm_multicompany_reporting_currency.crm_case_tree_view_oppor
msgid "Total"
msgstr ""

#. module: crm_multicompany_reporting_currency
#: model_terms:ir.ui.view,arch_db:crm_multicompany_reporting_currency.crm_case_tree_view_oppor
#: model_terms:ir.ui.view,arch_db:crm_multicompany_reporting_currency.crm_lead_view_form
msgid "Total (Multicompany Reporting Currency)"
msgstr ""
53 changes: 53 additions & 0 deletions crm_multicompany_reporting_currency/i18n/es.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * crm_multicompany_reporting_currency
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 15.0\n"
"Report-Msgid-Bugs-To: \n"
"PO-Revision-Date: 2023-09-26 14:18+0000\n"
"Last-Translator: Ivorra78 <[email protected]>\n"
"Language-Team: none\n"
"Language: es\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"
"X-Generator: Weblate 4.17\n"

#. module: crm_multicompany_reporting_currency
#: model:ir.model.fields,field_description:crm_multicompany_reporting_currency.field_crm_lead__amount_multicompany_reporting_currency
msgid "Amount Multicompany Reporting Currency"
msgstr "Importe Divisa de referencia multicompañía"

#. module: crm_multicompany_reporting_currency
#: model:ir.model,name:crm_multicompany_reporting_currency.model_res_config_settings
msgid "Config Settings"
msgstr "Configuración de Ajustes"

#. module: crm_multicompany_reporting_currency
#: model:ir.model.fields,field_description:crm_multicompany_reporting_currency.field_crm_lead__currency_rate
msgid "Currency Rate"
msgstr "Tipo de divisa"

#. module: crm_multicompany_reporting_currency
#: model:ir.model,name:crm_multicompany_reporting_currency.model_crm_lead
msgid "Lead/Opportunity"
msgstr "Iniciativa/Oportundad"

#. module: crm_multicompany_reporting_currency
#: model:ir.model.fields,field_description:crm_multicompany_reporting_currency.field_crm_lead__multicompany_reporting_currency_id
msgid "Multicompany Reporting Currency"
msgstr "Divisa de referencia de varias compañías"

#. module: crm_multicompany_reporting_currency
#: model_terms:ir.ui.view,arch_db:crm_multicompany_reporting_currency.crm_case_tree_view_oppor
msgid "Total"
msgstr "Total"

#. module: crm_multicompany_reporting_currency
#: model_terms:ir.ui.view,arch_db:crm_multicompany_reporting_currency.crm_case_tree_view_oppor
#: model_terms:ir.ui.view,arch_db:crm_multicompany_reporting_currency.crm_lead_view_form
msgid "Total (Multicompany Reporting Currency)"
msgstr "Total (divisa de referencia de varias compañías)"
53 changes: 53 additions & 0 deletions crm_multicompany_reporting_currency/i18n/it.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * crm_multicompany_reporting_currency
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 15.0\n"
"Report-Msgid-Bugs-To: \n"
"PO-Revision-Date: 2023-06-12 16:10+0000\n"
"Last-Translator: mymage <[email protected]>\n"
"Language-Team: none\n"
"Language: it\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"
"X-Generator: Weblate 4.17\n"

#. module: crm_multicompany_reporting_currency
#: model:ir.model.fields,field_description:crm_multicompany_reporting_currency.field_crm_lead__amount_multicompany_reporting_currency
msgid "Amount Multicompany Reporting Currency"
msgstr "Valuta resoconto valore multiazienda"

#. module: crm_multicompany_reporting_currency
#: model:ir.model,name:crm_multicompany_reporting_currency.model_res_config_settings
msgid "Config Settings"
msgstr "Impostazioni configurazione"

#. module: crm_multicompany_reporting_currency
#: model:ir.model.fields,field_description:crm_multicompany_reporting_currency.field_crm_lead__currency_rate
msgid "Currency Rate"
msgstr "Tariffa valuta"

#. module: crm_multicompany_reporting_currency
#: model:ir.model,name:crm_multicompany_reporting_currency.model_crm_lead
msgid "Lead/Opportunity"
msgstr "Contatto/Opportunità"

#. module: crm_multicompany_reporting_currency
#: model:ir.model.fields,field_description:crm_multicompany_reporting_currency.field_crm_lead__multicompany_reporting_currency_id
msgid "Multicompany Reporting Currency"
msgstr "Valuta resoconto multi azienda"

#. module: crm_multicompany_reporting_currency
#: model_terms:ir.ui.view,arch_db:crm_multicompany_reporting_currency.crm_case_tree_view_oppor
msgid "Total"
msgstr "Totale"

#. module: crm_multicompany_reporting_currency
#: model_terms:ir.ui.view,arch_db:crm_multicompany_reporting_currency.crm_case_tree_view_oppor
#: model_terms:ir.ui.view,arch_db:crm_multicompany_reporting_currency.crm_lead_view_form
msgid "Total (Multicompany Reporting Currency)"
msgstr "Totale (valuta resoconto multi azienda)"
2 changes: 2 additions & 0 deletions crm_multicompany_reporting_currency/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import crm_lead
from . import res_config_settings
83 changes: 83 additions & 0 deletions crm_multicompany_reporting_currency/models/crm_lead.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
# Copyright 2022 Camptocamp SA
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html)

from odoo import api, fields, models


class CrmLead(models.Model):
_inherit = "crm.lead"

def _get_multicompany_reporting_currency_id(self):
multicompany_reporting_currency_parameter = (
self.env["ir.config_parameter"]
.sudo()
.get_param(
"base_multicompany_reporting_currency.multicompany_reporting_currency"
)
)
return self.env["res.currency"].browse(
int(multicompany_reporting_currency_parameter)
)

multicompany_reporting_currency_id = fields.Many2one(
"res.currency",
compute="_compute_multicompany_reporting_currency_id",
readonly=True,
store=True,
default=_get_multicompany_reporting_currency_id,
)
currency_rate = fields.Float(
compute="_compute_currency_rate", store=True, digits=(12, 6)
)
amount_multicompany_reporting_currency = fields.Monetary(
currency_field="multicompany_reporting_currency_id",
compute="_compute_amount_multicompany_reporting_currency",
store=True,
index=True,
readonly=True,
)

@api.depends("company_currency")
def _compute_multicompany_reporting_currency_id(self):
multicompany_reporting_currency_id = (
self._get_multicompany_reporting_currency_id()
)
for record in self:
record.multicompany_reporting_currency_id = (
multicompany_reporting_currency_id
)

@api.depends("create_date", "company_id", "multicompany_reporting_currency_id")
def _compute_currency_rate(self):
# similar to currency_rate on sale.order
for record in self:
date = record.create_date or fields.Date.today()
if not record.company_id:
record.currency_rate = (
record.multicompany_reporting_currency_id.with_context(
date=date
).rate
or 1.0
)
elif (
record.company_currency and record.multicompany_reporting_currency_id
): # the following crashes if any one is undefined
record.currency_rate = self.env["res.currency"]._get_conversion_rate(
record.company_currency,
record.multicompany_reporting_currency_id,
record.company_id,
date,
)
else:
record.currency_rate = 1.0

Check warning on line 72 in crm_multicompany_reporting_currency/models/crm_lead.py

View check run for this annotation

Codecov / codecov/patch

crm_multicompany_reporting_currency/models/crm_lead.py#L72

Added line #L72 was not covered by tests

@api.depends(
"expected_revenue", "currency_rate", "multicompany_reporting_currency_id"
)
def _compute_amount_multicompany_reporting_currency(self):
for record in self:
if record.company_currency == record.multicompany_reporting_currency_id:
to_amount = record.expected_revenue
else:
to_amount = record.expected_revenue * record.currency_rate
record.amount_multicompany_reporting_currency = to_amount
19 changes: 19 additions & 0 deletions crm_multicompany_reporting_currency/models/res_config_settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Copyright 2022 Camptocamp SA
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html)

from odoo import models


class ResConfigSettings(models.TransientModel):
_inherit = "res.config.settings"

def set_values(self):
crm_lead = self.env["crm.lead"]
applied_currency = crm_lead._get_multicompany_reporting_currency_id()
super().set_values()
to_apply_currency = self.multicompany_reporting_currency
if applied_currency.id != to_apply_currency.id:
crm_lead.with_context(active_test=False).search([]).write(
{"multicompany_reporting_currency_id": to_apply_currency.id}
)
return True
3 changes: 3 additions & 0 deletions crm_multicompany_reporting_currency/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
* Maksym Yankin <[email protected]>
* [APSL](https://apsl.tech):
* Antoni Marroig <[email protected]>
3 changes: 3 additions & 0 deletions crm_multicompany_reporting_currency/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
This Module adds Amount in multicompany reporting currency to CRM Lead which can be used as a reporting tool.
You can then compare Expected Revenue in company currency to amount in multicompany reporting currency.
Multicompany reporting currency is installed from dependent https://github.com/OCA/sale-reporting/base_multicompany_reporting_currency module.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading