Browse Source

Jun 03: [FIX] Bug Fixed 'sale_discount_total'

pull/164/merge
RisvanaCybro 11 months ago
parent
commit
59b38f2abe
  1. 18
      sale_discount_total/__manifest__.py
  2. 7
      sale_discount_total/doc/RELEASE_NOTES.md
  3. 2
      sale_discount_total/models/__init__.py
  4. 75
      sale_discount_total/models/account_invoice.py
  5. 2
      sale_discount_total/models/discount_approval.py
  6. 1
      sale_discount_total/models/sale_order.py
  7. 4
      sale_discount_total/reports/invoice_report.py
  8. 14
      sale_discount_total/views/account_invoice_views.xml
  9. 3
      sale_discount_total/views/invoice_report.xml
  10. 3
      sale_discount_total/views/res_config_views.xml
  11. 3
      sale_discount_total/views/sale_order_report.xml
  12. 13
      sale_discount_total/views/sale_order_templates.xml
  13. 4
      sale_discount_total/views/sale_order_view.xml

18
sale_discount_total/__manifest__.py

@ -22,7 +22,7 @@
{
'name': 'Sale Discount on Total Amount',
'version': '14.0.1.1.0',
'version': '14.0.1.2.0',
'category': 'Sales Management',
'live_test_url': 'https://www.youtube.com/watch?v=CigmHe9iC4s&feature=youtu.be',
'summary': "Discount on Total in Sale and Invoice With Discount Limit and Approval",
@ -32,20 +32,22 @@
'description': """
Sale Discount for Total Amount
=======================
==============================
Module to manage discount on total amount in Sale.
as an specific amount or percentage
""",
'depends': ['sale',
'account', 'delivery'
'depends': [
'sale',
'account',
'delivery'
],
'data': [
'views/sale_view.xml',
'views/account_invoice_view.xml',
'views/sale_order_view.xml',
'views/account_invoice_views.xml',
'views/invoice_report.xml',
'views/sale_order_report.xml',
'views/res_config_view.xml',
'views/res_config_views.xml',
'views/sale_order_templates.xml',
],
'images': ['static/description/banner.png'],
'license': 'AGPL-3',

7
sale_discount_total/doc/RELEASE_NOTES.md

@ -1,4 +1,4 @@
## Module <inventory_barcode_scanning>
## Module <sale_discount_total>
#### 08.10.2020
#### Version 14.0.1.0.0
@ -10,5 +10,8 @@ Initial commit for Sale Discount On Total Amount
#### FIX
discount roundoff
#### 02.02.2024
#### Version 14.0.1.2.0
#### FIX
discount roundoff in website

2
sale_discount_total/models/__init__.py

@ -19,7 +19,7 @@
# If not, see <http://www.gnu.org/licenses/>.
#
#############################################################################
from . import sale
from . import sale_order
from . import account_invoice
from . import discount_approval

75
sale_discount_total/models/account_invoice.py

@ -60,14 +60,11 @@ class AccountInvoice(models.Model):
total = 0.0
total_currency = 0.0
currencies = set()
for line in move.line_ids:
if line.currency_id:
currencies.add(line.currency_id)
if move.is_invoice(include_receipts=True):
# === Invoices ===
if not line.exclude_from_invoice_tab:
# Untaxed amount.
total_untaxed += line.balance
@ -80,7 +77,8 @@ class AccountInvoice(models.Model):
total_tax_currency += line.amount_currency
total += line.balance
total_currency += line.amount_currency
elif line.account_id.user_type_id.type in ('receivable', 'payable'):
elif line.account_id.user_type_id.type in (
'receivable', 'payable'):
# Residual amount.
total_to_pay += line.balance
total_residual += line.amount_residual
@ -96,51 +94,67 @@ class AccountInvoice(models.Model):
else:
sign = -1
if move.discount_type == 'percent':
move.amount_discount = sum((line.quantity * line.price_unit * line.discount) / 100 for line in move.invoice_line_ids)
move.amount_discount = sum(
(line.quantity * line.price_unit * line.discount) / 100 for
line in move.invoice_line_ids)
else:
move.amount_discount = move.discount_rate
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 if len(currencies) == 1 else total)
move.amount_residual = -sign * (total_residual_currency if len(currencies) == 1 else total_residual)
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 if len(currencies) == 1 else total)
move.amount_residual = -sign * (total_residual_currency if len(
currencies) == 1 else total_residual)
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_total_signed = abs(
total) if move.move_type == 'entry' else -total
move.amount_residual_signed = total_residual
currency = len(currencies) == 1 and currencies.pop() or move.company_id.currency_id
currency = len(
currencies) == 1 and currencies.pop() or move.company_id.currency_id
# Compute 'payment_state'.
new_pmt_state = 'not_paid' if move.move_type != 'entry' else False
if move.is_invoice(include_receipts=True) and move.state == 'posted':
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()):
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, total_residual) != 0:
elif currency.compare_amounts(total_to_pay,
total_residual) != 0:
new_pmt_state = 'partial'
if new_pmt_state == 'paid' and move.move_type in ('in_invoice', 'out_invoice', 'entry'):
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)])
[('reversed_entry_id', '=', move.id),
('state', '=', 'posted'),
('move_type', '=', reverse_type)])
# We only set 'reversed' state in cas 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:
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
discount_type = fields.Selection([('percent', 'Percentage'), ('amount', 'Amount')], string='Discount Type',
readonly=True, states={'draft': [('readonly', False)]}, default='percent')
discount_rate = fields.Float('Discount Amount', digits=(16, 2), readonly=True,
discount_type = fields.Selection(
[('percent', 'Percentage'), ('amount', 'Amount')],
string='Discount Type',
readonly=True, states={'draft': [('readonly', False)]},
default='percent')
discount_rate = fields.Float('Discount Amount', digits=(16, 2),
readonly=True,
states={'draft': [('readonly', False)]})
amount_discount = fields.Monetary(string='Discount', store=True, readonly=True, compute='_compute_amount',
amount_discount = fields.Monetary(string='Discount', store=True,
readonly=True, compute='_compute_amount',
track_visibility='always')
@api.onchange('discount_type', 'discount_rate', 'invoice_line_ids')
@ -163,7 +177,6 @@ class AccountInvoice(models.Model):
line._onchange_price_subtotal()
inv._compute_invoice_taxes_by_group()
#
def button_dummy(self):
self.supply_rate()

2
sale_discount_total/models/discount_approval.py

@ -20,7 +20,7 @@
#
#############################################################################
from odoo import api, fields, models
from odoo import fields, models
class sale_discount(models.Model):

1
sale_discount_total/models/sale.py → sale_discount_total/models/sale_order.py

@ -87,7 +87,6 @@ class SaleOrder(models.Model):
return invoice_vals
def button_dummy(self):
self.supply_rate()
return True

4
sale_discount_total/reports/invoice_report.py

@ -30,6 +30,4 @@ class AccountInvoiceReport(models.Model):
def _select(self):
res = super(AccountInvoiceReport, self)._select()
select_str = res + """, line.discount AS discount """
return select_str
return res + """, line.discount AS discount """

14
sale_discount_total/views/account_invoice_view.xml → sale_discount_total/views/account_invoice_views.xml

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data>
<!--inheriting 'account.move' and adding fields-->
<record id="discount_account_invoice_view_form" model="ir.ui.view">
<field name="name">discount.account.invoice</field>
<field name="model">account.move</field>
@ -25,17 +25,5 @@
</xpath>
</field>
</record>
<!-- <record id="discount_view_invoice_line_tree" model="ir.ui.view">-->
<!-- <field name="name">discount.account.invoice.line.tree</field>-->
<!-- <field name="model">account.move.line.tree.grouped.sales.purchase</field>-->
<!-- <field name="inherit_id" ref="account.view_move_line_tree_grouped_sales_purchases"/>-->
<!-- <field name="arch" type="xml">-->
<!-- <xpath expr="//field[@name='debit']" position="attributes">-->
<!-- <attribute name="digits">[16, 2]</attribute>-->
<!-- </xpath>-->
<!-- </field>-->
<!-- </record>-->
</data>
</odoo>

3
sale_discount_total/views/invoice_report.xml

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data>
<!--inheriting 'report_invoice_document' template and adding amount_discount value -->
<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)"/>
@ -15,6 +15,5 @@
</tr>
</xpath>
</template>
</data>
</odoo>

3
sale_discount_total/views/res_config_view.xml → sale_discount_total/views/res_config_views.xml

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<!--inheriting 'res.config.settings' and adding fields-->
<record id="res_config_settings_view_form_sale_discount" model="ir.ui.view">
<field name="name">res.config.settings.view.form.inherit.sale.discount</field>
<field name="model">res.config.settings</field>
@ -7,7 +8,6 @@
<field name="inherit_id" ref="sale.res_config_settings_view_form" />
<field name="arch" type="xml">
<xpath expr="//div[@data-key='sale_management']/div[hasclass('o_settings_container')][2]/div[hasclass('o_setting_box')][2]" position="after">
<div class="col-xs-12 col-md-6 o_setting_box">
<div class="o_setting_left_pane">
<field name="so_order_approval"/>
@ -26,7 +26,6 @@
</div>
</div>
</div>
</xpath>
</field>
</record>

3
sale_discount_total/views/sale_order_report.xml

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data>
<!--inheriting 'report_saleorder_document' template and adding amount_discount value -->
<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)"/>
@ -16,6 +16,5 @@
</tr>
</xpath>
</template>
</data>
</odoo>

13
sale_discount_total/views/sale_order_templates.xml

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8" ?>
<odoo>
<!--inheriting 'sale_order_portal_content' template and updating precision of discount value -->
<template id="sale_order_portal_content_inherit_sale_discount_total" name="Order Discount" inherit_id="sale.sale_order_portal_content">
<xpath expr="//td[@t-if='display_discount']" position="replace">
<td t-if="display_discount" t-attf-class="text-right {{ 'd-none d-sm-table-cell' if report_type == 'html' else '' }}">
<strong t-if="line.discount &gt; 0" class="text-info">
<t t-esc="line.discount" t-options='{"widget": "float", "decimal_precision": "Product Price"}'/>%
</strong>
</td>
</xpath>
</template>
</odoo>

4
sale_discount_total/views/sale_view.xml → sale_discount_total/views/sale_order_view.xml

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data>
<!--inheriting 'sale.order' and adding fields-->
<record id="discount_sale_view_form" model="ir.ui.view">
<field name="name">discount.sale.order.form</field>
<field name="model">sale.order</field>
@ -40,7 +40,6 @@
</group>
<div class="oe_clear"/>
</group>
</xpath>
<!-- Roundoff the discount field -->
<xpath expr="//field[@name='order_line']/tree/field[@name='discount']" position="attributes">
@ -48,6 +47,5 @@
</xpath>
</field>
</record>
</data>
</odoo>
Loading…
Cancel
Save