Skip to content
Open
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
7 changes: 2 additions & 5 deletions product_analytic/README.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
.. image:: https://odoo-community.org/readme-banner-image
:target: https://odoo-community.org/get-involved?utm_source=readme
:alt: Odoo Community Association

================
Product Analytic
================
Expand All @@ -17,7 +13,7 @@ Product Analytic
.. |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/license-AGPL--3-blue.png
.. |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%2Faccount--analytic-lightgray.png?logo=github
Expand Down Expand Up @@ -137,6 +133,7 @@ Contributors
- Denis Roussel <denis.roussel@acsone.eu>
- Darius Žižys <darius@vialaurea.lt>
- Jacques-Etienne Baudoux (BCIM) <je@bcim.be>
- Alberto Nieto

Maintainers
-----------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ def _get_distribution(self, vals):
move_type = self.env.context.get("move_type")
if vals.get("product_id") and move_type and move_type in INV_TYPE_MAP:
product = self.env["product.product"].browse(vals["product_id"])
ana_accounts = product.product_tmpl_id._get_product_analytic_accounts()
company_id = vals.get("company_id") or self.env.company.id
ana_accounts = product.product_tmpl_id.with_company(
company_id
)._get_product_analytic_accounts()
ana_account = ana_accounts[INV_TYPE_MAP[move_type]]
if ana_account:
return {ana_account.id: 100}
Expand Down
1 change: 1 addition & 0 deletions product_analytic/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@
- Denis Roussel \<denis.roussel@acsone.eu\>
- Darius Žižys \<darius@vialaurea.lt\>
- Jacques-Etienne Baudoux (BCIM) \<je@bcim.be\>
- Alberto Nieto
49 changes: 22 additions & 27 deletions product_analytic/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="generator" content="Docutils: https://docutils.sourceforge.io/" />
<title>README.rst</title>
<title>Product Analytic</title>
<style type="text/css">

/*
Expand Down Expand Up @@ -360,21 +360,16 @@
</style>
</head>
<body>
<div class="document">
<div class="document" id="product-analytic">
<h1 class="title">Product Analytic</h1>


<a class="reference external image-reference" href="https://odoo-community.org/get-involved?utm_source=readme">
<img alt="Odoo Community Association" src="https://odoo-community.org/readme-banner-image" />
</a>
<div class="section" id="product-analytic">
<h1>Product Analytic</h1>
<!-- !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:24840186e5210a569c3582e9559fce3ce779f66cfb0c85fe243f9d03f7396677
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/license-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/account-analytic/tree/17.0/product_analytic"><img alt="OCA/account-analytic" src="https://img.shields.io/badge/github-OCA%2Faccount--analytic-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/account-analytic-17-0/account-analytic-17-0-product_analytic"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/account-analytic&amp;target_branch=17.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/account-analytic/tree/17.0/product_analytic"><img alt="OCA/account-analytic" src="https://img.shields.io/badge/github-OCA%2Faccount--analytic-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/account-analytic-17-0/account-analytic-17-0-product_analytic"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/account-analytic&amp;target_branch=17.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p>This module allows to define an analytic account at product or category
level for using it when creating invoices.</p>
<p><strong>Table of contents</strong></p>
Expand Down Expand Up @@ -404,7 +399,7 @@ <h1>Product Analytic</h1>
</ul>
</div>
<div class="section" id="usage">
<h2><a class="toc-backref" href="#toc-entry-1">Usage</a></h2>
<h1><a class="toc-backref" href="#toc-entry-1">Usage</a></h1>
<p>This module allows you to configure an <strong>income analytic account</strong> and
an <strong>expense analytic account</strong> on products and on product categories.
When you select the product in an invoice line, it will check if this
Expand All @@ -415,67 +410,67 @@ <h2><a class="toc-backref" href="#toc-entry-1">Usage</a></h2>
be set by default on the invoice line.</p>
</div>
<div class="section" id="changelog">
<h2><a class="toc-backref" href="#toc-entry-2">Changelog</a></h2>
<h1><a class="toc-backref" href="#toc-entry-2">Changelog</a></h1>
<div class="section" id="section-1">
<h3><a class="toc-backref" href="#toc-entry-3">15.0.1.0.0 (2022-01-28)</a></h3>
<h2><a class="toc-backref" href="#toc-entry-3">15.0.1.0.0 (2022-01-28)</a></h2>
<p>Migrated to odoo 15.</p>
</div>
<div class="section" id="section-2">
<h3><a class="toc-backref" href="#toc-entry-4">14.0.1.0.0 (2021-10-24)</a></h3>
<h2><a class="toc-backref" href="#toc-entry-4">14.0.1.0.0 (2021-10-24)</a></h2>
<p>Migrated to odoo 14.</p>
</div>
<div class="section" id="section-3">
<h3><a class="toc-backref" href="#toc-entry-5">13.0.1.0.0 (2020-01-08)</a></h3>
<h2><a class="toc-backref" href="#toc-entry-5">13.0.1.0.0 (2020-01-08)</a></h2>
<p>Migrated to odoo 13.</p>
</div>
<div class="section" id="section-4">
<h3><a class="toc-backref" href="#toc-entry-6">12.0.1.0.0 (2019-05-26)</a></h3>
<h2><a class="toc-backref" href="#toc-entry-6">12.0.1.0.0 (2019-05-26)</a></h2>
<p>Migrated to odoo 12.</p>
</div>
<div class="section" id="section-5">
<h3><a class="toc-backref" href="#toc-entry-7">11.0.1.0.0 (2018-05-18)</a></h3>
<h2><a class="toc-backref" href="#toc-entry-7">11.0.1.0.0 (2018-05-18)</a></h2>
<p>Migrated to odoo 11.</p>
</div>
<div class="section" id="section-6">
<h3><a class="toc-backref" href="#toc-entry-8">10.0.1.0.1 (2017-07-18)</a></h3>
<h2><a class="toc-backref" href="#toc-entry-8">10.0.1.0.1 (2017-07-18)</a></h2>
<p>[ADD] Demo data and feature to set analytic account for products.</p>
</div>
<div class="section" id="section-7">
<h3><a class="toc-backref" href="#toc-entry-9">10.0.1.0.0 (2017-06-13)</a></h3>
<h2><a class="toc-backref" href="#toc-entry-9">10.0.1.0.0 (2017-06-13)</a></h2>
<p>Migrated to odoo 10.</p>
</div>
<div class="section" id="section-8">
<h3><a class="toc-backref" href="#toc-entry-10">8.0.1.0.2 (2016-12-03)</a></h3>
<h2><a class="toc-backref" href="#toc-entry-10">8.0.1.0.2 (2016-12-03)</a></h2>
<p>[FIX] Travis errors.</p>
</div>
<div class="section" id="section-9">
<h3><a class="toc-backref" href="#toc-entry-11">8.0.1.0.1 (2016-01-05)</a></h3>
<h2><a class="toc-backref" href="#toc-entry-11">8.0.1.0.1 (2016-01-05)</a></h2>
<p>[IMP] Analytic account creating invoice lines.</p>
</div>
<div class="section" id="section-10">
<h3><a class="toc-backref" href="#toc-entry-12">8.0.1.0.0 (2015-11-30)</a></h3>
<h2><a class="toc-backref" href="#toc-entry-12">8.0.1.0.0 (2015-11-30)</a></h2>
<p>First version.</p>
</div>
</div>
<div class="section" id="bug-tracker">
<h2><a class="toc-backref" href="#toc-entry-13">Bug Tracker</a></h2>
<h1><a class="toc-backref" href="#toc-entry-13">Bug Tracker</a></h1>
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/account-analytic/issues">GitHub Issues</a>.
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
<a class="reference external" href="https://github.com/OCA/account-analytic/issues/new?body=module:%20product_analytic%0Aversion:%2017.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<p>Do not contact contributors directly about support or help with technical issues.</p>
</div>
<div class="section" id="credits">
<h2><a class="toc-backref" href="#toc-entry-14">Credits</a></h2>
<h1><a class="toc-backref" href="#toc-entry-14">Credits</a></h1>
<div class="section" id="authors">
<h3><a class="toc-backref" href="#toc-entry-15">Authors</a></h3>
<h2><a class="toc-backref" href="#toc-entry-15">Authors</a></h2>
<ul class="simple">
<li>Akretion</li>
<li>Tecnativa</li>
</ul>
</div>
<div class="section" id="contributors">
<h3><a class="toc-backref" href="#toc-entry-16">Contributors</a></h3>
<h2><a class="toc-backref" href="#toc-entry-16">Contributors</a></h2>
<ul class="simple">
<li>Alexis de Lattre &lt;<a class="reference external" href="mailto:alexis.delattre&#64;akretion.com">alexis.delattre&#64;akretion.com</a>&gt;</li>
<li>Javier Iniesta &lt;<a class="reference external" href="mailto:javieria&#64;antiun.com">javieria&#64;antiun.com</a>&gt;</li>
Expand All @@ -487,10 +482,11 @@ <h3><a class="toc-backref" href="#toc-entry-16">Contributors</a></h3>
<li>Denis Roussel &lt;<a class="reference external" href="mailto:denis.roussel&#64;acsone.eu">denis.roussel&#64;acsone.eu</a>&gt;</li>
<li>Darius Žižys &lt;<a class="reference external" href="mailto:darius&#64;vialaurea.lt">darius&#64;vialaurea.lt</a>&gt;</li>
<li>Jacques-Etienne Baudoux (BCIM) &lt;<a class="reference external" href="mailto:je&#64;bcim.be">je&#64;bcim.be</a>&gt;</li>
<li>Alberto Nieto</li>
</ul>
</div>
<div class="section" id="maintainers">
<h3><a class="toc-backref" href="#toc-entry-17">Maintainers</a></h3>
<h2><a class="toc-backref" href="#toc-entry-17">Maintainers</a></h2>
<p>This module is maintained by the OCA.</p>
<a class="reference external image-reference" href="https://odoo-community.org">
<img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" />
Expand All @@ -503,6 +499,5 @@ <h3><a class="toc-backref" href="#toc-entry-17">Maintainers</a></h3>
</div>
</div>
</div>
</div>
</body>
</html>
91 changes: 91 additions & 0 deletions product_analytic/tests/test_account_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,3 +273,94 @@ def test_create_out_preset(self):
int(analytic_account_id[0]),
self.analytic_account2.id,
)


class TestAccountAnalyticDistributionMultiCompany(TransactionCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
# Create two companies
cls.company_1, cls.company_2 = cls.env["res.company"].create(
[
{"name": "foo", "currency_id": cls.env.ref("base.USD").id},
{"name": "bar", "currency_id": cls.env.ref("base.USD").id},
]
)
cls.default_plan = cls.env["account.analytic.plan"].create(
{
"name": "Default Plan",
"applicability_ids": False,
}
)
# Create analytic accounts for each company
cls.analytic_account_1 = (
cls.env["account.analytic.account"]
.with_company(cls.company_1)
.create(
{
"name": "Analytic Account 1",
"plan_id": cls.default_plan.id,
"company_id": cls.company_1.id,
}
)
)
cls.analytic_account_2 = (
cls.env["account.analytic.account"]
.with_company(cls.company_2)
.create(
{
"name": "Analytic Account 2",
"plan_id": cls.default_plan.id,
"company_id": cls.company_2.id,
}
)
)
cls.product = cls.env["product.product"].create(
{
"name": "test product",
"lst_price": 50,
"standard_price": 50,
}
)
cls.product.with_company(cls.company_1).write(
{
"income_analytic_account_id": cls.analytic_account_1.id,
"expense_analytic_account_id": cls.analytic_account_1.id,
}
)
cls.product.with_company(cls.company_2).write(
{
"income_analytic_account_id": cls.analytic_account_2.id,
"expense_analytic_account_id": cls.analytic_account_2.id,
}
)

def test_distribution_multicompany(self):
# Simulate context for company 1
vals = {
"product_id": self.product.id,
"company_id": self.company_1.id,
}
ctx = self.env.context.copy()
ctx.update({"move_type": "out_invoice"})
distribution = (
self.env["account.analytic.distribution.model"]
.with_context(**ctx)
._get_distribution(vals)
)
self.assertTrue(distribution)
self.assertEqual(list(distribution.keys())[0], self.analytic_account_1.id)
# Simulate context for company 2
vals = {
"product_id": self.product.id,
"company_id": self.company_2.id,
}
ctx = self.env.context.copy()
ctx.update({"move_type": "out_invoice"})
distribution = (
self.env["account.analytic.distribution.model"]
.with_context(**ctx)
._get_distribution(vals)
)
self.assertTrue(distribution)
self.assertEqual(list(distribution.keys())[0], self.analytic_account_2.id)