Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[16.0][IMP] base_global_discount: Add check global discount in product #221

Merged
merged 1 commit into from
May 23, 2024
Merged
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
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_views.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
16 changes: 16 additions & 0 deletions base_global_discount/models/product_product.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Copyright 2024 Studio73 - Ferran Mora <[email protected]>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).

from odoo import fields, models


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

bypass_global_discount = fields.Boolean(
string="Don't apply global discount",
help=(
"If this checkbox is ticked, it means that this product will not be taken "
"into account when calculating the global discounts."
),
)
39 changes: 39 additions & 0 deletions base_global_discount/models/product_template.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Copyright 2024 Studio73 - Ferran Mora <[email protected]>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).

from odoo import api, fields, models


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

bypass_global_discount = fields.Boolean(
string="Don't apply global discount",
help=(
"If this checkbox is ticked, it means that this product will not be taken "
"into account when calculating the global discounts."
),
compute="_compute_bypass_global_discount",
inverse="_inverse_bypass_global_discount",
)

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

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

View check run for this annotation

Codecov / codecov/patch

base_global_discount/models/product_template.py#L21

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

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

View check run for this annotation

Codecov / codecov/patch

base_global_discount/models/product_template.py#L24

Added line #L24 was not covered by tests

@api.depends("product_variant_ids.bypass_global_discount")
def _compute_bypass_global_discount(self):
self.bypass_global_discount = False

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

View check run for this annotation

Codecov / codecov/patch

base_global_discount/models/product_template.py#L28

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

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

View check run for this annotation

Codecov / codecov/patch

base_global_discount/models/product_template.py#L31

Added line #L31 was not covered by tests
template.product_variant_ids.bypass_global_discount
)

def _inverse_bypass_global_discount(self):
if len(self.product_variant_ids) == 1:
self.product_variant_ids.bypass_global_discount = (

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

View check run for this annotation

Codecov / codecov/patch

base_global_discount/models/product_template.py#L37

Added line #L37 was not covered by tests
self.bypass_global_discount
)
32 changes: 32 additions & 0 deletions base_global_discount/views/product_views.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<record id="product_normal_form_view" model="ir.ui.view">
<field name="name">sale_order_global_discount.product_normal_form_view</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="bypass_global_discount"
groups="base_global_discount.group_global_discount"
/>
</xpath>
</field>
</record>
<record id="product_template_only_form_view" model="ir.ui.view">
<field name="name">product.template.sale_order_global_discount.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="bypass_global_discount"
attrs="{'invisible': [('product_variant_count', '>', 1)]}"
groups="base_global_discount.group_global_discount"
/>
</xpath>
</field>
</record>
</odoo>
Loading