diff --git a/base_locale_uom_default/README.rst b/base_locale_uom_default/README.rst new file mode 100644 index 000000000..37cfc013d --- /dev/null +++ b/base_locale_uom_default/README.rst @@ -0,0 +1,95 @@ +==================== +Locale - Default UoM +==================== + +.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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-LGPL--3-blue.png + :target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html + :alt: License: LGPL-3 +.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fserver--tools-lightgray.png?logo=github + :target: https://github.com/OCA/server-tools/tree/12.0/base_locale_uom_default + :alt: OCA/server-tools +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/server-tools-12-0/server-tools-12-0-base_locale_uom_default + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png + :target: https://runbot.odoo-community.org/runbot/149/12.0 + :alt: Try me on Runbot + +|badge1| |badge2| |badge3| |badge4| |badge5| + +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. + +**Table of contents** + +.. contents:: + :local: + +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='product.uom', + default=lambda s: s.env['res.lang'].default_uom_by_category('Time'), + ) + +Bug Tracker +=========== + +Bugs are tracked on `GitHub Issues `_. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us smashing it by providing a detailed and welcomed +`feedback `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +~~~~~~~ + +* LasLabs + +Contributors +~~~~~~~~~~~~ + +* Dave Lasley +* Rubén Bravo + +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. + +This module is part of the `OCA/server-tools `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/base_locale_uom_default/__init__.py b/base_locale_uom_default/__init__.py new file mode 100644 index 000000000..976409e16 --- /dev/null +++ b/base_locale_uom_default/__init__.py @@ -0,0 +1,4 @@ +# Copyright 2017 LasLabs Inc. +# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). + +from . import models diff --git a/base_locale_uom_default/__manifest__.py b/base_locale_uom_default/__manifest__.py new file mode 100644 index 000000000..89fe891dd --- /dev/null +++ b/base_locale_uom_default/__manifest__.py @@ -0,0 +1,26 @@ +# Copyright 2017 LasLabs Inc. +# Copyright 2019 Rubén Bravo +# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). + +{ + 'name': 'Locale - Default UoM', + 'summary': 'This provides settings to select default UoMs at the ' + 'language level.', + 'version': '12.0.1.0.0', + 'category': 'Extra Tools', + 'website': 'https://github.com/OCA/server-tools/', + 'author': 'LasLabs, ' + 'Odoo Community Association (OCA)', + 'license': 'LGPL-3', + 'application': False, + 'installable': True, + 'depends': [ + 'product', + ], + 'data': [ + 'views/res_lang_view.xml', + ], + 'demo': [ + 'demo/res_lang_demo.xml', + ], +} diff --git a/base_locale_uom_default/demo/res_lang_demo.xml b/base_locale_uom_default/demo/res_lang_demo.xml new file mode 100644 index 000000000..6c6dec797 --- /dev/null +++ b/base_locale_uom_default/demo/res_lang_demo.xml @@ -0,0 +1,14 @@ + + + + + + + + diff --git a/base_locale_uom_default/i18n/ar.po b/base_locale_uom_default/i18n/ar.po new file mode 100644 index 000000000..c593ce613 --- /dev/null +++ b/base_locale_uom_default/i18n/ar.po @@ -0,0 +1,36 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * base_locale_uom_default +# +# Translators: +# OCA Transbot , 2017 +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 10.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2017-12-01 02:10+0000\n" +"PO-Revision-Date: 2017-12-01 02:10+0000\n" +"Last-Translator: OCA Transbot , 2017\n" +"Language-Team: Arabic (https://www.transifex.com/oca/teams/23907/ar/)\n" +"Language: ar\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=6; plural=n==0 ? 0 : n==1 ? 1 : n==2 ? 2 : n%100>=3 " +"&& n%100<=10 ? 3 : n%100>=11 && n%100<=99 ? 4 : 5;\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 "" + +#. module: base_locale_uom_default +#: model:ir.model,name:base_locale_uom_default.model_res_lang +msgid "Languages" +msgstr "اللغات" + +#. module: base_locale_uom_default +#: code:addons/base_locale_uom_default/models/res_lang.py:24 +#, python-format +msgid "Only one default unit of measure per category may be selected." +msgstr "" diff --git a/base_locale_uom_default/i18n/base_locale_uom_default.pot b/base_locale_uom_default/i18n/base_locale_uom_default.pot new file mode 100644 index 000000000..dfd364c12 --- /dev/null +++ b/base_locale_uom_default/i18n/base_locale_uom_default.pot @@ -0,0 +1,31 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * base_locale_uom_default +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 10.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: base_locale_uom_default +#: model:ir.model.fields,field_description:base_locale_uom_default.field_res_lang_default_uom_ids +msgid "Default Units" +msgstr "" + +#. module: base_locale_uom_default +#: model:ir.model,name:base_locale_uom_default.model_res_lang +msgid "Languages" +msgstr "" + +#. module: base_locale_uom_default +#: code:addons/base_locale_uom_default/models/res_lang.py:24 +#, python-format +msgid "Only one default unit of measure per category may be selected." +msgstr "" + diff --git a/base_locale_uom_default/i18n/ca.po b/base_locale_uom_default/i18n/ca.po new file mode 100644 index 000000000..8a8a829a2 --- /dev/null +++ b/base_locale_uom_default/i18n/ca.po @@ -0,0 +1,35 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * base_locale_uom_default +# +# Translators: +# OCA Transbot , 2017 +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 10.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2017-12-01 02:10+0000\n" +"PO-Revision-Date: 2017-12-01 02:10+0000\n" +"Last-Translator: OCA Transbot , 2017\n" +"Language-Team: Catalan (https://www.transifex.com/oca/teams/23907/ca/)\n" +"Language: ca\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 "" + +#. module: base_locale_uom_default +#: model:ir.model,name:base_locale_uom_default.model_res_lang +msgid "Languages" +msgstr "Idiomes " + +#. module: base_locale_uom_default +#: code:addons/base_locale_uom_default/models/res_lang.py:24 +#, python-format +msgid "Only one default unit of measure per category may be selected." +msgstr "" diff --git a/base_locale_uom_default/i18n/de.po b/base_locale_uom_default/i18n/de.po new file mode 100644 index 000000000..bf48705c1 --- /dev/null +++ b/base_locale_uom_default/i18n/de.po @@ -0,0 +1,35 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * base_locale_uom_default +# +# Translators: +# Niki Waibel , 2017 +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 10.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2017-12-01 02:10+0000\n" +"PO-Revision-Date: 2017-12-01 02:10+0000\n" +"Last-Translator: Niki Waibel , 2017\n" +"Language-Team: German (https://www.transifex.com/oca/teams/23907/de/)\n" +"Language: de\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 "" + +#. module: base_locale_uom_default +#: model:ir.model,name:base_locale_uom_default.model_res_lang +msgid "Languages" +msgstr "Sprachen" + +#. module: base_locale_uom_default +#: code:addons/base_locale_uom_default/models/res_lang.py:24 +#, python-format +msgid "Only one default unit of measure per category may be selected." +msgstr "" diff --git a/base_locale_uom_default/i18n/es.po b/base_locale_uom_default/i18n/es.po new file mode 100644 index 000000000..a667ae3e1 --- /dev/null +++ b/base_locale_uom_default/i18n/es.po @@ -0,0 +1,36 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * base_locale_uom_default +# +# Translators: +# Pedro M. Baeza , 2017 +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 10.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2017-12-01 02:10+0000\n" +"PO-Revision-Date: 2019-04-07 20:45-0400\n" +"Last-Translator: Pedro M. Baeza , 2017\n" +"Language-Team: Spanish (https://www.transifex.com/oca/teams/23907/es/)\n" +"Language: es\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Plural-Forms: nplurals=2; plural=(n != 1);\n" +"X-Generator: Poedit 1.8.11\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 por defecto" + +#. 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:24 +#, python-format +msgid "Only one default unit of measure per category may be selected." +msgstr "Sólo se puede seleccionar una unidad de medida por defecto por categoría." diff --git a/base_locale_uom_default/i18n/fr.po b/base_locale_uom_default/i18n/fr.po new file mode 100644 index 000000000..acfb8ddf6 --- /dev/null +++ b/base_locale_uom_default/i18n/fr.po @@ -0,0 +1,38 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * base_locale_uom_default +# +# Translators: +# Quentin THEURET , 2017 +# OCA Transbot , 2017 +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 10.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2017-12-01 02:10+0000\n" +"PO-Revision-Date: 2017-12-01 02:10+0000\n" +"Last-Translator: OCA Transbot , 2017\n" +"Language-Team: French (https://www.transifex.com/oca/teams/23907/fr/)\n" +"Language: fr\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 "Unités par défaut" + +#. module: base_locale_uom_default +#: model:ir.model,name:base_locale_uom_default.model_res_lang +msgid "Languages" +msgstr "Langues" + +#. module: base_locale_uom_default +#: code:addons/base_locale_uom_default/models/res_lang.py:24 +#, python-format +msgid "Only one default unit of measure per category may be selected." +msgstr "" +"Seulement une unité de mesure par défaut peut être sélectionnée par " +"catégorie." diff --git a/base_locale_uom_default/i18n/hr.po b/base_locale_uom_default/i18n/hr.po new file mode 100644 index 000000000..7405e21ab --- /dev/null +++ b/base_locale_uom_default/i18n/hr.po @@ -0,0 +1,37 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * base_locale_uom_default +# +# Translators: +# Goran Kliska , 2017 +# Bole , 2018 +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 10.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2018-03-02 18:40+0000\n" +"PO-Revision-Date: 2018-03-02 18:40+0000\n" +"Last-Translator: Bole , 2018\n" +"Language-Team: Croatian (https://www.transifex.com/oca/teams/23907/hr/)\n" +"Language: hr\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=3; plural=n%10==1 && n%100!=11 ? 0 : n%10>=2 && n" +"%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2;\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 "Zadane jedinice" + +#. module: base_locale_uom_default +#: model:ir.model,name:base_locale_uom_default.model_res_lang +msgid "Languages" +msgstr "Jezici" + +#. module: base_locale_uom_default +#: code:addons/base_locale_uom_default/models/res_lang.py:24 +#, python-format +msgid "Only one default unit of measure per category may be selected." +msgstr "Samo jedna zadana jedinica mjere može biti odabrana za kategoriju." diff --git a/base_locale_uom_default/i18n/it.po b/base_locale_uom_default/i18n/it.po new file mode 100644 index 000000000..8948543b6 --- /dev/null +++ b/base_locale_uom_default/i18n/it.po @@ -0,0 +1,35 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * base_locale_uom_default +# +# Translators: +# OCA Transbot , 2017 +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 10.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2017-12-01 02:10+0000\n" +"PO-Revision-Date: 2017-12-01 02:10+0000\n" +"Last-Translator: OCA Transbot , 2017\n" +"Language-Team: Italian (https://www.transifex.com/oca/teams/23907/it/)\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" + +#. 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 "" + +#. module: base_locale_uom_default +#: model:ir.model,name:base_locale_uom_default.model_res_lang +msgid "Languages" +msgstr "Lingue" + +#. module: base_locale_uom_default +#: code:addons/base_locale_uom_default/models/res_lang.py:24 +#, python-format +msgid "Only one default unit of measure per category may be selected." +msgstr "" diff --git a/base_locale_uom_default/i18n/nl_NL.po b/base_locale_uom_default/i18n/nl_NL.po new file mode 100644 index 000000000..a4bd43118 --- /dev/null +++ b/base_locale_uom_default/i18n/nl_NL.po @@ -0,0 +1,36 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * base_locale_uom_default +# +# Translators: +# Peter Hageman , 2017 +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 10.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2017-12-01 02:10+0000\n" +"PO-Revision-Date: 2017-12-01 02:10+0000\n" +"Last-Translator: Peter Hageman , 2017\n" +"Language-Team: Dutch (Netherlands) (https://www.transifex.com/oca/" +"teams/23907/nl_NL/)\n" +"Language: nl_NL\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 "" + +#. module: base_locale_uom_default +#: model:ir.model,name:base_locale_uom_default.model_res_lang +msgid "Languages" +msgstr "Talen" + +#. module: base_locale_uom_default +#: code:addons/base_locale_uom_default/models/res_lang.py:24 +#, python-format +msgid "Only one default unit of measure per category may be selected." +msgstr "" diff --git a/base_locale_uom_default/i18n/sl.po b/base_locale_uom_default/i18n/sl.po new file mode 100644 index 000000000..8b836a9df --- /dev/null +++ b/base_locale_uom_default/i18n/sl.po @@ -0,0 +1,36 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * base_locale_uom_default +# +# Translators: +# OCA Transbot , 2017 +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 10.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2017-12-01 02:10+0000\n" +"PO-Revision-Date: 2017-12-01 02:10+0000\n" +"Last-Translator: OCA Transbot , 2017\n" +"Language-Team: Slovenian (https://www.transifex.com/oca/teams/23907/sl/)\n" +"Language: sl\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=4; plural=(n%100==1 ? 0 : n%100==2 ? 1 : n%100==3 || n" +"%100==4 ? 2 : 3);\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 "" + +#. module: base_locale_uom_default +#: model:ir.model,name:base_locale_uom_default.model_res_lang +msgid "Languages" +msgstr "Jeziki" + +#. module: base_locale_uom_default +#: code:addons/base_locale_uom_default/models/res_lang.py:24 +#, python-format +msgid "Only one default unit of measure per category may be selected." +msgstr "" diff --git a/base_locale_uom_default/i18n/tr.po b/base_locale_uom_default/i18n/tr.po new file mode 100644 index 000000000..4de0ca8f2 --- /dev/null +++ b/base_locale_uom_default/i18n/tr.po @@ -0,0 +1,35 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * base_locale_uom_default +# +# Translators: +# OCA Transbot , 2017 +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 10.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2017-12-01 02:10+0000\n" +"PO-Revision-Date: 2017-12-01 02:10+0000\n" +"Last-Translator: OCA Transbot , 2017\n" +"Language-Team: Turkish (https://www.transifex.com/oca/teams/23907/tr/)\n" +"Language: tr\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 "" + +#. module: base_locale_uom_default +#: model:ir.model,name:base_locale_uom_default.model_res_lang +msgid "Languages" +msgstr "Diller" + +#. module: base_locale_uom_default +#: code:addons/base_locale_uom_default/models/res_lang.py:24 +#, python-format +msgid "Only one default unit of measure per category may be selected." +msgstr "" diff --git a/base_locale_uom_default/i18n/zh_CN.po b/base_locale_uom_default/i18n/zh_CN.po new file mode 100644 index 000000000..31f944489 --- /dev/null +++ b/base_locale_uom_default/i18n/zh_CN.po @@ -0,0 +1,36 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * base_locale_uom_default +# +# Translators: +# liAnGjiA , 2017 +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 10.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2017-12-01 02:10+0000\n" +"PO-Revision-Date: 2017-12-01 02:10+0000\n" +"Last-Translator: liAnGjiA , 2017\n" +"Language-Team: Chinese (China) (https://www.transifex.com/oca/teams/23907/" +"zh_CN/)\n" +"Language: zh_CN\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=1; plural=0;\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 "默认单位" + +#. module: base_locale_uom_default +#: model:ir.model,name:base_locale_uom_default.model_res_lang +msgid "Languages" +msgstr "语言" + +#. module: base_locale_uom_default +#: code:addons/base_locale_uom_default/models/res_lang.py:24 +#, python-format +msgid "Only one default unit of measure per category may be selected." +msgstr "每个类别仅可选择一个默认度量单位。" diff --git a/base_locale_uom_default/models/__init__.py b/base_locale_uom_default/models/__init__.py new file mode 100644 index 000000000..0e41c564f --- /dev/null +++ b/base_locale_uom_default/models/__init__.py @@ -0,0 +1,4 @@ +# Copyright 2017 LasLabs Inc. +# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). + +from . import res_lang diff --git a/base_locale_uom_default/models/res_lang.py b/base_locale_uom_default/models/res_lang.py new file mode 100644 index 000000000..1cc31fdae --- /dev/null +++ b/base_locale_uom_default/models/res_lang.py @@ -0,0 +1,55 @@ +# Copyright 2017 LasLabs Inc. +# Copyright 2019 Rubén Bravo +# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). + +from odoo import api, fields, models, _ +from odoo.exceptions import ValidationError + + +class ResLang(models.Model): + + _inherit = 'res.lang' + + default_uom_ids = fields.Many2many( + string='Default Units', + comodel_name='uom.uom', + ) + + @api.multi + @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 (ResLang 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] diff --git a/base_locale_uom_default/readme/CONFIGURE.rst b/base_locale_uom_default/readme/CONFIGURE.rst new file mode 100644 index 000000000..a2bc2432d --- /dev/null +++ b/base_locale_uom_default/readme/CONFIGURE.rst @@ -0,0 +1 @@ +Set default unit of measures in the `Languages` menu in settings. diff --git a/base_locale_uom_default/readme/CONTRIBUTORS.rst b/base_locale_uom_default/readme/CONTRIBUTORS.rst new file mode 100644 index 000000000..47a52ddba --- /dev/null +++ b/base_locale_uom_default/readme/CONTRIBUTORS.rst @@ -0,0 +1,2 @@ +* Dave Lasley +* Rubén Bravo diff --git a/base_locale_uom_default/readme/DESCRIPTION.rst b/base_locale_uom_default/readme/DESCRIPTION.rst new file mode 100644 index 000000000..46422d260 --- /dev/null +++ b/base_locale_uom_default/readme/DESCRIPTION.rst @@ -0,0 +1,4 @@ +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. diff --git a/base_locale_uom_default/readme/USAGE.rst b/base_locale_uom_default/readme/USAGE.rst new file mode 100644 index 000000000..6ae04b605 --- /dev/null +++ b/base_locale_uom_default/readme/USAGE.rst @@ -0,0 +1,9 @@ +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='product.uom', + default=lambda s: s.env['res.lang'].default_uom_by_category('Time'), + ) diff --git a/base_locale_uom_default/static/description/icon.png b/base_locale_uom_default/static/description/icon.png new file mode 100644 index 000000000..3a0328b51 Binary files /dev/null and b/base_locale_uom_default/static/description/icon.png differ diff --git a/base_locale_uom_default/static/description/index.html b/base_locale_uom_default/static/description/index.html new file mode 100644 index 000000000..168690010 --- /dev/null +++ b/base_locale_uom_default/static/description/index.html @@ -0,0 +1,441 @@ + + + + + + +Locale - Default UoM + + + +
+

Locale - Default UoM

+ + +

Beta License: LGPL-3 OCA/server-tools Translate me on Weblate Try me on Runbot

+

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.

+

Table of contents

+ +
+

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='product.uom',
+        default=lambda s: s.env['res.lang'].default_uom_by_category('Time'),
+    )
+
+
+
+

Bug Tracker

+

Bugs are tracked on GitHub Issues. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us smashing it by providing a detailed and welcomed +feedback.

+

Do not contact contributors directly about support or help with technical issues.

+
+
+

Credits

+
+

Authors

+
    +
  • LasLabs
  • +
+
+
+

Contributors

+ +
+
+

Maintainers

+

This module is maintained by the OCA.

+Odoo Community Association +

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.

+

This module is part of the OCA/server-tools project on GitHub.

+

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

+
+
+
+ + diff --git a/base_locale_uom_default/tests/__init__.py b/base_locale_uom_default/tests/__init__.py new file mode 100644 index 000000000..e4ecbe573 --- /dev/null +++ b/base_locale_uom_default/tests/__init__.py @@ -0,0 +1,4 @@ +# Copyright 2017 LasLabs Inc. +# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). + +from . import test_res_lang diff --git a/base_locale_uom_default/tests/test_res_lang.py b/base_locale_uom_default/tests/test_res_lang.py new file mode 100644 index 000000000..2c3509c88 --- /dev/null +++ b/base_locale_uom_default/tests/test_res_lang.py @@ -0,0 +1,44 @@ +# Copyright 2017 LasLabs Inc. +# Copyright 2019 Rubén Bravo +# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). + +from odoo.tests.common import TransactionCase +from odoo.exceptions import ValidationError + + +class TestResLang(TransactionCase): + + def setUp(self): + super(TestResLang, 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(), + ) diff --git a/base_locale_uom_default/views/res_lang_view.xml b/base_locale_uom_default/views/res_lang_view.xml new file mode 100644 index 000000000..239e72dfa --- /dev/null +++ b/base_locale_uom_default/views/res_lang_view.xml @@ -0,0 +1,15 @@ + + + + + Res Lang Form - Default UoMs + res.lang + + + + + + + + +