Add module sale_agent

This commit is contained in:
Alexis de Lattre
2024-11-07 17:18:57 +01:00
parent f93f17b27b
commit e22badc605
13 changed files with 330 additions and 0 deletions

View File

@@ -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

View File

@@ -0,0 +1,15 @@
# Copyright 2024 Akretion France (https://www.akretion.com)
# @author Alexis de Lattre <alexis.delattre@akretion.com>
# 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"

View File

@@ -0,0 +1,21 @@
# Copyright 2024 Akretion France (https://www.akretion.com/)
# @author: Alexis de Lattre <alexis.delattre@akretion.com>
# 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

View File

@@ -0,0 +1,15 @@
# Copyright 2024 Akretion France (https://www.akretion.com/)
# @author: Alexis de Lattre <alexis.delattre@akretion.com>
# 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)

View File

@@ -0,0 +1,26 @@
# Copyright 2024 Akretion France (https://www.akretion.com/)
# @author: Alexis de Lattre <alexis.delattre@akretion.com>
# 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

View File

@@ -0,0 +1,16 @@
# Copyright 2024 Akretion France (https://www.akretion.com)
# @author Alexis de Lattre <alexis.delattre@akretion.com>
# 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