Skip to content

Commit

Permalink
[IMP] base_global_discount: Add check global discount in product
Browse files Browse the repository at this point in the history
  • Loading branch information
Rferri44-S73 authored and miguel-S73 committed Mar 15, 2024
1 parent 5be6ea5 commit 37e6539
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 0 deletions.
1 change: 1 addition & 0 deletions base_global_discount/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"security/security.xml",
"security/ir.model.access.csv",
"views/global_discount_views.xml",
"views/product_view.xml",
"views/res_partner_views.xml",
],
"application": False,
Expand Down
2 changes: 2 additions & 0 deletions base_global_discount/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
from . import global_discount
from . import product_product
from . import product_template
from . import res_partner
14 changes: 14 additions & 0 deletions base_global_discount/models/product_product.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Copyright 2023 Studio73 - Rafa Ferri <rafa.ferri@studio73.es>
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).

from odoo import fields, models


class ProductProduct(models.Model):
_inherit = "product.product"

not_apply_global_discount = fields.Boolean(
string="Don't apply global discount",
help="If this checkbox is ticked, it means changing global discount on sale order "
"won't impact sale order lines with this related product.",
)
38 changes: 38 additions & 0 deletions base_global_discount/models/product_template.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Copyright 2023 Studio73 - Rafa Ferri <rafa.ferri@studio73.es>
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).

from odoo import api, fields, models


class ProductTemplate(models.Model):
_inherit = "product.template"

not_apply_global_discount = fields.Boolean(
string="Don't apply global discount",
search="_search_not_apply_discount_apply",
compute="_compute_apply_discount_apply",
inverse="_inverse_apply_discount_apply",
help="If this checkbox is not ticked, it means changing global discount on sale order "
"won't impact sale order lines with this related product.",
)

def _search_not_apply_discount_apply(self, operator, value):
templates = self.with_context(active_test=False).search(

Check warning on line 20 in base_global_discount/models/product_template.py

View check run for this annotation

Codecov / codecov/patch

base_global_discount/models/product_template.py#L20

Added line #L20 was not covered by tests
[("product_variant_ids.not_apply_global_discount", operator, value)]
)
return [("id", "in", templates.ids)]

Check warning on line 23 in base_global_discount/models/product_template.py

View check run for this annotation

Codecov / codecov/patch

base_global_discount/models/product_template.py#L23

Added line #L23 was not covered by tests

@api.depends("product_variant_ids.not_apply_global_discount")
def _compute_apply_discount_apply(self):
self.not_apply_global_discount = True

Check warning on line 27 in base_global_discount/models/product_template.py

View check run for this annotation

Codecov / codecov/patch

base_global_discount/models/product_template.py#L27

Added line #L27 was not covered by tests
for template in self:
if len(template.product_variant_ids) == 1:
template.not_apply_global_discount = (

Check warning on line 30 in base_global_discount/models/product_template.py

View check run for this annotation

Codecov / codecov/patch

base_global_discount/models/product_template.py#L30

Added line #L30 was not covered by tests
template.product_variant_ids.not_apply_global_discount
)

def _inverse_apply_discount_apply(self):
if len(self.product_variant_ids) == 1:
self.product_variant_ids.not_apply_global_discount = (

Check warning on line 36 in base_global_discount/models/product_template.py

View check run for this annotation

Codecov / codecov/patch

base_global_discount/models/product_template.py#L36

Added line #L36 was not covered by tests
self.not_apply_global_discount
)
29 changes: 29 additions & 0 deletions base_global_discount/views/product_view.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<record id="product_normal_form_view" model="ir.ui.view">
<field name="name">product.only.form</field>
<field name="model">product.product</field>
<field name="priority" eval="16" />
<field name="inherit_id" ref="product.product_normal_form_view" />
<field name="arch" type="xml">
<xpath expr="//group[@name='group_standard_price']" position="inside">
<field name="not_apply_global_discount" />
</xpath>
</field>
</record>
<record id="product_template_only_form_view" model="ir.ui.view">
<field name="name">product.template.only.form</field>
<field name="model">product.template</field>
<field name="priority" eval="24" />
<field name="inherit_id" ref="product.product_template_only_form_view" />
<field name="arch" type="xml">
<xpath expr="//group[@name='group_standard_price']" position="inside">
<field
name="not_apply_global_discount"
invisible="product_variant_count > 1"
/>
</xpath>
</field>
</record>

</odoo>

0 comments on commit 37e6539

Please sign in to comment.