-
-
Notifications
You must be signed in to change notification settings - Fork 805
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FIX] purchase_duplicate_check: Code refactoring
- Loading branch information
Showing
7 changed files
with
108 additions
and
96 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
from . import purchase_order | ||
from . import purchase_order_line | ||
from . import res_config_settings |
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 |
---|---|---|
@@ -0,0 +1,60 @@ | ||
from odoo import _, fields, models | ||
|
||
|
||
class PurchaseOrderLine(models.Model): | ||
_inherit = "purchase.order.line" | ||
|
||
pending_order_ids = fields.Many2many( | ||
"purchase.order", | ||
string="Pending Orders", | ||
compute="_compute_pending_order_ids", | ||
) | ||
|
||
def _compute_pending_order_ids(self): | ||
purchase_order_obj = self.env["purchase.order"] | ||
for rec in self: | ||
if rec.product_type != "product": | ||
rec.pending_order_ids = False | ||
continue | ||
rfq_orders = purchase_order_obj.search( | ||
[ | ||
("order_line.product_id", "=", rec.product_id.id), | ||
("id", "!=", rec.order_id._origin.id), | ||
"|", | ||
("state", "in", ["draft", "sent"]), | ||
"&", | ||
"&", | ||
("state", "not in", ["draft", "sent"]), | ||
("picking_ids.picking_type_id.code", "=", "incoming"), | ||
("picking_ids.state", "not in", ["done", "cancel"]), | ||
] | ||
) | ||
rec.pending_order_ids = rfq_orders | ||
|
||
def _get_order_confirm_message(self): | ||
"""Get order confirmation message for pending orders""" | ||
message = "" | ||
for line in self: | ||
pending_orders = line.pending_order_ids | ||
if not pending_orders: | ||
continue | ||
product_line_msg = pending_orders._prepare_pending_orders_message( | ||
line.product_id.id | ||
) | ||
message += f""" | ||
Product <b>{line.product_id.name}</b><br/> | ||
{product_line_msg}<br/> | ||
""" | ||
return message | ||
|
||
def action_open_pending_orders(self): | ||
"""Action open pending purchase orders""" | ||
self.ensure_one() | ||
return { | ||
"name": _("Pending Orders"), | ||
"views": [[False, "tree"], [False, "form"]], | ||
"res_model": "purchase.order", | ||
"type": "ir.actions.act_window", | ||
"domain": [("id", "in", self.pending_order_ids.ids)], | ||
"context": {"create": False}, | ||
} |
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
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