Permalink
Browse files

Merge pull request #1 from eLBati/10.0-add-sale_commission_areamanage…

…r-lb

FIX sale_commission_areamanager partner interface and help fields
  • Loading branch information...
hurrinico committed Jun 14, 2017
2 parents f3a8f7c + 98b11fc commit e4ee2143eeca8da66f51d1fdc5d88221a38a7c67
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
{
'name': 'Sales commission Area Manager',
'version': '10.0.1.0.0',
'version': '10.0.1.0.7',
'author': 'Agile Business Group, '
'Odoo Community Association (OCA)',
"category": "Sales Management",
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
from . import res_partner
from . import account_invoice
from . import sale_order
from . import account_invoice_line
from . import sale_order_line

This file was deleted.

Oops, something went wrong.
@@ -0,0 +1,50 @@
# -*- coding: utf-8 -*-
from odoo import api, models
class AccountInvoiceLine(models.Model):
_inherit = "account.invoice.line"
@api.model
def _default_agents(self):
agents = []
partner_obj = self.env['res.partner']
if self.env.context.get('partner_id'):
partner = partner_obj.browse(
self.env.context['partner_id'])
for agent in partner.agents:
agents.append({'agent': agent.id,
'commission': agent.commission.id})
manager_dict = partner_obj.compute_area_manager(agent, self)
if manager_dict:
agents.append(manager_dict)
return [(0, 0, x) for x in agents]
agents = fields.One2many(
comodel_name="account.invoice.line.agent",
inverse_name="invoice_line", string="Agents & commissions",
help="Agents/Commissions related to the invoice line.",
default=_default_agents, copy=True)
class AccountInvoice(models.Model):
_inherit = "account.invoice"
@api.multi
def recompute_lines_agents(self):
for invoice in self:
for line in invoice.invoice_line_ids:
line.agents.unlink()
for agent in self.partner_id.agents:
line.agents.create({
'invoice_line': line.id,
'agent': agent.id,
'commission': agent.commission.id,
})
manager_dict = self.env[
'res.partner'].compute_area_manager(agent, line)
if manager_dict:
manager_dict['invoice_line'] = line.id
line.agents.create(manager_dict)
@@ -8,11 +8,34 @@ class ResPartner(models.Model):
area_manager_id = fields.Many2one(
comodel_name="res.partner",
domain="[('agent', '=', True), ('area_manager', '=', True)]")
domain="[('agent', '=', True), ('area_manager', '=', True)]",
help="Area Manager for the current agent")
area_manager = fields.Boolean(
string="Area Manager")
string="Area Manager", help="This agent is an area manager")
area_manager_sub_agent_ids = fields.One2many(
comodel_name="res.partner", inverse_name="area_manager_id",
string="Agents")
string="Agents", readonly=True)
commission_for_areamanager = fields.Many2one(
string="Commission For AreaManager", comodel_name="sale.commission")
string="Commission For AreaManager", comodel_name="sale.commission",
help="Commission for area manager applied the current agent")
def compute_area_manager(self, agent, line):
return_dict = {}
if agent.area_manager_id:
is_manager_already_there = False
for agent_line in line.agents:
if agent_line.agent == agent.area_manager_id:
is_manager_already_there = True
if is_manager_already_there:
return return_dict
else:
manager = agent.area_manager_id
if agent.commission_for_areamanager:
commission = agent.commission_for_areamanager.id
else:
commission = manager.commission.id
return_dict = {
'agent': manager.id,
'commission': commission,
}
return return_dict

This file was deleted.

Oops, something went wrong.
@@ -0,0 +1,45 @@
# -*- coding: utf-8 -*-
from odoo import api, models, fields
class SaleOrderLine(models.Model):
_inherit = "sale.order.line"
@api.model
def _default_agents(self):
agents = []
partner_obj = self.env['res.partner']
if self.env.context.get('partner_id'):
partner = partner_obj.browse(
self.env.context['partner_id'])
for agent in partner.agents:
agents.append({'agent': agent.id,
'commission': agent.commission.id})
manager_dict = partner_obj.compute_area_manager(agent, self)
if manager_dict:
agents.append(manager_dict)
return [(0, 0, x) for x in agents]
agents = fields.One2many(default=_default_agents)
class SaleOrder(models.Model):
_inherit = "sale.order"
@api.multi
def recompute_lines_agents(self):
partner_obj = self.env['res.partner']
for order in self:
for line in order.order_line:
line.agents.unlink()
for agent in self.partner_id.agents:
line.agents.create({
'sale_line': line.id,
'agent': agent.id,
'commission': agent.commission.id,
})
manager_dict = partner_obj.compute_area_manager(agent, line)
if manager_dict:
manager_dict['sale_line'] = line.id
line.agents.create(manager_dict)
@@ -16,7 +16,7 @@
</group>
<group col="2">
<field name="area_manager"/>
<field name="area_manager_id" attrs="{'invisible': [('area_manager', '=', False)]}"/>
<field name="area_manager_id" attrs="{'invisible': [('area_manager', '=', True)]}" context="{'default_agent': True, 'default_area_manager': True}"/>
<field name="commission_for_areamanager" attrs="{'invisible': [('area_manager', '=', True)]}"/>
</group>
<group colspan="4" string="Related Agents" attrs="{'invisible': [('area_manager', '=', False)]}">

0 comments on commit e4ee214

Please sign in to comment.