Browse Source

Jun 03: [FIX] Bug Fixed 'sale_discount_total'

pull/164/merge
RisvanaCybro 11 months ago
parent
commit
59b38f2abe
  1. 20
      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. 6
      sale_discount_total/reports/invoice_report.py
  8. 16
      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

20
sale_discount_total/__manifest__.py

@ -22,7 +22,7 @@
{ {
'name': 'Sale Discount on Total Amount', 'name': 'Sale Discount on Total Amount',
'version': '14.0.1.1.0', 'version': '14.0.1.2.0',
'category': 'Sales Management', 'category': 'Sales Management',
'live_test_url': 'https://www.youtube.com/watch?v=CigmHe9iC4s&feature=youtu.be', '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", 'summary': "Discount on Total in Sale and Invoice With Discount Limit and Approval",
@ -32,20 +32,22 @@
'description': """ 'description': """
Sale Discount for Total Amount Sale Discount for Total Amount
======================= ==============================
Module to manage discount on total amount in Sale. Module to manage discount on total amount in Sale.
as an specific amount or percentage as an specific amount or percentage
""", """,
'depends': ['sale', 'depends': [
'account', 'delivery' 'sale',
], 'account',
'delivery'
],
'data': [ 'data': [
'views/sale_view.xml', 'views/sale_order_view.xml',
'views/account_invoice_view.xml', 'views/account_invoice_views.xml',
'views/invoice_report.xml', 'views/invoice_report.xml',
'views/sale_order_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'], 'images': ['static/description/banner.png'],
'license': 'AGPL-3', '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 #### 08.10.2020
#### Version 14.0.1.0.0 #### Version 14.0.1.0.0
@ -10,5 +10,8 @@ Initial commit for Sale Discount On Total Amount
#### FIX #### FIX
discount roundoff 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/>. # If not, see <http://www.gnu.org/licenses/>.
# #
############################################################################# #############################################################################
from . import sale from . import sale_order
from . import account_invoice from . import account_invoice
from . import discount_approval from . import discount_approval

75
sale_discount_total/models/account_invoice.py

@ -60,14 +60,11 @@ class AccountInvoice(models.Model):
total = 0.0 total = 0.0
total_currency = 0.0 total_currency = 0.0
currencies = set() currencies = set()
for line in move.line_ids: for line in move.line_ids:
if line.currency_id: if line.currency_id:
currencies.add(line.currency_id) currencies.add(line.currency_id)
if move.is_invoice(include_receipts=True): if move.is_invoice(include_receipts=True):
# === Invoices === # === Invoices ===
if not line.exclude_from_invoice_tab: if not line.exclude_from_invoice_tab:
# Untaxed amount. # Untaxed amount.
total_untaxed += line.balance total_untaxed += line.balance
@ -80,7 +77,8 @@ class AccountInvoice(models.Model):
total_tax_currency += line.amount_currency total_tax_currency += line.amount_currency
total += line.balance total += line.balance
total_currency += line.amount_currency 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. # Residual amount.
total_to_pay += line.balance total_to_pay += line.balance
total_residual += line.amount_residual total_residual += line.amount_residual
@ -96,51 +94,67 @@ class AccountInvoice(models.Model):
else: else:
sign = -1 sign = -1
if move.discount_type == 'percent': 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: else:
move.amount_discount = move.discount_rate move.amount_discount = move.discount_rate
move.amount_untaxed = sign * (total_untaxed_currency if len(currencies) == 1 else total_untaxed) move.amount_untaxed = sign * (total_untaxed_currency if len(
move.amount_tax = sign * (total_tax_currency if len(currencies) == 1 else total_tax) currencies) == 1 else total_untaxed)
move.amount_total = sign * (total_currency if len(currencies) == 1 else total) move.amount_tax = sign * (
move.amount_residual = -sign * (total_residual_currency if len(currencies) == 1 else total_residual) 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_untaxed_signed = -total_untaxed
move.amount_tax_signed = -total_tax 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 move.amount_residual_signed = total_residual
currency = len(
currency = len(currencies) == 1 and currencies.pop() or move.company_id.currency_id currencies) == 1 and currencies.pop() or move.company_id.currency_id
# Compute 'payment_state'. # Compute 'payment_state'.
new_pmt_state = 'not_paid' if move.move_type != 'entry' else False new_pmt_state = 'not_paid' if move.move_type != 'entry' else False
if move.is_invoice(
if move.is_invoice(include_receipts=True) and move.state == 'posted': include_receipts=True) and move.state == 'posted':
if currency.is_zero(move.amount_residual): 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' new_pmt_state = 'paid'
else: else:
new_pmt_state = move._get_invoice_in_payment_state() 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' new_pmt_state = 'partial'
if new_pmt_state == 'paid' and move.move_type in (
if new_pmt_state == 'paid' and move.move_type in ('in_invoice', 'out_invoice', 'entry'): '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_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( 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 # 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') reverse_moves_full_recs = reverse_moves.mapped(
if reverse_moves_full_recs.mapped('reconciled_line_ids.move_id').filtered(lambda x: x not in ( 'line_ids.full_reconcile_id')
reverse_moves + reverse_moves_full_recs.mapped('exchange_move_id'))) == move: 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' new_pmt_state = 'reversed'
move.payment_state = new_pmt_state move.payment_state = new_pmt_state
discount_type = fields.Selection([('percent', 'Percentage'), ('amount', 'Amount')], string='Discount Type', discount_type = fields.Selection(
readonly=True, states={'draft': [('readonly', False)]}, default='percent') [('percent', 'Percentage'), ('amount', 'Amount')],
discount_rate = fields.Float('Discount Amount', digits=(16, 2), readonly=True, 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)]}) 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') track_visibility='always')
@api.onchange('discount_type', 'discount_rate', 'invoice_line_ids') @api.onchange('discount_type', 'discount_rate', 'invoice_line_ids')
@ -163,7 +177,6 @@ class AccountInvoice(models.Model):
line._onchange_price_subtotal() line._onchange_price_subtotal()
inv._compute_invoice_taxes_by_group() inv._compute_invoice_taxes_by_group()
#
def button_dummy(self): def button_dummy(self):
self.supply_rate() 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): 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 return invoice_vals
def button_dummy(self): def button_dummy(self):
self.supply_rate() self.supply_rate()
return True return True

6
sale_discount_total/reports/invoice_report.py

@ -29,7 +29,5 @@ class AccountInvoiceReport(models.Model):
discount = fields.Float('Discount', readonly=True) discount = fields.Float('Discount', readonly=True)
def _select(self): def _select(self):
res = super(AccountInvoiceReport,self)._select() res = super(AccountInvoiceReport, self)._select()
select_str = res + """, line.discount AS discount """ return res + """, line.discount AS discount """
return select_str

16
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"?> <?xml version="1.0" encoding="utf-8"?>
<odoo> <odoo>
<data> <data>
<!--inheriting 'account.move' and adding fields-->
<record id="discount_account_invoice_view_form" model="ir.ui.view"> <record id="discount_account_invoice_view_form" model="ir.ui.view">
<field name="name">discount.account.invoice</field> <field name="name">discount.account.invoice</field>
<field name="model">account.move</field> <field name="model">account.move</field>
@ -11,7 +11,7 @@
<attribute name="digits">[16, 2]</attribute> <attribute name="digits">[16, 2]</attribute>
</xpath> </xpath>
<xpath expr="//field[@name='amount_untaxed']" position="after"> <xpath expr="//field[@name='amount_untaxed']" position="after">
<field name="amount_discount"/> <field name="amount_discount"/>
</xpath> </xpath>
<xpath expr="//field[@name='narration']" position="after"> <xpath expr="//field[@name='narration']" position="after">
<div> <div>
@ -25,17 +25,5 @@
</xpath> </xpath>
</field> </field>
</record> </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> </data>
</odoo> </odoo>

3
sale_discount_total/views/invoice_report.xml

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<odoo> <odoo>
<data> <data>
<!--inheriting 'report_invoice_document' template and adding amount_discount value -->
<template id="report_invoice_customized" inherit_id="account.report_invoice_document"> <template id="report_invoice_customized" inherit_id="account.report_invoice_document">
<xpath expr="//span[@t-field='line.discount']" position="replace"> <xpath expr="//span[@t-field='line.discount']" position="replace">
<span t-esc="'%.2f'%(line.discount)"/> <span t-esc="'%.2f'%(line.discount)"/>
@ -15,6 +15,5 @@
</tr> </tr>
</xpath> </xpath>
</template> </template>
</data> </data>
</odoo> </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"?> <?xml version="1.0" encoding="utf-8"?>
<odoo> <odoo>
<!--inheriting 'res.config.settings' and adding fields-->
<record id="res_config_settings_view_form_sale_discount" model="ir.ui.view"> <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="name">res.config.settings.view.form.inherit.sale.discount</field>
<field name="model">res.config.settings</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="inherit_id" ref="sale.res_config_settings_view_form" />
<field name="arch" type="xml"> <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"> <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="col-xs-12 col-md-6 o_setting_box">
<div class="o_setting_left_pane"> <div class="o_setting_left_pane">
<field name="so_order_approval"/> <field name="so_order_approval"/>
@ -26,7 +26,6 @@
</div> </div>
</div> </div>
</div> </div>
</xpath> </xpath>
</field> </field>
</record> </record>

3
sale_discount_total/views/sale_order_report.xml

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<odoo> <odoo>
<data> <data>
<!--inheriting 'report_saleorder_document' template and adding amount_discount value -->
<template id="report_saleorder_customized" inherit_id="sale.report_saleorder_document"> <template id="report_saleorder_customized" inherit_id="sale.report_saleorder_document">
<xpath expr="//span[@t-field='line.discount']" position="replace"> <xpath expr="//span[@t-field='line.discount']" position="replace">
<span t-esc="'%.2f'%(line.discount)"/> <span t-esc="'%.2f'%(line.discount)"/>
@ -16,6 +16,5 @@
</tr> </tr>
</xpath> </xpath>
</template> </template>
</data> </data>
</odoo> </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"?> <?xml version="1.0" encoding="utf-8"?>
<odoo> <odoo>
<data> <data>
<!--inheriting 'sale.order' and adding fields-->
<record id="discount_sale_view_form" model="ir.ui.view"> <record id="discount_sale_view_form" model="ir.ui.view">
<field name="name">discount.sale.order.form</field> <field name="name">discount.sale.order.form</field>
<field name="model">sale.order</field> <field name="model">sale.order</field>
@ -40,7 +40,6 @@
</group> </group>
<div class="oe_clear"/> <div class="oe_clear"/>
</group> </group>
</xpath> </xpath>
<!-- Roundoff the discount field --> <!-- Roundoff the discount field -->
<xpath expr="//field[@name='order_line']/tree/field[@name='discount']" position="attributes"> <xpath expr="//field[@name='order_line']/tree/field[@name='discount']" position="attributes">
@ -48,6 +47,5 @@
</xpath> </xpath>
</field> </field>
</record> </record>
</data> </data>
</odoo> </odoo>
Loading…
Cancel
Save