From 355e77fc705060c4007cf6fda53132b50b1f1434 Mon Sep 17 00:00:00 2001 From: clementthomas Date: Mon, 27 Mar 2023 17:22:38 +0200 Subject: [PATCH] [ADD] project_name_from_lead --- project_name_from_lead/.gitignore | 2 + project_name_from_lead/README.rst | 57 +++++++++++++++++++++ project_name_from_lead/__init__.py | 3 ++ project_name_from_lead/__manifest__.py | 35 +++++++++++++ project_name_from_lead/models/__init__.py | 1 + project_name_from_lead/models/crm_lead.py | 17 ++++++ project_name_from_lead/models/sale_order.py | 12 +++++ 7 files changed, 127 insertions(+) create mode 100644 project_name_from_lead/.gitignore create mode 100644 project_name_from_lead/README.rst create mode 100644 project_name_from_lead/__init__.py create mode 100644 project_name_from_lead/__manifest__.py create mode 100644 project_name_from_lead/models/__init__.py create mode 100644 project_name_from_lead/models/crm_lead.py create mode 100644 project_name_from_lead/models/sale_order.py diff --git a/project_name_from_lead/.gitignore b/project_name_from_lead/.gitignore new file mode 100644 index 0000000..6da5887 --- /dev/null +++ b/project_name_from_lead/.gitignore @@ -0,0 +1,2 @@ +*.*~ +*pyc diff --git a/project_name_from_lead/README.rst b/project_name_from_lead/README.rst new file mode 100644 index 0000000..d5a2880 --- /dev/null +++ b/project_name_from_lead/README.rst @@ -0,0 +1,57 @@ +======================= +project_name_from_quote +======================= + +.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png + :target: https://odoo-community.org/page/development-status + :alt: Beta +.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 +.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Faccount--analytic-lightgray.png?logo=github + :target: https://github.com/elabore-coop/project-tools + :alt: elabore/hr-tools + +|badge1| |badge2| |badge3| + + +This module tranfers the Quote / Sale order title to the project name. + +Installation +============ + +Use Odoo normal module installation procedure to install ``project_name_from_quote``. + +Known issues / Roadmap +====================== + +None yet. + +Bug Tracker +=========== + +Bugs are tracked on `our issues website `_. 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 +======= + +Contributors +------------ + +* Stéphan Sainléger + +Funders +------- + +The development of this module has been financially supported by: +* Elabore (https://elabore.coop) +* Datactivist (https://datactivist.coop) + + +Maintainer +---------- + +This module is maintained by Elabore. diff --git a/project_name_from_lead/__init__.py b/project_name_from_lead/__init__.py new file mode 100644 index 0000000..5305644 --- /dev/null +++ b/project_name_from_lead/__init__.py @@ -0,0 +1,3 @@ +# -*- coding: utf-8 -*- + +from . import models \ No newline at end of file diff --git a/project_name_from_lead/__manifest__.py b/project_name_from_lead/__manifest__.py new file mode 100644 index 0000000..8a45c34 --- /dev/null +++ b/project_name_from_lead/__manifest__.py @@ -0,0 +1,35 @@ +# Copyright 2022 Stéphan Sainléger (Elabore) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +{ + "name": "project_name_from_lead", + "version": "14.0.1.0.0", + "author": "Elabore", + "website": "https://elabore.coop", + "maintainer": "Clément Thomas", + "license": "AGPL-3", + "category": "Tools", + "summary": "Use lead name as project name", + # any module necessary for this one to work correctly + "depends": [ + "base", + "sale_project", + ], + "qweb": [ + # "static/src/xml/*.xml", + ], + "external_dependencies": { + "python": [], + }, + # always loaded + "data": [], + # 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, +} \ No newline at end of file diff --git a/project_name_from_lead/models/__init__.py b/project_name_from_lead/models/__init__.py new file mode 100644 index 0000000..1b896aa --- /dev/null +++ b/project_name_from_lead/models/__init__.py @@ -0,0 +1 @@ +from . import sale_order, crm_lead \ No newline at end of file diff --git a/project_name_from_lead/models/crm_lead.py b/project_name_from_lead/models/crm_lead.py new file mode 100644 index 0000000..6031c71 --- /dev/null +++ b/project_name_from_lead/models/crm_lead.py @@ -0,0 +1,17 @@ +from odoo import models + +class Lead(models.Model): + _inherit = 'crm.lead' + + def write(self, vals): + """update project name if project created from lead + """ + for lead in self: + if 'name' in vals: + sale = self.env['sale.order'].search([('opportunity_id','=',lead.id)]) + if sale: + project = self.env['project.project'].search([('sale_order_id','=',sale.id)]) + if project: + project.name = vals['name'] + + return super(Lead, self).write(vals) diff --git a/project_name_from_lead/models/sale_order.py b/project_name_from_lead/models/sale_order.py new file mode 100644 index 0000000..5d50ff1 --- /dev/null +++ b/project_name_from_lead/models/sale_order.py @@ -0,0 +1,12 @@ +from typing import ValuesView +from odoo import models + + +class SaleOrderLine(models.Model): + _inherit = "sale.order.line" + + def _timesheet_create_project_prepare_values(self): + values = super(SaleOrderLine, self)._timesheet_create_project_prepare_values() + if self.order_id and self.order_id.opportunity_id: + values['name'] = self.order_id.opportunity_id.name + return values \ No newline at end of file