0

from odoo import api, models, fields, tools from odoo.tools.misc import formatLang

class SaleOrder(models.Model):

_inherit = 'sale.order'
commission = fields.Float(compute='_compute_commission')
@api.depends('user_id.commission')
def _compute_commission(self):
    for order in self:
        order.commission = order.user_id.commission

class AccountTaxGroup(models.Model):

_inherit = 'account.tax'
def _prepare_tax_totals(self, base_lines, currency, tax_lines=None):
    res = super()._prepare_tax_totals(base_lines, currency, tax_lines=tax_lines)
    commission_amount = 1900  # Calculate the commission amount here
    res['amount_untaxed'] -= commission_amount
    res['amount_total'] -= commission_amount
    res['formatted_amount_total'] = formatLang(self.env, res['amount_total'], currency_obj=currency)
    print(self.user_id.commission)
    return res

I want to access value of "commission" declared on "class SaleOrder" inside the "class AccountTaxGroup". How to do it?

1 Answer 1

0

for that, you need to open a field of order_id so that odoo can know from which record of 'sale.order' you want to take the value of the commission.

class AccountTaxGroup(models.Model):
    _inherit = 'account.tax'

    order_id = fields.Many2one('sale.order', string='Sale Order')

    def _prepare_tax_totals(self, base_lines, currency, tax_lines=None):
        res = super()._prepare_tax_totals(base_lines, currency, tax_lines=tax_lines)
        commission_amount = 1900  # Calculate the commission amount here
        res['amount_untaxed'] -= commission_amount
        res['amount_total'] -= commission_amount
        res['formatted_amount_total'] = formatLang(self.env, 
        res['amount_total'], currency_obj=currency)
        print(self.user_id.commission)
        sale_order_commission = self.order_id.commission
        print('########', sale_order_commission)
        return res
        
Sign up to request clarification or add additional context in comments.

1 Comment

Thank You. I solved it in another way. Thank you for reply.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.