0
votes

Odoo 10, How to create a commission field (Float) from configuration menu of sale (used for all sale order for a certain period of time) then assign it to a field, namely, sale_order_commission to calculate the commission for a sale_order ( based on amount_total of the sale_order form). Thanks

_inherit = "res.company"
commission_pct =  fields.Float( )
.....
_inherit = "sale.order"
commission_total = fields.Monetary(string="Commissions", 
    compute="_compute_commission_total_",        store=True)
....
_compute_commission_total_(self)
    commission_total = amount_total* "commission_pct from res.com"

However I failed to transfer the "commission_pct" to current self.env"

1

1 Answers

0
votes

you can setup as below: after struggling a while

class YourCompany(models.Model):
    _inherit = "res.company"

    company_commission =  fields.Float( default =15.00)
    commission_ids = fields.One2many( 'sale.order', 'company_id', 
        string="Commission_ids")

class SaleOrder(models.Model):
    _inherit = "sale.order"
    company_id = fields.Many2one('res.company', string='company_id', 
         required=True)
    company_commission = 
             fields.Float(related='company_id.company_commission', 
          string="Comm", store = True)

the "company_commission" field of model "sale.order" always automatically contains the value of "company_commission" field of model "res.company". Have a good day.