Skip to content
Closed
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
2 changes: 2 additions & 0 deletions .copier-answers.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ org_name: Odoo Community Association (OCA)
org_slug: OCA
rebel_module_groups:
- sale_packaging_default,sale_order_product_recommendation,sale_order_product_recommendation_packaging_default,sale_order_product_recommendation_elaboration
- sale_triple_discount
- sale_fixed_discount
repo_description: 'TODO: add repo description.'
repo_name: sale-workflow
repo_slug: sale-workflow
Expand Down
18 changes: 16 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,24 @@ jobs:
name: test with OCB
makepot: "true"
- container: ghcr.io/oca/oca-ci/py3.10-odoo16.0:latest
exclude: "sale_packaging_default,sale_order_product_recommendation,sale_order_product_recommendation_packaging_default,sale_order_product_recommendation_elaboration"
include: "sale_triple_discount"
name: test with Odoo
- container: ghcr.io/oca/oca-ci/py3.10-ocb16.0:latest
exclude: "sale_packaging_default,sale_order_product_recommendation,sale_order_product_recommendation_packaging_default,sale_order_product_recommendation_elaboration"
include: "sale_triple_discount"
name: test with OCB
makepot: "true"
- container: ghcr.io/oca/oca-ci/py3.10-odoo16.0:latest
include: "sale_fixed_discount"
name: test with Odoo
- container: ghcr.io/oca/oca-ci/py3.10-ocb16.0:latest
include: "sale_fixed_discount"
name: test with OCB
makepot: "true"
- container: ghcr.io/oca/oca-ci/py3.10-odoo16.0:latest
exclude: "sale_packaging_default,sale_order_product_recommendation,sale_order_product_recommendation_packaging_default,sale_order_product_recommendation_elaboration,sale_triple_discount,sale_fixed_discount"
name: test with Odoo
- container: ghcr.io/oca/oca-ci/py3.10-ocb16.0:latest
exclude: "sale_packaging_default,sale_order_product_recommendation,sale_order_product_recommendation_packaging_default,sale_order_product_recommendation_elaboration,sale_triple_discount,sale_fixed_discount"
name: test with OCB
makepot: "true"
services:
Expand Down
1 change: 1 addition & 0 deletions sale_fixed_discount/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"application": False,
"installable": True,
"depends": ["sale", "account_invoice_fixed_discount"],
"excludes": ["sale_triple_discount"],
"data": [
"security/res_groups.xml",
"reports/report_sale_order.xml",
Expand Down
11 changes: 7 additions & 4 deletions sale_fixed_discount/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@

/*
:Author: David Goodger (goodger@python.org)
:Id: $Id: html4css1.css 8954 2022-01-20 10:10:25Z milde $
:Id: $Id: html4css1.css 9511 2024-01-13 09:50:07Z milde $
:Copyright: This stylesheet has been placed in the public domain.

Default cascading style sheet for the HTML output of Docutils.
Despite the name, some widely supported CSS2 features are used.

See https://docutils.sourceforge.io/docs/howto/html-stylesheets.html for how to
customize this style sheet.
Expand Down Expand Up @@ -274,7 +275,7 @@
margin-left: 2em ;
margin-right: 2em }

pre.code .ln { color: grey; } /* line numbers */
pre.code .ln { color: gray; } /* line numbers */
pre.code, code { background-color: #eeeeee }
pre.code .comment, code .comment { color: #5C6576 }
pre.code .keyword, code .keyword { color: #3B0D06; font-weight: bold }
Expand All @@ -300,7 +301,7 @@
span.pre {
white-space: pre }

span.problematic {
span.problematic, pre.problematic {
color: red }

span.section-subtitle {
Expand Down Expand Up @@ -436,7 +437,9 @@ <h2><a class="toc-backref" href="#toc-entry-7">Contributors</a></h2>
<div class="section" id="maintainers">
<h2><a class="toc-backref" href="#toc-entry-8">Maintainers</a></h2>
<p>This module is maintained by the OCA.</p>
<a class="reference external image-reference" href="https://odoo-community.org"><img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" /></a>
<a class="reference external image-reference" href="https://odoo-community.org">
<img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" />
</a>
<p>OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.</p>
Expand Down
6 changes: 5 additions & 1 deletion sale_order_general_discount/models/sale_order_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,9 @@ def _compute_discount(self):
# set again to 0 to remove the discount on all the lines at the same
# time
if line.order_id.general_discount or line.order_id._origin.general_discount:
line.discount = line.order_id.general_discount
if "discount1" in self._fields:
# Compatibility with sale_triple_discount module
line.discount1 = line.order_id.general_discount
else:
line.discount = line.order_id.general_discount
return res
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class ResConfigSettings(models.TransientModel):

general_discount = fields.Selection(
[
("discount", "Discount"),
("discount1", "Discount 1"),
("discount2", "Discount 2"),
("discount3", "Discount 3"),
],
Expand All @@ -15,7 +15,7 @@ class ResConfigSettings(models.TransientModel):
)
pricelist_discount = fields.Selection(
[
("discount", "Discount"),
("discount1", "Discount 1"),
("discount2", "Discount 2"),
("discount3", "Discount 3"),
],
Expand Down
4 changes: 2 additions & 2 deletions sale_order_general_discount_triple/models/sale_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def onchange_general_discount(self):
self.env["ir.config_parameter"]
.sudo()
.get_param(
"sale_order_general_discount_triple.general_discount", "discount"
"sale_order_general_discount_triple.general_discount", "discount1"
)
)
if general_discount != "no_apply":
Expand All @@ -20,7 +20,7 @@ def onchange_general_discount(self):
def _create_delivery_line(self, carrier, price_unit):
res = super()._create_delivery_line(carrier, price_unit)
for line in self.order_line:
line._compute_discount()
line._compute_discount1()
line._compute_discount2()
line._compute_discount3()
return res
17 changes: 9 additions & 8 deletions sale_order_general_discount_triple/models/sale_order_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,22 @@
class SaleOrderLine(models.Model):
_inherit = "sale.order.line"

discount1 = fields.Float(compute="_compute_discount1", store=True, readonly=False)
discount2 = fields.Float(compute="_compute_discount2", store=True, readonly=False)
discount3 = fields.Float(compute="_compute_discount3", store=True, readonly=False)

@api.depends("product_id", "product_uom", "product_uom_qty")
def _compute_discount(self):
def _compute_discount1(self):
pricelist_discount = self._get_discount_field_position("pricelist_discount")
general_discount = self._get_discount_field_position("general_discount")
if "discount" not in [pricelist_discount, general_discount]:
self.update({"discount": 0.0})
if "discount1" not in [pricelist_discount, general_discount]:
self.update({"discount1": 0.0})
return
for line in self:
if pricelist_discount == "discount":
line.update({"discount": line._get_pricelist_discount()})
elif general_discount == "discount":
line.update({"discount": line.order_id.general_discount})
if pricelist_discount == "discount1":
line.update({"discount1": line._get_pricelist_discount()})
elif general_discount == "discount1":
line.update({"discount1": line.order_id.general_discount})
return

@api.depends("product_id", "product_uom", "product_uom_qty")
Expand Down Expand Up @@ -71,6 +72,6 @@ def _get_discount_field_position(self, field_name):
self.env["ir.config_parameter"]
.sudo()
.get_param(
"sale_order_general_discount_triple.{}".format(field_name), "discount"
"sale_order_general_discount_triple.{}".format(field_name), "discount1"
)
)
4 changes: 2 additions & 2 deletions sale_order_general_discount_triple/tests/test_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def setUpClass(cls):
)
setting_form = Form(cls.env["res.config.settings"])
setting_form.general_discount = "discount2"
setting_form.pricelist_discount = "discount"
setting_form.pricelist_discount = "discount1"
setting_form.group_discount_per_so_line = True
setting_form.save().set_values()

Expand All @@ -41,4 +41,4 @@ def test_action_result(self):
line.product_id = self.product
sale = sale_form.save()
self.assertEqual(sale.order_line.discount2, 10)
self.assertEqual(sale.order_line.discount, 20)
self.assertEqual(sale.order_line.discount1, 20)
1 change: 1 addition & 0 deletions sale_triple_discount/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ Contributors
* Pimolnat Suntian <pimolnats@ecosoft.co.th>
* Denis Leemann <denis.leemann@camptocamp.com>
* Manuel Regidor <manuel.regidor@sygel.es>
* Akim Juillerat <akim.juillerat@camptocamp.com>

Maintainers
~~~~~~~~~~~
Expand Down
1 change: 1 addition & 0 deletions sale_triple_discount/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
from . import models
from .hooks import post_load
4 changes: 3 additions & 1 deletion sale_triple_discount/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,16 @@

{
"name": "Sale Triple Discount",
"version": "16.0.1.0.4",
"version": "16.0.2.0.0",
"category": "Sales",
"author": "ADHOC SA, Agile Business Group, Tecnativa, "
"Odoo Community Association (OCA)",
"website": "https://github.com/OCA/sale-workflow",
"license": "AGPL-3",
"summary": "Manage triple discount on sale order lines",
"depends": ["sale_management", "account_invoice_triple_discount"],
"excludes": ["sale_fixed_discount"],
"data": ["views/sale_order_report.xml", "views/sale_order_view.xml"],
"installable": True,
"post_load": "post_load",
}
24 changes: 24 additions & 0 deletions sale_triple_discount/hooks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Copyright 2024 Camptocamp SA
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl)
import logging

import pkg_resources

from odoo.modules.module import get_manifest

_logger = logging.getLogger(__name__)


def post_load():
account_invoice_triple_discount_manifest = get_manifest(
"account_invoice_triple_discount"
)
if not pkg_resources.parse_version(
account_invoice_triple_discount_manifest["version"]
) >= pkg_resources.parse_version("16.0.2.0.0"):
msg = (

Check warning on line 19 in sale_triple_discount/hooks.py

View check run for this annotation

Codecov / codecov/patch

sale_triple_discount/hooks.py#L19

Added line #L19 was not covered by tests
"Module sale_triple_discount requires module "
"account_invoice_triple_discount >= 16.0.2.0.0"
)
_logger.error(msg)
raise Exception(msg)

Check warning on line 24 in sale_triple_discount/hooks.py

View check run for this annotation

Codecov / codecov/patch

sale_triple_discount/hooks.py#L23-L24

Added lines #L23 - L24 were not covered by tests
23 changes: 23 additions & 0 deletions sale_triple_discount/migrations/16.0.2.0.0/post-migrate.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Copyright 2024 Camptocamp SA
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl)

from openupgradelib import openupgrade


@openupgrade.logging()
def compute_discount(env):
lines_with_discount = env["sale.order.line"].search(
[
"|",
"|",
("discount1", "!=", 0),
("discount2", "!=", 0),
("discount3", "!=", 0),
]
)
lines_with_discount._compute_discount_consolidated()


@openupgrade.migrate()
def migrate(env, version):
compute_discount(env)
32 changes: 32 additions & 0 deletions sale_triple_discount/migrations/16.0.2.0.0/pre-migrate.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Copyright 2024 Camptocamp SA
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl)
from openupgradelib import openupgrade


def migrate_discount_to_discount1(env):
openupgrade.add_fields(
env,
[
(
"discount1",
"sale.order.line",
"sale_order_line",
"float",
"numeric",
"sale_triple_discount",
0.0,
)
],
)
openupgrade.logged_query(
env.cr,
"""
UPDATE sale_order_line
SET discount1 = discount;
""",
)


@openupgrade.migrate()
def migrate(env, version):
migrate_discount_to_discount1(env)
Loading
Loading