Skip to content

Commit

Permalink
Merge pull request #155 from credativUK/8.0-sale_pricelist_discount
Browse files Browse the repository at this point in the history
8.0 sale pricelist discount
  • Loading branch information
pedrobaeza committed Nov 6, 2015
2 parents d1f9d84 + d83eedf commit bd9aedb
Show file tree
Hide file tree
Showing 7 changed files with 241 additions and 0 deletions.
58 changes: 58 additions & 0 deletions sale_pricelist_discount/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg
:alt: License: AGPL-3

Sale Pricelist Discount
=======================

This module allows specifying a default percentage discount to apply
to sale order lines. This ensures the pricelist discount is visible
on quotations and sale orders.

Installation
============

Nothing special is needed to install this module.

Configuration
=============

Pricelist configuration:

* Add discount percentage value to pricelist items for which the
discount should be visible on sale order lines

Usage
=====

* Select pricelist on sale order line

* The discount defined on pricelist item will be populated as
the sale order line discount percentage

Known issues / Roadmap
======================

* Incompatible with product_visible_discount

Credits
=======

Contributors
------------

* Jacob Hicks <jacob.hicks@credativ.co.uk>

Maintainer
----------

.. image:: http://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: http://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.
21 changes: 21 additions & 0 deletions sale_pricelist_discount/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2015 credativ ltd (<http://www.credativ.co.uk>).
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################

from . import model
37 changes: 37 additions & 0 deletions sale_pricelist_discount/__openerp__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2015 credativ ltd (<http://www.credativ.co.uk>).
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################

{
'name': 'Sale Pricelist Discount',
'version': '1.0',
'category': 'Sale',
'author': 'credativ, Odoo Community Association (OCA)',
'website': 'http://www.credativ.co.uk',
'depends': [
'base',
'sale',
'product',
],
'data': [
'view/pricelist_view.xml'
],
'auto_install': False,
'installable': True,
}
22 changes: 22 additions & 0 deletions sale_pricelist_discount/model/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2015 credativ ltd (<http://www.credativ.co.uk>).
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################

from . import pricelist
from . import sale
34 changes: 34 additions & 0 deletions sale_pricelist_discount/model/pricelist.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2015 credativ ltd (<http://www.credativ.co.uk>).
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################

from openerp import fields, models
import openerp.addons.decimal_precision as dp


class ProductPricelistItem(models.Model):
_inherit = 'product.pricelist.item'

discount = fields.Float(
'Discount (%)',
digits_compute=dp.get_precision('Discount'),
help="Default discount applied on a sale order line.",
default=0.0,
)
54 changes: 54 additions & 0 deletions sale_pricelist_discount/model/sale.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2015 credativ ltd (<http://www.credativ.co.uk>).
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################

from openerp.osv import osv


class sale_order_line(osv.osv):
_inherit = "sale.order.line"

def product_id_change(
self, cr, uid, ids, 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,
context=None
):

res = super(sale_order_line, self).product_id_change(
cr, uid, ids, pricelist, product, qty, uom, qty_uos, uos, name,
partner_id, lang, update_tax, date_order, packaging=packaging,
fiscal_position=fiscal_position, flag=flag, context=context
)

if product and pricelist:
value = res['value']
pricelist_obj = self.pool.get('product.pricelist')
pricelist_item_obj = self.pool.get('product.pricelist.item')
list_price = pricelist_obj.price_rule_get(
cr, uid, [pricelist], product, qty or 1.0,
partner_id, context=context
)
rule_id = (list_price.get(pricelist) and
list_price[pricelist][1] or False)
value['discount'] = rule_id and pricelist_item_obj.read(
cr, uid, [rule_id], ['discount'])[0]['discount'] or 0.00

return res
15 changes: 15 additions & 0 deletions sale_pricelist_discount/view/pricelist_view.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<record model="ir.ui.view" id="product_pricelist_view_form_discount">
<field name="name">product.pricelist.item.form.discount</field>
<field name="model">product.pricelist.item</field>
<field name="inherit_id" ref="product.product_pricelist_item_form_view"/>
<field name="arch" type="xml">
<field name="price_max_margin" position="after">
<field name="discount"/>
</field>
</field>
</record>
</data>
</openerp>

0 comments on commit bd9aedb

Please sign in to comment.