Passa al contenuto
Menu
È necessario essere registrati per interagire con la community.
La domanda è stata contrassegnata
2 Risposte
12491 Visualizzazioni

Hello,

I want to get the field values of the sale order amount_total and will be my input on the next page. Since I will create a new page that will calculate the quotation sales order total amount together its discounts. 

I tried to do this:     total_price = fields.Monetary('sale.order.amount_total', string="Price Initial") 

The result was my odoo went 500 status. compiler error. 

class sale_com(models.Model):
      _inherit ='sale.order'

     total_price = fields.Monetary('sale.order.amount_total', string="Price Initial")  <- this gave me an error

Avatar
Abbandona
Risposta migliore

Hi, William

It is because you are trying to create related field using model name, but a related field required at relational field (Many2one) not model.

So in order to achieve this requirement you can use below ways.

  • Make it computed same as "amount_total" field like below

    • total_price = fields.Monetary(string='Price Initial', store=True, readonly=True, compute='_amount_all', tracking=4)
    • Inherit the "_amount_all" method,

      •     @api.depends('order_line.price_total')
            def _amount_all(self):
                """
                Compute the total amounts of the SO.
                """
                for order in self:
                    amount_untaxed = amount_tax = 0.0
                    for line in order.order_line:
                        amount_untaxed += line.price_subtotal
                        amount_tax += line.price_tax
                    order.update({
                        'amount_untaxed': amount_untaxed,
                        'amount_tax': amount_tax,
                        'amount_total': amount_untaxed + amount_tax,
                        'total_price': amount_untaxed + amount_tax,
                    })
  • Else instead of overriding existing computed method you can define your method like below,

    • total_price = fields.Monetary(string='Price Initial', store=True, readonly=True, compute='_total_price_method', tracking=4)
    • define the "_total_price_method" method,

      •     @api.depends('order_line.price_total')
            def _total_price_method(self):
                for order in self:
                    order.update({
                        'total_price': order.amount_total,
                    })
Feel free to ask in case you have any doubt related to the above point.


Thanks,
Ashish Singh (Team Lead)
Webkul Software Private Limited
Avatar
Abbandona
Autore Risposta migliore

I am still new to odoo development more like 2 weeks ago. Do you mean Inherit the "_amount_all" method is by creating a new function similar to this? For example:

class sale_commission(models.Model):
    _inherit = 'sale.order'

    
total_price = fields.Monetary(string='Price Initial', store=True, readonly=True, compute='_prod_price', tracking=4) @api.depends('order_line.price_total')

    def _prod_price(self):
        """
        Compute the total amounts of the SO.
        """
        for order in self:
            amount_untaxed = amount_tax = 0.0
            for line in order.order_line:
                amount_untaxed += line.price_subtotal
                amount_tax += line.price_tax
            order.update({
                'amount_untaxed': amount_untaxed,
                'amount_tax': amount_tax,
                'amount_total': amount_untaxed + amount_tax,
                'total_price': amount_untaxed + amount_tax,
            })

Thank you so much.

Avatar
Abbandona

Hi, William

No for inheriting a method you need to define the method with the actual method name "_amount_all" not with the new name and as it is computed method then you need to define the same definition as actual method have.

If you don't want to inherit the existing method then you can simply define you function like below,

@api.depends('order_line.price_total')

def _prod_price(self):

for order in self:

order.update({

'total_price': order.amount_total,

})

Thanks,

Post correlati Risposte Visualizzazioni Attività
4
mag 16
4705
0
mag 16
4611
1
apr 24
3581
1
ott 24
25652
0
ott 21
2710