Skip to Content
Menu
This question has been flagged
2 Replies
11199 Views

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
Discard
Best Answer

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
Discard
Author Best Answer

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
Discard

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,

Related Posts Replies Views Activity
4
May 16
3763
0
May 16
3733
1
Apr 24
2051
1
Oct 24
23270
0
Oct 21
1740