Skip to content

Commit

Permalink
Merge e678de0 into 33d67ee
Browse files Browse the repository at this point in the history
  • Loading branch information
pedrobaeza committed Nov 2, 2018
2 parents 33d67ee + e678de0 commit 6a54b0c
Show file tree
Hide file tree
Showing 18 changed files with 1,002 additions and 0 deletions.
132 changes: 132 additions & 0 deletions product_pricelist_supplierinfo/README.rst
@@ -0,0 +1,132 @@
========================================
Supplier info prices in sales pricelists
========================================

.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
:target: https://odoo-community.org/page/development-status
:alt: Beta
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fsale--workflow-lightgray.png?logo=github
:target: https://github.com/OCA/sale-workflow/tree/11.0/product_pricelist_supplierinfo
:alt: OCA/sale-workflow
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/sale-workflow-11-0/sale-workflow-11-0-product_pricelist_supplierinfo
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png
:target: https://runbot.odoo-community.org/runbot/167/11.0
:alt: Try me on Runbot

|badge1| |badge2| |badge3| |badge4| |badge5|

This module allows you to create a sales pricelist based on product
supplierinfo prices. If you want, you can bypass minimum quantity in pricelist
item.

**Table of contents**

.. contents::
:local:

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

Although this module doesn't depend technically on **Sales Management**, you
must install it for configuring and seeing the effects of it.

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

To configure pricelists with the new feature of this module, you need to:

#. Go to *Sales > Configuration > Settings* and check
"Multiple Sales Prices per Product" option and
"Prices computed from formulas" after that. You must have correct
permissions and you must install **Sales Management** app (sale) to see
these settings.
#. Create or edit a Sales Pricelist at *Sales > Catalog > Pricelists*.
#. Add or edit a pricelist item and check "Formula" option in
"Price Computation" section.
#. You will see the new option "Prices based on supplier info".
#. If you want to bypass the "Min.Quantity" field of the supplier info and
always select the lowest quantity price, check the option
"Ignore Supplier Info Min. Quantity".

Usage
=====

For adding supplier info:

#. Go to *Sales > Catalog > Products*
#. Open or create a product.
#. Go to "Purchase" page.
#. On "Vendors" section, add the supplier and prices.
#. You can drag and drop for reordering these lines.

Check the remark in known issues about the supplier info line selection.

For checking pricelists in action, you can (with `sale` module installed):

#. Go to *Sales > Orders > Quotations*
#. Create or edit a quotation.
#. Add a line.
#. Select a product with the criteria to match the pricelist from supplier
info.
#. See the proper price appears in the line.

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

* First line that matches by minimum quantity criteria, independently from the
supplier, will be the one that provides the price for the pricelist.
* There's no mechanism for selecting the supplier from possible sources like
sales orders.

Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/OCA/sale-workflow/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 <https://github.com/OCA/sale-workflow/issues/new?body=module:%20product_pricelist_supplierinfo%0Aversion:%2011.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

Do not contact contributors directly about support or help with technical issues.

Credits
=======

Authors
~~~~~~~

* Tecnativa

Contributors
~~~~~~~~~~~~

* `Tecnativa <https://www.tecnativa.com/>`_:

* Vicent Cubells <vicent.cubells@tecnativa.com>
* Pedro M. Baeza

Maintainers
~~~~~~~~~~~

This module is maintained by the OCA.

.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org

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.

This module is part of the `OCA/sale-workflow <https://github.com/OCA/sale-workflow/tree/11.0/product_pricelist_supplierinfo>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
1 change: 1 addition & 0 deletions product_pricelist_supplierinfo/__init__.py
@@ -0,0 +1 @@
from . import models
20 changes: 20 additions & 0 deletions product_pricelist_supplierinfo/__manifest__.py
@@ -0,0 +1,20 @@
# Copyright 2018 Tecnativa - Vicent Cubells
# Copyright 2018 Tecnativa - Pedro M. Baeza
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
{
"name": "Supplier info prices in sales pricelists",
"summary": "Allows to create priceslists based on supplier info",
"version": "11.0.1.0.0",
"category": "Sales",
"website": "https://github.com/OCA/sale-workflow",
"author": "Tecnativa,"
" Odoo Community Association (OCA)",
"license": "AGPL-3",
"depends": [
"product",
],
"data": [
"views/product_pricelist_item_views.xml",
],
"installable": True,
}
41 changes: 41 additions & 0 deletions product_pricelist_supplierinfo/i18n/es.po
@@ -0,0 +1,41 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * product_pricelist_supplierinfo
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 11.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2018-10-31 17:35+0000\n"
"PO-Revision-Date: 2018-10-31 17:35+0000\n"
"Last-Translator: <>\n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: \n"

#. module: product_pricelist_supplierinfo
#: model:ir.ui.view,arch_db:product_pricelist_supplierinfo.product_pricelist_supplier_item_form_view
msgid "<span attrs=\"{'invisible':[('base', '!=', 'supplierinfo')]}\">Supplier price - </span>"
msgstr "<span attrs=\"{'invisible':[('base', '!=', 'supplierinfo')]}\">Precio de proveedor - </span>"

#. module: product_pricelist_supplierinfo
#: model:ir.model.fields,field_description:product_pricelist_supplierinfo.field_product_pricelist_item_no_supplierinfo_min_quantity
msgid "Ignore Supplier Info Min. Quantity"
msgstr "Ignorar cantidad mínima de la info de proveedor"

#. module: product_pricelist_supplierinfo
#: model:ir.model,name:product_pricelist_supplierinfo.model_product_pricelist
msgid "Pricelist"
msgstr "Lista de precios"

#. module: product_pricelist_supplierinfo
#: model:ir.model,name:product_pricelist_supplierinfo.model_product_pricelist_item
msgid "Pricelist item"
msgstr "Item de Lista de precios"

#. module: product_pricelist_supplierinfo
#: model:ir.model,name:product_pricelist_supplierinfo.model_product_product
msgid "Product"
msgstr "Producto"
@@ -0,0 +1,42 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * product_pricelist_supplierinfo
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 11.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2018-10-31 17:37+0000\n"
"PO-Revision-Date: 2018-10-31 17:37+0000\n"
"Last-Translator: <>\n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: \n"

#. module: product_pricelist_supplierinfo
#: model:ir.ui.view,arch_db:product_pricelist_supplierinfo.product_pricelist_supplier_item_form_view
msgid "<span attrs=\"{'invisible':[('base', '!=', 'supplierinfo')]}\">Supplier price - </span>"
msgstr ""

#. module: product_pricelist_supplierinfo
#: model:ir.model.fields,field_description:product_pricelist_supplierinfo.field_product_pricelist_item_no_supplierinfo_min_quantity
msgid "Ignore Supplier Info Min. Quantity"
msgstr ""

#. module: product_pricelist_supplierinfo
#: model:ir.model,name:product_pricelist_supplierinfo.model_product_pricelist
msgid "Pricelist"
msgstr ""

#. module: product_pricelist_supplierinfo
#: model:ir.model,name:product_pricelist_supplierinfo.model_product_pricelist_item
msgid "Pricelist item"
msgstr ""

#. module: product_pricelist_supplierinfo
#: model:ir.model,name:product_pricelist_supplierinfo.model_product_product
msgid "Product"
msgstr ""

2 changes: 2 additions & 0 deletions product_pricelist_supplierinfo/models/__init__.py
@@ -0,0 +1,2 @@
from . import product_product
from . import product_pricelist
43 changes: 43 additions & 0 deletions product_pricelist_supplierinfo/models/product_pricelist.py
@@ -0,0 +1,43 @@
# Copyright 2018 Tecnativa - Vicent Cubells
# Copyright 2018 Tecnativa - Pedro M. Baeza
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from odoo import api, fields, models


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

@api.multi
def _compute_price_rule(self, products_qty_partner, date=False,
uom_id=False):
"""Recompute price after calling the atomic super method for
getting proper prices when based on supplier info.
"""
rule_obj = self.env['product.pricelist.item']
result = super(ProductPricelist, self)._compute_price_rule(
products_qty_partner, date, uom_id)
# Make sure all rule records are fetched at once at put in cache
rule_obj.browse(x[1] for x in result.values()).mapped('price_discount')
for product, qty, _partner in products_qty_partner:
rule = rule_obj.browse(result[product.id][1])
if rule.base == 'supplierinfo':
result[product.id] = (
product._get_supplierinfo_pricelist_price(
rule, date=date, quantity=qty,
), rule.id,
)
return result


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

base = fields.Selection(
selection_add=[
('supplierinfo', 'Prices based on supplier info'),
],
)
no_supplierinfo_min_quantity = fields.Boolean(
string='Ignore Supplier Info Min. Quantity',
)
71 changes: 71 additions & 0 deletions product_pricelist_supplierinfo/models/product_product.py
@@ -0,0 +1,71 @@
# Copyright 2018 Tecnativa - Vicent Cubells
# Copyright 2018 Tecnativa - Pedro M. Baeza
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from odoo import api, models, tools


class ProductProduct(models.Model):
_inherit = 'product.product'

def _get_supplierinfo_pricelist_price(self, rule, date=None,
quantity=None):
"""Method for getting the price from supplier info."""
self.ensure_one()
domain = [('id', 'in', self.seller_ids.ids)]
if not rule.no_supplierinfo_min_quantity and quantity:
domain += [
'|',
('min_qty', '=', False),
('min_qty', '>=', quantity),
]
if date:
domain += [
'|',
('date_start', '=', False),
('date_start', '<=', date),
'|',
('date_end', '=', False),
('date_end', '>=', date),
]
# We use a different default order because we are interested in getting
# the price for lowest minimum quantity
price = self.env['product.supplierinfo'].search(
domain, limit=1, order='sequence, min_qty, price',
)[-1:].price
if price:
# We have to replicate this logic in this method as pricelist
# method are atomic and we can't hack inside.
# Verbatim copy of part of product.pricelist._compute_price_rule.
qty_uom_id = self._context.get('uom') or self.uom_id.id
price_uom = self.env['product.uom'].browse([qty_uom_id])
convert_to_price_uom = (
lambda price: self.uom_id._compute_price(
price, price_uom))
price_limit = price
price = (price - (price * (rule.price_discount / 100))) or 0.0
if rule.price_round:
price = tools.float_round(
price, precision_rounding=rule.price_round)
if rule.price_surcharge:
price_surcharge = convert_to_price_uom(rule.price_surcharge)
price += price_surcharge
if rule.price_min_margin:
price_min_margin = convert_to_price_uom(rule.price_min_margin)
price = max(price, price_limit + price_min_margin)
if rule.price_max_margin:
price_max_margin = convert_to_price_uom(rule.price_max_margin)
price = min(price, price_limit + price_max_margin)
return price

@api.multi
def price_compute(self, price_type, uom=False, currency=False,
company=False):
"""Return dummy not falsy prices when computation is done from supplier
info for avoiding error on super method. We will later fill these with
correct values.
"""
if price_type == 'supplierinfo':
return dict.fromkeys(self.ids, 1.0)
return super(ProductProduct, self).price_compute(
price_type, uom=uom, currency=currency, company=company)
14 changes: 14 additions & 0 deletions product_pricelist_supplierinfo/readme/CONFIGURE.rst
@@ -0,0 +1,14 @@
To configure pricelists with the new feature of this module, you need to:

#. Go to *Sales > Configuration > Settings* and check
"Multiple Sales Prices per Product" option and
"Prices computed from formulas" after that. You must have correct
permissions and you must install **Sales Management** app (sale) to see
these settings.
#. Create or edit a Sales Pricelist at *Sales > Catalog > Pricelists*.
#. Add or edit a pricelist item and check "Formula" option in
"Price Computation" section.
#. You will see the new option "Prices based on supplier info".
#. If you want to bypass the "Min.Quantity" field of the supplier info and
always select the lowest quantity price, check the option
"Ignore Supplier Info Min. Quantity".
4 changes: 4 additions & 0 deletions product_pricelist_supplierinfo/readme/CONTRIBUTORS.rst
@@ -0,0 +1,4 @@
* `Tecnativa <https://www.tecnativa.com/>`_:

* Vicent Cubells <vicent.cubells@tecnativa.com>
* Pedro M. Baeza
3 changes: 3 additions & 0 deletions product_pricelist_supplierinfo/readme/DESCRIPTION.rst
@@ -0,0 +1,3 @@
This module allows you to create a sales pricelist based on product
supplierinfo prices. If you want, you can bypass minimum quantity in pricelist
item.
2 changes: 2 additions & 0 deletions product_pricelist_supplierinfo/readme/INSTALL.rst
@@ -0,0 +1,2 @@
Although this module doesn't depend technically on **Sales Management**, you
must install it for configuring and seeing the effects of it.
4 changes: 4 additions & 0 deletions product_pricelist_supplierinfo/readme/ROADMAP.rst
@@ -0,0 +1,4 @@
* First line that matches by minimum quantity criteria, independently from the
supplier, will be the one that provides the price for the pricelist.
* There's no mechanism for selecting the supplier from possible sources like
sales orders.

0 comments on commit 6a54b0c

Please sign in to comment.