@ -0,0 +1,54 @@ |
|||||
|
.. image:: https://img.shields.io/badge/license-AGPL--3-blue.svg |
||||
|
:target: https://www.gnu.org/licenses/agpl-3.0-standalone.html |
||||
|
:alt: License: AGPL-3 |
||||
|
|
||||
|
Sale Discount on Total Amount |
||||
|
============================= |
||||
|
Discount on Total in Sale and Invoice With Discount Limit and Approval |
||||
|
|
||||
|
Configuration |
||||
|
============= |
||||
|
- No additional configuration required |
||||
|
|
||||
|
Company |
||||
|
------- |
||||
|
* `Cybrosys Techno Solutions <https://cybrosys.com/>`__ |
||||
|
|
||||
|
License |
||||
|
------- |
||||
|
GNU Affero General Public License v3.0 (AGPL v3) |
||||
|
(http://www.gnu.org/licenses/agpl-3.0-standalone.html) |
||||
|
|
||||
|
Credits |
||||
|
------- |
||||
|
* Developer: |
||||
|
Faslu Rahman, |
||||
|
(V14) Muhammed P, |
||||
|
(V15) Sreerag E, |
||||
|
(V16) Sahla Sherin, |
||||
|
(V17) Jumana Haseen,. |
||||
|
(V18) Sreerag PM, |
||||
|
Contact : odoo@cybrosys.com |
||||
|
|
||||
|
Contacts |
||||
|
-------- |
||||
|
* Mail Contact : odoo@cybrosys.com |
||||
|
* Website : https://cybrosys.com |
||||
|
|
||||
|
Bug Tracker |
||||
|
----------- |
||||
|
Bugs are tracked on GitHub Issues. In case of trouble, please check there if |
||||
|
your issue has already been reported. |
||||
|
|
||||
|
Maintainer |
||||
|
========== |
||||
|
.. image:: https://cybrosys.com/images/logo.png |
||||
|
:target: https://cybrosys.com |
||||
|
|
||||
|
This module is maintained by Cybrosys Technologies. |
||||
|
|
||||
|
For support and more information, please visit `Our Website <https://cybrosys.com/>`__ |
||||
|
|
||||
|
Further information |
||||
|
=================== |
||||
|
HTML Description: `<static/description/index.html>`__ |
@ -0,0 +1,23 @@ |
|||||
|
# -*- coding: utf-8 -*- |
||||
|
############################################################################# |
||||
|
# |
||||
|
# Cybrosys Technologies Pvt. Ltd. |
||||
|
# |
||||
|
# Copyright (C) 2024-TODAY Cybrosys Technologies(<https://www.cybrosys.com>). |
||||
|
# Author: Sreerag PM(odoo@cybrosys.com) |
||||
|
# |
||||
|
# You can modify it under the terms of the GNU AFFERO |
||||
|
# GENERAL PUBLIC LICENSE (AGPL v3), Version 3. |
||||
|
# |
||||
|
# This program is distributed in the hope that it will be useful, |
||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
|
# GNU AFFERO GENERAL PUBLIC LICENSE (AGPL v3) for more details. |
||||
|
# |
||||
|
# You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE |
||||
|
# (AGPL v3) along with this program. |
||||
|
# If not, see <http://www.gnu.org/licenses/>. |
||||
|
# |
||||
|
############################################################################# |
||||
|
from . import models |
||||
|
from . import reports |
@ -0,0 +1,52 @@ |
|||||
|
# -*- coding: utf-8 -*- |
||||
|
############################################################################# |
||||
|
# |
||||
|
# Cybrosys Technologies Pvt. Ltd. |
||||
|
# |
||||
|
# Copyright (C) 2024-TODAY Cybrosys Technologies(<https://www.cybrosys.com>). |
||||
|
# Author: Sreerag PM(odoo@cybrosys.com) |
||||
|
# |
||||
|
# You can modify it under the terms of the GNU AFFERO |
||||
|
# GENERAL PUBLIC LICENSE (AGPL v3), Version 3. |
||||
|
# |
||||
|
# This program is distributed in the hope that it will be useful, |
||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
|
# GNU AFFERO GENERAL PUBLIC LICENSE (AGPL v3) for more details. |
||||
|
# |
||||
|
# You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE |
||||
|
# (AGPL v3) along with this program. |
||||
|
# If not, see <http://www.gnu.org/licenses/>. |
||||
|
# |
||||
|
############################################################################# |
||||
|
{ |
||||
|
'name': 'Sale Discount on Total Amount', |
||||
|
'version': '18.0.1.0.0', |
||||
|
'category': 'Sales Management', |
||||
|
'summary': "Discount on Total in Sale and Invoice With Discount Limit " |
||||
|
"and Approval", |
||||
|
'description': "This module is designed to manage discounts on the total " |
||||
|
"amount in sales. It will include features to apply " |
||||
|
"discounts either as a specific amount or a percentage. " |
||||
|
"This module will enhance the functionality of Odoo's sales " |
||||
|
"module, allowing users to easily manage and apply discounts" |
||||
|
" to sales orders based on their requirements.", |
||||
|
'author': 'Cybrosys Techno Solutions', |
||||
|
'company': 'Cybrosys Techno Solutions', |
||||
|
'maintainer': 'Cybrosys Techno Solutions', |
||||
|
'website': "https://www.cybrosys.com", |
||||
|
'live_test_url': 'https://www.youtube.com/watch?v=CigmHe9iC4s&feature=youtu.be', |
||||
|
'depends': ['sale_management', 'account'], |
||||
|
'data': [ |
||||
|
'views/res_config_settings_views.xml', |
||||
|
'views/sale_order_views.xml', |
||||
|
'views/account_move_views.xml', |
||||
|
'views/account_move_templates.xml', |
||||
|
'views/sale_order_templates.xml', |
||||
|
], |
||||
|
'images': ['static/description/banner.png'], |
||||
|
'license': 'AGPL-3', |
||||
|
'installable': True, |
||||
|
'auto_install': False, |
||||
|
'application': False, |
||||
|
} |
@ -0,0 +1,6 @@ |
|||||
|
## Module <sale_discount_total> |
||||
|
|
||||
|
#### 05.11.2024 |
||||
|
#### Version 18.0.1.0.0 |
||||
|
#### ADD |
||||
|
- Initial commit for Sale Discount On Total Amount |
@ -0,0 +1,26 @@ |
|||||
|
# -*- coding: utf-8 -*- |
||||
|
############################################################################# |
||||
|
# |
||||
|
# Cybrosys Technologies Pvt. Ltd. |
||||
|
# |
||||
|
# Copyright (C) 2024-TODAY Cybrosys Technologies(<https://www.cybrosys.com>). |
||||
|
# Author: Sreerag PM(odoo@cybrosys.com) |
||||
|
# |
||||
|
# You can modify it under the terms of the GNU AFFERO |
||||
|
# GENERAL PUBLIC LICENSE (AGPL v3), Version 3. |
||||
|
# |
||||
|
# This program is distributed in the hope that it will be useful, |
||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
|
# GNU AFFERO GENERAL PUBLIC LICENSE (AGPL v3) for more details. |
||||
|
# |
||||
|
# You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE |
||||
|
# (AGPL v3) along with this program. |
||||
|
# If not, see <http://www.gnu.org/licenses/>. |
||||
|
# |
||||
|
############################################################################# |
||||
|
from . import account_move |
||||
|
from . import res_company |
||||
|
from . import res_config_settings |
||||
|
from . import sale_order |
||||
|
from . import sale_order_line |
@ -0,0 +1,182 @@ |
|||||
|
# -*- coding: utf-8 -*- |
||||
|
############################################################################# |
||||
|
# |
||||
|
# Cybrosys Technologies Pvt. Ltd. |
||||
|
# |
||||
|
# Copyright (C) 2024-TODAY Cybrosys Technologies(<https://www.cybrosys.com>). |
||||
|
# Author: Sreerag PM(odoo@cybrosys.com) |
||||
|
# |
||||
|
# You can modify it under the terms of the GNU AFFERO |
||||
|
# GENERAL PUBLIC LICENSE (AGPL v3), Version 3. |
||||
|
# |
||||
|
# This program is distributed in the hope that it will be useful, |
||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
|
# GNU AFFERO GENERAL PUBLIC LICENSE (AGPL v3) for more details. |
||||
|
# |
||||
|
# You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE |
||||
|
# (AGPL v3) along with this program. |
||||
|
# If not, see <http://www.gnu.org/licenses/>. |
||||
|
# |
||||
|
############################################################################# |
||||
|
from odoo import api, fields, models |
||||
|
|
||||
|
|
||||
|
class AccountInvoice(models.Model): |
||||
|
"""This class inherits "account.move" model and adds discount_type, |
||||
|
discount_rate, amount_discount |
||||
|
""" |
||||
|
_inherit = "account.move" |
||||
|
|
||||
|
discount_type = fields.Selection( |
||||
|
[('percent', 'Percentage'), ('amount', 'Amount')], |
||||
|
string='Discount type', |
||||
|
default='percent', help="Type of discount.") |
||||
|
discount_rate = fields.Float('Discount Rate', digits=(16, 2), |
||||
|
help="Give the discount rate.") |
||||
|
amount_discount = fields.Monetary(string='Discount', store=True, |
||||
|
compute='_compute_amount', readonly=True, |
||||
|
help="Give the amount to be discounted.") |
||||
|
|
||||
|
@api.depends( |
||||
|
'line_ids.matched_debit_ids.debit_move_id.move_id.payment_ids.is_matched', |
||||
|
'line_ids.matched_debit_ids.debit_move_id.move_id.line_ids.amount_residual', |
||||
|
'line_ids.matched_debit_ids.debit_move_id.move_id.line_ids.amount_residual_currency', |
||||
|
'line_ids.matched_credit_ids.credit_move_id.move_id.payment_ids.is_matched', |
||||
|
'line_ids.matched_credit_ids.credit_move_id.move_id.line_ids.amount_residual', |
||||
|
'line_ids.matched_credit_ids.credit_move_id.move_id.line_ids.amount_residual_currency', |
||||
|
'line_ids.balance', |
||||
|
'line_ids.currency_id', |
||||
|
'line_ids.amount_currency', |
||||
|
'line_ids.amount_residual', |
||||
|
'line_ids.amount_residual_currency', |
||||
|
'line_ids.payment_id.state', |
||||
|
'line_ids.full_reconcile_id') |
||||
|
def _compute_amount(self): |
||||
|
"""This function computes amount based on taxed,untaxed""" |
||||
|
for move in self: |
||||
|
total_untaxed, total_untaxed_currency = 0.0, 0.0 |
||||
|
total_tax, total_tax_currency = 0.0, 0.0 |
||||
|
total_residual, total_residual_currency = 0.0, 0.0 |
||||
|
total, total_currency = 0.0, 0.0 |
||||
|
total_to_pay = move.amount_total |
||||
|
currencies = set() |
||||
|
for line in move.line_ids: |
||||
|
if move.is_invoice(True): |
||||
|
# === Invoices === |
||||
|
if line.display_type == 'tax' or ( |
||||
|
line.display_type == 'rounding' and |
||||
|
line.tax_repartition_line_id): |
||||
|
# Tax amount. |
||||
|
total_tax += line.balance |
||||
|
total_tax_currency += line.amount_currency |
||||
|
total += line.balance |
||||
|
total_currency += line.amount_currency |
||||
|
elif line.display_type in ('product', 'rounding'): |
||||
|
# Untaxed amount. |
||||
|
total_untaxed += line.balance |
||||
|
total_untaxed_currency += line.amount_currency |
||||
|
total += line.balance |
||||
|
total_currency += line.amount_currency |
||||
|
elif line.display_type == 'payment_term': |
||||
|
# Residual amount. |
||||
|
total_residual += line.amount_residual |
||||
|
total_residual_currency += line.amount_residual_currency |
||||
|
else: |
||||
|
# === Miscellaneous journal entry === |
||||
|
if line.debit: |
||||
|
total += line.balance |
||||
|
total_currency += line.amount_currency |
||||
|
sign = move.direction_sign |
||||
|
move.amount_untaxed = sign * (total_untaxed_currency if len( |
||||
|
currencies) == 1 else total_untaxed) |
||||
|
move.amount_tax = sign * ( |
||||
|
total_tax_currency if len(currencies) == 1 else total_tax) |
||||
|
move.amount_total = sign * total_currency |
||||
|
move.amount_residual = -sign * total_residual_currency |
||||
|
move.amount_untaxed_signed = -total_untaxed |
||||
|
move.amount_tax_signed = -total_tax |
||||
|
move.amount_total_signed = abs( |
||||
|
total) if move.move_type == 'entry' else -total |
||||
|
move.amount_residual_signed = total_residual |
||||
|
move.amount_total_in_currency_signed = abs( |
||||
|
move.amount_total) if move.move_type == 'entry' else -( |
||||
|
sign * move.amount_total) |
||||
|
currency = (len( |
||||
|
currencies) == 1 and currencies.pop() or |
||||
|
move.company_id.currency_id) |
||||
|
new_pmt_state = 'not_paid' if move.move_type != 'entry' else False |
||||
|
if move.is_invoice( |
||||
|
include_receipts=True) and move.state == 'posted': |
||||
|
if currency.is_zero(move.amount_residual): |
||||
|
if all(payment.is_matched for payment in |
||||
|
move._get_reconciled_payments()): |
||||
|
new_pmt_state = 'paid' |
||||
|
else: |
||||
|
new_pmt_state = move._get_invoice_in_payment_state() |
||||
|
elif currency.compare_amounts(total_to_pay, |
||||
|
abs(total_residual)) != 0: |
||||
|
new_pmt_state = 'partial' |
||||
|
if new_pmt_state == 'paid' and move.move_type in ( |
||||
|
'in_invoice', 'out_invoice', 'entry'): |
||||
|
reverse_type = (move.move_type == 'in_invoice' and 'in_refund' |
||||
|
or move.move_type == 'out_invoice' and |
||||
|
'out_refund' or 'entry') |
||||
|
reverse_moves = self.env['account.move'].search( |
||||
|
[('reversed_entry_id', '=', move.id), |
||||
|
('state', '=', 'posted'), |
||||
|
('move_type', '=', reverse_type)]) |
||||
|
# We only set 'reversed' state in case of 1 to 1 full |
||||
|
# reconciliation with a reverse entry; otherwise, we use the |
||||
|
# regular 'paid' state |
||||
|
reverse_moves_full_recs = reverse_moves.mapped( |
||||
|
'line_ids.full_reconcile_id') |
||||
|
if reverse_moves_full_recs.mapped( |
||||
|
'reconciled_line_ids.move_id').filtered( |
||||
|
lambda x: x not in ( |
||||
|
reverse_moves + reverse_moves_full_recs.mapped( |
||||
|
'exchange_move_id'))) == move: |
||||
|
new_pmt_state = 'reversed' |
||||
|
move.payment_state = new_pmt_state |
||||
|
|
||||
|
@api.onchange('discount_type', 'discount_rate', 'invoice_line_ids') |
||||
|
def _supply_rate(self): |
||||
|
"""This function calculates supply rates based on change of |
||||
|
discount_type, |
||||
|
discount_rate and invoice_line_ids""" |
||||
|
for inv in self: |
||||
|
if inv.discount_type == 'percent': |
||||
|
discount_totals = 0 |
||||
|
for line in inv.invoice_line_ids: |
||||
|
line.discount = inv.discount_rate |
||||
|
total_price = line.price_unit * line.quantity |
||||
|
discount_total = total_price - line.price_subtotal |
||||
|
discount_totals = discount_totals + discount_total |
||||
|
inv.amount_discount = discount_totals |
||||
|
line._compute_totals() |
||||
|
else: |
||||
|
total = 0.0 |
||||
|
for line in inv.invoice_line_ids: |
||||
|
total += (line.quantity * line.price_unit) |
||||
|
if inv.discount_rate != 0: |
||||
|
discount = (inv.discount_rate / total) * 100 |
||||
|
else: |
||||
|
discount = inv.discount_rate |
||||
|
for line in inv.invoice_line_ids: |
||||
|
line.discount = discount |
||||
|
inv.amount_discount = inv.discount_rate |
||||
|
line._compute_totals() |
||||
|
inv._compute_tax_totals() |
||||
|
|
||||
|
def button_dummy(self): |
||||
|
"""The button_dummy method is intended to perform some action related |
||||
|
to the supply rate and always return True""" |
||||
|
self.supply_rate() |
||||
|
return True |
||||
|
|
||||
|
|
||||
|
class AccountInvoiceLine(models.Model): |
||||
|
"""This class inherits "account.move.line" model and adds discount field""" |
||||
|
_inherit = "account.move.line" |
||||
|
discount = fields.Float(string='Discount (%)', digits=(16, 20), default=0.0, |
||||
|
help="Give the discount needed") |
@ -0,0 +1,38 @@ |
|||||
|
# -*- coding: utf-8 -*- |
||||
|
############################################################################# |
||||
|
# |
||||
|
# Cybrosys Technologies Pvt. Ltd. |
||||
|
# |
||||
|
# Copyright (C) 2024-TODAY Cybrosys Technologies(<https://www.cybrosys.com>). |
||||
|
# Author: Sreerag PM(odoo@cybrosys.com) |
||||
|
# |
||||
|
# You can modify it under the terms of the GNU AFFERO |
||||
|
# GENERAL PUBLIC LICENSE (AGPL v3), Version 3. |
||||
|
# |
||||
|
# This program is distributed in the hope that it will be useful, |
||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
|
# GNU AFFERO GENERAL PUBLIC LICENSE (AGPL v3) for more details. |
||||
|
# |
||||
|
# You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE |
||||
|
# (AGPL v3) along with this program. |
||||
|
# If not, see <http://www.gnu.org/licenses/>. |
||||
|
# |
||||
|
############################################################################# |
||||
|
from odoo import fields, models |
||||
|
|
||||
|
|
||||
|
class ResCompany(models.Model): |
||||
|
"""This class inherits 'res.company' and adds so_double_validation, |
||||
|
so_double_validation_limit to add validation limits""" |
||||
|
_inherit = 'res.company' |
||||
|
|
||||
|
so_double_validation = fields.Selection([ |
||||
|
('one_step', 'Confirm sale orders in one step'), |
||||
|
('two_step', 'Get 2 levels of approvals to confirm a sale order') |
||||
|
], string="Levels of Approvals", default='one_step', |
||||
|
help="Provide a double validation mechanism for sales discount.") |
||||
|
so_double_validation_limit = fields.Float( |
||||
|
string="Percentage of Discount that requires double validation'", |
||||
|
help="Minimum discount percentage for which a double validation is " |
||||
|
"required.") |
@ -0,0 +1,50 @@ |
|||||
|
# -*- coding: utf-8 -*- |
||||
|
############################################################################# |
||||
|
# |
||||
|
# Cybrosys Technologies Pvt. Ltd. |
||||
|
# |
||||
|
# Copyright (C) 2024-TODAY Cybrosys Technologies(<https://www.cybrosys.com>). |
||||
|
# Author: Sreerag PM(odoo@cybrosys.com) |
||||
|
# |
||||
|
# You can modify it under the terms of the GNU AFFERO |
||||
|
# GENERAL PUBLIC LICENSE (AGPL v3), Version 3. |
||||
|
# |
||||
|
# This program is distributed in the hope that it will be useful, |
||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
|
# GNU AFFERO GENERAL PUBLIC LICENSE (AGPL v3) for more details. |
||||
|
# |
||||
|
# You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE |
||||
|
# (AGPL v3) along with this program. |
||||
|
# If not, see <http://www.gnu.org/licenses/>. |
||||
|
# |
||||
|
############################################################################# |
||||
|
from odoo import fields, models |
||||
|
|
||||
|
|
||||
|
class ResConfigSettings(models.TransientModel): |
||||
|
"""This class inherits 'res.config.settings' model and adds fields |
||||
|
to the settings""" |
||||
|
_inherit = 'res.config.settings' |
||||
|
|
||||
|
so_order_approval = fields.Boolean( |
||||
|
string="Sale Discount Approval", |
||||
|
default=lambda self: self.env.user.company_id.so_double_validation == |
||||
|
'two_step', help="Activate/disable " |
||||
|
"sale order approval.") |
||||
|
so_double_validation = fields.Selection( |
||||
|
related='company_id.so_double_validation', |
||||
|
string="Levels of Approvals *", readonly=False, |
||||
|
help="Provide a double validation mechanism for sales discount.") |
||||
|
so_double_validation_limit = fields.Float( |
||||
|
string="Discount limit requires approval in %", |
||||
|
related='company_id.so_double_validation_limit', readonly=False, |
||||
|
help="Minimum discount percentage for which a double validation is " |
||||
|
"required." |
||||
|
) |
||||
|
|
||||
|
def set_values(self): |
||||
|
"""Function to set values""" |
||||
|
super(ResConfigSettings, self).set_values() |
||||
|
self.so_double_validation = 'two_step' if self.so_order_approval \ |
||||
|
else 'one_step' |
@ -0,0 +1,131 @@ |
|||||
|
# -*- coding: utf-8 -*- |
||||
|
############################################################################# |
||||
|
# |
||||
|
# Cybrosys Technologies Pvt. Ltd. |
||||
|
# |
||||
|
# Copyright (C) 2024-TODAY Cybrosys Technologies(<https://www.cybrosys.com>). |
||||
|
# Author: Sreerag PM(odoo@cybrosys.com) |
||||
|
# |
||||
|
# You can modify it under the terms of the GNU AFFERO |
||||
|
# GENERAL PUBLIC LICENSE (AGPL v3), Version 3. |
||||
|
# |
||||
|
# This program is distributed in the hope that it will be useful, |
||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
|
# GNU AFFERO GENERAL PUBLIC LICENSE (AGPL v3) for more details. |
||||
|
# |
||||
|
# You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE |
||||
|
# (AGPL v3) along with this program. |
||||
|
# If not, see <http://www.gnu.org/licenses/>. |
||||
|
# |
||||
|
############################################################################# |
||||
|
from odoo import api, fields, models |
||||
|
|
||||
|
|
||||
|
class SaleOrder(models.Model): |
||||
|
"""Inherit 'sale.order' model and add fields needed""" |
||||
|
_inherit = "sale.order" |
||||
|
|
||||
|
@api.depends('order_line.price_total') |
||||
|
def _amount_all(self): |
||||
|
"""Compute the total amounts of the SO.""" |
||||
|
for order in self: |
||||
|
amount_untaxed = amount_tax = amount_discount = 0.0 |
||||
|
for line in order.order_line: |
||||
|
amount_untaxed += line.price_subtotal |
||||
|
amount_tax += line.price_tax |
||||
|
amount_discount += ( |
||||
|
line.product_uom_qty * line.price_unit * line.discount) / 100 |
||||
|
order.update({ |
||||
|
'amount_untaxed': amount_untaxed, |
||||
|
'amount_tax': amount_tax, |
||||
|
'amount_discount': amount_discount, |
||||
|
'amount_total': amount_untaxed + amount_tax, |
||||
|
}) |
||||
|
|
||||
|
state = fields.Selection(selection_add=[ |
||||
|
('waiting', 'Waiting Approval'), |
||||
|
], string='Status', readonly=True, copy=False, index=True, |
||||
|
default='draft', help="Status of quotation.") |
||||
|
discount_type = fields.Selection( |
||||
|
[('percent', 'Percentage'), ('amount', 'Amount')], |
||||
|
string='Discount type', |
||||
|
default='percent', help="Type of discount.") |
||||
|
discount_rate = fields.Float('Discount Rate', digits=(16, 2), |
||||
|
help="Give the discount rate.") |
||||
|
amount_discount = fields.Monetary(string='Discount', store=True, |
||||
|
compute='_amount_all', readonly=True, |
||||
|
help="Give the amount to be discounted.") |
||||
|
amount_untaxed = fields.Monetary(string='Untaxed Amount', store=True, |
||||
|
readonly=True, compute='_amount_all', |
||||
|
help="Untaxed amount displayed.") |
||||
|
amount_tax = fields.Monetary(string='Taxes', store=True, readonly=True, |
||||
|
compute='_amount_all', |
||||
|
help="Taxes of product.") |
||||
|
amount_total = fields.Monetary(string='Total', store=True, readonly=True, |
||||
|
compute='_amount_all', |
||||
|
help="Total amount provided.") |
||||
|
|
||||
|
def action_confirm(self): |
||||
|
"""This function super action_confirm method""" |
||||
|
discount = 0.0 |
||||
|
no_line = 0.0 |
||||
|
if self.company_id.so_double_validation == 'two_step': |
||||
|
for line in self.order_line: |
||||
|
no_line += 1 |
||||
|
discount += line.discount |
||||
|
discount = (discount / no_line) |
||||
|
if (self.company_id.so_double_validation_limit and discount > |
||||
|
self.company_id.so_double_validation_limit): |
||||
|
self.state = 'waiting' |
||||
|
return True |
||||
|
super(SaleOrder, self).action_confirm() |
||||
|
|
||||
|
def action_approve(self): |
||||
|
"""This super the class and calls the action_confirm method on clicking |
||||
|
approve button""" |
||||
|
super(SaleOrder, self).action_confirm() |
||||
|
return |
||||
|
|
||||
|
def _can_be_confirmed(self): |
||||
|
"""This function _can_be_confirmed adds waiting state """ |
||||
|
self.ensure_one() |
||||
|
return self.state in {'draft', 'sent', 'waiting'} |
||||
|
|
||||
|
@api.onchange('discount_type', 'discount_rate', 'order_line') |
||||
|
def supply_rate(self): |
||||
|
"""This function calculates supply rates based on change of |
||||
|
discount_type, discount_rate and invoice_line_ids""" |
||||
|
for order in self: |
||||
|
if order.discount_type == 'percent': |
||||
|
for line in order.order_line: |
||||
|
line.discount = order.discount_rate |
||||
|
else: |
||||
|
total = 0.0 |
||||
|
for line in order.order_line: |
||||
|
total += round((line.product_uom_qty * line.price_unit)) |
||||
|
if order.discount_rate != 0: |
||||
|
discount = ( |
||||
|
order.discount_rate / total) * 100 if total > 0 else 0 |
||||
|
else: |
||||
|
discount = order.discount_rate |
||||
|
for line in order.order_line: |
||||
|
line.discount = discount |
||||
|
new_sub_price = (line.price_unit * (discount / 100)) |
||||
|
line.total_discount = line.price_unit - new_sub_price |
||||
|
|
||||
|
def _prepare_invoice(self, ): |
||||
|
"""Super sale order class and update with fields""" |
||||
|
invoice_vals = super(SaleOrder, self)._prepare_invoice() |
||||
|
invoice_vals.update({ |
||||
|
'discount_type': self.discount_type, |
||||
|
'discount_rate': self.discount_rate, |
||||
|
'amount_discount': self.amount_discount, |
||||
|
}) |
||||
|
return invoice_vals |
||||
|
|
||||
|
def button_dummy(self): |
||||
|
"""The button_dummy method is intended to perform some action related |
||||
|
to the supply rate and always return True""" |
||||
|
self.supply_rate() |
||||
|
return True |
@ -0,0 +1,34 @@ |
|||||
|
# -*- coding: utf-8 -*- |
||||
|
############################################################################# |
||||
|
# |
||||
|
# Cybrosys Technologies Pvt. Ltd. |
||||
|
# |
||||
|
# Copyright (C) 2024-TODAY Cybrosys Technologies(<https://www.cybrosys.com>). |
||||
|
# Author: Sreerag PM(odoo@cybrosys.com) |
||||
|
# |
||||
|
# You can modify it under the terms of the GNU AFFERO |
||||
|
# GENERAL PUBLIC LICENSE (AGPL v3), Version 3. |
||||
|
# |
||||
|
# This program is distributed in the hope that it will be useful, |
||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
|
# GNU AFFERO GENERAL PUBLIC LICENSE (AGPL v3) for more details. |
||||
|
# |
||||
|
# You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE |
||||
|
# (AGPL v3) along with this program. |
||||
|
# If not, see <http://www.gnu.org/licenses/>. |
||||
|
# |
||||
|
############################################################################# |
||||
|
from odoo import fields, models |
||||
|
|
||||
|
|
||||
|
class SaleOrderLine(models.Model): |
||||
|
"""This class inherits "sale.order.line" and adds fields discount, |
||||
|
total_discount """ |
||||
|
_inherit = "sale.order.line" |
||||
|
|
||||
|
discount = fields.Float(string='Discount (%)', digits=(16, 20), default=0.0, |
||||
|
help="Discount needed.") |
||||
|
total_discount = fields.Float(string="Total Discount", default=0.0, |
||||
|
store=True, help="Total discount can be" |
||||
|
"specified here.") |
@ -0,0 +1,23 @@ |
|||||
|
# -*- coding: utf-8 -*- |
||||
|
############################################################################# |
||||
|
# |
||||
|
# Cybrosys Technologies Pvt. Ltd. |
||||
|
# |
||||
|
# Copyright (C) 2024-TODAY Cybrosys Technologies(<https://www.cybrosys.com>). |
||||
|
# Author: Sreerag PM(odoo@cybrosys.com) |
||||
|
# |
||||
|
# You can modify it under the terms of the GNU AFFERO |
||||
|
# GENERAL PUBLIC LICENSE (AGPL v3), Version 3. |
||||
|
# |
||||
|
# This program is distributed in the hope that it will be useful, |
||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
|
# GNU AFFERO GENERAL PUBLIC LICENSE (AGPL v3) for more details. |
||||
|
# |
||||
|
# You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE |
||||
|
# (AGPL v3) along with this program. |
||||
|
# If not, see <http://www.gnu.org/licenses/>. |
||||
|
# |
||||
|
############################################################################# |
||||
|
from . import account_invoice_report |
||||
|
from . import sale_report |
@ -0,0 +1,34 @@ |
|||||
|
# -*- coding: utf-8 -*- |
||||
|
############################################################################# |
||||
|
# |
||||
|
# Cybrosys Technologies Pvt. Ltd. |
||||
|
# |
||||
|
# Copyright (C) 2024-TODAY Cybrosys Technologies(<https://www.cybrosys.com>). |
||||
|
# Author: Sreerag PM(odoo@cybrosys.com) |
||||
|
# |
||||
|
# You can modify it under the terms of the GNU AFFERO |
||||
|
# GENERAL PUBLIC LICENSE (AGPL v3), Version 3. |
||||
|
# |
||||
|
# This program is distributed in the hope that it will be useful, |
||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
|
# GNU AFFERO GENERAL PUBLIC LICENSE (AGPL v3) for more details. |
||||
|
# |
||||
|
# You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE |
||||
|
# (AGPL v3) along with this program. |
||||
|
# If not, see <http://www.gnu.org/licenses/>. |
||||
|
# |
||||
|
############################################################################# |
||||
|
from odoo import fields, models |
||||
|
from odoo.tools import SQL |
||||
|
|
||||
|
|
||||
|
class AccountInvoiceReport(models.Model): |
||||
|
"""This class inherits the model 'account.invoice.report'""" |
||||
|
_inherit = 'account.invoice.report' |
||||
|
|
||||
|
discount = fields.Float('Discount', readonly=True, |
||||
|
help="Specify the discount.") |
||||
|
|
||||
|
def _select(self) -> SQL: |
||||
|
return SQL("%s, line.discount AS discount", super()._select()) |
@ -0,0 +1,40 @@ |
|||||
|
# -*- coding: utf-8 -*- |
||||
|
############################################################################# |
||||
|
# |
||||
|
# Cybrosys Technologies Pvt. Ltd. |
||||
|
# |
||||
|
# Copyright (C) 2024-TODAY Cybrosys Technologies(<https://www.cybrosys.com>). |
||||
|
# Author: Sreerag PM(odoo@cybrosys.com) |
||||
|
# |
||||
|
# You can modify it under the terms of the GNU AFFERO |
||||
|
# GENERAL PUBLIC LICENSE (AGPL v3), Version 3. |
||||
|
# |
||||
|
# This program is distributed in the hope that it will be useful, |
||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
|
# GNU AFFERO GENERAL PUBLIC LICENSE (AGPL v3) for more details. |
||||
|
# |
||||
|
# You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE |
||||
|
# (AGPL v3) along with this program. |
||||
|
# If not, see <http://www.gnu.org/licenses/>. |
||||
|
# |
||||
|
############################################################################# |
||||
|
from odoo import fields, models |
||||
|
from odoo.tools import SQL |
||||
|
|
||||
|
|
||||
|
class DiscountSaleReport(models.Model): |
||||
|
"""This class inherits 'sale.report' and adds field discount""" |
||||
|
_inherit = 'sale.report' |
||||
|
|
||||
|
discount = fields.Float('Discount', readonly=True, |
||||
|
help="Specify the discount amount.") |
||||
|
|
||||
|
def _select(self) -> SQL: |
||||
|
"""It extends the behavior of a method in the class by adding a |
||||
|
new column, discount, to the SQL query. This new column represents |
||||
|
the total discount for sales transactions, calculated based on |
||||
|
various factors and values related to the sale. """ |
||||
|
return SQL( |
||||
|
"%s, sum(l.product_uom_qty / u.factor * u2.factor * cr.rate * l.price_unit * l.discount / 100.0) as discount", |
||||
|
super()._select()) |
After Width: | Height: | Size: 2.2 KiB |
After Width: | Height: | Size: 28 KiB |
After Width: | Height: | Size: 628 KiB |
After Width: | Height: | Size: 1.1 KiB |
After Width: | Height: | Size: 210 KiB |
After Width: | Height: | Size: 209 KiB |
After Width: | Height: | Size: 109 KiB |
After Width: | Height: | Size: 495 B |
After Width: | Height: | Size: 1.0 KiB |
After Width: | Height: | Size: 624 B |
After Width: | Height: | Size: 136 KiB |
After Width: | Height: | Size: 214 KiB |
After Width: | Height: | Size: 36 KiB |
After Width: | Height: | Size: 3.6 KiB |
After Width: | Height: | Size: 310 B |
After Width: | Height: | Size: 929 B |
After Width: | Height: | Size: 1.3 KiB |
After Width: | Height: | Size: 3.3 KiB |
After Width: | Height: | Size: 1.4 KiB |
After Width: | Height: | Size: 17 KiB |
After Width: | Height: | Size: 542 B |
After Width: | Height: | Size: 576 B |
After Width: | Height: | Size: 733 B |
After Width: | Height: | Size: 4.3 KiB |
After Width: | Height: | Size: 1.2 KiB |
After Width: | Height: | Size: 4.0 KiB |
After Width: | Height: | Size: 1.7 KiB |
After Width: | Height: | Size: 738 KiB |
After Width: | Height: | Size: 2.2 KiB |
After Width: | Height: | Size: 911 B |
After Width: | Height: | Size: 1.1 KiB |
After Width: | Height: | Size: 1.2 KiB |
After Width: | Height: | Size: 1.2 KiB |
After Width: | Height: | Size: 600 B |
After Width: | Height: | Size: 673 B |
After Width: | Height: | Size: 2.0 KiB |
After Width: | Height: | Size: 462 B |
After Width: | Height: | Size: 2.1 KiB |
After Width: | Height: | Size: 926 B |
After Width: | Height: | Size: 9.0 KiB |
After Width: | Height: | Size: 23 KiB |
After Width: | Height: | Size: 7.0 KiB |
After Width: | Height: | Size: 878 B |
After Width: | Height: | Size: 1.2 KiB |
After Width: | Height: | Size: 653 B |
After Width: | Height: | Size: 800 B |
After Width: | Height: | Size: 905 B |
After Width: | Height: | Size: 189 KiB |
After Width: | Height: | Size: 4.3 KiB |
After Width: | Height: | Size: 839 B |
After Width: | Height: | Size: 1.7 KiB |
After Width: | Height: | Size: 5.9 KiB |
After Width: | Height: | Size: 1.6 KiB |
After Width: | Height: | Size: 34 KiB |
After Width: | Height: | Size: 26 KiB |
After Width: | Height: | Size: 3.8 KiB |
After Width: | Height: | Size: 23 KiB |
After Width: | Height: | Size: 1.9 KiB |
After Width: | Height: | Size: 2.3 KiB |
After Width: | Height: | Size: 427 B |
After Width: | Height: | Size: 627 B |
After Width: | Height: | Size: 1.1 KiB |
After Width: | Height: | Size: 1.2 KiB |
After Width: | Height: | Size: 988 B |
After Width: | Height: | Size: 3.7 KiB |
After Width: | Height: | Size: 5.0 KiB |
After Width: | Height: | Size: 875 B |
After Width: | Height: | Size: 1.2 KiB |
After Width: | Height: | Size: 126 KiB |
After Width: | Height: | Size: 86 KiB |
After Width: | Height: | Size: 90 KiB |
After Width: | Height: | Size: 118 KiB |
After Width: | Height: | Size: 142 KiB |
After Width: | Height: | Size: 138 KiB |
After Width: | Height: | Size: 189 KiB |
After Width: | Height: | Size: 171 KiB |
After Width: | Height: | Size: 97 KiB |
After Width: | Height: | Size: 207 KiB |
After Width: | Height: | Size: 174 KiB |
After Width: | Height: | Size: 880 KiB |
After Width: | Height: | Size: 92 KiB |
After Width: | Height: | Size: 13 KiB |
@ -0,0 +1,19 @@ |
|||||
|
<?xml version="1.0" encoding="utf-8"?> |
||||
|
<odoo> |
||||
|
<!--Inherited Template for invoice document--> |
||||
|
<template id="report_invoice_customized" |
||||
|
inherit_id="account.report_invoice_document"> |
||||
|
<xpath expr="//span[@t-field='line.discount']" position="replace"> |
||||
|
<span t-esc="'%.2f'%(line.discount)"/> |
||||
|
</xpath> |
||||
|
<xpath expr="//tr[hasclass('is-subtotal')]" position="after"> |
||||
|
<tr> |
||||
|
<td>Discount</td> |
||||
|
<td class="text-right"> |
||||
|
<span t-field="o.amount_discount"/> |
||||
|
</td> |
||||
|
</tr> |
||||
|
</xpath> |
||||
|
</template> |
||||
|
</odoo> |
||||
|
|
@ -0,0 +1,24 @@ |
|||||
|
<?xml version="1.0" encoding="utf-8"?> |
||||
|
<odoo> |
||||
|
<!--Inherited view form of account.move--> |
||||
|
<record id="view_move_form" model="ir.ui.view"> |
||||
|
<field name="name">account.move.view.form.inherit.sale.discount.total |
||||
|
</field> |
||||
|
<field name="model">account.move</field> |
||||
|
<field name="inherit_id" ref="account.view_move_form"/> |
||||
|
<field name="arch" type="xml"> |
||||
|
<xpath expr="//field[@name='discount']" position="attributes"> |
||||
|
<attribute name="digits">[16, 2]</attribute> |
||||
|
</xpath> |
||||
|
<xpath expr="//field[@name='tax_totals']" position="after"> |
||||
|
<field name="amount_discount" readonly="1" force_save="1"/> |
||||
|
</xpath> |
||||
|
<xpath expr="//field[@name='narration']" position="before"> |
||||
|
<group> |
||||
|
<field name="discount_type" width="50px"/> |
||||
|
<field name="discount_rate" class="oe_inline"/> |
||||
|
</group> |
||||
|
</xpath> |
||||
|
</field> |
||||
|
</record> |
||||
|
</odoo> |
@ -0,0 +1,34 @@ |
|||||
|
<?xml version="1.0" encoding="utf-8"?> |
||||
|
<odoo> |
||||
|
<!--Inherited view form of res config settings--> |
||||
|
<record id="res_config_settings_view_form" model="ir.ui.view"> |
||||
|
<field name="name"> |
||||
|
res.config.settings.view.form.inherit.sale.discount.total |
||||
|
</field> |
||||
|
<field name="model">res.config.settings</field> |
||||
|
<field name="priority" eval="10"/> |
||||
|
<field name="inherit_id" ref="sale.res_config_settings_view_form"/> |
||||
|
<field name="arch" type="xml"> |
||||
|
<xpath expr="//block[@id='pricing_setting_container']" |
||||
|
position="inside"> |
||||
|
<setting id="discount_sale_order_lines" |
||||
|
string="Sale Discount Approval" |
||||
|
help="Managers must approve document"> |
||||
|
<field name="so_order_approval" |
||||
|
field_id="so_order_approval_0"/> |
||||
|
<div class="content-group" |
||||
|
invisible="not so_order_approval"> |
||||
|
<div class="mt16"> |
||||
|
<label for="so_double_validation_limit" |
||||
|
class="o_light_label mr8"/> |
||||
|
<field name="so_double_validation_limit" |
||||
|
class="oe_inline" |
||||
|
can_write="True" |
||||
|
field_id="so_double_validation_limit_0"/> |
||||
|
</div> |
||||
|
</div> |
||||
|
</setting> |
||||
|
</xpath> |
||||
|
</field> |
||||
|
</record> |
||||
|
</odoo> |
@ -0,0 +1,19 @@ |
|||||
|
<?xml version="1.0" encoding="utf-8"?> |
||||
|
<odoo> |
||||
|
<!--Inherited Template for sale order report--> |
||||
|
<template id="report_saleorder_customized" |
||||
|
inherit_id="sale.report_saleorder_document"> |
||||
|
<xpath expr="//span[@t-field='line.discount']" position="replace"> |
||||
|
<span t-esc="'%.2f'%(line.discount)"/> |
||||
|
</xpath> |
||||
|
<xpath expr="//tr[hasclass('is-subtotal')]" position="after"> |
||||
|
<tr> |
||||
|
<td>Total Discount</td> |
||||
|
<td class="text-right"> |
||||
|
<span t-field="doc.amount_discount" |
||||
|
t-options='{"widget": "monetary", "display_currency": doc.pricelist_id.currency_id}'/> |
||||
|
</td> |
||||
|
</tr> |
||||
|
</xpath> |
||||
|
</template> |
||||
|
</odoo> |