Add module sale_agent
This commit is contained in:
5
sale_agent/models/__init__.py
Normal file
5
sale_agent/models/__init__.py
Normal 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
|
||||
15
sale_agent/models/account_invoice_report.py
Normal file
15
sale_agent/models/account_invoice_report.py
Normal 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"
|
||||
21
sale_agent/models/account_move.py
Normal file
21
sale_agent/models/account_move.py
Normal 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
|
||||
15
sale_agent/models/res_partner.py
Normal file
15
sale_agent/models/res_partner.py
Normal 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)
|
||||
26
sale_agent/models/sale_order.py
Normal file
26
sale_agent/models/sale_order.py
Normal 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
|
||||
16
sale_agent/models/sale_report.py
Normal file
16
sale_agent/models/sale_report.py
Normal 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
|
||||
Reference in New Issue
Block a user