Skip to content
Extraits de code Groupes Projets
Sélectionner une révision Git
  • c212661dff0b53defd4cdae09662ffc252400a5b
  • 14.0 par défaut protégée
  • 14.0-new-fact
  • Renomage
  • 6-tva-non-prise-en-compte
5 résultats

main.py

Blame
  • acc_contract.py 3,62 Kio
    # Copyright 2022 Le Filament (<http://www.le-filament.com>)
    # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
    
    from odoo import api, fields, models
    
    
    class AccContract(models.Model):
        _name = "acc.contract"
        _inherit = ["portal.mixin"]
        _description = "Contrats"
    
        # ------------------------------------------------------
        # 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")
        type = fields.Selection(
            [
                ("vente_achat", "Achat/Vente"),
                ("convention", "Convention Enedis"),
                ("pmo", "Pmo"),
                ("facture", "Facture importée"),
                ("all", "Contrat pour tous"),
                ("other", "Autre document"),
            ],
            string="Type de contrat",
        )
        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)
    
            for doc in docs:
                operation_id = doc.acc_operation_id
                if doc.seller_id:
                    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:
                    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)
            return docs
    
        # ------------------------------------------------------
        # 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)