mirror of
https://github.com/bringout/oca-purchase.git
synced 2026-04-20 11:42:08 +02:00
Add oca-purchase submodule with 96 purchase modules moved from oca-workflow-process
🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
b0628ee8ea
commit
7378b233e9
3994 changed files with 334316 additions and 0 deletions
|
|
@ -0,0 +1,54 @@
|
|||
# © 2023 Solvos Consultoría Informática (<http://www.solvos.es>)
|
||||
# Copyright 2023 Tecnativa - Stefan Ungureanu
|
||||
# Copyright 2023 Tecnativa - Pedro M. Baeza
|
||||
# Copyright 2024 Tecnativa - Víctor Martínez
|
||||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
|
||||
|
||||
from odoo import api, fields, models
|
||||
|
||||
|
||||
class PurchaseOrder(models.Model):
|
||||
_inherit = "purchase.order"
|
||||
|
||||
is_user_id_editable = fields.Boolean(
|
||||
compute="_compute_is_user_id_editable",
|
||||
)
|
||||
team_id = fields.Many2one(
|
||||
"purchase.team",
|
||||
string="Team",
|
||||
index=True,
|
||||
auto_join=True,
|
||||
compute="_compute_team_id",
|
||||
store=True,
|
||||
readonly=False,
|
||||
)
|
||||
|
||||
def _compute_is_user_id_editable(self):
|
||||
is_user_id_editable = self.env.user.has_group(
|
||||
"purchase.group_purchase_manager"
|
||||
) or not self.env.user.has_group("purchase_security.group_purchase_own_orders")
|
||||
self.is_user_id_editable = is_user_id_editable
|
||||
|
||||
@api.depends("user_id")
|
||||
def _compute_team_id(self):
|
||||
"""When a user is assigned, the first team which the user belongs to is
|
||||
assigned, and if no one, the first purchase team.
|
||||
"""
|
||||
first_team = self.env["purchase.team"].search([], limit=1)
|
||||
for record in self:
|
||||
record.team_id = record.user_id.purchase_team_ids[:1] or first_team
|
||||
|
||||
@api.onchange("partner_id")
|
||||
def onchange_partner_id(self):
|
||||
res = super().onchange_partner_id()
|
||||
if self.partner_id:
|
||||
partner = self.partner_id.commercial_partner_id
|
||||
if not self.env.context.get("default_user_id"):
|
||||
self.user_id = partner.purchase_user_id or self.env.user
|
||||
if not self.env.context.get("default_team_id"):
|
||||
self.team_id = (
|
||||
partner.purchase_team_id
|
||||
or self.user_id.purchase_team_ids[:1]
|
||||
or self.env["purchase.team"].search([], limit=1)
|
||||
)
|
||||
return res
|
||||
Loading…
Add table
Add a link
Reference in a new issue