This question has been flagged


I want to bring the total value of the invoice to the stock.picking using the origin to bring it right I tried to do something else, it did not work can you help me?

from odoo import api, fields, models, _ from odoo.exceptions import UserError



class StockPicking(models.Model):

    _inherit = 'stock.picking'


    def get_x_total(self):

        current_total = self.env['account.invoice'].search([('origin','=',self.origin)])

        x_total = current_total.('account.invoice').amount_total


        return x_total


    x_amout_total = fields.Float('Valor Total', default=lambda self: self.get_x_total())

Avatar
Discard
Best Answer

Origin its a charlar field. Its editable so its bot the best option to make a search.

I would set a compute field, instead of default. But anyways I think its not working because of this line:

x_total = current_total.('account.invoice').amount_total

Try:

x_total = current_total.amount_total
Avatar
Discard
Author Best Answer

Consegui usando o seguinte cod

class StockPicking(models.Model):

    _inherit = 'stock.picking'


'''FUNCAO PARA PEGAR DENTRO DO ACCOUNT.INVOICE O VALOR TOTAL DA FATURA E JOGAR DENTRO DA VARIAVEL X_AMOUNT_TOTAL 

(FUNCAO USADA PARA PODER COLOCAR VALOR DA FATURA DENTRO DO RELATORIO DE NOTA DE ENTREGA'''

    @api.one

    @api.depends('priority')

    def get_x_total(self):

        invoice = self.env['account.invoice'].search([('origin','=',self.origin)])

        x_total_valor = sum(line.amount_total for line in invoice)

        self.x_amount_total = x_total_valor


    x_amount_total = fields.Float(string='Valor da Fatura', compute='get_x_total',store=True)

Avatar
Discard