[ADD] project_link_from_invoice: first commit

new module to easily access to project from invoices
This commit is contained in:
clementthomas
2023-04-27 14:58:17 +02:00
parent 34dfc13936
commit cd663ec6e5
7 changed files with 274 additions and 0 deletions

View File

@@ -0,0 +1,47 @@
=================
project_link_from_invoice
=================
Easily access to your projects from invoices
View project(s) in invoices tree view
Access to related projects of an invoice from a button
Installation
============
Use Odoo normal procedure to install add-ons to install
``project_link_from_invoice``.
Known issues / Roadmap
======================
Bug Tracker
===========
Bugs are tracked on `our issues website
<https://github.com/elabore-coop/project-tools/issues>`_. In case of
trouble, please check there if your issue has already been
reported. If you spotted it first, help us smashing it by providing a
detailed and welcomed feedback.
Credits
=======
Images
------
* Elabore: `Icon <https://elabore.coop/web/image/res.company/1/logo?unique=f3db262>`_.
Contributors
------------
* Clément Thomas
Funders
-------
The development of this module has been financially supported by:
* Elabore (https://elabore.coop)
Maintainer
----------
This module is maintained by Elabore.

View File

@@ -0,0 +1,3 @@
# -*- coding: utf-8 -*-
from . import models

View File

@@ -0,0 +1,93 @@
# Copyright 2022 Stéphan Sainléger (Elabore)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
{
"name": "project_link_from_invoice",
"version": "14.0.0.0.0",
"author": "Elabore",
"website": "https://github.com/elabore-coop/project-tools",
"maintainer": "Clément Thomas",
"license": "AGPL-3",
"category": "Tools",
"summary": "Add link from invoice to project",
"description": """
:image: https://img.shields.io/badge/licence-AGPL--3-blue.svg
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
=================
project_link_from_invoice
=================
Users can access to related project from invoices
Installation
============
Install ``project_link_from_invoice``, all dependencies will be installed by default.
Known issues / Roadmap
======================
None yet.
Bug Tracker
===========
Bugs are tracked on `our issues website
<https://github.com/elabore-coop/project-tools/issues>`_. In case of
trouble, please check there if your issue has already been
reported. If you spotted it first, help us smashing it by providing a
detailed and welcomed feedback.
Credits
=======
Images
------
* Elabore: `Icon <https://elabore.coop/web/image/res.company/1/logo?unique=f3db262>`_.
Contributors
------------
* Clément Thomas <https://github.com/stephansainleger>
Funders
-------
The development of this module has been financially supported by:
* Elabore (https://elabore.coop)
Maintainer
----------
This module is maintained by Elabore.
""",
# any module necessary for this one to work correctly
"depends": [
"base",
"project",
"account",
"sale"
],
"qweb": [
# "static/src/xml/*.xml",
],
"external_dependencies": {
"python": [],
},
# always loaded
"data": [
"views/account_move_view.xml",
],
# only loaded in demonstration mode
"demo": [],
"js": [],
"css": [],
"installable": True,
# Install this module automatically if all dependency have been previously
# and independently installed. Used for synergetic or glue modules.
"auto_install": False,
"application": False,
}

View File

@@ -0,0 +1,58 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * project_link_from_invoice
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 14.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2023-04-27 12:47+0000\n"
"PO-Revision-Date: 2023-04-27 12:47+0000\n"
"Last-Translator: \n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: \n"
#. module: project_link_from_invoice
#: model:ir.model.fields,field_description:project_link_from_invoice.field_account_move__display_name
msgid "Display Name"
msgstr "Nom affiché"
#. module: project_link_from_invoice
#: model:ir.model.fields,field_description:project_link_from_invoice.field_account_move__id
msgid "ID"
msgstr ""
#. module: project_link_from_invoice
#: model:ir.model,name:project_link_from_invoice.model_account_move
msgid "Journal Entry"
msgstr "Pièce comptable"
#. module: project_link_from_invoice
#: model:ir.model.fields,field_description:project_link_from_invoice.field_account_move____last_update
msgid "Last Modified on"
msgstr "Dernière modification le"
#. module: project_link_from_invoice
#: model:ir.model.fields,field_description:project_link_from_invoice.field_account_bank_statement_line__project_ids
#: model:ir.model.fields,field_description:project_link_from_invoice.field_account_move__project_ids
#: model:ir.model.fields,field_description:project_link_from_invoice.field_account_payment__project_ids
msgid "Project"
msgstr "Projet"
#. module: project_link_from_invoice
#: model:ir.model.fields,field_description:project_link_from_invoice.field_account_bank_statement_line__project_count
#: model:ir.model.fields,field_description:project_link_from_invoice.field_account_move__project_count
#: model:ir.model.fields,field_description:project_link_from_invoice.field_account_payment__project_count
msgid "Project Count"
msgstr "Numbre de projets"
#. module: project_link_from_invoice
#: model_terms:ir.ui.view,arch_db:project_link_from_invoice.view_move_form_project_link_from_invoice_inherit
#: model:ir.model.fields,field_description:project_link_from_invoice.field_account_bank_statement_line__projects_name
#: model:ir.model.fields,field_description:project_link_from_invoice.field_account_move__projects_name
#: model:ir.model.fields,field_description:project_link_from_invoice.field_account_payment__projects_name
msgid "Project(s)"
msgstr "Projet(s)"

View File

@@ -0,0 +1,3 @@
# -*- coding: utf-8 -*-
from . import account_move

View File

@@ -0,0 +1,38 @@
from odoo import models, fields, api
class AccountMove(models.Model):
_inherit = "account.move"
project_ids = fields.Many2many('project.project', name="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 tree 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, "tree"], [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)

View File

@@ -0,0 +1,32 @@
<?xml version="1.0" encoding="UTF-8"?>
<odoo>
<record id="view_move_form_project_link_from_invoice_inherit" model="ir.ui.view">
<field name="name">account.move.form.project.link</field>
<field name="model">account.move</field>
<field name="inherit_id" ref="account.view_move_form" />
<field name="priority" eval="99" />
<field name="arch" type="xml">
<xpath expr="//header" position="inside">
<button name="action_open_projects"
string="Project(s)" class="oe_highlight" type="object" icon="fa-puzzle-piece"
invisible="[]" attrs="{'invisible': [('project_count', '=', 0)]}" />
</xpath>
<xpath expr="//header" position="after">
<field name="project_count" invisible="1" />
</xpath>
</field>
</record>
<record id="view_invoice_tree_project_link_from_invoice_inherit" model="ir.ui.view">
<field name="name">account.invoice.tree.project.link</field>
<field name="model">account.move</field>
<field name="inherit_id" ref="account.view_invoice_tree"/>
<field name="arch" type="xml">
<xpath expr="//tree/field[@name='invoice_date']" position="before">
<field name="projects_name" />
</xpath>
</field>
</record>
</odoo>