Skip to content

Commit

Permalink
[MIG] purchase_exception: Migration to 13.0
Browse files Browse the repository at this point in the history
  • Loading branch information
teewux authored and kittiu committed Jul 4, 2021
1 parent ddd5031 commit cd851ed
Show file tree
Hide file tree
Showing 11 changed files with 15 additions and 82 deletions.
3 changes: 2 additions & 1 deletion purchase_exception/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Purchase Exception
:target: https://runbot.odoo-community.org/runbot/142/12.0
:alt: Try me on Runbot

|badge1| |badge2| |badge3| |badge4| |badge5|
|badge1| |badge2| |badge3| |badge4| |badge5|

This module allows you attach several customizable exceptions to your
purchase order in a way that you can filter orders by exceptions type and fix them.
Expand Down Expand Up @@ -67,6 +67,7 @@ Contributors

* Mourad EL HADJ MIMOUNE <[email protected]>
* Sudhir Arya <[email protected]>
* Darius Martinkus <[email protected]>

Maintainers
~~~~~~~~~~~
Expand Down
4 changes: 2 additions & 2 deletions purchase_exception/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
{
"name": "Purchase Exception",
"summary": "Custom exceptions on purchase order",
"version": "12.0.1.1.0",
"version": "13.0.1.0.0",
"category": "Generic Modules/Purchase",
"author": "Akretion, Odoo Community Association (OCA)",
"website": "https://github.com/OCA/purchase-workflow",
"depends": ["purchase", "base_exception",],
"depends": ["purchase", "base_exception"],
"license": "AGPL-3",
"data": [
"data/purchase_exception_data.xml",
Expand Down
16 changes: 0 additions & 16 deletions purchase_exception/migrations/12.0.1.0.1/noupdate_changes.xml

This file was deleted.

10 changes: 0 additions & 10 deletions purchase_exception/migrations/12.0.1.0.1/post-migration.py

This file was deleted.

1 change: 1 addition & 0 deletions purchase_exception/models/exception_rule.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Copyright 2017 Akretion (http://www.akretion.com)
# Copyright 2020 Camptocamp SA
# Mourad EL HADJ MIMOUNE <[email protected]>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).

Expand Down
27 changes: 3 additions & 24 deletions purchase_exception/models/purchase.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
# Copyright 2017 Akretion (http://www.akretion.com)
# Copyright 2020 Camptocamp SA
# Mourad EL HADJ MIMOUNE <[email protected]>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).

import logging

from odoo import api, models

logger = logging.getLogger(__name__)


class PurchaseOrder(models.Model):
_inherit = ["purchase.order", "base.exception"]
Expand All @@ -20,22 +17,6 @@ def test_all_draft_orders(self):
order_set.detect_exceptions()
return True

@api.model
def _exception_rule_eval_context(self, rec):
# TODO remove in v13
# We keep this only for backward compatibility
res = super()._exception_rule_eval_context(rec)
if res.get("purchase"):
logger.warning(
"""
For a full compatibility with future versions of this module,
please use 'self' instead of 'purchase' in your
custom exceptions rules.
"""
)
res["purchase"] = rec
return res

@api.model
def _reverse_field(self):
return "purchase_ids"
Expand All @@ -57,15 +38,13 @@ def onchange_ignore_exception(self):
if self.state == "purchase":
self.ignore_exception = False

@api.multi
def button_confirm(self):
if self.detect_exceptions() and not self.ignore_exception:
return self._popup_exceptions()
return super(PurchaseOrder, self).button_confirm()
return super().button_confirm()

@api.multi
def button_draft(self):
res = super(PurchaseOrder, self).button_draft()
res = super().button_draft()
for order in self:
order.exception_ids = False
order.main_exception_id = False
Expand Down
25 changes: 1 addition & 24 deletions purchase_exception/models/purchase_line.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
# Copyright 2017 Akretion (http://www.akretion.com)
# Copyright 2020 Camptocamp SA
# Mourad EL HADJ MIMOUNE <[email protected]>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).

import logging

from odoo import api, fields, models

logger = logging.getLogger(__name__)


class PurchaseOrderLine(models.Model):
_inherit = ["purchase.order.line", "base.exception.method"]
Expand All @@ -17,33 +14,13 @@ class PurchaseOrderLine(models.Model):
related="order_id.ignore_exception", store=True, string="Ignore Exceptions"
)

@api.multi
def _get_main_records(self):
return self.mapped("order_id")

@api.model
def _reverse_field(self):
return "purchase_ids"

@api.multi
def _detect_exceptions(self, rule):
records = super()._detect_exceptions(rule)
return records.mapped("order_id")

@api.model
def _exception_rule_eval_context(self, rec):
# TODO remove in v13
# We keep this only for backward compatibility, because some existing
# rules may use the variable "purchase_line". But we should remove this
# code during v13 migration.
res = super()._exception_rule_eval_context(rec)
if res.get("purchase_line"):
logger.warning(
"""
For a full compatibility with future versions of this module,
please use 'self' instead of 'purchase_line' in your
custom exceptions rules.
"""
)
res["purchase_line"] = rec
return res
1 change: 1 addition & 0 deletions purchase_exception/tests/test_purchase_exception.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Copyright 2017 Akretion (http://www.akretion.com)
# Copyright 2020 Camptocamp SA
# Mourad EL HADJ MIMOUNE <[email protected]>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from datetime import datetime
Expand Down
2 changes: 1 addition & 1 deletion purchase_exception/views/purchase_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
<field name="model">purchase.order</field>
<field name="inherit_id" ref="purchase.view_purchase_order_filter" />
<field name="arch" type="xml">
<filter name="activities_my" position="after">
<filter name="activities_exception" position="after">
<separator orientation="vertical" />
<filter
icon="fa-exclamation-circle"
Expand Down
7 changes: 4 additions & 3 deletions purchase_exception/wizard/purchase_exception_confirm.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
# Copyright 2017 Akretion (http://www.akretion.com)
# Copyright 2020 Camptocamp SA
# Mourad EL HADJ MIMOUNE <[email protected]>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).

from odoo import api, fields, models
from odoo import fields, models


class PurchaseExceptionConfirm(models.TransientModel):
_name = "purchase.exception.confirm"
_description = "Purchase exception wizard"
_inherit = ["exception.rule.confirm"]

related_model_id = fields.Many2one("purchase.order", "Purchase")

@api.multi
def action_confirm(self):
self.ensure_one()
if self.ignore:
self.related_model_id.button_draft()
self.related_model_id.ignore_exception = True
self.related_model_id.button_confirm()
return super(PurchaseExceptionConfirm, self).action_confirm()
return super().action_confirm()
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
<field name="name">Outstanding exceptions to manage</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">purchase.exception.confirm</field>
<field name="view_type">form</field>
<field name="view_mode">form</field>
<field name="view_id" ref="base_exception.view_exception_rule_confirm" />
<field name="target">new</field>
Expand Down

0 comments on commit cd851ed

Please sign in to comment.