Skip to content

Commit

Permalink
[MIG] sale_global_discount: Migration to 17.0
Browse files Browse the repository at this point in the history
  • Loading branch information
miguel-S73 committed Aug 14, 2024
1 parent a7355c0 commit 6c0ddbf
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 14 deletions.
4 changes: 4 additions & 0 deletions sale_global_discount/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@ Contributors

- Omar Castiñeira <omar@comunitea.com>

- `Studio73 <https://www.studio73.es>`__

- Miguel Gandia

Maintainers
-----------

Expand Down
2 changes: 1 addition & 1 deletion sale_global_discount/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
{
"name": "Sale Global Discount",
"version": "16.0.1.0.0",
"version": "17.0.1.0.0",
"category": "Sales Management",
"author": "Tecnativa," "Odoo Community Association (OCA)",
"website": "https://github.com/OCA/sale-workflow",
Expand Down
22 changes: 12 additions & 10 deletions sale_global_discount/hooks.py
Original file line number Diff line number Diff line change
@@ -1,39 +1,41 @@
from odoo.tools.sql import column_exists


def _pre_init_global_discount_fields(cr):
if not column_exists(cr, "sale_order", "amount_global_discount"):
cr.execute(
def _pre_init_global_discount_fields(env):
if not column_exists(env.cr, "sale_order", "amount_global_discount"):
env.cr.execute(
"""
ALTER TABLE "sale_order"
ADD COLUMN "amount_global_discount" double precision DEFAULT 0
"""
)
cr.execute(
env.cr.execute(
"""
ALTER TABLE "sale_order" ALTER COLUMN "amount_global_discount" DROP DEFAULT
"""
)
if not column_exists(cr, "sale_order", "amount_untaxed_before_global_discounts"):
cr.execute(
if not column_exists(
env.cr, "sale_order", "amount_untaxed_before_global_discounts"
):
env.cr.execute(
"""
ALTER TABLE "sale_order"
ADD COLUMN "amount_untaxed_before_global_discounts" double precision
"""
)
cr.execute(
env.cr.execute(
"""
update sale_order set amount_untaxed_before_global_discounts = amount_untaxed
"""
)
if not column_exists(cr, "sale_order", "amount_total_before_global_discounts"):
cr.execute(
if not column_exists(env.cr, "sale_order", "amount_total_before_global_discounts"):
env.cr.execute(
"""
ALTER TABLE "sale_order"
ADD COLUMN "amount_total_before_global_discounts" double precision
"""
)
cr.execute(
env.cr.execute(
"""
update sale_order set amount_total_before_global_discounts = amount_total
"""
Expand Down
5 changes: 3 additions & 2 deletions sale_global_discount/models/sale_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def _check_global_discounts_sanity(self):
return True
taxes_keys = {}
for line in self.order_line.filtered(
lambda l: not l.display_type and l.product_id
lambda _line: not _line.display_type and _line.product_id
):
if not line.tax_id:
raise exceptions.UserError(
Expand Down Expand Up @@ -141,11 +141,12 @@ def _compute_tax_totals(self):

@api.onchange("partner_id")
def onchange_partner_id_set_gbl_disc(self):
commercial = self.partner_id.commercial_partner_id
self.global_discount_ids = (
self.partner_id.customer_global_discount_ids.filtered(
lambda d: d.company_id == self.company_id
)
or self.partner_id.commercial_partner_id.customer_global_discount_ids.filtered(
or commercial.customer_global_discount_ids.filtered(
lambda d: d.company_id == self.company_id
)
)
Expand Down
4 changes: 4 additions & 0 deletions sale_global_discount/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,7 @@
- David Vidal
- Pedro M. Baeza
- Omar Castiñeira \<<omar@comunitea.com>\>

- [Studio73](https://www.studio73.es)
- Miguel Gandia

4 changes: 4 additions & 0 deletions sale_global_discount/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,10 @@ <h2><a class="toc-backref" href="#toc-entry-7">Contributors</a></h2>
</ul>
</li>
<li>Omar Castiñeira &lt;<a class="reference external" href="mailto:omar&#64;comunitea.com">omar&#64;comunitea.com</a>&gt;</li>
<li><a class="reference external" href="https://www.studio73.es">Studio73</a><ul>
<li>Miguel Gandia</li>
</ul>
</li>
</ul>
</div>
<div class="section" id="maintainers">
Expand Down
4 changes: 3 additions & 1 deletion sale_global_discount/tests/test_sale_global_discount.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ def setUpClass(cls, chart_template_ref=None):
"account_id": cls.account.id,
}
)
cls.pricelist = cls.env.ref("product.list0")
cls.pricelist = cls.env["product.pricelist"].create(
{"name": "Public Pricelist", "sequence": 1}
)
cls.partner_1 = cls.env["res.partner"].create(
{"name": "Mr. Odoo", "property_product_pricelist": cls.pricelist.id}
)
Expand Down

0 comments on commit 6c0ddbf

Please sign in to comment.