diff --git a/contract_fixed_discount/README.rst b/contract_fixed_discount/README.rst new file mode 100644 index 00000000000..e69de29bb2d diff --git a/contract_fixed_discount/__init__.py b/contract_fixed_discount/__init__.py new file mode 100644 index 00000000000..0650744f6bc --- /dev/null +++ b/contract_fixed_discount/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/contract_fixed_discount/__manifest__.py b/contract_fixed_discount/__manifest__.py new file mode 100644 index 00000000000..f34e1f11519 --- /dev/null +++ b/contract_fixed_discount/__manifest__.py @@ -0,0 +1,19 @@ +# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html + +{ + "name": "Contract Fixed Discount", + "version": "14.0.1.0.0", + "category": "Contract Management", + "author": "Foodles, Odoo Community Association (OCA)", + "maintainers": [], + "website": "https://github.com/OCA/contract", + "depends": [ + "account_invoice_fixed_discount", + "contract", + ], + "data": [ + "views/abstract_contract_line.xml", + ], + "license": "AGPL-3", + "installable": True, +} diff --git a/contract_fixed_discount/models/__init__.py b/contract_fixed_discount/models/__init__.py new file mode 100644 index 00000000000..6143a36501b --- /dev/null +++ b/contract_fixed_discount/models/__init__.py @@ -0,0 +1 @@ +from . import contract_line diff --git a/contract_fixed_discount/models/contract_line.py b/contract_fixed_discount/models/contract_line.py new file mode 100644 index 00000000000..7a1573de6ce --- /dev/null +++ b/contract_fixed_discount/models/contract_line.py @@ -0,0 +1,60 @@ +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import _, api, fields, models +from odoo.exceptions import ValidationError + + +class ContractAbstractContractLine(models.AbstractModel): + _inherit = "contract.abstract.contract.line" + + discount_fixed = fields.Float( + string="Discount (Fixed)", + digits="Product Price", + default=0.00, + help="Fixed amount discount.", + ) + + @api.onchange("discount") + def _onchange_discount(self): + if self.discount: + self.discount_fixed = 0.0 + + @api.onchange("discount_fixed") + def _onchange_discount_fixed(self): + if self.discount_fixed: + self.discount = 0.0 + + @api.constrains("discount", "discount_fixed") + def _check_only_one_discount(self): + for rec in self: + for line in rec: + if line.discount and line.discount_fixed: + raise ValidationError( + _("You can only set one type of discount per line.") + ) + + @api.depends("quantity", "price_unit", "discount", "discount_fixed") + def _compute_price_subtotal(self): + for line in self: + subtotal = line.quantity * line.price_unit + + if line.discount: + discount = line.discount / 100 + subtotal *= 1 - discount + elif line.discount_fixed: + subtotal -= line.discount_fixed + + if line.contract_id.pricelist_id: + cur = line.contract_id.pricelist_id.currency_id + line.price_subtotal = cur.round(subtotal) + else: + line.price_subtotal = subtotal + + +class ContractLine(models.Model): + _inherit = "contract.line" + + def _prepare_invoice_line(self, move_form): + vals = super()._prepare_invoice_line(move_form=move_form) + vals["discount_fixed"] = self.discount_fixed + return vals diff --git a/contract_fixed_discount/readme/CONTRIBUTORS.rst b/contract_fixed_discount/readme/CONTRIBUTORS.rst new file mode 100644 index 00000000000..15086c2ef95 --- /dev/null +++ b/contract_fixed_discount/readme/CONTRIBUTORS.rst @@ -0,0 +1,4 @@ +* `Foodles `_: + + * Damien Crier + * Pierre Verkest diff --git a/contract_fixed_discount/readme/DESCRIPTION.rst b/contract_fixed_discount/readme/DESCRIPTION.rst new file mode 100644 index 00000000000..ec25000d3e3 --- /dev/null +++ b/contract_fixed_discount/readme/DESCRIPTION.rst @@ -0,0 +1 @@ +This module extends the functionality of contracts to allow you to apply fixed amount discounts at contract line level. diff --git a/contract_fixed_discount/views/abstract_contract_line.xml b/contract_fixed_discount/views/abstract_contract_line.xml new file mode 100644 index 00000000000..9f34c6668a5 --- /dev/null +++ b/contract_fixed_discount/views/abstract_contract_line.xml @@ -0,0 +1,23 @@ + + + + + contract.abstract.contract.line form view (in contract) + contract.abstract.contract.line + + + + + + + + + diff --git a/setup/contract_fixed_discount/odoo/addons/contract_fixed_discount b/setup/contract_fixed_discount/odoo/addons/contract_fixed_discount new file mode 120000 index 00000000000..fce7ee26dc0 --- /dev/null +++ b/setup/contract_fixed_discount/odoo/addons/contract_fixed_discount @@ -0,0 +1 @@ +../../../../contract_fixed_discount \ No newline at end of file diff --git a/setup/contract_fixed_discount/setup.py b/setup/contract_fixed_discount/setup.py new file mode 100644 index 00000000000..28c57bb6403 --- /dev/null +++ b/setup/contract_fixed_discount/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)