Newer
Older
# Copyright 2022 Le Filament (<http://www.le-filament.com>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
class AccContract(models.Model):
_name = "acc.contract"
# ------------------------------------------------------
# Fields declaration
# ------------------------------------------------------
acc_operation_id = fields.Many2one("acc.operation", "Opération")
seller_id = fields.Many2one("res.partner", "Contractant 1")
buyer_id = fields.Many2one("res.partner", "Contractant 2")
start_date = fields.Date("Début du contrat")
end_date = fields.Date("Fin du contrat")
document = fields.Binary("Document attaché", required=True, attachment=True)
name = fields.Char("Nom du document")
# ------------------------------------------------------
# SQL Constraints
# ------------------------------------------------------
# ------------------------------------------------------
# Default methods
# ------------------------------------------------------
# ------------------------------------------------------
# Computed fields / Search Fields
# ------------------------------------------------------
# ------------------------------------------------------
# Onchange / Constraints
# ------------------------------------------------------
# ------------------------------------------------------
# CRUD methods (ORM overrides)
# ------------------------------------------------------
@api.model_create_multi
def create(self, vals_list):
docs = super(AccContract, self).create(vals_list)
if doc.seller_id and not doc.seller_id.is_pmo:
user_seller = self.env["res.users"].search(
[("partner_id", "=", doc.seller_id.id)]
if user_seller.has_group("base.group_portal"):
template = self.env.ref(
"acc_operation.email_template_document",
raise_if_not_found=False,
)
template.with_context(
operation_id=operation_id.description
).send_mail(doc.seller_id.id, force_send=True)
if doc.buyer_id and not doc.buyer_id.is_pmo:
user_buyer = self.env["res.users"].search(
[("partner_id", "=", doc.buyer_id.id)]
if user_buyer.has_group("base.group_portal"):
template = self.env.ref(
"acc_operation.email_template_document",
raise_if_not_found=False,
)
template.with_context(
operation_id=operation_id.description
).send_mail(doc.buyer_id.id, force_send=True)
# ------------------------------------------------------
# Actions
# ------------------------------------------------------
# ------------------------------------------------------
# Business methods
# ------------------------------------------------------
def _compute_access_url(self):
super(AccContract, self)._compute_access_url()
for contract in self:
contract.access_url = "/contract/%s" % (contract.id)