Commit c28b47a9 authored by Ángel Ramírez Isea's avatar Ángel Ramírez Isea
Browse files

Initial commit

parents
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*.pyc
__init__.pyc
# C extensions
*.so
# Distribution / packaging
.Python
env/
build/
develop-eggs/
downloads/
eggs/
.eggs/
lib64/
parts/
sdist/
var/
*.egg-info/
.installed.cfg
*.egg
# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec
# Installer logs
pip-log.txt
pip-delete-this-directory.txt
# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*,cover
# Translations
*.mo
*.pot
# Django stuff:
*.log
# Sphinx documentation
docs/_build/
# PyBuilder
target/
# Archivos grandes
*.sql
*.zip
*orig*
*.ods
*.tar.gz
# Extension IDE's
.idea/
# Others repo
#territorial_pd/*
vzla_code/*
l10n_ve_base/*
Locale - Default UoM
====================
This module adds a concept of a default unit of measure on languages, unique by
unit category type.
It also provides a method that can be used in fields to work from said defaults.
Configuration
=============
Set default unit of measures in the `Languages` menu in settings.
Usage
=====
Fields that want to implement the language default should use the provided
method, such as in the below example:
class MyModel(models.Model):
_name = 'my.model'
time_uom_id = fields.Many2one(
string='Time Units',
comodel_name='uom.uom',
default=lambda s: s.env['res.lang'].default_uom_by_category('Time'),
)
Credits
=======
Contributors
------------
This version
------------
* Ángel Ramírez Isea <angel.ramirez.isea@yandex.com>
Original Contributors
---------------------
* Dave Lasley <dave@laslabs.com>
Maintainer
----------
This module is maintained by Asociaciones Cooperativas de Procesamiento
Unificado Informático, R.S.; Simón Rodríguez para el Conocimiento Libre, R.S.;
y Soluciones Informáticas para el Desarrollo de Inclusión Social, R.S.
To contribute to this module, please visit https://git.labviv.org.ve/labviv.
# Copyright 2017 LasLabs Inc.
# Copyright 2020 LabViv.
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).
from . import models
# Copyright 2017 LasLabs Inc.
# Copyright 2020 LabViv.
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).
{
'name': 'Locale - Default UoM',
'description': 'Allows selection of default UoMs at the language level.',
'version': '13.0.1.0.1',
'category': 'Extra Tools',
'author': 'LasLabs Inc.',
'website': 'https://git.labviv.org.ve/',
'license': 'LGPL-3',
'application': False,
'installable': True,
'depends': ['base', 'product'],
'data': [
'views/res_lang_view.xml',
],
'demo': [
'demo/res_lang_demo.xml',
],
'maintainer': 'Ángel Ramírez Isea <angel.ramirez.isea@yandex.com>'
}
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record id="base.lang_en" model="res.lang">
<field
name="default_uom_ids"
eval="[(6, 0, [
ref('uom.product_uom_unit'),
ref('uom.product_uom_hour'),
ref('uom.product_uom_lb'),
ref('uom.product_uom_inch'),
ref('uom.product_uom_floz'),
])]"
/>
</record>
</odoo>
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * base_locale_uom_default
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 13.0\n"
"Report-Msgid-Bugs-To: angel.ramirez.isea@yandex.com\n"
"POT-Creation-Date: 2020-06-22 17:39+0000\n"
"PO-Revision-Date: 2020-07-17 16:58+0000\n"
"Last-Translator: LabViv <angel.ramirez.isea@yandex.com>, 2020\n"
"Language-Team: \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: base_locale_uom_default
#: model:ir.model.fields,field_description:base_locale_uom_default.field_res_lang__default_uom_ids
msgid "Default Units"
msgstr "Unidades predeterminadas"
#. module: base_locale_uom_default
#: model:ir.model,name:base_locale_uom_default.model_res_lang
msgid "Languages"
msgstr "Idiomas"
#. module: base_locale_uom_default
#: code:addons/base_locale_uom_default/models/res_lang.py:0
#, python-format
msgid ""
"Only one default unit of measure per category may be "
"selected."
msgstr "Sólo puede seleccionar una unidad por categoría"
# Copyright 2017 LasLabs Inc.
# Copyright 2020 LabViv.
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).
from . import res_lang
# Copyright 2017 LasLabs Inc.
# Copyright 2020 LabViv.
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).
from odoo import api, fields, models
from odoo.exceptions import ValidationError
class Lang(models.Model):
_inherit = 'res.lang'
default_uom_ids = fields.Many2many(
string='Default Units',
comodel_name='uom.uom',
)
@api.constrains('default_uom_ids')
def _check_default_uom_ids(self):
for record in self:
categories = set(record.default_uom_ids.mapped('category_id'))
if len(categories) != len(record.default_uom_ids):
raise ValidationError(
'Only one default unit of measure per category may be\
selected.'
)
@api.model
def default_uom_by_category(self, category_name, lang=None):
"""Return the default UoM for language for the input UoM Category.
Args:
category_name (str): Name of the UoM category to get the default
for.
lang (Lang or str, optional): Recordset or code of the language
to get the default for. Will use the current user language if
omitted.
Returns:
ProductUom: Unit of measure representing the default, if set.
Empty recordset otherwise.
"""
if lang is None:
lang = self.env.user.lang
if isinstance(lang, str):
lang = self.env['res.lang'].search(
[('code', '=', lang)], limit=1,
)
results = lang.default_uom_ids.filtered(
lambda r: r.category_id.name == category_name,
)
return results[:1]
# Copyright 2017 LasLabs Inc.
# Copyright 2020 LabViv.
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).
from . import test_res_lang
# Copyright 2017 LasLabs Inc.
# Copyright 2020 LabViv.
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).
from odoo.exceptions import ValidationError
from odoo.tests.common import TransactionCase
class TestLang(TransactionCase):
def setUp(self):
super(TestLang, self).setUp()
self.lang = self.env.ref('base.lang_en')
self.env.user.lang = self.lang.code
self.uom = self.env.ref('uom.product_uom_dozen')
self.lang.default_uom_ids = [(6, 0, self.uom.ids)]
def test_check_default_uom_ids_fail(self):
"""It should not allow multiple UoMs of the same category."""
with self.assertRaises(ValidationError):
self.lang.default_uom_ids = [
(4, self.env.ref('uom.product_uom_unit').id),
]
def test_check_default_uom_ids_pass(self):
"""It should allow multiple UoMs of different categories."""
self.lang.default_uom_ids = [
(4, self.env.ref('uom.product_uom_kgm').id),
]
self.assertEqual(len(self.lang.default_uom_ids), 2)
def test_default_uom_by_category_exist(self):
"""It should return the default UoM if existing."""
self.assertEqual(
self.env['res.lang'].default_uom_by_category('Unit'),
self.uom,
)
def test_default_uom_by_category_no_exist(self):
"""It should return empty recordset when no default UoM."""
self.assertEqual(
self.env['res.lang'].default_uom_by_category('Volume'),
self.env['uom.uom'].browse(),
)
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record id="res_lang_form" model="ir.ui.view">
<field name="name">Res Lang Form - Default UoMs</field>
<field name="model">res.lang</field>
<field name="inherit_id" ref="base.res_lang_form"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='iso_code']" position="after">
<field name="default_uom_ids"/>
</xpath>
</field>
</record>
</odoo>
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment