-
-
Notifications
You must be signed in to change notification settings - Fork 534
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
303 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from . import models |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# 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", | ||
"views/contract_line.xml", | ||
"views/contract.xml", | ||
], | ||
"license": "AGPL-3", | ||
"installable": True, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from . import abstract_contract_line, contract_line |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# 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.") | ||
) | ||
|
||
def _compute_price_subtotal_helper(self): | ||
self.ensure_one() | ||
subtotal = self.quantity * self.price_unit | ||
if self.discount: | ||
subtotal = super()._compute_price_subtotal_helper() | ||
elif self.discount_fixed: | ||
subtotal -= self.discount_fixed | ||
return subtotal | ||
|
||
@api.depends("quantity", "price_unit", "discount", "discount_fixed") | ||
def _compute_price_subtotal(self): | ||
super()._compute_price_subtotal() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
from odoo import models | ||
|
||
|
||
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
* `Foodles <https://www.foodles.co>`_: | ||
|
||
* Damien Crier <[email protected]> | ||
* Pierre Verkest <[email protected]> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
This module extends the functionality of contracts to allow you to apply fixed amount discounts at contract line level. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from . import test_contract_discount_fixed, test_contract_invoice_discount_fixed |
64 changes: 64 additions & 0 deletions
64
contract_fixed_discount/tests/test_contract_discount_fixed.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
# Copyright 2023 Foodles (http://www.foodles.co/) | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
from odoo.exceptions import ValidationError | ||
from odoo.tests import Form | ||
|
||
from odoo.addons.contract.tests.test_contract import TestContractBase | ||
|
||
|
||
class TestContractDiscounts(TestContractBase): | ||
@classmethod | ||
def setUpClass(cls): | ||
super().setUpClass() | ||
|
||
cls.contract4 = cls.env["contract.contract"].create( | ||
{ | ||
"name": "Test Contract4", | ||
"partner_id": cls.partner.id, | ||
"pricelist_id": cls.partner.property_product_pricelist.id, | ||
"line_recurrence": True, | ||
"contract_line_ids": [ | ||
( | ||
0, | ||
0, | ||
{ | ||
"product_id": cls.product_1.id, | ||
"name": "Services from #START# to #END#", | ||
"quantity": 1, | ||
"uom_id": cls.product_1.uom_id.id, | ||
"price_unit": 100, | ||
"discount_fixed": 48, | ||
"recurring_rule_type": "monthly", | ||
"recurring_interval": 1, | ||
"date_start": "2018-02-15", | ||
"recurring_next_date": "2018-02-22", | ||
}, | ||
) | ||
], | ||
} | ||
) | ||
|
||
def test_onchange_discount(self): | ||
contract = Form(self.contract) | ||
line = contract.contract_line_ids.edit(0) | ||
line.discount_fixed = 42 | ||
self.assertFalse(line.discount) | ||
|
||
def test_onchange_discount_fixed(self): | ||
contract = Form(self.contract) | ||
line = contract.contract_line_ids.edit(0) | ||
line.discount = 42 | ||
self.assertFalse(line.discount_fixed) | ||
|
||
def test_constraint_discount_discount_fixed(self): | ||
with self.assertRaisesRegex( | ||
ValidationError, "You can only set one type of discount per line." | ||
): | ||
self.contract4.contract_line_ids.discount = 42 | ||
|
||
def test_price_subtotal_discount_percent(self): | ||
self.assertEqual(self.contract.contract_line_ids.price_subtotal, 50.0) | ||
|
||
def test_price_subtotal_discount_fixed(self): | ||
self.assertEqual(self.contract4.contract_line_ids.price_subtotal, 52.0) |
42 changes: 42 additions & 0 deletions
42
contract_fixed_discount/tests/test_contract_invoice_discount_fixed.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# Copyright 2023 Foodles (http://www.foodles.co/) | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
from odoo.addons.contract.tests.test_contract import TestContractBase | ||
|
||
|
||
class TestContractDiscounts(TestContractBase): | ||
@classmethod | ||
def setUpClass(cls): | ||
super().setUpClass() | ||
|
||
cls.contract4 = cls.env["contract.contract"].create( | ||
{ | ||
"name": "Test Contract4", | ||
"partner_id": cls.partner.id, | ||
"pricelist_id": cls.partner.property_product_pricelist.id, | ||
"line_recurrence": True, | ||
"contract_line_ids": [ | ||
( | ||
0, | ||
0, | ||
{ | ||
"product_id": cls.product_1.id, | ||
"name": "Services from #START# to #END#", | ||
"quantity": 1, | ||
"uom_id": cls.product_1.uom_id.id, | ||
"price_unit": 100, | ||
"discount_fixed": 48, | ||
"recurring_rule_type": "monthly", | ||
"recurring_interval": 1, | ||
"date_start": "2018-02-15", | ||
"recurring_next_date": "2018-02-22", | ||
}, | ||
) | ||
], | ||
} | ||
) | ||
|
||
def test_invoice_lines_discount_fixed(self): | ||
invoice = self.contract4.recurring_create_invoice() | ||
self.assertEquals(invoice.invoice_line_ids.discount_fixed, 48) | ||
self.assertEquals(invoice.invoice_line_ids.discount, 0) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<odoo> | ||
|
||
<record | ||
id="contract_abstract_contract_line_add_discount_fixed_form_view" | ||
model="ir.ui.view" | ||
> | ||
<field | ||
name="name" | ||
>contract.abstract.contract.line form view (in contract)</field> | ||
<field name="model">contract.abstract.contract.line</field> | ||
<field | ||
name="inherit_id" | ||
ref="contract.contract_abstract_contract_line_form_view" | ||
/> | ||
|
||
<field name="arch" type="xml"> | ||
<field name="discount" position="after"> | ||
<field | ||
name="discount_fixed" | ||
groups="product.group_discount_per_so_line" | ||
/> | ||
</field> | ||
</field> | ||
</record> | ||
|
||
</odoo> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<odoo> | ||
<record id="contract_contract_form_view" model="ir.ui.view"> | ||
<field name="name">contract.contract form view (in contract)</field> | ||
<field name="model">contract.contract</field> | ||
<field name="inherit_id" ref="contract.contract_contract_form_view" /> | ||
<field name="arch" type="xml"> | ||
<xpath | ||
expr="//field[@name='contract_line_fixed_ids']//tree//field[@name='discount']" | ||
position="after" | ||
> | ||
<field | ||
name="discount_fixed" | ||
groups="product.group_discount_per_so_line" | ||
optional="show" | ||
/> | ||
</xpath> | ||
<xpath | ||
expr="//field[@name='contract_line_ids']//tree//field[@name='discount']" | ||
position="after" | ||
> | ||
<field | ||
name="discount_fixed" | ||
groups="product.group_discount_per_so_line" | ||
optional="show" | ||
/> | ||
</xpath> | ||
</field> | ||
</record> | ||
</odoo> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<odoo> | ||
|
||
<record id="contract_line_tree_view" model="ir.ui.view"> | ||
<field name="name">contract.contract_line_tree_view</field> | ||
<field name="model">contract.line</field> | ||
<field name="inherit_id" ref="contract.contract_line_tree_view" /> | ||
|
||
<field name="arch" type="xml"> | ||
<field name="discount" position="after"> | ||
<field | ||
name="discount_fixed" | ||
groups="product.group_discount_per_so_line" | ||
optional="show" | ||
/> | ||
</field> | ||
</field> | ||
</record> | ||
|
||
<record id="contract_line_report_tree_view" model="ir.ui.view"> | ||
<field name="name">contract.contract_line_report_tree_view</field> | ||
<field name="model">contract.line</field> | ||
<field name="inherit_id" ref="contract.contract_line_report_tree_view" /> | ||
|
||
<field name="arch" type="xml"> | ||
<field name="discount" position="after"> | ||
<field | ||
name="discount_fixed" | ||
groups="product.group_discount_per_so_line" | ||
optional="show" | ||
/> | ||
</field> | ||
</field> | ||
</record> | ||
|
||
</odoo> |
1 change: 1 addition & 0 deletions
1
setup/contract_fixed_discount/odoo/addons/contract_fixed_discount
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../../../contract_fixed_discount |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import setuptools | ||
|
||
setuptools.setup( | ||
setup_requires=['setuptools-odoo'], | ||
odoo_addon=True, | ||
) |