From e22badc605fd02fabd9b90b41da26237a4dd1c19 Mon Sep 17 00:00:00 2001 From: Alexis de Lattre Date: Thu, 7 Nov 2024 17:18:57 +0100 Subject: [PATCH] Add module sale_agent --- sale_agent/__init__.py | 1 + sale_agent/__manifest__.py | 22 ++++++++ sale_agent/models/__init__.py | 5 ++ sale_agent/models/account_invoice_report.py | 15 ++++++ sale_agent/models/account_move.py | 21 ++++++++ sale_agent/models/res_partner.py | 15 ++++++ sale_agent/models/sale_order.py | 26 +++++++++ sale_agent/models/sale_report.py | 16 ++++++ sale_agent/views/account_invoice_report.xml | 21 ++++++++ sale_agent/views/account_move.xml | 48 +++++++++++++++++ sale_agent/views/res_partner.xml | 55 +++++++++++++++++++ sale_agent/views/sale_order.xml | 59 +++++++++++++++++++++ sale_agent/views/sale_report.xml | 26 +++++++++ 13 files changed, 330 insertions(+) create mode 100644 sale_agent/__init__.py create mode 100644 sale_agent/__manifest__.py create mode 100644 sale_agent/models/__init__.py create mode 100644 sale_agent/models/account_invoice_report.py create mode 100644 sale_agent/models/account_move.py create mode 100644 sale_agent/models/res_partner.py create mode 100644 sale_agent/models/sale_order.py create mode 100644 sale_agent/models/sale_report.py create mode 100644 sale_agent/views/account_invoice_report.xml create mode 100644 sale_agent/views/account_move.xml create mode 100644 sale_agent/views/res_partner.xml create mode 100644 sale_agent/views/sale_order.xml create mode 100644 sale_agent/views/sale_report.xml diff --git a/sale_agent/__init__.py b/sale_agent/__init__.py new file mode 100644 index 0000000..0650744 --- /dev/null +++ b/sale_agent/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/sale_agent/__manifest__.py b/sale_agent/__manifest__.py new file mode 100644 index 0000000..cb695c9 --- /dev/null +++ b/sale_agent/__manifest__.py @@ -0,0 +1,22 @@ +# Copyright 2024 Akretion (http://www.akretion.com) +# @author Alexis de Lattre +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +{ + 'name': 'Sale Agent', + 'version': '16.0.1.0.0', + 'category': 'Sales', + 'license': 'AGPL-3', + 'summary': 'Add agent on partner, sale order and customer invoice/refund', + 'author': 'Akretion', + 'website': 'https://github.com/akretion/odoo-usability', + 'depends': ['sale'], + 'data': [ + "views/res_partner.xml", + "views/sale_order.xml", + "views/sale_report.xml", + "views/account_move.xml", + "views/account_invoice_report.xml", + ], + 'installable': True, +} diff --git a/sale_agent/models/__init__.py b/sale_agent/models/__init__.py new file mode 100644 index 0000000..6dd4239 --- /dev/null +++ b/sale_agent/models/__init__.py @@ -0,0 +1,5 @@ +from . import res_partner +from . import sale_order +from . import sale_report +from . import account_move +from . import account_invoice_report diff --git a/sale_agent/models/account_invoice_report.py b/sale_agent/models/account_invoice_report.py new file mode 100644 index 0000000..e34b6b4 --- /dev/null +++ b/sale_agent/models/account_invoice_report.py @@ -0,0 +1,15 @@ +# Copyright 2024 Akretion France (https://www.akretion.com) +# @author Alexis de Lattre +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import fields, models + + +class AccountInvoiceReport(models.Model): + _inherit = "account.invoice.report" + + invoice_agent_id = fields.Many2one("res.partner", string="Agent", readonly=True) + + def _select(self): + select_str = super()._select() + return f"{select_str}, move.invoice_agent_id AS invoice_agent_id" diff --git a/sale_agent/models/account_move.py b/sale_agent/models/account_move.py new file mode 100644 index 0000000..4ca7630 --- /dev/null +++ b/sale_agent/models/account_move.py @@ -0,0 +1,21 @@ +# Copyright 2024 Akretion France (https://www.akretion.com/) +# @author: Alexis de Lattre +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import api, fields, models + + +class AccountMove(models.Model): + _inherit = 'account.move' + + invoice_agent_id = fields.Many2one( + 'res.partner', domain=[('agent', '=', True)], ondelete='restrict', string="Agent", + compute='_compute_invoice_agent_id', store=True, readonly=False, precompute=True) + + @api.depends('partner_id', 'move_type') + def _compute_invoice_agent_id(self): + for move in self: + if move.is_sale_document() and move.partner_id: + move.invoice_agent_id = move.partner_id.commercial_partner_id.agent_id.id or False + else: + move.invoice_agent_id = False diff --git a/sale_agent/models/res_partner.py b/sale_agent/models/res_partner.py new file mode 100644 index 0000000..424fab2 --- /dev/null +++ b/sale_agent/models/res_partner.py @@ -0,0 +1,15 @@ +# Copyright 2024 Akretion France (https://www.akretion.com/) +# @author: Alexis de Lattre +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import fields, models + + +class ResPartner(models.Model): + _inherit = 'res.partner' + + agent = fields.Boolean() + # agent_id is only displayed on parent partner + # on sale.order and invoice, it uses commercial_partner_id.agent_id.id + agent_id = fields.Many2one( + 'res.partner', domain=[('agent', '=', True)], ondelete='restrict', copy=False) diff --git a/sale_agent/models/sale_order.py b/sale_agent/models/sale_order.py new file mode 100644 index 0000000..5c832cb --- /dev/null +++ b/sale_agent/models/sale_order.py @@ -0,0 +1,26 @@ +# Copyright 2024 Akretion France (https://www.akretion.com/) +# @author: Alexis de Lattre +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import api, fields, models + + +class SaleOrder(models.Model): + _inherit = 'sale.order' + + agent_id = fields.Many2one( + 'res.partner', domain=[('agent', '=', True)], ondelete='restrict', + compute='_compute_agent_id', store=True, readonly=False, precompute=True) + + @api.depends('partner_id') + def _compute_agent_id(self): + for order in self: + if order.partner_id: + order.agent_id = order.partner_id.commercial_partner_id.agent_id.id or False + else: + order.agent_id = False + + def _prepare_invoice(self): + vals = super()._prepare_invoice() + vals['invoice_agent_id'] = self.agent_id.id or False + return vals diff --git a/sale_agent/models/sale_report.py b/sale_agent/models/sale_report.py new file mode 100644 index 0000000..ffd2db6 --- /dev/null +++ b/sale_agent/models/sale_report.py @@ -0,0 +1,16 @@ +# Copyright 2024 Akretion France (https://www.akretion.com) +# @author Alexis de Lattre +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import fields, models + + +class SaleReport(models.Model): + _inherit = "sale.report" + + agent_id = fields.Many2one("res.partner", readonly=True) + + def _select_additional_fields(self): + res = super()._select_additional_fields() + res["agent_id"] = "s.agent_id" + return res diff --git a/sale_agent/views/account_invoice_report.xml b/sale_agent/views/account_invoice_report.xml new file mode 100644 index 0000000..90169c6 --- /dev/null +++ b/sale_agent/views/account_invoice_report.xml @@ -0,0 +1,21 @@ + + + + + agent.account.invoice.report.search + account.invoice.report + + + + + + + + + + + diff --git a/sale_agent/views/account_move.xml b/sale_agent/views/account_move.xml new file mode 100644 index 0000000..7a952d6 --- /dev/null +++ b/sale_agent/views/account_move.xml @@ -0,0 +1,48 @@ + + + + + + + + agent.account.move.form + account.move + + + + + + + + + + agent.account.move.tree + account.move + + + + + + + + + + agent.account.move.search + account.move + + + + + + + + + + + + + diff --git a/sale_agent/views/res_partner.xml b/sale_agent/views/res_partner.xml new file mode 100644 index 0000000..a13a7c3 --- /dev/null +++ b/sale_agent/views/res_partner.xml @@ -0,0 +1,55 @@ + + + + + + + + agent.res.partner.form + res.partner + + + + + + + + + + + + + agent.res.partner.tree + res.partner + + + + + + + + + + agent.res.partner.search + res.partner + + + + + + + + + + + + + + + + + diff --git a/sale_agent/views/sale_order.xml b/sale_agent/views/sale_order.xml new file mode 100644 index 0000000..a5034bd --- /dev/null +++ b/sale_agent/views/sale_order.xml @@ -0,0 +1,59 @@ + + + + + + + + agent.sale.order.form + sale.order + + + + + + + + + + agent.sale.order.tree + sale.order + + + + + + + + + + agent.sale.order.tree + sale.order + + + + + + + + + + agent.sale.order.search + sale.order + + + + + + + + + + + + + diff --git a/sale_agent/views/sale_report.xml b/sale_agent/views/sale_report.xml new file mode 100644 index 0000000..35246c7 --- /dev/null +++ b/sale_agent/views/sale_report.xml @@ -0,0 +1,26 @@ + + + + + + + + agent.sale.report.form + sale.report + + + + + + + + + + + + +