Skip to content

Commit

Permalink
Update for public release
Browse files Browse the repository at this point in the history
  • Loading branch information
os-ia committed Dec 23, 2020
0 parents commit 953639a
Show file tree
Hide file tree
Showing 13 changed files with 1,073 additions and 0 deletions.
661 changes: 661 additions & 0 deletions LICENSE

Large diffs are not rendered by default.

39 changes: 39 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<div align="center">
<a href="https://www.odoo.com/documentation/12.0/index.html">
<img alt="odoo version" src="https://img.shields.io/badge/odoo-version%2012-875A7B.svg?style=flat"></img>
</a>
<a href="http://www.alliantum.com">
<img alt="company" src="https://img.shields.io/badge/company-Alliantum-blue.svg?style=flat"></img>
</a>
<a href="http://www.gnu.org/licenses/agpl-3.0-standalone.html">
<img alt="license" src="https://img.shields.io/badge/license-AGPL--3-blue.svg?style=flat"></img>
</a>
<a href="https://github.com/Alliantum/odoo_no_fractions/releases/latest">
<img alt="module version" src="https://img.shields.io/github/v/tag/Alliantum/odoo_no_fractions?color=blue&label=version&style=flat">
</a>
</div>

<div align="center">
<a href="http://www.alliantum.com">
<img src="./static/description/icon.png" width="10%">
</a>
<div>
<h1>Avoid UoM Fractions</h1>
Avoid selling non-integer quantities of a Unit of Measure category.
<hr>
</div>
<div>
<img src="./static/description/demo.gif" width="90%" style="border-radius: 5px">
</div>
</div>

## Usage

Install this add-on and it will be automatically ready to use.

Allow only integer amounts when purchasing products that have this option enabled on its
Unit of Measure's category.

## Contributors

- [Alliantum](http://www.alliantum.com)
3 changes: 3 additions & 0 deletions __init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# -*- coding: utf-8 -*-

from . import models
16 changes: 16 additions & 0 deletions __manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# -*- coding: utf-8 -*-
{
'name': "Avoid UoM Fractions",
'summary': """Avoid selling non-integer quantities of a Unit of Measure category""",
'description': """
""",
'author': "Alliantum",
'website': "https://www.alliantum.com",
'version': '12.0.1.0.0',
'license': 'AGPL-3',
'category': 'Warehouse',
'depends': ['uom', 'sale', 'account'],
'data': [
'views/product_uom_categ.xml',
],
}
84 changes: 84 additions & 0 deletions i18n/de.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * odoo_no_fractions
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 12.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2020-12-23 15:54+0000\n"
"PO-Revision-Date: 2020-12-23 15:54+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: odoo_no_fractions
#: model:ir.model.fields,field_description:odoo_no_fractions.field_uom_category__avoid_sell_fractions
msgid "Avoid Sell Fractions"
msgstr "Vermeiden Sie den Verkauf von Fraktionen"

#. module: odoo_no_fractions
#: code:addons/odoo_no_fractions/models/account_line.py:19
#: code:addons/odoo_no_fractions/models/sale_order_line.py:18
#, python-format
msgid "Invalid Product Quantity"
msgstr "Ungültige Produktmenge"

#. module: odoo_no_fractions
#: model:ir.model,name:odoo_no_fractions.model_account_invoice_line
msgid "Invoice Line"
msgstr "Rechungsposition"

#. module: odoo_no_fractions
#: model:ir.model,name:odoo_no_fractions.model_uom_category
msgid "Product UoM Categories"
msgstr "Kategorien für Maßeinheiten von Produkten"

#. module: odoo_no_fractions
#: model:ir.model,name:odoo_no_fractions.model_sale_order_line
msgid "Sales Order Line"
msgstr "Auftragsposition"

#. module: odoo_no_fractions
#: code:addons/odoo_no_fractions/models/sale_order_line.py:19
#: code:addons/odoo_no_fractions/models/sale_order_line.py:36
#: code:addons/odoo_no_fractions/models/sale_order_line.py:62
#: code:addons/odoo_no_fractions/models/sale_order_line.py:72
#, python-format
msgid "Your're trying to sell {} {} of the product {}.\n"
" However the UoM for that product ( {} ) doesn't allow to sell floating point amounts of it. Please enter a non-decimal Ordered Qty."
msgstr "Sie versuchen zu verkaufen {} {} des Produkts {}.\n Die UoM für dieses Produkt ( {} ) erlaubt es jedoch nicht, Fließkommabeträge davon zu verkaufen. Bitte geben Sie eine nicht-dezimale Bestellmenge ein."

#. module: odoo_no_fractions
#: code:addons/odoo_no_fractions/models/account_line.py:63
#: code:addons/odoo_no_fractions/models/account_line.py:73
#, python-format
msgid "Your're trying to sell {} {} of the product {}.\n"
" However the UoM for that product ( {} ) doesn't allow to sell floating point amounts of it. Please enter a non-decimal Ordered Quantity."
msgstr "Sie versuchen zu verkaufen {} {} des Produkts {}.\n Die UoM für dieses Produkt ( {} ) erlaubt es jedoch nicht, Fließkommabeträge davon zu verkaufen. Bitte geben Sie eine nicht-dezimale Bestellmenge ein."

#. module: odoo_no_fractions
#: code:addons/odoo_no_fractions/models/account_line.py:20
#: code:addons/odoo_no_fractions/models/account_line.py:37
#, python-format
msgid "Your're trying to sell {} {} of the product {}.\n"
" However the UoM for that product ( {} ) doesn't allow to sell floating point amounts of it. Please enter a non-decimal Quantity."
msgstr "Sie versuchen zu verkaufen {} {} des Produkts {}.\n Die UoM für dieses Produkt ( {} ) erlaubt es jedoch nicht, Fließkommabeträge davon zu verkaufen. Bitte geben Sie eine nicht-dezimale Bestellmenge ein."

#. module: odoo_no_fractions
#: code:addons/odoo_no_fractions/models/sale_order_line.py:54
#, python-format
msgid "Your're trying to sell {} {}.\n"
" However the UoM for that product ( {} ) doesn't allow to sell floating point amounts of it. Please enter a non-decimal Ordered Qty."
msgstr "Sie versuchen zu verkaufen {} {} des Produkts {}.\n Die UoM für dieses Produkt ( {} ) erlaubt es jedoch nicht, Fließkommabeträge davon zu verkaufen. Bitte geben Sie eine nicht-dezimale Bestellmenge ein."

#. module: odoo_no_fractions
#: code:addons/odoo_no_fractions/models/account_line.py:55
#, python-format
msgid "Your're trying to sell {} {}.\n"
" However the UoM for that product ( {} ) doesn't allow to sell floating point amounts of it. Please enter a non-decimal Ordered Quantity."
msgstr "Sie versuchen zu verkaufen {} {} des Produkts {}.\n Die UoM für dieses Produkt ( {} ) erlaubt es jedoch nicht, Fließkommabeträge davon zu verkaufen. Bitte geben Sie eine nicht-dezimale Bestellmenge ein."

84 changes: 84 additions & 0 deletions i18n/odoo_no_fractions.pot
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * odoo_no_fractions
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 12.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2020-12-23 15:54+0000\n"
"PO-Revision-Date: 2020-12-23 15:54+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: odoo_no_fractions
#: model:ir.model.fields,field_description:odoo_no_fractions.field_uom_category__avoid_sell_fractions
msgid "Avoid Sell Fractions"
msgstr ""

#. module: odoo_no_fractions
#: code:addons/odoo_no_fractions/models/account_line.py:19
#: code:addons/odoo_no_fractions/models/sale_order_line.py:18
#, python-format
msgid "Invalid Product Quantity"
msgstr ""

#. module: odoo_no_fractions
#: model:ir.model,name:odoo_no_fractions.model_account_invoice_line
msgid "Invoice Line"
msgstr ""

#. module: odoo_no_fractions
#: model:ir.model,name:odoo_no_fractions.model_uom_category
msgid "Product UoM Categories"
msgstr ""

#. module: odoo_no_fractions
#: model:ir.model,name:odoo_no_fractions.model_sale_order_line
msgid "Sales Order Line"
msgstr ""

#. module: odoo_no_fractions
#: code:addons/odoo_no_fractions/models/sale_order_line.py:19
#: code:addons/odoo_no_fractions/models/sale_order_line.py:36
#: code:addons/odoo_no_fractions/models/sale_order_line.py:62
#: code:addons/odoo_no_fractions/models/sale_order_line.py:72
#, python-format
msgid "Your're trying to sell {} {} of the product {}.\n"
" However the UoM for that product ( {} ) doesn't allow to sell floating point amounts of it. Please enter a non-decimal Ordered Qty."
msgstr ""

#. module: odoo_no_fractions
#: code:addons/odoo_no_fractions/models/account_line.py:63
#: code:addons/odoo_no_fractions/models/account_line.py:73
#, python-format
msgid "Your're trying to sell {} {} of the product {}.\n"
" However the UoM for that product ( {} ) doesn't allow to sell floating point amounts of it. Please enter a non-decimal Ordered Quantity."
msgstr ""

#. module: odoo_no_fractions
#: code:addons/odoo_no_fractions/models/account_line.py:20
#: code:addons/odoo_no_fractions/models/account_line.py:37
#, python-format
msgid "Your're trying to sell {} {} of the product {}.\n"
" However the UoM for that product ( {} ) doesn't allow to sell floating point amounts of it. Please enter a non-decimal Quantity."
msgstr ""

#. module: odoo_no_fractions
#: code:addons/odoo_no_fractions/models/sale_order_line.py:54
#, python-format
msgid "Your're trying to sell {} {}.\n"
" However the UoM for that product ( {} ) doesn't allow to sell floating point amounts of it. Please enter a non-decimal Ordered Qty."
msgstr ""

#. module: odoo_no_fractions
#: code:addons/odoo_no_fractions/models/account_line.py:55
#, python-format
msgid "Your're trying to sell {} {}.\n"
" However the UoM for that product ( {} ) doesn't allow to sell floating point amounts of it. Please enter a non-decimal Ordered Quantity."
msgstr ""

5 changes: 5 additions & 0 deletions models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# -*- coding: utf-8 -*-

from . import account_line
from . import sale_order_line
from . import uom_uom
79 changes: 79 additions & 0 deletions models/account_line.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# -*- coding: utf-8 -*-

from odoo import models, api, _
from odoo.exceptions import ValidationError


class AccountInvoiceLine(models.Model):
_inherit = 'account.invoice.line'

@api.multi
@api.onchange('product_id', 'uom_id')
def _check_avoid_fractions(self):
"""If the uom category of a product has `avoid_sell_fractions` enabled, and the
quantity is not an integer, display a warning"""
for line in self:
if line.uom_id.category_id.avoid_sell_fractions:
if int(line.quantity) != line.quantity:
warning = {
'title': _('Invalid Product Quantity'),
'message': _("Your're trying to sell {} {} of the product {}.\n"
" However the UoM for that product ( {} ) doesn't allow to"
" sell floating point amounts of it. Please enter a non-decimal Quantity.").format(line.quantity,
line.uom_id.name,
line.product_id.name,
line.uom_id.name),
}
return {'warning': warning}

@api.model_create_multi
def create(self, vals_list):
"""If the uom category of a product has `avoid_sell_fractions` enabled, and the
quantity is not an integer, return an error that prevents the creation of the invoice"""
lines = super(AccountInvoiceLine, self).create(vals_list)
for line in lines:
if line.uom_id.category_id.avoid_sell_fractions:
if int(line.quantity) != line.quantity:
raise ValidationError(_("Your're trying to sell {} {} of the product {}.\n"
" However the UoM for that product ( {} ) doesn't allow to"
" sell floating point amounts of it. Please enter a non-decimal Quantity.").format(line.quantity,
line.uom_id.name,
line.product_id.name,
line.uom_id.name))
return lines

@api.multi
def write(self, vals):
"""If the uom category of a product has `avoid_sell_fractions` enabled, and the
quantity is not an integer, return an error that prevents saving the invoice when
a change was made to the quantity or the uom"""
res = super(AccountInvoiceLine, self).write(vals)
if vals.get('uom_id'):
uom_id = self.env['uom.uom'].browse(vals.get('uom_id'))
if uom_id.category_id.avoid_sell_fractions:
if vals.get('quantity') and (int(vals.get('quantity')) != vals.get('quantity')):
raise ValidationError(_("Your're trying to sell {} {}.\n"
" However the UoM for that product ( {} ) doesn't allow to"
" sell floating point amounts of it. Please enter a non-decimal Ordered Quantity.").format(vals.get('quantity'),
uom_id.name,
uom_id.name))
else:
for line in self:
if int(line.quantity) != line.quantity:
raise ValidationError(_("Your're trying to sell {} {} of the product {}.\n"
" However the UoM for that product ( {} ) doesn't allow to"
" sell floating point amounts of it. Please enter a non-decimal Ordered Quantity.").format(line.quantity,
line.uom_id.name,
line.product_id.name,
line.uom_id.name))
elif vals.get('quantity'):
for line in self:
if line.uom_id.category_id.avoid_sell_fractions:
if int(vals.get('quantity')) != vals.get('quantity'):
raise ValidationError(_("Your're trying to sell {} {} of the product {}.\n"
" However the UoM for that product ( {} ) doesn't allow to"
" sell floating point amounts of it. Please enter a non-decimal Ordered Quantity.").format(vals.get('quantity'),
line.uom_id.name,
line.product_id.name,
line.uom_id.name))
return res
Loading

0 comments on commit 953639a

Please # to comment.