Bonjour en ce mement je suis sur odoo 13 et j'aimerais modifier la valeur du field amount du modéle account.payment je veut que sa valeur change en foction d'un champ calculer total_a_payer que j'ai créer dans le modéle account.move mais je ne sais pas comment faire appel a ma fonction qui se trouve dans le modéle account.payment a partir du modéle account.move
Merci pour votre réponse voici mon code

Modéle account.move.py
Code python : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
 
from odoo import fields, models,api
 
 
class InheritSaleOrder(models.Model):
    _inherit = 'account.move'
 
    pourcent_retenu_garentie= fields.Integer(
        string="Retenue de garentie (%)",  
    )
    retenu_garentie= fields.Float(
        string="Retenue de garentie", 
        compute='_compute_rg',
    )
    total_a_payer= fields.Float(
        string="Total a payer", 
        compute='_compute_tp',
    )
 
    @api.depends('pourcent_retenu_garentie', 'amount_total')
    def _compute_rg(self):
        for record in self:
            record.retenu_garentie = record.amount_total * record.pourcent_retenu_garentie/100
 
 
    @api.depends('retenu_garentie', 'amount_total')
    def _compute_tp(self):
        for record in self:
            record.total_a_payer = record.amount_total-record.retenu_garentie
 
#Fonction pour récupérer la valeur du champ 
    def get_totel_a_payer(self):
        return self.total_a_payer

Modéle account.payment.py

Code python : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
 
 
from odoo import fields, models,api
import logging as log
 
 
class InheritAcountPayment(models.Model):
    _inherit = 'account.payment'
    custom_amount= fields.Monetary(string="Montant Personalisé", required=True)
 
    @api.model
    def _compute_payment_amount(self, invoices, currency, journal, date):
        '''Compute the total amount for the payment wizard.
 
        :param invoices:    Invoices on which compute the total as an account.invoice recordset.
        :param currency:    The payment's currency as a res.currency record.
        :param journal:     The payment's journal as an account.journal record.
        :param date:        The payment's date as a datetime.date object.
        :return:            The total amount to pay the invoices.
        '''
        company = journal.company_id
        currency = currency or journal.currency_id or company.currency_id
        date = date or fields.Date.today()
        var = self.env['account.move'].search([('pourcent_retenu_garentie','>','0')])
        new = self.env['account.move'].browse(var)
        for x in var :
           { #y = [x.total_a_payer]
                        log.warning(x.total_a_payer) } 
 
        if not invoices:
            return 0.0
 
        self.env['account.move'].flush(['type', 'currency_id'])
        self.env['account.move.line'].flush(['amount_residual', 'amount_residual_currency', 'move_id', 'account_id'])
        self.env['account.account'].flush(['user_type_id'])
        self.env['account.account.type'].flush(['type'])
        self._cr.execute('''
            SELECT
                move.type AS type,
                move.currency_id AS currency_id,
                SUM(line.amount_residual) AS amount_residual,
                SUM(line.amount_residual_currency) AS residual_currency
            FROM account_move move
            LEFT JOIN account_move_line line ON line.move_id = move.id
            LEFT JOIN account_account account ON account.id = line.account_id
            LEFT JOIN account_account_type account_type ON account_type.id = account.user_type_id
            WHERE move.id IN %s
            AND account_type.type IN ('receivable', 'payable')
            GROUP BY move.id, move.type
        ''', [tuple(invoices.ids)])
        query_res = self._cr.dictfetchall()
 
        total = 0.0
        for res in query_res:
            move_currency = self.env['res.currency'].browse(res['currency_id'])
            if move_currency == currency and move_currency != company.currency_id:
                total += res['residual_currency']
            else:
                total += company.currency_id._convert(res['amount_residual'], currency, company, date)
                #total += company.currency_id._convert(res['total_a_payer'], currency, company, date)
        return total
 
 
    def _prepare_payment_vals(self, invoices):
        '''Create the payment values.
 
        :param invoices: The invoices/bills to pay. In case of multiple
            documents, they need to be grouped by partner, bank, journal and
            currency.
        :return: The payment values as a dictionary.
        '''
        amount = self.env['account.payment']._compute_payment_amount(invoices, invoices[0].currency_id, self.journal_id, self.payment_date)
        values = {
            'journal_id': self.journal_id.id,
            'payment_method_id': self.payment_method_id.id,
            'payment_date': self.payment_date,
            'communication': self._prepare_communication(invoices),
            'invoice_ids': [(6, 0, invoices.ids)],
            'payment_type': ('inbound' if amount > 0 else 'outbound'),
            'amount': abs(amount),
            'currency_id': invoices[0].currency_id.id,
            'partner_id': invoices[0].commercial_partner_id.id,
            'partner_type': MAP_INVOICE_TYPE_PARTNER_TYPE[invoices[0].type],
            'partner_bank_account_id': invoices[0].invoice_partner_bank_id.id,
        }
        return values

Merci d'avance pour votre aide j'aimerais bien avoir de la documentation concernant ce point si c'est possible merci