Skip to content

Commit

Permalink
Merge branch '12.0-imp-sale_discount_display_amount-backport-from-14.…
Browse files Browse the repository at this point in the history
…0-pr-2951+31' of git+ssh://github.com/sergiocorato/sale-workflow into 12.0
  • Loading branch information
Pretecno committed Jun 13, 2024
2 parents 93796f3 + ffbf685 commit 4d5494c
Show file tree
Hide file tree
Showing 11 changed files with 104 additions and 22 deletions.
2 changes: 1 addition & 1 deletion sale_discount_display_amount/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
'summary': """
This addon intends to display the amount of the discount computed on
sale_order_line and sale_order level""",
'version': '12.0.1.2.0',
'version': '12.0.1.3.0',
'license': 'AGPL-3',
'author': 'ACSONE SA/NV,Odoo Community Association (OCA)',
'website': 'https://github.com/OCA/sale-workflow',
Expand Down
2 changes: 2 additions & 0 deletions sale_discount_display_amount/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@
COLUMNS = (
("sale_order", "price_total_no_discount"),
("sale_order", "discount_total"),
("sale_order", "discount_subtotal"),
("sale_order", "price_subtotal_no_discount"),
("sale_order_line", "price_subtotal_no_discount"),
("sale_order_line", "price_total_no_discount"),
("sale_order_line", "discount_total"),
("sale_order_line", "discount_subtotal"),
)


Expand Down
36 changes: 24 additions & 12 deletions sale_discount_display_amount/i18n/it.po
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * sale_discount_display_amount
# * sale_discount_display_amount
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 12.0\n"
"Report-Msgid-Bugs-To: \n"
"PO-Revision-Date: 2023-09-03 13:37+0000\n"
"Last-Translator: Francesco Foresti <[email protected]>\n"
"Language-Team: none\n"
"Language: it\n"
"POT-Creation-Date: 2024-03-11 08:38+0000\n"
"PO-Revision-Date: 2024-03-11 08:38+0000\n"
"Last-Translator: <>\n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: nplurals=2; plural=n != 1;\n"
"X-Generator: Weblate 4.17\n"
"Plural-Forms: \n"

#. module: sale_discount_display_amount
#: model_terms:ir.ui.view,arch_db:sale_discount_display_amount.report_saleorder_document_inherit
Expand All @@ -26,11 +25,17 @@ msgstr "<strong>Subtotale Sconto</strong>"
msgid "<strong>Subtotal Without Discount</strong>"
msgstr "<strong>Subtotale senza sconto</strong>"

#. module: sale_discount_display_amount
#: model:ir.model.fields,field_description:sale_discount_display_amount.field_sale_order__discount_subtotal
#: model:ir.model.fields,field_description:sale_discount_display_amount.field_sale_order_line__discount_subtotal
msgid "Discount Subtotal"
msgstr "Sconto concordato"

#. module: sale_discount_display_amount
#: model:ir.model.fields,field_description:sale_discount_display_amount.field_sale_order__discount_total
#: model:ir.model.fields,field_description:sale_discount_display_amount.field_sale_order_line__discount_total
msgid "Discount Subtotal"
msgstr "Subtotale sconto"
msgid "Discount total"
msgstr "Sconto concordato"

#. module: sale_discount_display_amount
#: model:ir.model,name:sale_discount_display_amount.model_sale_order
Expand All @@ -40,10 +45,17 @@ msgstr "Ordine di vendita"
#. module: sale_discount_display_amount
#: model:ir.model,name:sale_discount_display_amount.model_sale_order_line
msgid "Sales Order Line"
msgstr "Riga ordine di vendita"
msgstr "Linea d'ordine di vendita"

#. module: sale_discount_display_amount
#: model:ir.model.fields,field_description:sale_discount_display_amount.field_sale_order__price_subtotal_no_discount
#: model:ir.model.fields,field_description:sale_discount_display_amount.field_sale_order_line__price_subtotal_no_discount
msgid "Subtotal Without Discount"
msgstr "Imponibile parziale"

#. module: sale_discount_display_amount
#: model:ir.model.fields,field_description:sale_discount_display_amount.field_sale_order__price_total_no_discount
#: model:ir.model.fields,field_description:sale_discount_display_amount.field_sale_order_line__price_total_no_discount
msgid "Subtotal Without Discount"
msgstr "Subtotale senza sconto"
msgid "Total Without Discount"
msgstr "Imponibile parziale"

18 changes: 16 additions & 2 deletions sale_discount_display_amount/i18n/sale_discount_display_amount.pot
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 12.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2024-03-11 09:07+0000\n"
"PO-Revision-Date: 2024-03-11 09:07+0000\n"
"Last-Translator: <>\n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
Expand All @@ -23,10 +25,16 @@ msgstr ""
msgid "<strong>Subtotal Without Discount</strong>"
msgstr ""

#. module: sale_discount_display_amount
#: model:ir.model.fields,field_description:sale_discount_display_amount.field_sale_order__discount_subtotal
#: model:ir.model.fields,field_description:sale_discount_display_amount.field_sale_order_line__discount_subtotal
msgid "Discount Subtotal"
msgstr ""

#. module: sale_discount_display_amount
#: model:ir.model.fields,field_description:sale_discount_display_amount.field_sale_order__discount_total
#: model:ir.model.fields,field_description:sale_discount_display_amount.field_sale_order_line__discount_total
msgid "Discount Subtotal"
msgid "Discount total"
msgstr ""

#. module: sale_discount_display_amount
Expand All @@ -39,9 +47,15 @@ msgstr ""
msgid "Sales Order Line"
msgstr ""

#. module: sale_discount_display_amount
#: model:ir.model.fields,field_description:sale_discount_display_amount.field_sale_order__price_subtotal_no_discount
#: model:ir.model.fields,field_description:sale_discount_display_amount.field_sale_order_line__price_subtotal_no_discount
msgid "Subtotal Without Discount"
msgstr ""

#. module: sale_discount_display_amount
#: model:ir.model.fields,field_description:sale_discount_display_amount.field_sale_order__price_total_no_discount
#: model:ir.model.fields,field_description:sale_discount_display_amount.field_sale_order_line__price_total_no_discount
msgid "Subtotal Without Discount"
msgid "Total Without Discount"
msgstr ""

Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import logging

from odoo import SUPERUSER_ID
from odoo.api import Environment

_logger = logging.getLogger(__name__)


def migrate(cr, version):
_logger.info("Compute discount columns")
env = Environment(cr, SUPERUSER_ID, {})

query = """
select distinct order_id from sale_order_line where discount > 0.0;
"""

cr.execute(query)
order_ids = cr.fetchall()

orders = env["sale.order"].search([("id", "in", order_ids)])
orders.mapped("order_line")._compute_discount()
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import logging

from odoo.tools.sql import column_exists, create_column

_logger = logging.getLogger(__name__)

COLUMNS = (
("sale_order", "discount_subtotal"),
("sale_order_line", "discount_subtotal"),
)


def migrate(cr, version):
for table, column in COLUMNS:
if not column_exists(cr, table, column):
_logger.info("Create discount column %s in database", column)
create_column(cr, table, column, "numeric")
11 changes: 10 additions & 1 deletion sale_discount_display_amount/models/sale_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ class SaleOrder(models.Model):
_inherit = 'sale.order'

discount_total = fields.Monetary(
compute="_compute_discount_total",
string="Discount total",
currency_field="currency_id",
store=True,
)
discount_subtotal = fields.Monetary(
compute='_compute_discount_total',
string='Discount Subtotal',
currency_field='currency_id',
Expand All @@ -21,7 +27,7 @@ class SaleOrder(models.Model):
)
price_total_no_discount = fields.Monetary(
compute='_compute_discount_total',
string='Subtotal Without Discount',
string='Total Without Discount',
currency_field='currency_id',
store=True)

Expand All @@ -37,6 +43,8 @@ def _get_compute_discount_total_depends(self):
def _compute_discount_total(self):
for order in self:
discount_total = sum(order.order_line.mapped('discount_total'))
discount_subtotal = sum(
order.order_line.mapped("discount_subtotal"))
price_subtotal_no_discount = sum(
order.order_line.mapped('price_subtotal_no_discount')
)
Expand All @@ -46,6 +54,7 @@ def _compute_discount_total(self):
order.update(
{
'discount_total': discount_total,
"discount_subtotal": discount_subtotal,
'price_subtotal_no_discount': price_subtotal_no_discount,
'price_total_no_discount': price_total_no_discount,
}
Expand Down
7 changes: 6 additions & 1 deletion sale_discount_display_amount/models/sale_order_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ class SaleOrderLine(models.Model):
_inherit = 'sale.order.line'

discount_total = fields.Monetary(
compute="_compute_amount", string="Discount total", store=True
)
discount_subtotal = fields.Monetary(
compute='_compute_amount',
string='Discount Subtotal',
store=True)
Expand All @@ -19,7 +22,7 @@ class SaleOrderLine(models.Model):
)
price_total_no_discount = fields.Monetary(
compute='_compute_amount',
string='Subtotal Without Discount',
string='Total Without Discount',
store=True)

def _compute_discount(self):
Expand All @@ -39,9 +42,11 @@ def _compute_discount(self):
price_subtotal_no_discount = taxes['total_excluded']
price_total_no_discount = taxes['total_included']
discount_total = price_total_no_discount - line.price_total
discount_subtotal = price_subtotal_no_discount - line.price_subtotal

line.update({
'discount_total': discount_total,
"discount_subtotal": discount_subtotal,
'price_subtotal_no_discount': price_subtotal_no_discount,
'price_total_no_discount': price_total_no_discount
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,4 @@ def test_sale_discount_value(self):
self.assertAlmostEqual(so.price_subtotal_no_discount, 30.75)
self.assertAlmostEqual(so.price_total_no_discount, 35.36)
self.assertAlmostEqual(so.discount_total, 3.53)
self.assertAlmostEqual(so.discount_subtotal, 3.07)
7 changes: 4 additions & 3 deletions sale_discount_display_amount/views/sale_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@
<field name="arch" type="xml">
<data>
<xpath expr="//field[@name='amount_untaxed']" position="before">
<field name="price_subtotal_no_discount" />
<field name="price_total_no_discount" />
<field name="discount_total"/>
<field name="price_subtotal_no_discount" groups="account.group_show_line_subtotals_tax_excluded" />
<field name="discount_subtotal" groups="account.group_show_line_subtotals_tax_excluded" />
<field name="price_total_no_discount" groups="account.group_show_line_subtotals_tax_included" />
<field name="discount_total" groups="account.group_show_line_subtotals_tax_included" />
</xpath>
</data>
</field>
Expand Down
4 changes: 2 additions & 2 deletions sale_order_lot_selection/models/sale.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ class SaleOrderLine(models.Model):
@api.multi
@api.onchange('product_id')
def product_id_change(self):
result = super(SaleOrderLine, self).product_id_change()
res = super(SaleOrderLine, self).product_id_change()
self.lot_id = False
return result
return res

@api.onchange('product_id')
def _onchange_product_id_set_lot_domain(self):
Expand Down

0 comments on commit 4d5494c

Please sign in to comment.