forked from OCA/purchase-workflow
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpurchase_requisition.py
More file actions
31 lines (26 loc) · 1.17 KB
/
purchase_requisition.py
File metadata and controls
31 lines (26 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# Copyright 2021 Tecnativa - Víctor Martínez
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from odoo import api, models
class PurchaseRequisition(models.Model):
_inherit = "purchase.requisition"
@api.model
def create(self, vals):
"""It is not possible to intercept _run_buy() to add lines instead of creating
multiple records.
This method is used to find if there is any previously created record with
the same values to add the line instead of creating a new record.
"""
if self.env.context.get("grouped_by_procurement") and vals.get(
"procurement_group_id"
):
domain = self._prepare_purchase_requisition_grouped_domain(vals)
purchase_requisition = self.search(domain)
if purchase_requisition:
purchase_requisition.write({"line_ids": vals.get("line_ids")})
return purchase_requisition
return super().create(vals)
def _prepare_purchase_requisition_grouped_domain(self, vals):
return [
("procurement_group_id", "=", vals.get("procurement_group_id")),
("state", "=", "draft"),
]