-
-
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
10 changed files
with
116 additions
and
0 deletions.
There are no files selected for viewing
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,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, | ||
} |
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 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,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 |
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 <damien.crier@foodles.co> | ||
* Pierre Verkest <pierreverkest84@gmail.com> |
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,23 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<odoo> | ||
<!--FORM view--> | ||
<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" optional="hide" /> | ||
</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, | ||
) |