-
-
Notifications
You must be signed in to change notification settings - Fork 276
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[IMP] base_global_discount: Add check global discount in product
- Loading branch information
1 parent
5be6ea5
commit 37e6539
Showing
5 changed files
with
84 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.", | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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( | ||
[("product_variant_ids.not_apply_global_discount", operator, value)] | ||
) | ||
return [("id", "in", templates.ids)] | ||
|
||
@api.depends("product_variant_ids.not_apply_global_discount") | ||
def _compute_apply_discount_apply(self): | ||
self.not_apply_global_discount = True | ||
for template in self: | ||
if len(template.product_variant_ids) == 1: | ||
template.not_apply_global_discount = ( | ||
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 = ( | ||
self.not_apply_global_discount | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |