Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MIG][9.0] sale_commission #67

Merged
merged 4 commits into from
May 30, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@ cache: pip

addons:
apt:
sources:
- pov-wkhtmltopdf
packages:
- expect-dev # provides unbuffer utility
- python-lxml # because pip installation is slow
- wkhtmltopdf

language: python

Expand All @@ -20,6 +23,10 @@ env:
virtualenv:
system_site_packages: true

before_install:
- "export DISPLAY=:99.0"
- "sh -e /etc/init.d/xvfb start"

install:
- git clone https://github.com/OCA/maintainer-quality-tools.git ${HOME}/maintainer-quality-tools
- export PATH=${HOME}/maintainer-quality-tools/travis:${PATH}
Expand Down
10 changes: 6 additions & 4 deletions sale_commission/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Known issues / Roadmap
* Make it totally multi-company aware.
* Allow to calculate and pay in other currency different from company one.
* Allow to group by agent when generating invoices.
* Migrate RML report to Qweb


Bug Tracker
Expand All @@ -28,7 +29,7 @@ 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%0Aversion:%208.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
`here <https://github.com/OCA/commission/issues/new?body=module:%20sale_commission%0Aversion:%209.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.


Credits
Expand All @@ -44,6 +45,7 @@ Contributors
* Daniel Campos <danielcampos@avanzosc.es>
* Pedro M. Baeza <pedro.baeza@serviciosbaeza.com>
* Oihane Crucelaegui <oihanecruce@gmail.com>
* Iván Todorovich <ivan.todorovich@gmail.com>

Icon
----

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

URL below (https)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Expand All @@ -53,14 +55,14 @@ Icon
Maintainer
----------

.. image:: http://odoo-community.org/logo.png
.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: http://odoo-community.org
: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.
To contribute to this module, please visit https://odoo-community.org.
2 changes: 2 additions & 0 deletions sale_commission/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# -*- coding: utf-8 -*-
# © 2011 Pexego Sistemas Informáticos (<http://www.pexego.es>)
# © 2015-2016 Pedro M. Baeza (<http://www.serviciosbaeza.com>)
# © 2015-2016 Oihane Crucelaegui
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html

from . import models
Expand Down
56 changes: 26 additions & 30 deletions sale_commission/__openerp__.py
Original file line number Diff line number Diff line change
@@ -1,54 +1,50 @@
# -*- coding: utf-8 -*-
# © 2011 Pexego Sistemas Informáticos (<http://www.pexego.es>)
# © 2015 Avanzosc (<http://www.avanzosc.es>)
# © 2015 Pedro M. Baeza (<http://www.serviciosbaeza.com>)
# © 2015-2016 Pedro M. Baeza (<http://www.serviciosbaeza.com>)
# © 2015-2016 Oihane Crucelaegui
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html

{
'name': 'Sales commissions',
'version': '8.0.2.3.0',
'version': '9.0.1.0.0',
'author': 'Pexego, '
'Savoire-faire linux, '
'Savoir-faire linux, '
'Avanzosc, '
'Abstract, '
'Serv. Tecnol. Avanzados - Pedro M. Baeza, '
'Odoo Community Association (OCA)',
"category": "Sales Management",
'category': 'Sales Management',
'license': 'AGPL-3',
'depends': [
'base',
'account',
'product',
'sale'
'sale',
],
'contributors': [

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not necessary: in README. Only individuals here anyway

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a field in ir_module_module that is filed with this data, that's why I include it.

"Pexego",
"Davide Corio <davide.corio@domsense.com>",
"Joao Alfredo Gama Batista <joao.gama@savoirfairelinux.com>",
"Sandy Carter <sandy.carter@savoirfairelinux.com>",
"Giorgio Borelli <giorgio.borelli@abstract.it>",
"Daniel Campos <danielcampos@avanzosc.es>",
"Pedro M. Baeza <pedro.baeza@serviciosbaeza.com>",
"Oihane Crucelaegui <oihanecruce@gmail.com>",
"Iván Todorovich <ivan.todorovich@gmail.com",
'Davide Corio <davide.corio@domsense.com>',
'Joao Alfredo Gama Batista <joao.gama@savoirfairelinux.com>',
'Sandy Carter <sandy.carter@savoirfairelinux.com>',
'Giorgio Borelli <giorgio.borelli@abstract.it>',
'Daniel Campos <danielcampos@avanzosc.es>',
'Pedro M. Baeza <pedro.baeza@serviciosbaeza.com>',
'Oihane Crucelaegui <oihanecruce@gmail.com>',
'Iván Todorovich <ivan.todorovich@gmail.com>',
],
"data": [
"security/ir.model.access.csv",
"views/product_template_view.xml",
"views/res_partner_view.xml",
"views/sale_commission_view.xml",
"views/sale_order_view.xml",
"views/account_invoice_view.xml",
"views/settlement_view.xml",
"wizard/wizard_settle.xml",
"wizard/wizard_invoice.xml",
# "report/cc_commission_report.xml"
'data': [
'security/ir.model.access.csv',
'views/product_template_view.xml',
'views/res_partner_view.xml',
'views/sale_commission_view.xml',
'views/sale_order_view.xml',
'views/account_invoice_view.xml',
'views/settlement_view.xml',
'wizard/wizard_settle.xml',
'wizard/wizard_invoice.xml',
],
"demo": [
'demo': [
'demo/sale_agent_demo.xml',
],
'test': [
'test/sale_commission_demo.yml',
],
'installable': False
'installable': True,
}
2 changes: 2 additions & 0 deletions sale_commission/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# -*- coding: utf-8 -*-
# © 2011 Pexego Sistemas Informáticos (<http://www.pexego.es>)
# © 2015-2016 Pedro M. Baeza (<http://www.serviciosbaeza.com>)
# © 2015-2016 Oihane Crucelaegui
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html

from . import product_template
Expand Down
10 changes: 5 additions & 5 deletions sale_commission/models/account_invoice.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# -*- coding: utf-8 -*-
# © 2011 Pexego Sistemas Informáticos (<http://www.pexego.es>)
# © 2015 Avanzosc (<http://www.avanzosc.es>)
# © 2015 Pedro M. Baeza (<http://www.serviciosbaeza.com>)
# © 2015-2016 Pedro M. Baeza (<http://www.serviciosbaeza.com>)
# © 2015-2016 Oihane Crucelaegui
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html

from openerp import api, fields, models
Expand All @@ -11,11 +12,11 @@ class AccountInvoice(models.Model):
"""Invoice inherit to add salesman"""
_inherit = "account.invoice"

@api.depends('invoice_line.agents.amount')
@api.depends('invoice_line_ids.agents.amount')
def _compute_commission_total(self):
for record in self:
record.commission_total = 0.0
for line in record.invoice_line:
for line in record.invoice_line_ids:
record.commission_total += sum(x.amount for x in line.agents)

commission_total = fields.Float(
Expand Down Expand Up @@ -122,8 +123,7 @@ class AccountInvoiceLineAgent(models.Model):
def onchange_agent(self):
self.commission = self.agent.commission

@api.depends('commission.commission_type', 'invoice_line.price_subtotal',
'commission.amount_base_type')
@api.depends('invoice_line.price_subtotal')
def _compute_amount(self):
for line in self:
line.amount = 0.0
Expand Down
3 changes: 2 additions & 1 deletion sale_commission/models/product_template.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# -*- coding: utf-8 -*-
# © 2011 Pexego Sistemas Informáticos (<http://www.pexego.es>)
# © 2015 Avanzosc (<http://www.avanzosc.es>)
# © 2015 Pedro M. Baeza (<http://www.serviciosbaeza.com>)
# © 2015-2016 Pedro M. Baeza (<http://www.serviciosbaeza.com>)
# © 2015-2016 Oihane Crucelaegui
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html

from openerp import fields, models
Expand Down
3 changes: 2 additions & 1 deletion sale_commission/models/res_partner.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# -*- coding: utf-8 -*-
# © 2011 Pexego Sistemas Informáticos (<http://www.pexego.es>)
# © 2015 Avanzosc (<http://www.avanzosc.es>)
# © 2015 Pedro M. Baeza (<http://www.serviciosbaeza.com>)
# © 2015-2016 Pedro M. Baeza (<http://www.serviciosbaeza.com>)
# © 2015-2016 Oihane Crucelaegui
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html

from openerp import api, fields, models
Expand Down
3 changes: 2 additions & 1 deletion sale_commission/models/sale_commission.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# -*- coding: utf-8 -*-
# © 2011 Pexego Sistemas Informáticos (<http://www.pexego.es>)
# © 2015 Avanzosc (<http://www.avanzosc.es>)
# © 2015 Pedro M. Baeza (<http://www.serviciosbaeza.com>)
# © 2015-2016 Pedro M. Baeza (<http://www.serviciosbaeza.com>)
# © 2015-2016 Oihane Crucelaegui
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html

from openerp import api, exceptions, fields, models, _
Expand Down
17 changes: 8 additions & 9 deletions sale_commission/models/sale_order.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# -*- coding: utf-8 -*-
# © 2011 Pexego Sistemas Informáticos (<http://www.pexego.es>)
# © 2015 Avanzosc (<http://www.avanzosc.es>)
# © 2015 Pedro M. Baeza (<http://www.serviciosbaeza.com>)
# © 2015-2016 Pedro M. Baeza (<http://www.serviciosbaeza.com>)
# © 2015-2016 Oihane Crucelaegui
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html

from openerp import api, fields, models
Expand Down Expand Up @@ -38,19 +39,18 @@ def _default_agents(self):

agents = fields.One2many(
string="Agents & commissions",
comodel_name='sale.order.line.agent', inverse_name='sale_line',
comodel_name="sale.order.line.agent", inverse_name="sale_line",
copy=True, readonly=True, default=_default_agents)
commission_free = fields.Boolean(
string="Comm. free", related="product_id.commission_free",
store=True, readonly=True)

@api.model
def _prepare_order_line_invoice_line(self, line, account_id=False):
vals = super(SaleOrderLine, self)._prepare_order_line_invoice_line(
line, account_id=account_id)
@api.multi
def _prepare_invoice_line(self, qty):
vals = super(SaleOrderLine, self)._prepare_invoice_line(qty)
vals['agents'] = [
(0, 0, {'agent': x.agent.id,
'commission': x.commission.id}) for x in line.agents]
'commission': x.commission.id}) for x in self.agents]
return vals


Expand All @@ -76,8 +76,7 @@ class SaleOrderLineAgent(models.Model):
def onchange_agent(self):
self.commission = self.agent.commission

@api.depends('commission.commission_type', 'sale_line.price_subtotal',
'commission.amount_base_type')
@api.depends('sale_line.price_subtotal')
def _compute_amount(self):
for line in self:
line.amount = 0.0
Expand Down
63 changes: 26 additions & 37 deletions sale_commission/models/settlement.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# -*- coding: utf-8 -*-
# © 2011 Pexego Sistemas Informáticos (<http://www.pexego.es>)
# © 2015 Avanzosc (<http://www.avanzosc.es>)
# © 2015 Pedro M. Baeza (<http://www.serviciosbaeza.com>)
# © 2015-2016 Pedro M. Baeza (<http://www.serviciosbaeza.com>)
# © 2015-2016 Oihane Crucelaegui
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html

from openerp import api, exceptions, fields, models, _
Expand Down Expand Up @@ -68,45 +69,37 @@ def action_invoice(self):
}

def _prepare_invoice_header(self, settlement, journal, date=False):
invoice_obj = self.env['account.invoice']
invoice_vals = {
invoice = self.env['account.invoice'].new({
'partner_id': settlement.agent.id,
'type': ('in_invoice' if journal.type == 'purchase' else
'in_refund'),
'date_invoice': date,
'journal_id': journal.id,
'company_id': self.env.user.company_id.id,
'state': 'draft',
}
})
# Get other invoice values from partner onchange
invoice_vals.update(invoice_obj.onchange_partner_id(
type=invoice_vals['type'],
partner_id=invoice_vals['partner_id'],
company_id=invoice_vals['company_id'])['value'])
return invoice_vals
invoice._onchange_partner_id()
return invoice._convert_to_write(invoice._cache)

def _prepare_invoice_line(self, settlement, invoice_vals, product):
invoice_line_obj = self.env['account.invoice.line']
invoice_line_vals = {
def _prepare_invoice_line(self, settlement, invoice, product):
invoice_line = self.env['account.invoice.line'].new({
'invoice_id': invoice.id,
'product_id': product.id,
'quantity': 1,
}
})
# Get other invoice line values from product onchange
invoice_line_vals.update(invoice_line_obj.product_id_change(
product=invoice_line_vals['product_id'], uom_id=False,
type=invoice_vals['type'], qty=invoice_line_vals['quantity'],
partner_id=invoice_vals['partner_id'],
fposition_id=invoice_vals['fiscal_position'])['value'])
# Put line taxes
invoice_line_vals['invoice_line_tax_id'] = \
[(6, 0, tuple(invoice_line_vals['invoice_line_tax_id']))]
invoice_line._onchange_product_id()
invoice_line_vals = invoice_line._convert_to_write(invoice_line._cache)
# Put commission fee
invoice_line_vals['price_unit'] = settlement.total
if invoice.type == 'in_refund':
invoice_line_vals['price_unit'] = -settlement.total
else:
invoice_line_vals['price_unit'] = settlement.total
# Put period string
partner = self.env['res.partner'].browse(invoice_vals['partner_id'])
lang = self.env['res.lang'].search(
[('code', '=', partner.lang or self.env.context.get('lang',
'en_US'))])
[('code', '=', invoice.partner_id.lang or
self.env.context.get('lang', 'en_US'))])
date_from = fields.Date.from_string(settlement.date_from)
date_to = fields.Date.from_string(settlement.date_to)
invoice_line_vals['name'] += "\n" + _('Period: from %s to %s') % (
Expand All @@ -122,29 +115,25 @@ def _add_extra_invoice_lines(self, settlement):
return []

@api.multi
def make_invoices(self, journal, refund_journal, product, date=False):
def make_invoices(self, journal, product, date=False):
invoice_obj = self.env['account.invoice']
invoice_line_obj = self.env['account.invoice.line']
for settlement in self:
# select the proper journal according to settlement's amount
# considering _add_extra_invoice_lines sum of values
extra_invoice_lines = self._add_extra_invoice_lines(settlement)
extra_total = sum(x['price_unit'] for x in extra_invoice_lines)
invoice_journal = (journal if
(settlement.total + extra_total) >= 0 else
refund_journal)
False)
invoice_vals = self._prepare_invoice_header(
settlement, invoice_journal, date=date)
invoice_lines_vals = []
invoice_lines_vals.append(self._prepare_invoice_line(
settlement, invoice_vals, product))
invoice_lines_vals += extra_invoice_lines
# invert invoice values if it's a refund
if invoice_vals['type'] == 'in_refund':
for line in invoice_lines_vals:
line['price_unit'] = -line['price_unit']
invoice_vals['invoice_line'] = [(0, 0, x)
for x in invoice_lines_vals]
invoice = invoice_obj.create(invoice_vals)
invoice_line_vals = self._prepare_invoice_line(
settlement, invoice, product)
invoice_line_obj.create(invoice_line_vals)
for invoice_line_vals in extra_invoice_lines:
invoice_line_obj.create(invoice_line_vals)
settlement.state = 'invoiced'
settlement.invoice = invoice.id

Expand Down
Loading