Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .gitignore
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unneccary changes.

Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,10 @@ dmypy.json

# Pyre type checker
.pyre/

.eslintignore
.eslintrc.json
jsconfig.json
package.json
package-lock.json
node_modules/
1 change: 1 addition & 0 deletions sale_discount/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
9 changes: 9 additions & 0 deletions sale_discount/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
'name': 'sale_discount',
'depends': ['base', 'sale'],
'application': True,
'installable': True,
'author': 'estate',
'category': 'Tutorials',
'license': 'AGPL-3',
}
2 changes: 2 additions & 0 deletions sale_discount/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import sale_order
from . import sale_order_line
35 changes: 35 additions & 0 deletions sale_discount/models/sale_order.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import re
from odoo import models, api


class SaleOrder(models.Model):
_inherit = 'sale.order'

@api.onchange('order_line')
def _onchange_recalculate_global_discount(self):
discount_lines = self.env['sale.order.line']
for line in self.order_line:
if line._is_global_discount():
discount_lines += line

if not discount_lines:
return

product_lines = self.env['sale.order.line']
for line in self.order_line:
if not line._is_global_discount() and not line.is_downpayment:
product_lines += line

if not product_lines:
self.order_line -= discount_lines
return

subtotal = 0
for line in product_lines:
subtotal += line.price_subtotal

for discount_line in discount_lines:
match = re.search(r"(\d+(?:\.\d+)?)%", discount_line.name)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this required?

if match:
percent = float(match.group(1))
discount_line.price_unit = -(subtotal * percent / 100)
10 changes: 10 additions & 0 deletions sale_discount/models/sale_order_line.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from odoo import models, api


class SaleOrderLine(models.Model):
_inherit = 'sale.order.line'

@api.onchange('price_unit', 'product_uom_qty', 'discount')
def _onchange_recalc_discount(self):
if self.order_id:
self.order_id._onchange_recalculate_global_discount()