Skip to Content
Menu
This question has been flagged
1 Reply
1577 Views

In sales during customer creation,

In model res.partner I have included a field Is a agent.If the customer is a agent then commission amount will be asked.Otherwise,invisible

In Sale Orders,

In model sale.order I have to get the commision amount if the customer entered is a agent..

How to get that...

My model res.partners inherited is-

from odoo import models, fields, api


#Model of Agent-Commision
class agent_comission(models.Model):
    _inherit = 'res.partner'
     
    agent = fields.Boolean(string='Is a Agent',default=False)
    commission_amount = fields.Integer(string='Commission Amount',store=True)

agent_name = fields.Many2one(
      comodel_name="res.partner", required=True,
      domain="[('agent', '=', True)]")

My View is of res.partner inherited:-

<?xml version="1.0" encoding="UTF-8"?>
<odoo>
    <data>
<record model="ir.ui.view" id="view_agent_form">
    <field name="name">res.partner.form.inherit</field>
    <field name="model">res.partner</field>
    <field name="inherit_id" ref="base.view_partner_form"/>
    <field name="arch" type="xml">
        <field name="website" position="before">
            <field name="agent"/>
            <field name="commission_amount" attrs="{'invisible': [('agent', '=',False)]}"/></field>
    </field>
</record>

How to implement it..

Please Help..

Thanks in Advance


Avatar
Discard
Best Answer

Hi,

Write an onchange function for the field partner_id in the sale order line and do it.

In the onchange function you can check whether it is agent or not and do it accordingly.


Thanks

Avatar
Discard
Author

Thank you..

Or we can implement using related field

commission_percent = fields.Integer(string='Commission Percentage',related='partner_id.commission_amount',store=True)