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

=================
Product UoM UNECE
=================
Expand All @@ -13,7 +17,7 @@ Product UoM UNECE
.. |badge1| image:: https://img.shields.io/badge/maturity-Production%2FStable-green.png
:target: https://odoo-community.org/page/development-status
:alt: Production/Stable
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
.. |badge2| image:: https://img.shields.io/badge/license-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%2Fcommunity--data--files-lightgray.png?logo=github
Expand Down Expand Up @@ -78,6 +82,7 @@ Contributors
* Andrea Stirpe
* Levent Karakaş <leventk@eskayazilim.com.tr>
* Pedro M. Baeza
* Souheil Bejaoui <souheil.bejaoui@acsone.eu>

Maintainers
~~~~~~~~~~~
Expand Down
31 changes: 30 additions & 1 deletion uom_unece/models/uom_uom.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
# @author: Alexis de Lattre <alexis.delattre@akretion.com>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import fields, models
from odoo import api, fields, models
from odoo.tools import ormcache


class UomUom(models.Model):
Expand All @@ -13,3 +14,31 @@ class UomUom(models.Model):
help="Standard nomenclature of the United Nations Economic "
"Commission for Europe (UNECE).",
)

@api.model
@ormcache()
def _get_uom_id_by_unece_code(self):
uoms = self.search([("unece_code", "!=", False)])
return {u.unece_code: u.id for u in uoms}

def get_uom_id_by_unece_code(self, unece_code):
uom_ids_by_code = self._get_uom_id_by_unece_code()
return uom_ids_by_code.get(unece_code)

@api.model_create_multi
def create(self, vals_list):
records = super().create(vals_list)
if records.filtered("unece_code"):
self._get_uom_id_by_unece_code.clear_cache(self)
return records

def write(self, vals):
res = super().write(vals)
if "unece_code" in vals:
self._get_uom_id_by_unece_code.clear_cache(self)
return res

def unlink(self):
res = super().unlink()
self._get_uom_id_by_unece_code.clear_cache(self)
return res
1 change: 1 addition & 0 deletions uom_unece/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
* Andrea Stirpe
* Levent Karakaş <leventk@eskayazilim.com.tr>
* Pedro M. Baeza
* Souheil Bejaoui <souheil.bejaoui@acsone.eu>
38 changes: 24 additions & 14 deletions uom_unece/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="generator" content="Docutils: https://docutils.sourceforge.io/" />
<title>Product UoM UNECE</title>
<title>README.rst</title>
<style type="text/css">

/*
:Author: David Goodger (goodger@python.org)
:Id: $Id: html4css1.css 8954 2022-01-20 10:10:25Z milde $
:Id: $Id: html4css1.css 9511 2024-01-13 09:50:07Z milde $
:Copyright: This stylesheet has been placed in the public domain.

Default cascading style sheet for the HTML output of Docutils.
Despite the name, some widely supported CSS2 features are used.

See https://docutils.sourceforge.io/docs/howto/html-stylesheets.html for how to
customize this style sheet.
Expand Down Expand Up @@ -274,7 +275,7 @@
margin-left: 2em ;
margin-right: 2em }

pre.code .ln { color: grey; } /* line numbers */
pre.code .ln { color: gray; } /* line numbers */
pre.code, code { background-color: #eeeeee }
pre.code .comment, code .comment { color: #5C6576 }
pre.code .keyword, code .keyword { color: #3B0D06; font-weight: bold }
Expand All @@ -300,7 +301,7 @@
span.pre {
white-space: pre }

span.problematic {
span.problematic, pre.problematic {
color: red }

span.section-subtitle {
Expand Down Expand Up @@ -359,16 +360,21 @@
</style>
</head>
<body>
<div class="document" id="product-uom-unece">
<h1 class="title">Product UoM UNECE</h1>
<div class="document">


<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-uom-unece">
<h1>Product UoM UNECE</h1>
<!-- !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:fdd27cf72a54fe5c4eace2d374481dd2ded7f0d5f3e768d6bd1a37355e74816b
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Production/Stable" src="https://img.shields.io/badge/maturity-Production%2FStable-green.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/community-data-files/tree/16.0/uom_unece"><img alt="OCA/community-data-files" src="https://img.shields.io/badge/github-OCA%2Fcommunity--data--files-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/community-data-files-16-0/community-data-files-16-0-uom_unece"><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/community-data-files&amp;target_branch=16.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="Production/Stable" src="https://img.shields.io/badge/maturity-Production%2FStable-green.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/community-data-files/tree/16.0/uom_unece"><img alt="OCA/community-data-files" src="https://img.shields.io/badge/github-OCA%2Fcommunity--data--files-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/community-data-files-16-0/community-data-files-16-0-uom_unece"><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/community-data-files&amp;target_branch=16.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p>This module adds a field <em>UNECE Code</em> on units of measure to allow the use of
a standard written by the
<a class="reference external" href="http://www.unece.org">United Nations Economic Commission for Europe</a> (which
Expand Down Expand Up @@ -397,38 +403,41 @@ <h1 class="title">Product UoM UNECE</h1>
</ul>
</div>
<div class="section" id="configuration">
<h1><a class="toc-backref" href="#toc-entry-1">Configuration</a></h1>
<h2><a class="toc-backref" href="#toc-entry-1">Configuration</a></h2>
<p>This module automatically adds the UNECE Code on the existing units of measure.</p>
</div>
<div class="section" id="bug-tracker">
<h1><a class="toc-backref" href="#toc-entry-2">Bug Tracker</a></h1>
<h2><a class="toc-backref" href="#toc-entry-2">Bug Tracker</a></h2>
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/community-data-files/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/community-data-files/issues/new?body=module:%20uom_unece%0Aversion:%2016.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">
<h1><a class="toc-backref" href="#toc-entry-3">Credits</a></h1>
<h2><a class="toc-backref" href="#toc-entry-3">Credits</a></h2>
<div class="section" id="authors">
<h2><a class="toc-backref" href="#toc-entry-4">Authors</a></h2>
<h3><a class="toc-backref" href="#toc-entry-4">Authors</a></h3>
<ul class="simple">
<li>Akretion</li>
</ul>
</div>
<div class="section" id="contributors">
<h2><a class="toc-backref" href="#toc-entry-5">Contributors</a></h2>
<h3><a class="toc-backref" href="#toc-entry-5">Contributors</a></h3>
<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>Andrea Stirpe</li>
<li>Levent Karakaş &lt;<a class="reference external" href="mailto:leventk&#64;eskayazilim.com.tr">leventk&#64;eskayazilim.com.tr</a>&gt;</li>
<li>Pedro M. Baeza</li>
<li>Souheil Bejaoui &lt;<a class="reference external" href="mailto:souheil.bejaoui&#64;acsone.eu">souheil.bejaoui&#64;acsone.eu</a>&gt;</li>
</ul>
</div>
<div class="section" id="maintainers">
<h2><a class="toc-backref" href="#toc-entry-6">Maintainers</a></h2>
<h3><a class="toc-backref" href="#toc-entry-6">Maintainers</a></h3>
<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" /></a>
<a class="reference external image-reference" href="https://odoo-community.org">
<img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" />
</a>
<p>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.</p>
Expand All @@ -439,5 +448,6 @@ <h2><a class="toc-backref" href="#toc-entry-6">Maintainers</a></h2>
</div>
</div>
</div>
</div>
</body>
</html>
1 change: 1 addition & 0 deletions uom_unece/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import test_uom_unece
44 changes: 44 additions & 0 deletions uom_unece/tests/test_uom_unece.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Copyright 2026 ACSONE SA/NV
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo.tests.common import TransactionCase


class TestUomUnece(TransactionCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.uom_model = cls.env["uom.uom"]
cls.uom_unit = cls.env.ref("uom.product_uom_unit")
cls.uom_dozen = cls.env.ref("uom.product_uom_dozen")
cls.uom_hour = cls.env.ref("uom.product_uom_hour")

def test_get_uom_id_by_unece_code(self):
self.assertEqual(
self.uom_model.get_uom_id_by_unece_code("C62"), self.uom_unit.id
)
self.assertEqual(
self.uom_model.get_uom_id_by_unece_code("DPC"), self.uom_dozen.id
)
self.assertEqual(
self.uom_model.get_uom_id_by_unece_code("HUR"), self.uom_hour.id
)

def test_get_uom_id_by_unece_code_unknown(self):
self.assertFalse(self.uom_model.get_uom_id_by_unece_code("UNKNOWN"))

def test_get_uom_id_by_unece_code_cache_invalidation_on_write(self):
self.assertEqual(
self.uom_model.get_uom_id_by_unece_code("C62"), self.uom_unit.id
)
self.uom_unit.write({"unece_code": "C62_NEW"})
self.assertFalse(self.uom_model.get_uom_id_by_unece_code("C62"))
self.assertEqual(
self.uom_model.get_uom_id_by_unece_code("C62_NEW"), self.uom_unit.id
)

def test_get_uom_id_by_unece_code_cache_invalidation_on_unlink(self):
uom = self.uom_hour.copy({"name": "Test Hour Copy", "unece_code": "ZZZ"})
self.assertEqual(self.uom_model.get_uom_id_by_unece_code("ZZZ"), uom.id)
uom.unlink()
self.assertFalse(self.uom_model.get_uom_id_by_unece_code("ZZZ"))
Loading