Skip to content

Commit

Permalink
Merge PR #181 into 16.0
Browse files Browse the repository at this point in the history
Signed-off-by legalsylvain
  • Loading branch information
github-grap-bot committed Dec 17, 2024
2 parents 31b9ade + 644014b commit c9441c9
Show file tree
Hide file tree
Showing 15 changed files with 240 additions and 0 deletions.
32 changes: 32 additions & 0 deletions product_accounts/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
============================
User Limited Access Settings
============================

Create a new Administration group with limited access to create only users and companies

Purpose
=======

This module does this and that...

Explain the use case.

Configuration
=============

To configure this module, you need to:

#. Go to ...

Usage
=====

To use this module, you need to:

#. Go to ...


How to test
===========

...
1 change: 1 addition & 0 deletions product_accounts/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
17 changes: 17 additions & 0 deletions product_accounts/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Copyright 2024 GRAP
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

{
"name": "Product - Accounting Settings",
"summary": """Compute and display income - expense account
at product level""",
"version": "16.0.1.0.0",
"license": "AGPL-3",
"author": "GRAP",
"website": "https://github.com/grap/grap-odoo-incubator",
"depends": ["account"],
"data": [
"views/view_product_template.xml",
"views/view_product_product.xml",
],
}
27 changes: 27 additions & 0 deletions product_accounts/i18n/fr.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * product_accounts
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 16.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2024-12-03 22:37+0000\n"
"PO-Revision-Date: 2024-12-03 22:37+0000\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: product_accounts
#: model:ir.model.fields,field_description:product_accounts.field_product_product__accounts
#: model:ir.model.fields,field_description:product_accounts.field_product_template__accounts
msgid "Accounts"
msgstr "Comptes"

#. module: product_accounts
#: model:ir.model,name:product_accounts.model_product_template
msgid "Product"
msgstr "Produit"
1 change: 1 addition & 0 deletions product_accounts/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import product_template
25 changes: 25 additions & 0 deletions product_accounts/models/product_template.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Copyright 2024 Sylvain LE GAL - GRAP
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import api, fields, models


class ProductTemplate(models.Model):
_inherit = "product.template"

accounts = fields.Char(compute="_compute_accounting_settings")

@api.depends(
"company_id",
"categ_id.property_account_income_categ_id",
"categ_id.property_account_expense_categ_id",
"property_account_income_id",
"property_account_expense_id",
)
def _compute_accounting_settings(self):
for template in self:
company = template.company_id or self.env.company
res = template.with_company(company)._get_product_accounts()
expense_code = res["expense"] and res["expense"].code or "-"
income_code = res["income"] and res["income"].code or "-"
template.accounts = f"{expense_code} / {income_code}"
8 changes: 8 additions & 0 deletions product_accounts/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
This module extends the odoo account module, to display explicitely
accounts configured on products tree view.

.. figure:: ../static/description/product_tree.png

The information is also available on product form view.

.. figure:: ../static/description/product_form.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions product_accounts/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import test_module
65 changes: 65 additions & 0 deletions product_accounts/tests/test_module.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# Copyright (C) 2024 - Today: GRAP (http://www.grap.coop)
# @author: Sylvain LE GAL (https://twitter.com/legalsylvain)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from odoo.tests.common import TransactionCase


class TestModule(TransactionCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.AccountAccount = cls.env["account.account"]
cls.product = cls.env.ref("product.product_product_25_product_template")
cls.category = cls.env.ref("product.product_category_5")
cls.company = cls.env.ref("base.main_company")
cls.product.company_id = cls.company.id
cls.product.property_account_expense_id = False
cls.product.property_account_income_id = False
cls.category.property_account_expense_categ_id = False
cls.category.property_account_income_categ_id = False
cls.expense_account_1 = cls.AccountAccount.create(
{
"code": "6P.EXP1",
"name": "6P.EXP1 Name",
"account_type": "expense",
"company_id": cls.company.id,
}
)
cls.income_account_1 = cls.AccountAccount.create(
{
"code": "7P.INC1",
"name": "7P.INC1 Name",
"account_type": "income",
"company_id": cls.company.id,
}
)
cls.expense_account_2 = cls.AccountAccount.create(
{
"code": "6P.EXP2",
"name": "6P.EXP2 Name",
"account_type": "expense",
"company_id": cls.company.id,
}
)
cls.income_account_2 = cls.AccountAccount.create(
{
"code": "7P.INC2",
"name": "7P.INC2 Name",
"account_type": "income",
"company_id": cls.company.id,
}
)

def test_account_computation(self):
self.assertEqual(self.product.accounts, "- / -")

self.category.property_account_expense_categ_id = self.expense_account_1.id
self.assertEqual(self.product.accounts, "6P.EXP1 / -")

self.category.property_account_income_categ_id = self.income_account_1.id
self.assertEqual(self.product.accounts, "6P.EXP1 / 7P.INC1")

self.product.property_account_expense_id = self.expense_account_2.id
self.product.property_account_income_id = self.income_account_2.id
self.assertEqual(self.product.accounts, "6P.EXP2 / 7P.INC2")
16 changes: 16 additions & 0 deletions product_accounts/views/view_product_product.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright 2024 Sylvain LE GAL - GRAP
License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). -->

<odoo>

<record id="view_product_product_tree" model="ir.ui.view">
<field name="model">product.product</field>
<field name="inherit_id" ref="product.product_product_tree_view" />
<field name="arch" type="xml">
<field name="uom_id" position="after">
<field name="accounts" optional="show"/>
</field>
</field>
</record>
</odoo>
40 changes: 40 additions & 0 deletions product_accounts/views/view_product_template.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright 2024 Sylvain LE GAL - GRAP
License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). -->

<odoo>

<record id="view_product_template_form" model="ir.ui.view">
<field name="model">product.template</field>
<field name="inherit_id" ref="product.product_template_form_view" />
<field name="arch" type="xml">
<xpath expr="//field[@name='sale_ok']/.." position="before">
<span class="d-inline-block">
<label for="accounts"/>
<field name="accounts" style="margin-right: 5px;"/>
</span>
</xpath>
</field>
</record>

<record id="view_product_template_tree" model="ir.ui.view">
<field name="model">product.template</field>
<field name="inherit_id" ref="product.product_template_tree_view" />
<field name="arch" type="xml">
<field name="uom_id" position="after">
<field name="accounts" optional="show"/>
</field>
</field>
</record>

<record id="view_product_template_tree_account" model="ir.ui.view">
<field name="model">product.template</field>
<field name="inherit_id" ref="account.product_template_view_tree" />
<field name="arch" type="xml">
<field name="list_price" position="after">
<field name="accounts" optional="show"/>
</field>
</field>
</record>

</odoo>
1 change: 1 addition & 0 deletions setup/product_accounts/odoo/addons/product_accounts
6 changes: 6 additions & 0 deletions setup/product_accounts/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import setuptools

setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)

0 comments on commit c9441c9

Please sign in to comment.