[MIG] project_link_from_invoice: migrate to 18.0
This commit is contained in:
2
project_link_from_invoice/models/__init__.py
Normal file
2
project_link_from_invoice/models/__init__.py
Normal file
@@ -0,0 +1,2 @@
|
||||
|
||||
from . import account_move
|
||||
49
project_link_from_invoice/models/account_move.py
Normal file
49
project_link_from_invoice/models/account_move.py
Normal file
@@ -0,0 +1,49 @@
|
||||
# Copyright 2022 Stéphan Sainléger (Elabore)
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
from odoo import api, fields, models
|
||||
|
||||
|
||||
class AccountMove(models.Model):
|
||||
_inherit = "account.move"
|
||||
|
||||
project_ids = fields.Many2many(
|
||||
"project.project", string="Projects", compute="_get_related_project_ids"
|
||||
)
|
||||
project_count = fields.Integer("Project Count", compute="_get_related_project_ids")
|
||||
projects_name = fields.Char("Project(s)", compute="_get_related_project_ids")
|
||||
|
||||
def action_open_projects(self):
|
||||
"""Open related projects, in form or list view depending on project numbers."""
|
||||
project_ids = self.project_ids.ids
|
||||
action = self.env["ir.actions.actions"]._for_xml_id(
|
||||
"project.open_view_project_all"
|
||||
)
|
||||
|
||||
if self.project_count == 1:
|
||||
action["res_id"] = project_ids[0]
|
||||
action["views"] = [[False, "form"]]
|
||||
else:
|
||||
action["views"] = [[False, "list"], [False, "form"]]
|
||||
|
||||
action["domain"] = [("id", "in", project_ids)]
|
||||
|
||||
del action["target"] # to display breadcrumbs
|
||||
|
||||
return action
|
||||
|
||||
@api.depends("line_ids.sale_line_ids")
|
||||
def _get_related_project_ids(self):
|
||||
for move in self:
|
||||
projects = self.env["project.task"].search(
|
||||
[
|
||||
(
|
||||
"sale_order_id",
|
||||
"in",
|
||||
move.line_ids.sale_line_ids.order_id.ids,
|
||||
)
|
||||
]
|
||||
).project_id
|
||||
move.project_ids = projects.ids
|
||||
move.projects_name = " ; ".join([p.name for p in projects])
|
||||
move.project_count = len(projects)
|
||||
Reference in New Issue
Block a user