forked from OCA/commission
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ADD] sale_commission_product: module for commission exception by product
- Loading branch information
1 parent
1121be6
commit 1df3cc3
Showing
12 changed files
with
785 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg | ||
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html | ||
:alt: License: AGPL-3 | ||
|
||
======================= | ||
Sale Commission Product | ||
======================= | ||
|
||
This module was written to extend the functionality of sale_commission to | ||
support commissions in products. | ||
|
||
Bug Tracker | ||
=========== | ||
|
||
Bugs are tracked on `GitHub Issues <https://github.com/OCA/commission/issues>`_. | ||
In case of trouble, please check there if your issue has already been reported. | ||
If you spotted it first, help us smashing it by providing a detailed and welcomed feedback `here | ||
<https://github.com/OCA/commission/issues/new?body=module:%20sale_commission_product%0Aversion:%208. | ||
%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_. | ||
|
||
|
||
Credits | ||
======= | ||
|
||
Contributors | ||
------------ | ||
|
||
* Alejandro Sánchez <alejandro@asr-oss.com> | ||
|
||
Icon | ||
---- | ||
* https://openclipart.org/detail/98491/open-box | ||
* http://commons.wikimedia.org/wiki/File:Percent_18e.svg | ||
* https://openclipart.org/detail/43969/pile-of-golden-coins-by-j_alves | ||
|
||
Maintainer | ||
---------- | ||
|
||
.. image:: https://odoo-community.org/logo.png | ||
:alt: Odoo Community Association | ||
:target: https://odoo-community.org | ||
|
||
This module is maintained by the OCA. | ||
|
||
OCA, or the Odoo Community Association, is a nonprofit organization whose | ||
mission is to support the collaborative development of Odoo features and | ||
promote its widespread use. | ||
|
||
To contribute to this module, please visit http://odoo-community.org. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# -*- coding: utf-8 -*- | ||
# © 2015 Alejandro Sánchez Ramírez (<http://www.asr-oss.com>) | ||
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html | ||
|
||
from . import models |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# -*- coding: utf-8 -*- | ||
# © 2015 Alejandro Sánchez Ramírez (<http://www.asr-oss.com>) | ||
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html | ||
|
||
{ | ||
'name': 'Sale commissions product', | ||
'version': '8.0.1.0.0', | ||
'author': 'Asr Oss - Alejandro Sánchez, ' | ||
'Odoo Community Association (OCA)', | ||
"category": "Generic Modules/Sales & Purchases", | ||
'license': 'AGPL-3', | ||
'depends': [ | ||
'sale_commission', | ||
'web_widget_one2many_tags', | ||
], | ||
'contributors': [ | ||
"Alejandro Sánchez <alejandro@asr-oss.com>", | ||
], | ||
"data": [ | ||
"security/ir.model.access.csv", | ||
"views/product_view.xml", | ||
], | ||
"installable": True, | ||
"auto_install": False, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
# Translation of Odoo Server. | ||
# This file contains the translation of the following modules: | ||
# * sale_commission_product | ||
# | ||
msgid "" | ||
msgstr "" | ||
"Project-Id-Version: Odoo Server 8.0\n" | ||
"Report-Msgid-Bugs-To: \n" | ||
"POT-Creation-Date: 2015-10-05 18:31+0000\n" | ||
"PO-Revision-Date: 2015-10-05 22:48+0100\n" | ||
"Last-Translator: Alejandro Sanchez <alejandro@asr-oss.com>\n" | ||
"Language-Team: \n" | ||
"MIME-Version: 1.0\n" | ||
"Content-Type: text/plain; charset=UTF-8\n" | ||
"Content-Transfer-Encoding: 8bit\n" | ||
"Plural-Forms: \n" | ||
|
||
#. module: sale_commission_product | ||
#: field:product.product.agent,agent:0 | ||
msgid "Agent" | ||
msgstr "Agente" | ||
|
||
#. module: sale_commission_product | ||
#: view:product.product.agent:sale_commission_product.view_product_product_agent_tree | ||
msgid "Agents" | ||
msgstr "Agentes" | ||
|
||
#. module: sale_commission_product | ||
#: view:product.product:sale_commission_product.product_product_form_view_commission_product | ||
#: field:product.product,agents:0 | ||
msgid "Agents & commissions" | ||
msgstr "Agentes y comisiones" | ||
|
||
#. module: sale_commission_product | ||
#: field:product.product.agent,commission:0 | ||
msgid "Commission" | ||
msgstr "Comisiones" | ||
|
||
#. module: sale_commission_product | ||
#: field:product.product.agent,create_uid:0 | ||
msgid "Created by" | ||
msgstr "Creado por" | ||
|
||
#. module: sale_commission_product | ||
#: field:product.product.agent,create_date:0 | ||
msgid "Created on" | ||
msgstr "Creado en" | ||
|
||
#. module: sale_commission_product | ||
#: field:product.product.agent,id:0 | ||
msgid "ID" | ||
msgstr "ID" | ||
|
||
#. module: sale_commission_product | ||
#: model:ir.model,name:sale_commission_product.model_account_invoice_line | ||
msgid "Invoice Line" | ||
msgstr "Línea de factura" | ||
|
||
#. module: sale_commission_product | ||
#: field:product.product.agent,write_uid:0 | ||
msgid "Last Updated by" | ||
msgstr "Última actualización por" | ||
|
||
#. module: sale_commission_product | ||
#: field:product.product.agent,write_date:0 | ||
msgid "Last Updated on" | ||
msgstr "Última actualización en" | ||
|
||
#. module: sale_commission_product | ||
#: model:ir.model,name:sale_commission_product.model_product_product | ||
msgid "Product" | ||
msgstr "Producto" | ||
|
||
#. module: sale_commission_product | ||
#: field:product.product.agent,product_id:0 | ||
msgid "Product id" | ||
msgstr "Producto" | ||
|
||
#. module: sale_commission_product | ||
#: model:ir.model,name:sale_commission_product.model_sale_order_line | ||
msgid "Sales Order Line" | ||
msgstr "Línea pedido de venta" | ||
|
||
#. module: sale_commission_product | ||
#: sql_constraint:product.product.agent:0 | ||
msgid "You can only add one time each agent." | ||
msgstr "Sólo puede añadir una vez cada agente." | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# -*- coding: utf-8 -*- | ||
# © 2015 Alejandro Sánchez Ramírez (<http://www.asr-oss.com>) | ||
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html | ||
|
||
from . import product | ||
from . import sale_order | ||
from . import account_invoice |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# -*- coding: utf-8 -*- | ||
# © 2015 Alejandro Sánchez Ramírez (<http://www.asr-oss.com>) | ||
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html | ||
|
||
from openerp import models, api | ||
|
||
|
||
class AccountInvoiceLine(models.Model): | ||
_inherit = "account.invoice.line" | ||
|
||
@api.multi | ||
def product_id_change( | ||
self, product, uom_id, qty=0, name='', | ||
type='out_invoice', partner_id=False, fposition_id=False, | ||
price_unit=False, currency_id=False, company_id=None): | ||
|
||
res = super(AccountInvoiceLine, self).product_id_change( | ||
product, uom_id, qty, name, type, partner_id, | ||
fposition_id, price_unit, currency_id, company_id) | ||
|
||
if partner_id and product: | ||
agent_list = [] | ||
partner = self.env["res.partner"].browse(partner_id) | ||
for agent in partner.agents: | ||
# default commission_id for agent | ||
commission_id = agent.commission.id | ||
commission_id_product = self.env["product.product.agent"]\ | ||
.get_commission_id_product(product, agent) | ||
if commission_id_product: | ||
commission_id = commission_id_product | ||
agent_list.append({'agent': agent.id, | ||
'commission': commission_id | ||
}) | ||
|
||
res['value']['agents'] = [(0, 0, x) for x in agent_list] | ||
|
||
return res |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# -*- coding: utf-8 -*- | ||
# © 2015 Alejandro Sánchez Ramírez (<http://www.asr-oss.com>) | ||
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html | ||
|
||
from openerp import api, fields, models | ||
|
||
|
||
class ProductProduct(models.Model): | ||
_inherit = 'product.product' | ||
|
||
agents = fields.One2many( | ||
string="Agents & commissions", | ||
comodel_name='product.product.agent', inverse_name='product_id', | ||
copy=True, readonly=True) | ||
|
||
|
||
class ProductProductAgent(models.Model): | ||
_name = 'product.product.agent' | ||
|
||
@api.multi | ||
def get_commission_id_product(self, product, agent): | ||
commission_id = False | ||
# commission_id for all agent | ||
for commission_all_agent in self.search( | ||
[('product_id', '=', product), ('agent', '=', False)]): | ||
commission_id = commission_all_agent.commission.id | ||
# commission_id for agent | ||
for product_agent_id in self.search( | ||
[('product_id', '=', product), ('agent', '=', agent.id)]): | ||
commission_id = product_agent_id.commission.id | ||
return commission_id | ||
|
||
product_id = fields.Many2one( | ||
comodel_name="product.product", | ||
required=True, | ||
ondelete="cascade", | ||
string="") | ||
agent = fields.Many2one( | ||
comodel_name="res.partner", required=False, ondelete="restrict", | ||
domain="[('agent', '=', True')]") | ||
commission = fields.Many2one( | ||
comodel_name="sale.commission", required=True, ondelete="restrict") | ||
|
||
@api.multi | ||
def name_get(self): | ||
res = [] | ||
for record in self: | ||
name = "%s: %s" % (record.agent.name, record.commission.name) | ||
res.append((record.id, name)) | ||
return res | ||
|
||
_sql_constraints = [ | ||
('unique_agent', 'UNIQUE(product_id, agent)', | ||
'You can only add one time each agent.') | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# -*- coding: utf-8 -*- | ||
# © 2015 Alejandro Sánchez Ramírez (<http://www.asr-oss.com>) | ||
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html | ||
|
||
from openerp import api, models | ||
|
||
|
||
class SaleOrderLine(models.Model): | ||
_inherit = "sale.order.line" | ||
|
||
@api.multi | ||
def product_id_change(self, pricelist, product, qty=0, | ||
uom=False, qty_uos=0, uos=False, name='', | ||
partner_id=False, lang=False, update_tax=True, | ||
date_order=False, packaging=False, | ||
fiscal_position=False, flag=False): | ||
|
||
res = super(SaleOrderLine, self).product_id_change( | ||
pricelist, product, qty=qty, uom=uom, qty_uos=qty_uos, uos=uos, | ||
name=name, partner_id=partner_id, lang=lang, update_tax=update_tax, | ||
date_order=date_order, packaging=packaging, | ||
fiscal_position=fiscal_position, flag=flag) | ||
|
||
if partner_id and product: | ||
agent_list = [] | ||
partner = self.env["res.partner"].browse(partner_id) | ||
|
||
for agent in partner.agents: | ||
# default commission_id for agent | ||
commission_id = agent.commission.id | ||
commission_id_product = self.env["product.product.agent"]\ | ||
.get_commission_id_product(product, agent) | ||
if commission_id_product: | ||
commission_id = commission_id_product | ||
|
||
agent_list.append({'agent': agent.id, | ||
'commission': commission_id | ||
}) | ||
|
||
res['value']['agents'] = [(0, 0, x) for x in agent_list] | ||
|
||
return res |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
"id","name","model_id:id","group_id:id","perm_read","perm_write","perm_create","perm_unlink" | ||
"access_product_product_agent","access_product_product_agent","model_product_product_agent","base.group_sale_salesman",1,1,1,1 |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.